problem_id
stringlengths 32
32
| name
stringclasses 1
value | problem
stringlengths 200
14k
| solutions
stringlengths 12
1.12M
| test_cases
stringlengths 37
74M
| difficulty
stringclasses 3
values | language
stringclasses 1
value | source
stringclasses 7
values | num_solutions
int64 12
1.12M
| starter_code
stringlengths 0
956
|
---|---|---|---|---|---|---|---|---|---|
1feff0bbb6db34aa1565412375bccb8f | UNKNOWN | There are $n$ products in the shop. The price of the $i$-th product is $a_i$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.
In fact, the owner of the shop can change the price of some product $i$ in such a way that the difference between the old price of this product $a_i$ and the new price $b_i$ is at most $k$. In other words, the condition $|a_i - b_i| \le k$ should be satisfied ($|x|$ is the absolute value of $x$).
He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $b_i$ of each product $i$ should be positive (i.e. $b_i > 0$ should be satisfied for all $i$ from $1$ to $n$).
Your task is to find out the maximum possible equal price $B$ of all productts with the restriction that for all products the condiion $|a_i - B| \le k$ should be satisfied (where $a_i$ is the old price of the product and $B$ is the same new price of all products) or report that it is impossible to find such price $B$.
Note that the chosen price $B$ should be integer.
You should answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 100$) β the number of queries. Each query is presented by two lines.
The first line of the query contains two integers $n$ and $k$ ($1 \le n \le 100, 1 \le k \le 10^8$) β the number of products and the value $k$. The second line of the query contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^8$), where $a_i$ is the price of the $i$-th product.
-----Output-----
Print $q$ integers, where the $i$-th integer is the answer $B$ on the $i$-th query.
If it is impossible to equalize prices of all given products with restriction that for all products the condition $|a_i - B| \le k$ should be satisfied (where $a_i$ is the old price of the product and $B$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
-----Example-----
Input
4
5 1
1 1 2 3 1
4 2
6 4 8 5
2 2
1 6
3 5
5 2 5
Output
2
6
-1
7
-----Note-----
In the first example query you can choose the price $B=2$. It is easy to see that the difference between each old price and each new price $B=2$ is no more than $1$.
In the second example query you can choose the price $B=6$ and then all the differences between old and new price $B=6$ will be no more than $2$.
In the third example query you cannot choose any suitable price $B$. For any value $B$ at least one condition out of two will be violated: $|1-B| \le 2$, $|6-B| \le 2$.
In the fourth example query all values $B$ between $1$ and $7$ are valid. But the maximum is $7$, so it's the answer. | ["for ei in range(int(input())):\n n, k = map(int, input().split())\n A = list(map(int, input().split()))\n ans = min(A) + k\n for i in A:\n if ans != -1 and abs(ans - i) > k:\n ans = -1\n print(ans)", "q=int(input())\nfor i in range(q):\n n,k=[int(x) for x in input().split()]\n a=[int(x) for x in input().split()]\n x=min(a)\n y=max(a)\n if x+k<y-k:\n print(-1)\n else:\n print(x+k)\n", "q=int(input())\nfor i in range(q):\n n, k = map(int, input().split())\n a=list(map(int, input().split()))\n mi = min(a)\n ma = max(a)\n if ma-mi>2*k:\n print(-1)\n else:\n print(mi+k)", "for i in range(int(input())):\n n, k = list(map(int, input().split()))\n t = [int(i) for i in input().split()]\n r = min(t)\n s = max(t)\n if s - (s + r) // 2 > k:\n print(-1)\n continue\n print(r + k)\n", "q = int(input())\nfor i in range(q):\n n, k = map(int, input().split())\n a = [int(i) for i in input().split()]\n if max(a) - min(a) <= 2 * k:\n print(min(a) + k)\n else:\n print(-1)", "def main():\n import sys\n input = sys.stdin.readline\n \n def intersection(a, b, c, d):\n return max(a, c), min(b, d)\n \n def solve():\n n, k = map(int, input().split())\n arr = list(map(int, input().split()))\n \n a, b = 0, 10**18\n for x in arr:\n a, b = intersection(a, b, x - k, x + k)\n \n if a > b:\n print(-1)\n else:\n print(b)\n \n for _ in range(int(input())):\n solve()\n \n return 0\n\nmain()", "q = int(input())\nfor query in range(q):\n\tn, k = list(map(int,input().split()))\n\tl = list(map(int,input().split()))\n\ta = min(l)\n\tb = max(l)\n\tif b - a <= 2 * k:\n\t\tprint(a + k)\n\telse:\n\t\tprint(-1)\n", "q=int(input())\nfor i in range(q):\n n,k=list(map(int,input().split()))\n it=list(map(int,input().split()))\n ti=[i+k for i in it]\n st=False\n s=min(it)\n for i in it:\n if i-k>s+k:\n st=True\n break\n if st:\n print(-1)\n else:\n print(min(ti))\n", "q = int(input())\n\nfor request in range(q):\n\tn, k = list(map(int, input().split()))\n\ta = list(map(int, input().split()))\n\n\tb = min(a) + k\n\tif max(a) > b + k:\n\t\tprint(-1)\n\telse:\n\t\tprint(b)\n", "t=int(input())\nfor _ in range(t):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n m1=min(a)\n m2=max(a)\n if m2-m1<k:\n print(m1+k)\n elif m2-m1>2*k:\n print(-1)\n else:\n print(m1+k)\n \n", "req = int(input())\nfor i in range(req):\n amount, edit = map(int, input().split())\n price = list(map(int, input().split()))\n price.sort()\n if amount == 1:\n print(price[0] + edit)\n elif price[0] + edit >= price[-1] - edit:\n print(price[0] + edit)\n else:\n print(-1)", "Q = int(input())\nfor _ in range(Q):\n N, K = list(map(int, input().split()))\n A = [int(a) for a in input().split()]\n mi = min(A)\n ma = max(A)\n if ma-mi <= 2*K:\n print(mi+K)\n else:\n print(-1)\n", "q = int(input())\n\nfor i in range(q):\n n, k = [int(x) for x in input().split()]\n line = [int(x) for x in input().split()]\n\n if max(line) - min(line) > 2 * k:\n print(-1)\n continue\n else:\n print(min(line) + k)\n", "#570_B\n\ncases = int(input())\n\nfor i in range(0, cases):\n ln1 = [int(j) for j in input().split(\" \")]\n nums = [int(j) for j in input().split(\" \")]\n k = ln1[1]\n n1 = min(nums)\n n2 = max(nums)\n if n2 - n1 > k * 2:\n print(-1)\n else:\n print(max(n1 + k, n2 - k))\n", "n=int(input())\nfor i in range(n):\n\tn,k=map(int,input().split())\n\ta=list(map(int,input().split()))\n\tif max(a)-min(a)>2*k:\n\t\tprint(-1)\n\telse:\n\t\tprint(min(a)+k)", "import sys\ninput = sys.stdin.readline\n\nQ=int(input())\nfor testcase in range(Q):\n n,k=list(map(int,input().split()))\n A=list(map(int,input().split()))\n\n if min(A)+k<max(A)-k:\n print(-1)\n else:\n print(min(A)+k)\n \n", "for i in range(int(input())):\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n a.sort()\n b,c=a[0],a[-1]\n if c-b>k*2:print(-1)\n else:print(b+k)", "for i in range(int(input())):\n m, k = [int(j) for j in input().split()]\n data = [int(j) for j in input().split()]\n mn = min(data)\n mx = max(data)\n if mx - mn > 2 * k:\n print(-1)\n else:\n print(mn + k)\n", "q = int(input())\nfor y in range(q):\n n, k = list(map(int,input().split()))\n a = list(map(int, input().split()))\n mn, mx = min(a), max(a)\n if k*2 < mx-mn:\n print(-1)\n else:\n print(mn+k)\n", "q=int(input())\nfor _ in range(q):\n n,k=map(int,input().split())\n a=[int(i) for i in input().split()]\n a.sort()\n if a[-1]-a[0]>2*k:\n print(-1)\n else:\n print(a[0]+k)", "q = int(input())\n\nfor i in range(q):\n n, k = tuple([int(x) for x in input().split()])\n a = [int(x) for x in input().split()]\n if (max(a) - min(a) > 2 * k):\n print(-1)\n else:\n print(min(a) + k)", "for _ in range(int(input())):\n a,b=map(int,input().split())\n c=list(map(int,input().split()))\n c.sort()\n if a==1:\n print(c[0]+b)\n else:\n if c[-1]-c[0]<=2*b:\n print(c[0]+b)\n else:\n print('-1')", "q = int(input())\nfor _ in range(q):\n n, k = list(map(int, input().split()))\n u = list(map(int, input().split()))\n m1 = min(u)\n m2 = max(u)\n if m2 - m1 > 2 * k:\n print(-1)\n continue\n print(m1 + k)\n", "for _ in range(int(input())):\n n, k = list(map(int, input().split()))\n li = list(map(int,input().split()))\n if max(li) - min(li) > 2 * k:\n print(-1)\n continue\n e = max(li)\n f = min(li)\n print(f + k)"] | {
"inputs": [
"4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5\n",
"1\n2 3\n5 15\n",
"1\n1 5\n5\n",
"5\n8 19551489\n31131899 17585660 3913937 14521321 5400652 96097161 58347480 35051437\n1 55716143\n15578410\n7 19560555\n65980880 53703939 20259503 99698023 98868060 83313210 9926424\n6 72321938\n59271765 72426489 16625497 51598082 31475864 53103921\n7 44965081\n49955408 62397026 39981552 92586939 39282289 4905754 96079902\n",
"1\n3 100000000\n100000000 100000000 100000000\n",
"1\n1 100000000\n100000000\n",
"1\n2 1\n100000000 100000000\n"
],
"outputs": [
"2\n6\n-1\n7\n",
"-1\n",
"10\n",
"-1\n71294553\n-1\n88947435\n-1\n",
"200000000\n",
"200000000\n",
"100000001\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 6,056 | |
ee0e6c87f238058ed671b6b4cd03d9ec | UNKNOWN | You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$.
Your task is to remove the minimum number of elements to make this array good.
An array of length $k$ is called good if $k$ is divisible by $6$ and it is possible to split it into $\frac{k}{6}$ subsequences $4, 8, 15, 16, 23, 42$.
Examples of good arrays: $[4, 8, 15, 16, 23, 42]$ (the whole array is a required sequence); $[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); $[]$ (the empty array is good).
Examples of bad arrays: $[4, 8, 15, 16, 42, 23]$ (the order of elements should be exactly $4, 8, 15, 16, 23, 42$); $[4, 8, 15, 16, 23, 42, 4]$ (the length of the array is not divisible by $6$); $[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 5 \cdot 10^5$) β the number of elements in $a$.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ (each $a_i$ is one of the following numbers: $4, 8, 15, 16, 23, 42$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
Print one integer β the minimum number of elements you have to remove to obtain a good array.
-----Examples-----
Input
5
4 8 15 16 23
Output
5
Input
12
4 8 4 15 16 8 23 15 16 42 23 42
Output
0
Input
15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42
Output
3 | ["#!/usr/bin/env python\nn = int(input())\na = list(map(int, input().split()))\nk = [None, 4, 8, 15, 16, 23, 42]\ns = [n, 0, 0, 0, 0, 0, 0]\nfor ai in a:\n for i in range(6, 0, -1):\n if ai == k[i] and s[i - 1] > 0:\n s[i] += 1; s[i - 1] -= 1\n break\nprint(n - 6 * s[-1])\n", "from sys import stdin\nn=int(stdin.readline().strip())\ndp=[0 for i in range(6)]\nd={4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}\ns=list(map(int,stdin.readline().strip().split()))\nfor i in range(n-1,-1,-1):\n if s[i]==42:\n dp[5]+=1\n continue\n elif dp[d[s[i]]+1]>dp[d[s[i]]]:\n dp[d[s[i]]]+=1\nprint(n-6*dp[0])\n", "n=int(input())\nl1=list(map(int,input().split()))\nx=[4,8,15,16,23,42]\ncount=[0]*6\nfor item in l1:\n if item==4:\n count[0]+=1\n elif item==8:\n if count[0]>count[1]:\n count[1]+=1\n elif item==15:\n if count[1]>count[2]:\n count[2]+=1\n elif item==16:\n if count[2]>count[3]:\n count[3]+=1\n elif item==23:\n if count[3]>count[4]:\n count[4]+=1\n elif item==42:\n if count[4]>count[5]:\n count[5]+=1\nprint(n-6*count[5])\n", "n = int(input())\na = [int(s) for s in input().split(' ')]\ncol = 0\nb = [0, 0, 0, 0, 0, 0]\nfor el in a:\n if el == 4:\n b[0] += 1\n elif el == 8:\n if b[0] > 0:\n b[0] -= 1\n b[1] += 1\n else:\n col += 1\n elif el == 15:\n if b[1] > 0:\n b[1] -= 1\n b[2] += 1\n else:\n col += 1\n elif el == 16:\n if b[2] > 0:\n b[2] -= 1\n b[3] += 1\n else:\n col += 1\n elif el == 23:\n if b[3] > 0:\n b[3] -= 1\n b[4] += 1\n else:\n col += 1\n elif el == 42:\n if b[4] > 0:\n b[4] -= 1\n b[5] += 1\n else:\n col += 1\n else:\n col += 1\ncol += b[0] + 2*b[1] + 3*b[2] + 4*b[3] + 5*b[4]\nprint(col)", "from collections import Counter\n\nn = int(input().strip())\nnums = list(map(int, input().strip().split()))\n\nres = 0\nstate = []\ncounter = Counter()\nprev = {\n 8: 4,\n 15: 8,\n 16: 15,\n 23: 16,\n 42: 23,\n}\ngood_nums = [4, 8, 15, 16, 23, 42]\n\nfor i, num in enumerate(nums):\n if num == 4:\n counter[num] += 1\n elif counter[num] < counter[prev[num]]:\n counter[num] += 1\n if num == 42:\n for good_num in good_nums:\n counter[good_num] -= 1\n else:\n res += 1\n\nres += sum(counter.values())\n\nprint(res)", "n = int(input()) \ncnt = {i: 0 for i in range(1, 7)}\ncnt[0] = float('inf')\nf = {x: i + 1 for i, x in enumerate((4, 8, 15, 16, 23, 42))}\nfor e in map(int, input().split()):\n e = f[e]\n if cnt[e - 1] > 0:\n cnt[e] += 1\n cnt[e - 1] -= 1\nprint(n - 6 * cnt[6])", "D = {4:0, 8:1, 15:2, 16:3, 23:4, 42:5}\nN = int(input())\nA = [D[int(a)] for a in input().split()]\nX = [0] * 6\nfor a in A:\n if a == 0:\n X[a] += 1\n else:\n if X[a-1]:\n X[a-1] -= 1\n X[a] += 1\nprint(N-X[5]*6)\n", "n = int(input())\nkol = [0, 0, 0, 0, 0, 0]\nind = [4, 8, 15, 16, 23, 42]\ndelete = 0\nfor i in map(int,input().split()):\n for j in range(6):\n if ind[j] == i:\n cur = j\n break\n if cur == 0:\n kol[0] += 1\n else:\n if kol[cur-1] != 0:\n kol[cur-1] -= 1\n kol[cur] += 1\n else:\n delete += 1\nprint(delete + kol[0] + kol[1]*2 + kol[2]*3 + kol[3]*4 + kol[4]*5)", "def main():\n n = int(input())\n a = [int(i) for i in input().split()]\n used = [0 for i in range(n)]\n sh = [4, 8, 15, 16, 23, 42]\n time = 0\n arr = [0 for i in range(6)]\n for i in range(n):\n if a[i] == sh[0]:\n arr[0] += 1\n elif a[i] == sh[1]:\n if arr[0] > 0:\n arr[0] -= 1\n arr[1] += 1\n elif a[i] == sh[2]:\n if arr[1] > 0:\n arr[1] -= 1\n arr[2] += 1\n elif a[i] == sh[3]:\n if arr[2] > 0:\n arr[2] -= 1\n arr[3] += 1\n elif a[i] == sh[4]:\n if arr[3] > 0:\n arr[3] -= 1\n arr[4] += 1\n elif a[i] == sh[5]:\n if arr[4] > 0:\n arr[4] -= 1\n arr[5] += 1\n print(n - (arr[-1] * 6))\n\n\nmain()\n", "n = int(input())\narr = list(map(int, input().split()))\n_4, _8, _15, _16, _23, _42 = 0, 0, 0, 0, 0, 0\n\nfor i in arr:\n if i == 4:\n _4 += 1\n \n if i == 8 and _4 > _8:\n _8 += 1\n\n\n elif i == 15 and _8 > _15:\n _15 += 1\n\n elif i == 16 and _15 > _16:\n _16 += 1\n\n elif i == 23 and _16 > _23:\n _23 += 1\n\n elif i == 42 and _23 > _42:\n _42 += 1\n\nprint(n - _42 * 6)\n", "import sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nB=[]\nC=[]\nD=[]\nE=[]\nF=[]\nG=[]\n\nfor i in range(n):\n if A[i]==4:\n B.append(i)\n\n if A[i]==8:\n C.append(i)\n\n if A[i]==15:\n D.append(i)\n\n if A[i]==16:\n E.append(i)\n\n if A[i]==23:\n F.append(i)\n\n if A[i]==42:\n G.append(i)\n\nNOW=0\nBi=0\nCi=0\nDi=0\nEi=0\nFi=0\nGi=0\n\nANS=0\n\nwhile True:\n \n for b in range(Bi,len(B)):\n NOW=B[b]\n Bi=b+1\n break\n else:\n break\n\n #print(\"!\")\n\n for c in range(Ci,len(C)):\n if C[c]>=NOW:\n NOW=C[c]\n Ci=c+1\n break\n else:\n break\n\n for d in range(Di,len(D)):\n if D[d]>=NOW:\n NOW=D[d]\n Di=d+1\n break\n else:\n break\n\n for e in range(Ei,len(E)):\n if E[e]>=NOW:\n NOW=E[e]\n Ei=e+1\n break\n else:\n break\n\n for f in range(Fi,len(F)):\n if F[f]>=NOW:\n NOW=F[f]\n Fi=f+1\n break\n else:\n break\n\n for g in range(Gi,len(G)):\n if G[g]>=NOW:\n NOW=G[g]\n Gi=g+1\n break\n else:\n break\n\n ANS+=6\n\nprint(len(A)-ANS)\n\n \n", "input() # discard n\nnum = [4,8,15,16,23,42]\nprev = {i:j for i,j in zip(num[1:], num)}\nc = {v:0 for v in num}\nn = 0\nfor a in map(int, input().split()):\n #print('before', a, c)\n if a == num[0]: # first\n c[a] += 1\n else:\n if c[prev[a]]:\n c[prev[a]] -= 1\n if a != num[-1]: c[a] += 1\n else: n += 1 # waste\n #print('after', a, c)\n\n#print(c)\nfor i,v in enumerate(num):\n #print(i,v,c[v])\n n += (i+1)*c[v]\n\nprint(n)\n", "n = int(input())\na = list(map(int, input().split()))\n\ng = [0 for i in range(43)]\nans = 0\n\nfor i in a:\n if i == 4:\n g[4] += 1\n elif i == 8:\n if g[4] > 0:\n g[4] -= 1\n g[8] += 1\n else:\n ans += 1\n elif i == 15:\n if g[8] > 0:\n g[8] -= 1\n g[15] += 1\n else:\n ans += 1\n elif i == 16:\n if g[15] > 0:\n g[15] -= 1\n g[16] += 1\n else:\n ans += 1\n elif i == 23:\n if g[16] > 0:\n g[16] -= 1\n g[23] += 1\n else:\n ans += 1\n elif i == 42:\n if g[23] > 0:\n g[23]-=1\n else:\n ans += 1\n else:\n ans += 1\nans += (g[4] + 2*g[8] + 3*g[15] + 4*g[16]+ 5*g[23])\nprint(ans)", "n = int(input())\ns= list(map(int,input().split()))\ncount = [0]*6\nfor temp in s:\n if temp==4:\n count[0]+=1\n elif temp==8 and count[0]>count[1]:\n count[1]+=1\n elif temp==15 and count[1]>count[2]:\n count[2]+=1\n elif temp==16 and count[2]>count[3]:\n count[3]+=1\n elif temp==23 and count[3]>count[4]:\n count[4]+=1\n elif temp==42 and count[4]>count[5]:\n count[5]+=1\n else:\n pass\n#print(count)\nout = n - 6*min(count)\nprint(out)", "n = int(input())\na = [int(x) for x in input().split()]\nexist = [4,8,15,16,23,42]\ns = set(exist)\nwaiting = [0] * 6\nans = 0\nfor x in a:\n if x not in s:\n ans += 1\n continue\n if x == 4:\n waiting[0] += 1\n continue\n pos = exist.index(x)\n if waiting[pos - 1] == 0:\n ans += 1\n continue\n waiting[pos - 1] -= 1\n if x != 42:\n waiting[pos] += 1\n# print(waiting)\nfor i in range(6):\n ans += (i + 1) * waiting[i]\nprint(ans)\n \n", "n = int(input())\nx = [4, 8, 15, 16, 23, 42]\nr = [0] * len(x)\nz = 0\nfor v in map(int, input().split()):\n i = x.index(v)\n if not i or r[i-1] > r[i]:\n r[i] += 1\n else:\n z += 1\nz += sum(v-r[-1] for v in r)\nprint(z)\n", "n = int(input())\nl = list(map(int, input().split()))\nx = [4,8,15,16,23,42]\n# if(n == 0):\n# \tprint(0)\n# elif(n<6):\n# \tprint(n)\n# elif(n==6):\n# \tif(l==x):\n# \t\tprint(0)\n# \telse:\n# \t\tprint(n)\n# else:\nd = {}\nfor i in x:\n\td[i] = 0\ncount = 0\nfor i in range(n):\n\tif(l[i]==4):\n\t\td[4]+=1\n\telif(l[i]==8):\n\t\tif(d[4]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[4]-=1\n\t\t\td[8]+=1\n\telif(l[i]==15):\n\t\tif(d[8]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[8]-=1\n\t\t\td[15]+=1\n\telif(l[i]==16):\n\t\tif(d[15]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[15]-=1\n\t\t\td[16]+=1\n\telif(l[i]==23):\n\t\tif(d[16]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[16]-=1\n\t\t\td[23]+=1\n\telse:\n\t\tif(d[23]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[23]-=1\n\t\t\td[42]+=1\ncount+= d[4] + (2*d[8]) + (3*d[15]) + (4*d[16]) + (5*d[23])\nprint(count)", "import sys\nfrom collections import Counter\n\ndef input():\n return sys.stdin.readline().strip()\n\ndef dinput():\n return int(input())\n\ndef tinput():\n return input().split()\n\ndef rinput():\n return map(int, tinput())\n\ndef main():\n n = int(input())\n aleonov = list(rinput())\n rt = [4, 8, 15, 16, 23, 42]\n leonov = []\n for i in range(6):\n leonov.append(0)\n for i in range(n):\n if aleonov[i] == rt[0]:\n leonov[0] += 1\n elif aleonov[i] == rt[1]:\n if leonov[0] > 0:\n leonov[0] -= 1\n leonov[1] += 1\n elif aleonov[i] == rt[2]:\n if leonov[1] > 0:\n leonov[1] -= 1\n leonov[2] += 1\n elif aleonov[i] == rt[3]:\n if leonov[2] > 0:\n leonov[2] -= 1\n leonov[3] += 1\n elif aleonov[i] == rt[4]:\n if leonov[3] > 0:\n leonov[3] -= 1\n leonov[4] += 1\n elif aleonov[i] == rt[5]:\n if leonov[4] > 0:\n leonov[4] -= 1\n leonov[5] += 1\n print(n - (leonov[-1] * 6))\n\n\nmain()", "for _ in range(1):\n n=int(input())\n a=list(map(int,input().split()))\n d={}\n b=[4,8,15,16,23,42]\n c=[0]*50\n for i in a:\n if i==4:\n c[i]+=1\n elif c[b[b.index(i) - 1]]>0:\n c[b[b.index(i) - 1]]-=1\n c[i]+=1\n \n print(n- (c[42])*6)\n", "n = int(input())\narr = list(map(int,input().split()))\nans = 0\ncounter = [0] * 6\nd = {4:0,8:1,15:2,16:3,23:4,42:5}\n\nfor a in arr:\n index = d[a]\n counter[index] += 1\n if index > 0 and counter[index] > counter[index-1]:\n counter[index] -= 1\n ans += 1\n \nans += sum(counter) - counter[5] * 6\n\nprint(ans)\n", "'''input\n15\n4 8 4 8 15 16 8 16 23 15 16 4 42 23 42\n'''\n# its just a simulation\nfrom sys import stdin, setrecursionlimit\nimport heapq\n\n\n\ndef refine(arr):\n\taux = []\n\tfor i in range(len(arr)):\n\t\tif arr[i] in [4, 8, 15, 16, 23, 42]:\n\t\t\taux.append(arr[i])\n\treturn aux\n\n# main starts\nn = int(stdin.readline().strip())\narr = list(map(int, stdin.readline().split()))\narr = refine(arr)\nmydict = dict()\nmydict[4] = 0; mydict[8] = 0; mydict[15] = 0; mydict[16] = 0;\nmydict[23] = 0; mydict[42] = 0\n\nfor i in range(len(arr)):\n\tif arr[i] == 4:\n\t\tmydict[4] += 1\n\telif arr[i] == 8:\n\t\tif mydict[4] >= mydict[8] + 1:\n\t\t\tmydict[8] += 1\n\telif arr[i] == 15:\n\t\tif mydict[8] >= mydict[15] + 1:\n\t\t\tmydict[15] += 1\n\n\telif arr[i] == 16:\n\t\tif mydict[15] >= mydict[16] + 1:\n\t\t\tmydict[16] += 1\n\telif arr[i] == 23:\n\t\tif mydict[16] >= mydict[23] + 1:\n\t\t\tmydict[23] += 1\n\telif arr[i] == 42:\n\t\tif mydict[23] >= mydict[42] + 1:\n\t\t\tmydict[42] += 1\n\nprint(n - mydict[42] * 6 )\n", "from collections import defaultdict\n\nMEMBERS = (4, 8, 15, 16, 23, 42)\nprogress = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}\n\nn = int(input())\na = list(map(int, input().split()))\nidx = []\ncounts = defaultdict(int)\nfor num in a:\n if progress[num] == 0:\n counts[0] += 1\n else:\n if counts[progress[num] - 1] > 0:\n counts[progress[num] - 1] -= 1\n counts[progress[num]] += 1\nprint(n - counts[5] * 6)\n", "n = int(input())\na = list(map(int,input().split()))\n\nans = 0\n\nchk = {4:0,8:1,15:2,16:3,23:4,42:5}\n\nct = [0]*6\nfor i in a:\n if i not in [4,8,15,16,23,42]:\n ans+=1\nfor i in a:\n if i in [4,8,15,16,23,42]:\n if i==4:\n ct[0]+=1\n else:\n if ct[chk[i]-1]>ct[chk[i]]:\n ct[chk[i]]+=1\n else:\n ans+=1\nans1 = ct[5]\nfor i in ct:\n ans += (i-ans1)\nprint(ans)", "n = int(input())\na = list(map(int,input().split()))\ndp = [0,0,0,0,0,0]\nfor k in range(n):\n if a[k] == 4:\n dp[0] += 1\n elif a[k] == 8:\n dp[1] = min(dp[0],dp[1]+1)\n elif a[k] == 15:\n dp[2] = min(dp[1],dp[2]+1)\n elif a[k] == 16:\n dp[3] = min(dp[2],dp[3]+1)\n elif a[k] == 23:\n dp[4] = min(dp[3],dp[4]+1)\n else:\n dp[5] = min(dp[4],dp[5]+1)\n\nprint(n-6*dp[5])\n"] | {
"inputs": [
"5\n4 8 15 16 23\n",
"12\n4 8 4 15 16 8 23 15 16 42 23 42\n",
"15\n4 8 4 8 15 16 8 16 23 15 16 4 42 23 42\n",
"1\n4\n",
"1\n42\n",
"100\n4 42 23 23 8 42 16 23 42 16 42 8 4 23 4 4 23 42 16 42 23 23 23 42 4 42 8 8 16 23 15 23 16 4 42 15 15 23 16 15 16 4 4 15 23 42 42 15 8 23 8 23 4 15 16 15 42 8 23 16 15 42 23 8 4 16 15 16 23 16 16 4 23 16 8 23 16 15 23 4 4 8 15 4 4 15 8 23 23 4 4 8 8 4 42 15 4 4 42 16\n",
"123\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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n"
],
"outputs": [
"5\n",
"0\n",
"3\n",
"1\n",
"1\n",
"64\n",
"123\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 14,010 | |
b26203f40354fab057a4240da2048287 | UNKNOWN | You are given two integers $a$ and $b$.
In one move, you can choose some integer $k$ from $1$ to $10$ and add it to $a$ or subtract it from $a$. In other words, you choose an integer $k \in [1; 10]$ and perform $a := a + k$ or $a := a - k$. You may use different values of $k$ in different moves.
Your task is to find the minimum number of moves required to obtain $b$ from $a$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The only line of the test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case, print the answer: the minimum number of moves required to obtain $b$ from $a$.
-----Example-----
Input
6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000
Output
0
3
2
92
87654322
9150
-----Note-----
In the first test case of the example, you don't need to do anything.
In the second test case of the example, the following sequence of moves can be applied: $13 \rightarrow 23 \rightarrow 32 \rightarrow 42$ (add $10$, add $9$, add $10$).
In the third test case of the example, the following sequence of moves can be applied: $18 \rightarrow 10 \rightarrow 4$ (subtract $8$, subtract $6$). | ["for _ in range(int(input())):\n a,b=map(int,input().split())\n print((abs(a-b)+9)//10)", "for _ in range(int(input())):\n a,b = map(int,input().split())\n print((abs(b - a) + 9) // 10)", "import sys\nimport math\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef MI():\n\treturn map(int, sys.stdin.readline().split())\n\ndef SI():\n\treturn sys.stdin.readline().strip()\nt = II()\nfor q in range(t):\n\ta,b = MI()\n\tprint(math.ceil(abs(a-b)/10))", "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush,heappop,heapify\nimport math\nfrom collections import *\nfrom functools import reduce, cmp_to_key\nimport sys\ninput = sys.stdin.readline\n\nfrom itertools import accumulate\nfrom functools import lru_cache\n\nM = mod = 10000\ndef factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))\ndef inv_mod(n):return pow(n, mod - 2, mod)\n \ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef li2():return [i for i in input().rstrip('\\n')]\ndef li3():return [int(i) for i in input().rstrip('\\n')]\n\n\nfor _ in range(val()):\n a, b = sorted(li())\n print(math.ceil((b - a)/10))", "for _ in range(int(input())):\n a, b = list(map(int, input().split()))\n print(-(-abs(a - b) // 10))\n", "#Bhargey Mehta (Senior)\n#DA-IICT, Gandhinagar\nimport sys, math\nmod = 10**9 + 7\n\ndef solve(test_index):\n a, b = list(map(int, input().split()))\n ans = math.ceil(abs(a-b) / 10)\n print(ans)\n return\n\nif 'PyPy' not in sys.version:\n sys.stdin = open('input.txt', 'r')\n\nsys.setrecursionlimit(100000)\nnum_tests = 1\nnum_tests = int(input())\nfor test in range(1, num_tests+1):\n #print(\"Case #{}: \".format(test), end=\"\")\n solve(test)\n", "#!/usr/bin/env pypy3\n\nimport math\n\nT = int(input())\nfor t in range(T):\n\tA, B = input().split()\n\tA = int(A)\n\tB = int(B)\n\tprint(math.ceil(abs(B-A)/10))", "t = int(input())\nfor _ in range(t):\n a,b = list(map(int, input().split()))\n ans = (abs(a-b)+9)//10\n print(ans)\n", "t=int(input())\nfor you in range(t):\n l=input().split()\n a=int(l[0])\n b=int(l[1])\n z=abs(a-b)\n print((z+9)//10)\n", "import sys\n# from collections import deque\n# from collections import Counter\n# from math import sqrt\n# from math import log\nfrom math import ceil\n# from bisect import bisect_left, bisect_right\n\n# alpha=['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# mod=10**9+7\n# mod=998244353\n\n# def BinarySearch(a,x): \n# \ti=bisect_left(a,x) \n# \tif(i!=len(a) and a[i]==x): \n# \t\treturn i \n# \telse: \n# \t\treturn -1\n\n# def sieve(n): \n# \tprime=[True for i in range(n+1)]\n# \tp=2\n# \twhile(p*p<=n): \n# \t\tif (prime[p]==True): \n# \t\t\tfor i in range(p*p,n+1,p): \n# \t\t\t\tprime[i]=False\n# \t\tp+=1\n# \tprime[0]=False\n# \tprime[1]=False\n# \ts=set()\n# \tfor i in range(len(prime)):\n# \t\tif(prime[i]):\n# \t\ts.add(i)\n# \treturn s\n\n# def gcd(a, b):\n# \tif(a==0):\n# \t\treturn b \n# \treturn gcd(b%a,a)\n\nfast_reader=sys.stdin.readline\nfast_writer=sys.stdout.write\n\ndef input():\n\treturn fast_reader().strip()\n\ndef print(*argv):\n\tfast_writer(' '.join((str(i)) for i in argv))\n\tfast_writer('\\n')\n\n#____________________________________________________________________________________________________________________________________\n\nfor _ in range(int(input())):\n\ta,b=map(int, input().split())\n\tprint(ceil(abs(a-b)/10))", "import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor i in range(int(input())):\n#for i in range(1):\n a, b = list(map(int, input().split()))\n print(abs(a - b) // 10 + (1 if abs(a - b) % 10 != 0 else 0))\n", "# map(int, input().split())\nrw = int(input())\nfor wewq in range(rw):\n a, b = list(map(int, input().split()))\n d = abs(a - b)\n print((d + 9) // 10)\n\n\n\n"] | {
"inputs": [
"6\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n",
"1\n5 5\n",
"11\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n",
"2\n5 5\n5 5\n",
"4\n5 5\n5 5\n5 5\n5 5\n",
"7\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n",
"3\n7 7\n2 2\n3 3\n"
],
"outputs": [
"0\n3\n2\n92\n87654322\n9150\n",
"0\n",
"0\n3\n2\n92\n87654322\n9150\n0\n3\n2\n92\n87654322\n",
"0\n0\n",
"0\n0\n0\n0\n",
"0\n0\n0\n0\n0\n0\n0\n",
"0\n0\n0\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 4,273 | |
9db7075c9d4787f820464cded41629e3 | UNKNOWN | You are given three integers $x, y$ and $n$. Your task is to find the maximum integer $k$ such that $0 \le k \le n$ that $k \bmod x = y$, where $\bmod$ is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with given $x, y$ and $n$ you need to find the maximum possible integer from $0$ to $n$ that has the remainder $y$ modulo $x$.
You have to answer $t$ independent test cases. It is guaranteed that such $k$ exists for each test case.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) β the number of test cases. The next $t$ lines contain test cases.
The only line of the test case contains three integers $x, y$ and $n$ ($2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$).
It can be shown that such $k$ always exists under the given constraints.
-----Output-----
For each test case, print the answer β maximum non-negative integer $k$ such that $0 \le k \le n$ and $k \bmod x = y$. It is guaranteed that the answer always exists.
-----Example-----
Input
7
7 5 12345
5 0 4
10 5 15
17 8 54321
499999993 9 1000000000
10 5 187
2 0 999999999
Output
12339
0
15
54306
999999995
185
999999998
-----Note-----
In the first test case of the example, the answer is $12339 = 7 \cdot 1762 + 5$ (thus, $12339 \bmod 7 = 5$). It is obvious that there is no greater integer not exceeding $12345$ which has the remainder $5$ modulo $7$. | ["ntest = int(input())\nfor testcase in range(ntest):\n x, y, n = list(map(int, input().split()))\n t = (n - y) // x * x + y\n print(t)\n", "def read_int():\n return int(input())\n\n\ndef read_ints():\n return list(map(int, input().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n x, y, n = read_ints()\n ans = n // x * x + y\n if ans > n:\n ans -= x\n print(ans)\n", "for _ in range(int(input())):\n x,y,n=map(int,input().split())\n k=(n-y)//x*x+y\n print(k)", "tests = int(input())\nfor _ in range(tests):\n x, y, n = list(map(int, input().split()))\n f = n // x * x\n if f + y <= n:\n print(f + y)\n else:\n print(f - x + y)\n", "for _ in range(int(input())):\n x, y, n = list(map(int, input().split()))\n ans = y\n dif = n - ans\n dif %= x\n ans = n - dif\n print(ans)\n", "t=int(input())\nfor you in range(t):\n l=input().split()\n x=int(l[0])\n y=int(l[1])\n n=int(l[2])\n z=(n-y)//x\n print(z*x+y)\n", "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush,heappop\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\nM = mod = 998244353\ndef factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))\ndef inv_mod(n):return pow(n, mod - 2, mod)\n \ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef li2():return [i for i in input().rstrip('\\n')]\ndef li3():return [int(i) for i in input().rstrip('\\n')]\n\n\nfor _ in range(val()):\n a,b,n = li()\n temp = n//a\n ans = b + a*temp\n if ans > n:\n ans -= a\n print(ans)", "def main():\n t = int(input())\n for i in range(t):\n solve()\n\ndef solve():\n x, y, n = list(map(int, input().split(\" \")))\n\n if n % x >= y:\n print((n // x) * x + y)\n else:\n print((n // x - 1) * x + y)\n\nmain()\n\n", "\ntt = int(input())\n\nfor loop in range(tt):\n\n x,y,n = list(map(int,input().split()))\n\n tmp = n // x * x + y\n if tmp > n:\n tmp -= x\n\n print (tmp)\n", "T = int(input())\nfor _ in range(T):\n x, y, n = list(map(int, input().split()))\n ans = (n // x)*x + y\n while(ans > n):\n ans -= x\n print(ans)\n", "import sys\nimport random\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef rinput():\n return map(int, tinput())\n\ndef fiinput():\n return map(float, tinput())\n \ndef rlinput():\n return list(map(int, input().split()))\ndef trinput():\n return tuple(rinput())\n\ndef srlinput():\n return sorted(list(map(int, input().split())))\n\ndef NOYES(fl):\n if fl:\n print(\"NO\")\n else:\n print(\"YES\")\ndef YESNO(fl):\n if fl:\n print(\"YES\")\n else:\n print(\"NO\")\n \ndef main(): \n #n = iinput()\n #k = iinput() \n #m = iinput() \n #n = int(sys.stdin.readline().strip()) \n #n, k = rinput()\n #n, m = rinput()\n #m, k = rinput()\n #n, k, m = rinput()\n #n, m, k = rinput()\n #k, n, m = rinput()\n #k, m, n = rinput() \n #m, k, n = rinput()\n #m, n, k = rinput()\n #q = srlinput()\n #q = linput()\n x, y, n = rinput()\n res = n - y\n print(x * (res // x) + y)\n\n \nfor inytd in range(iinput()):\n main()", "import sys\n\ninp = [int(x) for x in sys.stdin.read().split()]; ii = 0\n\nttt = inp[ii]; ii += 1\nfor _ in range(ttt):\n\tx, y, n = inp[ii: ii + 3]; ii += 3\n\trem = y % x\n\tprint((n - rem) // x * x + rem)", "import sys\nimport math\nimport itertools\nimport functools\nimport collections\nimport operator\nimport fileinput\nimport copy\n\nORDA = 97 # a\ndef ii(): return int(input())\ndef mi(): return map(int, input().split())\ndef li(): return [int(i) for i in input().split()]\ndef lcm(a, b): return abs(a * b) // math.gcd(a, b)\ndef revn(n): return str(n)[::-1]\ndef dd(): return collections.defaultdict(int)\ndef ddl(): return collections.defaultdict(list)\ndef sieve(n):\n if n < 2: return list()\n prime = [True for _ in range(n + 1)]\n p = 3\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 += 2\n r = [2]\n for p in range(3, n + 1, 2):\n if prime[p]:\n r.append(p)\n return r\ndef divs(n, start=1):\n r = []\n for i in range(start, int(math.sqrt(n) + 1)):\n if (n % i == 0):\n if (n / i == i):\n r.append(i)\n else:\n r.extend([i, n // i])\n return r\ndef divn(n, primes):\n divs_number = 1\n for i in primes:\n if n == 1:\n return divs_number\n t = 1\n while n % i == 0:\n t += 1\n n //= i\n divs_number *= t\ndef prime(n):\n if n == 2: return True\n if n % 2 == 0 or n <= 1: return False\n sqr = int(math.sqrt(n)) + 1\n for d in range(3, sqr, 2):\n if n % d == 0: return False\n return True\ndef convn(number, base):\n newnumber = 0\n while number > 0:\n newnumber += number % base\n number //= base\n return newnumber\ndef cdiv(n, k): return n // k + (n % k != 0)\ndef ispal(s):\n for i in range(len(s) // 2 + 1):\n if s[i] != s[-i - 1]:\n return False\n return True\n\n\nfor _ in range(ii()):\n x, y, n = mi()\n print(((n - y) // x) * x + y)", "t = int(input())\nfor _ in range(t):\n x,y,n = map(int,input().split())\n k = y\n k += ((n-y)//x)*x\n print(k)", "for nt in range(int(input())):\n\tx,y,n = map(int,input().split())\n\tr = n%x\n\tif r==y:\n\t\tprint (n)\n\t\tcontinue\n\tif y<r:\n\t\tprint (n-(r-y))\n\t\tcontinue\n\tprint (n-(x)+(y-r))", "for _ in range(int(input())):\n x,y,n=list(map(int,input().split()))\n z=n//x\n p = n%x\n if p>=y:\n print(z*x+y)\n else:\n print((z-1)*x+y)\n", "for _ in range(int(input())):\n x, y, n = list(map(int, input().split()))\n z = (n - y) // x\n print(x * z + y)", "t = int(input())\nfor _ in range(t):\n\tx, y, n = map(int, input().split())\n\n\tma = (n//x)*x\n\n\tif ma + y <= n:\n\t\tans = ma + y\n\telse:\n\t\tans = ma - x + y\n\n\tprint(ans)", "# for _ in range(1):\nfor _ in range(int(input())):\n x, y, n = map(int, input().split())\n # n = int(input())\n # arr = list(map(int, input().split()))\n # s = input()\n r = n % x\n if r < y:\n n -= n % x + 1\n n -= n % x - y\n print(n)", "def solve():\n x, y, n = map(int, input().split())\n k = n % x\n if k >= y:\n print(n - k + y)\n else:\n print(n - x - k + y)\n\n\n[solve() for i in range(int(input()))]", "a=int(input())\nfor i in range(a):\n x,y,n=list(map(int,input().split()))\n r=(n//x)*x\n if(r+y<=n):\n print(r+y)\n else:\n print(max(r-x+y,y))\n", "for _ in range(int(input())):\n x,y,n=map(int,input().split())\n ans=(n//x)*x\n ans+=y\n if ans>n:\n ans-=x\n print(ans) ", "\n\nfor _ in range(int(input())):\n\ta,b,c=map(int,input().split())\n\n\tcan=c%a\n\n\tif(can>=b):\n\t\tprint((c//a)*a+b)\n\telse:\n\t\tprint((c//a-1)*a+b)", "for _ in range(int(input())):\n x, y, n = map(int, input().split())\n if n % x < y:\n print(x * (n // x - 1) + y)\n else:\n print(x * (n // x) + y)", "import bisect\nimport sys\nimport math\ninput = sys.stdin.readline\nimport functools\n\nfrom collections import defaultdict\n\n############ ---- Input Functions ---- ############\n\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(list(map(int,input().split())))\n\n############ ---- Solution ---- ############\n\ndef solve(case):\n [x, y, n] = inlt()\n res = (n // x) * x + y\n if res > n:\n res -= x\n return res\n \n\nif len(sys.argv) > 1 and sys.argv[1].startswith(\"input\"):\n f = open(\"./\" + sys.argv[1], 'r')\n input = f.readline\n\nT = inp()\nfor i in range(T):\n res = solve(i+1)\n print(str(res))\n", "import sys\n# from collections import defaultdict\nt=1\nt=int(input())\nfor i in range(t):\n # n=int(input())\n x,y,n=list(map(int,sys.stdin.readline().strip().split()))\n # a,b,c,d=list(sys.stdin.readline().strip().split())\n # n,k=list(map(int,sys.stdin.readline().strip().split()))\n \n a=(n//x)*x+y\n b=((n//x)-1)*x+y\n \n if(a<=n):\n print(a)\n else:\n print(b)", "# Created by: WeirdBugsButOkay\n# 28-06-2020, 20:05:31\n\nimport math\n\ndef solve() :\n x, y, n = list(map(int, input().split()))\n rem = n // x\n rem *= x\n rem += y\n if rem > n :\n rem -= x\n print(rem)\n\nt = 1\nt = int(input())\nfor _ in range (0, t) :\n solve()\n"] | {
"inputs": [
"7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999\n",
"1\n1000000000 0 999999999\n",
"1\n43284 1 33424242\n",
"1\n31 2 104\n",
"1\n943643 1 23522222\n",
"1\n4452384 1 3573842\n",
"1\n33 6 100\n"
],
"outputs": [
"12339\n0\n15\n54306\n999999995\n185\n999999998\n",
"0\n",
"33415249\n",
"95\n",
"22647433\n",
"1\n",
"72\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,217 | |
aa2e7e19c677c5592160500288a0795a | UNKNOWN | International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are $n$ candy boxes in the shop for sale. The $i$-th box contains $d_i$ candies.
Polycarp wants to prepare the maximum number of gifts for $k$ girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by $k$. In other words, two boxes $i$ and $j$ ($i \ne j$) can be combined as a gift if $d_i + d_j$ is divisible by $k$.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5, 1 \le k \le 100$) β the number the boxes and the number the girls.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$), where $d_i$ is the number of candies in the $i$-th box.
-----Output-----
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
-----Examples-----
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
-----Note-----
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes): $(2, 3)$; $(5, 6)$; $(1, 4)$.
So the answer is $6$.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes): $(6, 8)$; $(2, 3)$; $(1, 4)$; $(5, 7)$.
So the answer is $8$.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes): $(1, 2)$; $(6, 7)$.
So the answer is $4$. | ["n, k = map(int, input().split())\nD = list(map(int, input().split()))\nz = {i: 0 for i in range(k)}\nfor i in range(n):\n z[D[i] % k] += 1\ncnt = z[0] // 2\nfor q in range(1, k // 2 + k % 2):\n cnt += min(z[q], z[k - q])\nif k % 2 == 0:\n cnt += z[k // 2] // 2\nprint(cnt * 2)", "n, k = map(int, input().split())\nd = list(map(int, input().split()))\n\ncount = [0] * k\nfor x in d:\n count[x%k] += 1\n\nresult = count[0]//2\nfor i in range(1, k):\n if i*2 >= k:\n break\n result += min(count[i], count[k-i])\n\nif k%2==0:\n result += count[k//2]//2\nprint(result*2)", "n, k = list(map(int, input().split()))\ncounts = [0] * k\nfor i in map(int, input().split()):\n counts[i % k] += 1\n\nc = counts[0] // 2\nfor i in range(1, k):\n if 2 * i >= k:\n break\n c += min(counts[i], counts[k - i])\nif k % 2 == 0:\n c += counts[k // 2] // 2\n\nprint(2 * c)\n", "def main():\n n, k = list(map(int, input().split()))\n cnt = [0] * k\n ans = 0\n arr = list(map(int, input().split()))\n for el in arr:\n t = el % k\n if (cnt[(k - t) % k] > 0):\n cnt[(k - t) % k] -= 1\n ans += 2\n else:\n cnt[t] += 1\n print(ans)\n \n \nmain()\n", "n, k = list(map(int, input().split()))\n\nans = [0] * k\n\na = list(map(int, input().split()))\n\nfor c in a:\n\tans[c % k] += 1\nkol = ans[0] - ans[0] % 2\nfor i in range(1, int(k / 2 + 0.5)):\n\tkol += min(ans[i], ans[k - i]) * 2\n\t#print(ans[i], ans[k - i], i)\n\nif k % 2 == 0:\n\tkol += ans[k // 2] - ans[k // 2] % 2\n#print(ans)\nprint(kol)\n", "n, k = list(map(int,input().split()))\ndi = list(map(int,input().split()))\nai = [0] * k\nfor i in di:\n ai[i % k] += 1\nans = ai[0] // 2\nai[0] = 0\nfor i in range(1,k):\n num = i\n num2 = k - i\n if num != num2:\n ans += min(ai[num], ai[num2])\n else:\n ans += ai[num] // 2\n ai[num] = 0\n ai[num2] = 0\nprint(ans * 2)\n", "n, k = list(map(int, input().split()))\nd = list(map(int, input().split()))\ndi = dict()\nfor i in range(n):\n if d[i] % k in di:\n di[d[i] % k] += 1\n else:\n di[d[i] % k] = 1\nans = 0\nif 0 in di:\n ans = di[0] // 2\nfor i in range(1, k // 2 + 1):\n if i in di and k - i in di:\n if i == k - i:\n ans += di[i] // 2\n else:\n ans += min(di[i], di[k - i])\nprint(ans * 2)\n", "n,k = [int(x) for x in input().split()]\n\nL = [int(x) for x in input().split()]\n\nD = [0]*k\n\nfor i in L:\n D[i%k] += 1\n \ns = 0 \nfor i in range((k+2)//2):\n if i == 0:\n s += 2*(D[0]//2)\n elif (k%2 == 0) and (i == k//2):\n s += 2*(D[i]//2)\n else:\n s += 2*min(D[i],D[k-i])\n \nprint(s)", "n,k=map(int,input().split())\nd=[*map(int,input().split())]\ncnt=[0]*k\nfor i in d:\n cnt[i%k]+=1\nans=cnt[0]//2\nfor i in range(1,k):\n req=k-i\n if i<req:\n ans+=min(cnt[i],cnt[req])\n elif i==req:\n ans+=cnt[i]//2\nprint(ans*2)", "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nd = [0] * k\nfor i in range(n):\n d[a[i] % k] += 1\n\nnum = 0\nfor i in range(k):\n if k - i < i:\n break\n if i == 0:\n num += d[i] // 2\n elif i == k - i:\n num += d[i] // 2\n else:\n num += min(d[i], d[k - i])\n\nprint(num * 2)\n", "from collections import Counter as C\nn, k = map(int, input().split())\nl = [int(x) % k for x in input().split()]\nc = C(l)\nres = 0\nfor i in range(k):\n j = -i % k\n vi, vj = c.get(i, 0), c.get(j, 0)\n if i == j:\n res += vi // 2\n else:\n res += min(vi, vj)\n c[i] = 0\nprint(res * 2)", "n, K = map(int, input().split())\narr = map(int, input().split())\nfreq = [0 for _ in range(K)]\nfor x in arr:\n freq[x%K] += 1\nans = 2*(freq[0]//2)\nfor i in range(1, K):\n if i < K-i:\n ans += 2*(min(freq[i], freq[K-i]))\n elif i == K-i:\n ans += 2*(freq[i]//2)\nprint(ans)", "n,k = list(map(int,input().split()))\nl = list(map(int,input().split()))\n\nd = {}\n\nfor i in range(k):\n d[i] = 0\n\nfor i in range(len(l)):\n l[i] = l[i]%k\n d[l[i]] += 1 \n\ns = 0\n\ns += d[0]//2\n\nfor i in range(1,k//2):\n s += min(d[i],d[k-i])\n\nif k % 2 == 0:\n s += d[k//2] // 2\nelse:\n if k != 1:\n s += min(d[k//2],d[k-k//2])\n \nprint(s*2)\n", "n,k=list(map(int,input().split()))\nD=list(map(int,input().split()))\n\nD2=[d%k for d in D]\n\nfrom collections import Counter\nc=Counter(D2)\n\nANS=c[0]//2*2\nif k%2==0:\n ANS+=c[k//2]//2*2\nfor i in range(1,-(-k//2)):\n ANS+=min(c[i],c[k-i])*2\n\nprint(ANS)\n \n", "# -*- coding: utf-8 -*-\n# @Time : 2019/3/7 23:13\n# @Author : LunaFire\n# @Email : [email protected]\n# @File : B. Preparation for International Women's Day.py\n\nfrom collections import Counter\n\n\ndef main():\n n, k = map(int, input().split())\n d = list(map(int, input().split()))\n\n counter = Counter()\n for x in d:\n counter[x % k] += 1\n\n ret = counter[0] // 2 * 2\n for i in range(1, k):\n if i != k - i:\n ret += min(counter[i], counter[k - i])\n else:\n ret += counter[i] // 2 * 2\n print(ret)\n\n\ndef __starting_point():\n main()\n__starting_point()", "n, k = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\ndivs = {}\nhandled = [False, ] * k\n\nfor x in a:\n divs[x % k] = divs.get(x % k, 0) + 1\n\nresult = divs.get(0, 0) - divs.get(0, 0) % 2\n\nfor i in range(1, k):\n if not handled[i] and not handled[k - i]:\n if i != k - i:\n result += 2 * min(divs.get(i, 0), divs.get(k - i, 0))\n else:\n result += divs.get(i, 0) - divs.get(i, 0) % 2\n handled[i] = handled[k - i] = True\n\nprint(result)\n", "#map(int,input().split())\n#int(input())\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nd = dict()\nfor i in range(n):\n m=a[i]%k\n if m not in d:\n d[m]=1\n else:\n d[m]+=1\nans=0\nif 0 in d:\n ans = d[0]//2\nh=k//2\nif k%2==0 and h in d:\n ans += d[h]//2\nfor i in range(1,(k+1)//2):\n if i in d and k-i in d:\n ans += min(d[i],d[k-i])\nprint(ans*2)", "from math import floor\nfrom collections import defaultdict\n\nn, k = map(int, input().split())\na = defaultdict(int)\nfor i in input().split():\n i = int(i) % k\n a[i] += 1\nr = 0\nfor i in range(floor(k / 2) + 1):\n if i == 0 or i == k - i:\n r += a[i] // 2\n else:\n r += min(a[i], a[k - i])\nprint(r * 2)", "n,k=tuple(map(int,input().strip().split(\" \")))\nnumbers=tuple(map(int,input().strip().split(\" \")))\nl=[]\nfor i in range(k):\n l.append(0)\nfor i in numbers:\n l[i%k]+=1\ns=(l[0]//2)*2\nimport math\nfor g in range(1,math.ceil(k/2)):\n s=s+(min(l[g],l[k-g])*2)\nif(k%2==0):\n s=s+((l[k//2]//2)*2)\nprint(s)", "def main():\n n,k = list(map(int,input().split()))\n candy = list(map(int,input().split()))\n candies = []\n zeroes = 0\n for i in candy:\n mod = i%k\n if mod == 0:\n zeroes += 1\n else:\n candies.append(mod)\n\n candies.sort()\n\n boxes = zeroes//2\n\n candy_dict = {}\n\n for i in candies:\n if i not in list(candy_dict.keys()):\n candy_dict[i] = 1\n else:\n candy_dict[i] += 1\n\n #print (candy_dict)\n for i in candy_dict:\n if candy_dict[i] > 0:\n if (k-i) in list(candy_dict.keys()):\n if candy_dict[k-i] > 0:\n if i == (k-i):\n box = candy_dict[i]//2\n candy_dict[i] = candy_dict[i]%2\n else:\n box = min(candy_dict[i],candy_dict[k-i])\n candy_dict[i] -= box\n candy_dict[k-i] -= box\n boxes += box\n\n print(2*boxes)\n \n\nmain()\n", "n,k=list(map(int,input().split()))\na=[int(x)%k for x in input().split()]\nf={}\nan=0\nfor i in a:\n if -i in f and f[-i]>0:\n an+=2\n f[-i]-=1\n elif k-i in f and f[k-i]>0:\n an+=2\n f[k-i]-=1\n else:\n if i not in f:f[i]=0\n f[i]+=1\nprint(an)\n", "n, k = list(map(int, input().split()))\nd = list(map(int, input().split()))\nost = [0] * k\nfor i in range(n):\n ost[d[i] % k] += 1\nans = ost[0] // 2\nfor i in range(1, k // 2 + 1):\n if i != k - i:\n ans += min(ost[i], ost[k - i])\n else:\n ans += ost[i] // 2\nprint(ans * 2)\n", "n, k = map(int, input().split())\ncandies = list(map(int, input().split()))\n\ndiv = [0 for i in range(k)]\n\nfor i in candies:\n div[i % k] += 1\n\n\nres = (div[0] // 2)*2\nif k % 2 == 1:\n c = k//2 +1\nelse:\n c = k//2 + 1\nfor i in range(1, c):\n res += 2 * min(div[i], div[k - i]) if i != k - i else (div[i] // 2)*2\nprint(res)", "n,k = list(map(int,input().split()))\nnum = list(map(int,input().split()))\ngay = []\nfor i in num:\n\tgay.append(i%k)\nnumber = [0] * 101\nfor i in gay:\n\tnumber[i] += 1\n#print(number)\ni = 0\nchuj = 1\nwynik = 0\nwhile i<k:\n\tif i == (k-i)%k:\n\t\tif number[i] > 1:\n\t\t\tnumber[i] -= 2\n\t\t\twynik += 1\n\t\telse:\n\t\t\tnumber[i] = 0\n\t\t\ti += 1\n\telse:\n\t\tif number[i] > 0:\n\t\t\tif number[(k-i)%k]>0:\n\t\t\t\tnumber[i] -= 1\n\t\t\t\tnumber[(k-i)%k] -= 1\n\t\t\t\twynik += 1\n\t\t\telse:\n\t\t\t\tnumber[i] = 0\n\t\tif number[i] == 0:\n\t\t\ti += 1\nprint(2*wynik)"] | {
"inputs": [
"7 2\n1 2 2 3 2 4 10\n",
"8 2\n1 2 2 3 2 4 6 10\n",
"7 3\n1 2 2 3 2 4 5\n",
"1 2\n120\n",
"2 9\n80 1\n",
"2 9\n81 1\n",
"3 1\n1 1 1\n"
],
"outputs": [
"6\n",
"8\n",
"4\n",
"0\n",
"2\n",
"0\n",
"2\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,497 | |
757c71d7cd26e4bc7d4726992543174e | UNKNOWN | You are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive).
Print the string S after lowercasing the K-th character in it.
-----Constraints-----
- 1 β€ N β€ 50
- 1 β€ K β€ N
- S is a string of length N consisting of A, B and C.
-----Input-----
Input is given from Standard Input in the following format:
N K
S
-----Output-----
Print the string S after lowercasing the K-th character in it.
-----Sample Input-----
3 1
ABC
-----Sample Output-----
aBC
| ["N, K = map(int, input().split())\nS = input()\nprint(\"\".join(c.lower() if i == K else c for i, c in enumerate(S, 1)))", "n,k = list(map(int,input().split()))\nS = input()\nprint( S[:k-1]+S[k-1].lower()+ S[k:])", "N, K = map(int, input().split())\nS = list(input())\nS[K - 1] = S[K - 1].lower()\n\nprint(\"\".join(S))", "N,K = map(int,input().split())\nS = input()\n\n# (K-1)\u6587\u5b57\u76ee\u307e\u3067 + K\u6587\u5b57\u76ee + K+1\u6587\u5b57\u76ee\u304b\u3089\nprint(S[:K-1] + S[K-1].lower() + S[K:])", "n, k = map(int, input().split())\ns = input()\nfor i in range(len(s)):\n if(i == k - 1):\n print(str.lower(s[i]), end='')\n else:\n print(s[i], end='')\nprint()", "n, k = map(int, input().split())\ns = input()\ns = s[k-1:] + s[:k-1]\nans = s.capitalize().swapcase()\nprint(ans[n-k+1:] + ans[:n-k+1])", "N, K = map(int, input().split())\nS = input()\n\nans = ''\nfor i in range(N):\n if i != K - 1:\n ans += S[i]\n else:\n ans += S[i].lower()\n\nprint(ans)", "N, K = map(int, input().split())\nS = list(input())\nS[K-1] = S[K-1].lower()\nprint(\"\".join(S))", "N, K = list(map(int,input().split()))\nS = input()\n\ncapital = ['A','B','C']\nsmall = ['a','b','c']\n\ni = capital.index(S[K-1])\nans = S[:K-1]+small[i]+S[K:]\nprint(ans)\n", "n,k = list(map(int,input().split()))\ns = list(input())\ns[k-1] = s[k-1].lower()\nprint((''.join(s)))\n", "n, k = list(map(int, input().split()))\ns = input()\n\nprint((s[:k - 1] + chr(ord(s[k - 1]) + 32) + s[k:]))\n", "N, K = input().strip().split()\nS = input()\nN = int(N)\nK = int(K)\nS = list(S)\nif S[K-1] == 'A':\n S[K-1] = 'a'\nelif S[K-1] == 'B':\n S[K-1] = 'b'\nelse:\n S[K-1] = 'c'\nprint(''.join(S))", "n,k = map(int,input().split())\ns = list(input())\nif s[k-1] == \"A\":\n s[k-1] = \"a\"\nelif s[k-1] == \"B\":\n s[k-1] = \"b\"\nelif s[k-1] == \"C\":\n s[k-1] = \"c\"\nans = ''.join(s)\nprint(ans)", "N,K = map(int,input().split())\nmoji = str(input())\nans = moji[:K-1] + moji[K-1].lower() + moji[K:]\nprint(ans)", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n, k = Input()\n s = input()\n print(\"\".join(ch.lower() if index==k else ch for index, ch in enumerate(s, 1)))\n\n\nmain()", "n,k=map(int,input().split())\ns=list(input())\nif s[k-1]==\"A\":\n s[k-1]=\"a\"\nelif s[k-1]==\"B\":\n s[k-1]=\"b\"\nelse:\n s[k-1]=\"c\"\na=\"\"\nfor i in range(n):\n a+=s[i]\nprint(a)", "n, k = list(map(int, input().split()))\ns = input()\n\nprint((s[:k-1] + s[k-1].lower() + s[k:]))\n", "n,k=map(int,input().split())\ns=input()\nprint(s[:k-1]+s[k-1].lower()+s[k:])", "N, K = map(int, input().split())\nS = list(input())\n\nS[K-1] = S[K-1].lower()\nans = ''\nfor s in S:\n ans += s\nprint(ans)", "n,k = [int(x) for x in input().split()]\ns = input()\n \nk -= 1\ns = list(s)\n\nif s[k] == \"A\":\n s[k] = \"a\"\nelif s[k] == \"B\":\n s[k] = \"b\"\nelif s[k] == \"C\":\n s[k] = \"c\"\n \nprint(\"\".join(s))", "N, K = list(map(int, input().split()))\nS = list(input())\n\n \nif(S[K-1] == \"A\"):\n S[K-1] = \"a\"\nelif(S[K-1] == \"B\"):\n S[K-1] = \"b\"\nelif(S[K-1] == \"C\"):\n S[K-1] = \"c\"\n \n\"\".join(S)\n\nS_1 = S[0]\nfor i in range(1,N):\n S_1 = S_1 + S[i]\nprint(S_1)\n", "n, k = list(map(int, input().split()))\ns = input()\n\nans = s[:k-1] + s[k-1].swapcase() + s[k:]\n\nprint(ans)", "n, k = map(int, input().split())\ns = str(input())\nans = ''\nif s[k-1] == 'A':\n ans = s[:k-1] + 'a' + s[k:]\n print(ans)\n return\nelif s[k-1] == 'B':\n ans = s[:k-1] + 'b' + s[k:]\n print(ans)\n return\nelif s[k-1] == 'C':\n ans = s[:k-1] + 'c' + s[k:]\n print(ans)\n return", "N, K = map(int, input().split())\nS = input()\n \nif S[K-1] == 'A': rep = 'a'\nelif S[K-1] == 'B': rep = 'b'\nelse: rep = 'c'\n\n# (K-1)\u6587\u5b57\u76ee\u307e\u3067 + K\u6587\u5b57\u76ee + K+1\u6587\u5b57\u76ee\u304b\u3089\nprint(S[:K-1] + rep + S[K:])", "N, K = map(int, input().split())\nS = input()\nprint(S[:K-1] + S[K-1].lower() + S[K:])", "n, k = map(int,input().split())\ns = input()\nprint(s[:k - 1], end = '')\nprint(str.swapcase(s[k - 1]), end = '')\nprint(s[k:])", "N, K = map(int, input().split())\nK -= 1\nS = list(input())\nfor i, c in enumerate(S):\n if i == K:\n c = c.lower()\n print(c, end='')\nprint('')", "N, K = map(int, input().split())\nS = input()\nans = ''\nfor i in range(N):\n if i == K-1:\n if S[i] == 'A':\n ans += 'a'\n elif S[i] == 'B':\n ans += 'b'\n else:\n ans += 'c'\n else:\n ans += S[i]\nprint(ans)", "n,k = map(int,input().split())\ns = list(input())\ns[k-1] = s[k-1].lower()\nfor i in s :\n print(i,end='')\nprint()", "N,K=map(int,input().split())\nS=list(input())\nS[K-1]=S[K-1].lower()\n\nans=\"\"\nfor i in S:\n ans+=i\nprint(ans)", "n,k=list(map(int,input().split()))\ns=list(input())\ns[k-1]=s[k-1].lower()\nprint((\"\".join(s)))\n", "n, k = map(int, input().split())\ns = str(input())\nif s[k-1] == 'A':\n ans = s[:k-1] + 'a' + s[k:]\nelif s[k-1] == 'B':\n ans = s[:k-1] + 'b' + s[k:]\nelse:\n ans = s[:k-1] + 'c' + s[k:]\nprint(ans)", "N, K = map(int, input().split())\nS = list(input())\nif S[K-1] == 'A':\n S[K-1] = 'a'\nif S[K-1] == 'B':\n S[K-1] = 'b'\nif S[K-1] == 'C':\n S[K-1] = 'c'\nfor i in S:\n print(i,end=\"\")", "n, k = map(int, input().split())\nlist01 = list(input())\nlist01[k - 1] = str.lower(list01[k - 1])\na = ''.join(list01)\nprint(a)", "s,k=list(map(int,input().split()))\ns = input()\nprint((s[:k-1]+s[k-1].lower()+s[k:]))\n", "n,k=map(int, input().split())\ns=input()\nif s[k-1]=='A':\n s=s[:k-1]+'a'+s[k:]\nif s[k-1]=='B':\n s=s[:k-1]+'b'+s[k:]\nif s[k-1]=='C':\n s=s[:k-1]+'c'+s[k:]\nprint(s)", "n,k=map(int,input().split())\ndef replace(m):\n if m==\"A\":\n return \"a\"\n elif m==\"B\":\n return \"b\"\n else:\n return \"c\"\n \nabc_str=list(input())\nabc_str[k-1]=replace(abc_str[k-1])\nabc_str=\"\".join(abc_str)\nprint(abc_str)", "n,k = map(int, input().split())\ns = input()\n\nprint(s[:k-1]+s[k-1].swapcase()+s[k:])", "n, k = map(int, input().split())\ns = input()\nprint(s[:k-1]+s[k-1].lower()+s[k:])", "N, K = map(int, input().split())\nS = input()\nans = S[:K - 1] + S[K - 1].lower() + S[K:]\nprint(ans)", "n, k = list(map(int, input().split()))\ns = list(input())\n\ntmp = s.pop(k - 1)\nl = tmp.lower()\ns.insert(k - 1, l)\nprint((''.join(s)))\n", "N, K = map(int, input().split())\nS = str(input())\n\nans = ''\nans += S[:K-1]\nif S[K-1] == 'A':\n ans += 'a'\nelif S[K-1] == 'B':\n ans += 'b'\nelse:\n ans += 'c'\nans += S[K:]\nprint(ans)", "N, K = map(int, input().split())\nS = list(input())\nS[K-1] = S[K-1].lower()\nprint(''.join(S))", "N, K = map(int, input().split())\nS = input()\n\nprint(S[:(K - 1)] + 'abc'[ord(S[K - 1]) - ord('A')] + S[K:])", "N,K = map(int,input().split())\nS = list(input())\n\nS[K-1] = S[K-1].lower()\nans = ''.join(S)\nprint(ans)", "n,k=list(map(int,input().split()))\ns=input()\nprint((s[:k-1]+s[k-1].lower()+s[k:]))\n", "N, K = list(map(int, input().split()))\nS = list(input())\n\nS[K-1] = S[K-1].lower()\n\nprint((''.join(S)))\n", "# ABC126\n# A Changing a Character\nn, k = list(map(int, input().split()))\nS = list(input())\nx = S.pop(k-1).lower()\nS.insert((k-1),x)\nprint((\"\".join(S)))\n", "n,k=map(int,input().split())\ns=list(input())\ns[k-1]=s[k-1].lower() \nprint(''.join(s)) ", "n, k = map(int, input().split())\ns = input()\nans = s[:k-1] + chr(ord(s[k-1])+32) + s[k:]\nprint(ans)", "N,K = map(int, input().split())\nS = str(input())\nA = ''\nfor i in range(N):\n if i + 1 == K:\n A += S[i].lower()\n else:\n A += S[i]\nprint(A)", "a,b=input().split()\na=int(a)\nb=int(b)\nc=input()\nh,i,j=c[:(b-1)],c[b-1],c[(b):]\nif i==\"A\":\n i=\"a\"\nif i==\"B\":\n i=\"b\"\nif i==\"C\":\n i=\"c\"\nprint(h+i+j)", "n,k=map(int, input().split())\ns=list(input())\n\nss=s[k-1]\np=ss.lower()\n#print(p)\ns[k-1]=p\n#print(s[k-1])\n#print(s)\n\nans=\"\".join(s)\nprint(ans)", "N,K = map(int,input().split())\nS = list(input())\n\nS[K-1] = S[K-1].lower()\n\nprint(\"\".join(S))", "n, k = map(int, input().split())\ns = input()\nprint(s[:k-1] + s.lower()[k-1] + s[k:])", "n,k=map(int,input().split())\ns=list(input())\ns[k-1]=s[k-1].lower()\nprint(''.join(s))", "n,k = map(int, input().split())\ns = input()\nk -= 1\nprint(s[:k] + s[k].lower() + s[k+1:])", "n, k = list(map(int, input().split()))\ns = list(input())\ns[k - 1] = chr(ord(s[k - 1]) + ord('a') - ord('A'))\nprint((''.join(s)))\n", "N,K = map(int,input().split())\nS = str(input())\nT = list(map(str,S))\n\nfor i in range(N):\n if i == K-1:\n T[i] = str.lower(T[i])\n\nprint(\"\".join(T))", "n,k=map(int,input().split())\ns=list(input())\ns[k-1]=str.lower(s[k-1])\nprint(''.join(s))", "N,K=map(int, input().split())\nS=list(input())\n\nS[K-1]=S[K-1].lower()\n\nprint(\"\".join(S))", "n, k = list(map(int, input().split()))\ns = input()\nprint((s[:k-1] + s[k-1].lower() + s[k:]))\n", "n,k=list(map(int,input().split(' ')))\ns=input()\nm=''\nif s[k-1].isupper():\n m=s[k-1].lower()\nelse:\n m=s[k-1].upper()\n\nprint((s[:k-1]+m+s[k:]))\n", "N,K = map(int,input().split())\nS = input()\nlsS = list(S)\nlsS[K-1] = lsS[K-1].lower()\nans = ''.join(lsS)\nprint(ans)", "n, k = map(int, input().split())\ns = list(input())\ns[k-1] = s[k-1].lower()\nprint(''.join(s))", "N, K = map(int,input().split())\nS = input()\nans = []\nfor i in range(N):\n if i == K - 1:\n x = ord(S[i])\n x += 32\n y = chr(x)\n ans.append(y)\n else:\n ans.append(S[i])\n\nprint(''.join(ans))", "n,k = map(int,input().split())\ns = list(input())\n\nfor i in range(1,n+1):\n if i == k:\n print(s[i-1].lower(),end=\"\")\n continue\n print(s[i-1],end=\"\")", "N,K=map(int,input().split())\nS=list(input())\nS[K-1]=S[K-1].lower()\nprint(\"\".join(S))", "n, k = list(map(int, input().split()))\ns = input()\nprint((s[:k-1]+s[k-1].lower()+s[k:]))\n", "n, k = map(int,input().split())\ns = input()\nresult_s = ''\na = 0\n\nfor s in list(s):\n a += 1\n if a==k:\n s = s.lower()\n result_s += s\n\nprint(result_s)", "n, k = map(int, input().split())\ns = input()\nss = ''\nfor i in range(n):\n if i == k-1:\n ss += s[i].lower()\n else:\n ss += s[i]\nprint(ss)", "Omoji = ['A','B','C']\nKmoji = ['a','b','c']\nn,k = map(int,input().split())\ns = str(input())\nans = ''\nfor i in range(n):\n if i==(k-1):\n for j in range(len(Omoji)):\n if s[i]==Omoji[j]:\n ans += Kmoji[j]\n else:\n ans += s[i]\nprint(ans)", "n,k = map(int,input().split())\ns = input()\nprint(s[:k-1]+s[k-1].lower()+s[k:])\nprint('\\n')", "num = input().split()\n\nN = int(num[0])\nK = int(num[1])\n\nS = input()\n\nS2 = S[K-1]\n\nS = S[:K-1] + S2.lower() + S[K:]\n\nprint(S)", "n, k = list(map(int, input().split()))\ns = input()\nprint((s[:k - 1] + s[k - 1].lower() + s[k:]))\n", "N,K = map(int,input().split())\nS = list(input())\nS[K-1] = S[K-1].lower()\nprint(''.join(S))", "n, k = map(int, input().split())\ns = input()\n\nABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nabc = 'abcdefghijklmnopqrstuvwxyz'\nprint(s[:k-1] + abc[ABC.index(s[k-1])] + s[k:])", "n,k = map(int,input().split())\ns = input()\n\nprint(s[:k-1]+s[k-1].lower()+s[k:])", "n,k = map(int,input().split())\ns = input()\nsl = []\nfor i in range(n):\n if i+1 == k:\n sl.append(s[i].lower())\n else:\n sl.append(s[i])\nprint(''.join(sl))", "N, K = map(int, input().split())\nS = input()\n\ns = list(S)\ns[K-1] = s[K-1].lower()\nprint(''.join(s))", "N, K = map(int, input().split())\nS = input()\n\nprint(S[:K-1] + S[K-1].lower() + S[K:])", "n,k = map(int,input().split())\ns = input()\nprint(s[:k-1]+s[k-1].swapcase()+s[k:])", "n,k=list(map(int,input().split()))\ns=input()\nprint((s[:k-1]+s[k-1].lower()+s[k:]))\n", "n, k = map(int, input().split())\ns = list(input())\n\ns[k-1] = s[k-1].swapcase()\nprint(\"\".join(s))", "N,K = map(int,input().split())\nS = str(input())\nL = []\n\nfor i in range(N):\n L.append(S[i])\n if i == K-1:\n L[i] = S[i].lower()\n\nprint(''.join(map(str,L)))", "n ,k = map(int,input().split())\ns = list(input())\ns[k-1:k] = ''.join(s[k-1:k]).lower()\nprint(''.join(s))", "N,K=list(map(int,input().split()))\nS=input()\nprint((S[0:K-1]+S[K-1].lower()+S[K:N]))\n", "n, k = map(int, input().split())\ns = input()\nc = 'a' if s[k-1] == 'A' else 'b' if s[k-1] == 'B' else 'c'\nprint(s[:k-1] + c + s[k:])", "n, k = list(map(int, input().split()))\n\ns = input()\n\nL = []\nfor i in range(n):\n L.append(s[i])\n\nL[k-1] = str.lower(L[k-1])\nans = str()\nfor i in range(n):\n ans += L[i]\nprint(ans)\n \n", "N,K=map(int,input().split())\nS=list(input())\nfor i in range(N):\n if i==K-1:\n S[i]=chr(ord(S[i])+32)\nprint(''.join(S))", "n,k = map(int,input().split())\ns = list(input())\n\nif s[k - 1] == 'A':\n s[k - 1] = 'a'\nif s[k - 1] == 'B':\n s[k - 1] = 'b'\nif s[k - 1] == 'C':\n s[k - 1] = 'c'\nstrA = ''.join(s)\nprint(strA)", "n, k = map(int, input().split())\ns = input()\nprint(s[:k-1]+s[k-1].lower()+s[k:])", "N, K = list(map(int, input().split()))\nS = input()\nans = \"\"\nfor i in range(len(S)):\n if i == K-1:\n ans += S[i].lower()\n else:\n ans += S[i]\n\nprint(ans)\n", "_, K = [int(i) for i in input().split()]\nS = input()\nprint((S[:K - 1] + S[K - 1].lower() + S[K:]))\n", "N,K=list(map(int, input().split()))\nS=input().strip()\nc=S[K-1].lower()\nprint((S[:K-1]+c+S[K:]))\n\n", "n,k = list(map(int,input().split()))\n\ns = list(input())\nt = ''\nfor j,i in enumerate(s):\n if j == k-1:t += i.lower()\n else:t+=i\nprint(t)\n", "N, K = map(int, input().split())\nS = input()\n\ns = S[K-1].lower()\nprint(S[:K-1] + s + S[K:])", "def str_replace_to_lower() -> str:\n len_str, target_index = map(int, input().split())\n word = input()\n list_of_word = list(word)\n list_of_word[target_index - 1] = list_of_word[target_index - 1].lower()\n\n return ''.join(list_of_word)\n\n\nprint(str_replace_to_lower())"] | {"inputs": ["3 1\nABC\n", "4 3\nCABA\n", "20 15\nBBBBAAACBCABBCAACAAC\n", "40 38\nBCCACCBCACABBBBBCBABCCCABBAACBBBAAABACCA\n", "1 1\nA\n", "50 27\nACBCABCCCAACACCBBBACCBCBBBCCBAAAABAACACAAACCACCCCA\n", "50 50\nCABABCBBCBABCAACBCBBAAAACBCBCBBABBABBBCCBAACCAACAB\n"], "outputs": ["aBC\n", "CAbA\n", "BBBBAAACBCABBCaACAAC\n", "BCCACCBCACABBBBBCBABCCCABBAACBBBAAABAcCA\n", "a\n", "ACBCABCCCAACACCBBBACCBCBBBcCBAAAABAACACAAACCACCCCA\n", "CABABCBBCBABCAACBCBBAAAACBCBCBBABBABBBCCBAACCAACAb\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 14,149 | |
22803adf0fbaa6b1cb87b33bd4c0a27b | UNKNOWN | You have decided to write a book introducing good restaurants.
There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.
No two restaurants have the same score.
You want to introduce the restaurants in the following order:
- The restaurants are arranged in lexicographical order of the names of their cities.
- If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
-----Constraints-----
- 1 β€ N β€ 100
- S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
- 0 β€ P_i β€ 100
- P_i is an integer.
- P_i β P_j (1 β€ i < j β€ N)
-----Input-----
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
-----Output-----
Print N lines. The i-th line (1 β€ i β€ N) should contain the identification number of the restaurant that is introduced i-th in the book.
-----Sample Input-----
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
-----Sample Output-----
3
4
6
1
5
2
The lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2. | ["n=int(input())\na=[]\nfor i in range(n):\n t=list(input().split())\n t[1]=int(t[1])\n t.append(i)\n a.append(t)\na.sort(key=lambda x:(x[0],-x[1]))\nfor t in a:\n print(t[2]+1)", "n = int(input())\nsp =[[] for _ in range(n)]\nfor i in range(n):\n sp[i] = list(input().split())\n sp[i].append(i+1)\n\nssp = sorted(sp, key=lambda x:(x[0],-int(x[1])))\nfor i in range(n):\n print(ssp[i][2])", "import re\nn = int(input())\nR = []\nfor i in range(n):\n S, P = input().split()\n R.append((S, int(P),int(i+1)))\n\nPoint = []\nfor j in range(n):\n Point.append(R[j][0])\nPoint = list(sorted(set(Point)))\nPoint\nSR = sorted(R, key=lambda x:(x[0], -int(x[1])))\nfor k in range(n):\n print(SR[k][2])\npass", "N = int(input())\nl = []\nfor i in range(N):\n s,p = input().split()\n l.append([s,int(p),i+1])\n\nl = sorted(l,key = lambda x:x[1],reverse=True)\nl = sorted(l,key = lambda x:x[0])\n\nfor i in range(N):\n print(l[i][2])", "n=int(input())\n\nsp=[]\nfor i in range(n):\n s,p=input().split()\n sp.append([s,int(p),i+1])\n\nsp=sorted(sp,key=lambda x:(x[0],-x[1]))\n\nfor i in range(n):\n print(sp[i][2])", "from operator import itemgetter\nn=int(input())\nSP=[list(map(str,input().split())) for i in range(n)]\nfor sp in SP:\n sp[1] = -1*int(sp[1])\nSPsort = sorted(SP,key=itemgetter(0,1))\nfor i in range(n):\n print(SP.index(SPsort[i])+1)", "N = int(input())\n\nl = []\n\nfor i in range(N):\n s, p = input().split()\n \n l.append([i + 1, s, int(p)])\n \nl = sorted(l, key=lambda x: x[2], reverse=True)\nl = sorted(l, key=lambda x: x[1])\n\nfor x in l:\n print(x[0])", "\nN = int(input())\n\nd = []\nfor i in range(N):\n city, score = input().split()\n d.append({'city':city,'score':int(score),'index':i+1})\n\n\nsorted_d = sorted(d, key=lambda x:x['city'])\n\nunique_city = []\n\nfor i in sorted_d:\n if i['city'] not in unique_city:\n unique_city.append(i['city'])\n\nfor city in unique_city:\n pool = [x for x in sorted_d if x['city']==city]\n sorted_pool = sorted(pool, key=lambda x:x['score'], reverse=True)\n for i in sorted_pool:\n print((i['index']))\n", "n = int(input())\na = [list(input().split(\" \")) for i in range(n)]\nb = []\nfor i in a:\n b.append([i[0], 1000-int(i[1])])\nc = sorted(b)\n\n#print(b, c)\nfor i in c:\n print(b.index(i)+1)", "import bisect,collections,copy,heapq,itertools,math,numpy,string\nimport sys\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\nN = I()\nSPs = [LS() for _ in range(N)]\n\ntmp = 1\nfor SP in SPs:\n \n SP[1] = int(SP[1])\n SP.append(tmp)\n tmp += 1\n\nSPs = sorted(SPs, key=lambda x:(x[0],-x[1]), reverse=False)\n\nfor ans in SPs:\n print(ans[2])", "N = int(input())\nSP = [list(input().split()) for _ in range(N)]\n\nfor i in range(N):\n SP[i].append(i+1)\n \nans = sorted(SP, key=lambda x:(x[0], -int(x[1])))\n\n#for i in range(N):\n# print(ans[i][2])\n\nfor i in ans:\n print(i[2])", "n=int(input())\nd=[]\nans=[0]*n\nfor i in range(n):\n s,p = input().split()\n p = -int(p)\n d.append([i+1,s,p])\nd2 = sorted(d, key=lambda x:(x[1], x[2]))\nfor i in range(n):\n print(d2[i][0])", "n = int(input())\n\ns = []\n\nfor i in range(n):\n\ts.append((input()+' '+str(i)).split())\n\nfor i in range(n):\n\ts[i][1] = int(s[i][1])\n \ns.sort(key=lambda x:x[1], reverse=True)\ns.sort(key=lambda x:x[0])\n\nfor i in s:\n\tprint(int(i[2])+1)", "n=int(input())\ns=[]\nfor i in range(n):\n tmp=input().split()\n tmp[1]=100-int(tmp[1])\n s.append(tmp+[str(i+1)])\ns=sorted(s)\n\nfor i in range(n):\n print((s[i][-1]))\n", "N = int(input())\nSP = []\nidx = 1\n\nfor _ in range(N):\n\tS, P = input().split()\n\tSP.append([idx, S, int(P)])\n\tidx += 1\n\nSP.sort(key = lambda x:(x[1], -x[2]))\n\nfor i in range(N):\n\tprint(SP[i][0])", "n = int(input())\nr = []\nfor i in range(n):\n a = list(input().split())\n a[1] = int(a[1])\n a.append(i + 1)\n r.append(a)\nr.sort(key = lambda x: x[1], reverse = True)\nr.sort(key = lambda x: x[0])\nfor i in r:\n print(i[2])", "n = int(input())\na = sorted([input().split() + [i+1] for i in range(n)], key=lambda x:(x[0], -int(x[1])))\nfor n, s, i in a:\n print(i)\n", "N = int(input())\nlst = []\nfor _ in range(N):\n S, P = input().split()\n lst.append([S, int(P)])\ndct = dict(enumerate(lst))\nlst2 = sorted(lst)\n\ndct2 = {}\nfor n in lst2:\n if not n[0] in dct2:\n dct2[n[0]] = []\n dct2[n[0]].append(n[1])\n else:\n dct2[n[0]].append(n[1])\n\nfor m in dct2.keys():\n dct2[m] = sorted(dct2[m], reverse=True)\n \nlst3 = []\nfor x in dct2.keys():\n for y in dct2[x]:\n lst3.append([x, y])\n\nfor i in lst3:\n for k, v in dct.items():\n if i == v:\n print(k+1)", "N = int(input())\nRest = dict()\nParg = [0]*(101)\nfor i in range(N):\n S, P = map(str,input().split())\n P = int(P)\n if S not in Rest:\n Rest[S] = [P]\n else:\n Rest[S] += [P]\n Parg[P] = i+1 \nRestsort = sorted(Rest)\nfor cit in Restsort:\n box = Rest[cit]\n box.sort(reverse = True)\n for j in box:\n print(Parg[j])", "n = int(input())\ns_p = [ list(map(str, input().split())) for i in range(n) ]\n\nd = {}\nfor i, v in enumerate(s_p):\n s = v[0]\n p = v[1]\n if s not in d.keys():\n d[s] = [(i, p)]\n else:\n d[s] = sorted(d[s] + [(i,p)], key=lambda x: int(x[1]), reverse=True)\n\nfor key in sorted(d.keys()):\n for i,j in d[key]:\n print(i+1)", "N = int(input())\n\nmy_list = []\n\nfor i in range(N):\n sp = input().split()\n sp[1] = int(sp[1])\n sp.insert(0, i+1)\n \n my_list.append(sp)\n \nmy_list.sort(key = lambda x: x[2], reverse=True)\nmy_list.sort(key = lambda x: x[1])\n\nfor i in my_list:\n print(i[0])", "from operator import itemgetter \nn = int(input())\npoint = []\nans = []\nfor i in range(n):\n a,b = input().split()\n s = [a,int(b),i+1]\n point.append(s)\n\ns_point = sorted(point,key=itemgetter(1),reverse=True)\ns_point = sorted(s_point,key=itemgetter(0))\n[print(s_point[j][2]) for j in range(n)]", "n = int(input())\nc = []\nfor i in range(n):\n a, b = input().split()\n c.append([i+1, a, -int(b)])\n\nc = sorted(c, key=lambda x: (x[1], x[2]))\nfor i in c:\n print(i[0])", "n = int(input())\nsp = list([input().split() for i in range(n)])\nsp2 =[[i] + sp[i] for i in range(n)]\n\nans = sorted(sp2, key= lambda x:int(x[2]), reverse=True)\n\nans2 = sorted(ans, key =lambda x:x[1])\nfor i in range(n):\n \n print(ans2[i][0] +1)", "n = int(input())\ntbl = []\n\nfor i in range(n):\n l = list(map(str,input().split()))\n l[1] = int(l[1])\n l2 = [l[1], l[0], i + 1]\n tbl.append(l2)\n\ntbl.sort(key = lambda x:(x[1], -x[0]))\nfor i in range(n):\n print((tbl[i][2]))\n", "N=int(input())\n\nguide=[]\n\nfor i in range(N):\n name,score=map(str,input().split())\n guide.append([i,name,int(score)])\n\nguide_sorted=sorted(guide,reverse=True,key=lambda x:x[2])\nguide_sorted=sorted(guide_sorted,key=lambda x:x[1])\n\nfor i in range(N):\n print(guide_sorted[i][0]+1)", "n= int(input())\nx = [input().split() for i in range(n)]\nfor i in range(n):\n x[i].append(i+1)\ny= sorted(x,key= lambda i:(i[0],-int(i[1])))\nfor i in range(n):\n print(y[i][2])", "n = int(input())\ncity = []\nl = []\nfor i in range(n):\n s,p = input().split()\n if s not in city: city.append(s)\n l.append((s, int(p), i+1))\n \ncity = sorted(set(city))\nl = sorted(l, key=lambda x: x[1], reverse=True)\nfor i in city:\n for j in l:\n if i == j[0]: print(j[2])", "n=int(input())\nsp=[]\nfor i in range(n):\n s,p=input().split()\n sp.append([s,int(p),i+1])\n \nsp=sorted(sp,key=lambda x:(x[0],-x[1]))\n\nfor i in range(n):\n print(sp[i][2])", "N=int(input())\nSP=[[input().split(),i+1] for i in range(N)]\nSP_sort=sorted(SP,key=lambda x:(x[0][0],-int(x[0][1])))\n\nfor i in range(N):\n print((SP_sort[i][1]))\n", "n = int(input())\na = [input().split() for i in range(n)]\nfor i in range(n):\n a[i][1] = int(a[i][1])\n a[i].append(i + 1)\na.sort()\nfor i in range(100):\n for j in range(1,n):\n if a[j][0] == a[j-1][0] and a[j][1] > a[j-1][1]:\n a[j-1],a[j] = a[j],a[j-1]\nfor i in range(n):\n print(a[i][2])", "N = int(input())\nSP = []\nfor i in range(N):\n s, p = input().split()\n p = int(p)\n SP.append((s,p,i+1))\n\nSP.sort(key=lambda x: (x[0], -x[1]))\nfor i in range(N):\n print((SP[i][2]))\n", "def solver():\n N = int(input())\n ans = []\n for i in range(1, N+1):\n s, p = [n for n in input().split()]\n ans.append({'id': i, 'city': s , 'point': int(p)})\n ans_s = sorted(ans, key=lambda x: (x['city'], -x['point']))\n for j in ans_s:\n print((j['id']))\n\ndef __starting_point():\n solver()\n\n__starting_point()", "n = int(input())\n\nlst = []\nfor i in range(1, n + 1):\n s, p = input().split()\n lst.append([i, s, -int(p)])\nlst.sort(key=lambda x: (x[1], x[2]))\nfor i in lst:\n print(i[0])", "N = int(input())\nbook = []\nfor i in range(N):\n city, sco = input().split()\n sco = int(sco)\n book.append({'city':city, 'score':sco, 'number':i+1})\n\nbook.sort(key = lambda x: (x['city'],-x['score']))\n\nfor j in range(N):\n print((book[j]['number']))\n", "#import bisect,collections,copy,heapq,itertools,math,numpy,string\nimport sys\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\nN = int(input())\nSPs = [list(map(str, input().split())) for _ in range(N)]\n\ntmp = 1\nfor SP in SPs:\n \n SP[1] = int(SP[1])\n SP.append(tmp)\n tmp += 1\n\nSPs = sorted(SPs, key=lambda x:(x[0],-x[1]), reverse=False)\n\nfor ans in SPs:\n print(ans[2])", "N = int(input())\nbook = []\nfor i in range(1, N+1):\n city, point = input().split()\n point = int(point)\n book.append(((city, -point), i))\nbook.sort()\n\nfor info in book:\n print(info[1])", "n = int(input())\nsp = [input().split() for i in range(n)]\n\nfor i in range(n) :\n sp[i][1] = int(sp[i][1])\n sp[i].append(i+1)\n\nsp.sort()\n\nfor i in range(100):\n for j in range(1,n) :\n if sp[j][0] == sp[j-1][0] :\n if sp[j][1] > sp[j-1][1] :\n sp[j-1],sp[j] = sp[j],sp[j-1]\n\nfor i in range(n):\n print((sp[i][2]))\n", "n = int(input())\nsp = [list(map(str,input().split())) for i in range(n)]\nfor i in range(1,n+1):\n sp[i-1][1] = int(sp[i-1][1])\n sp[i-1].append(i)\nfrom operator import itemgetter\nsp.sort(key = itemgetter(1),reverse = True)\nsp.sort(key = itemgetter(0))\nfor i in range(n):\n print(sp[i][2])", "n = int(input())\nlst = []\nfor i in range(n):\n s, p = input().split()\n lst.append([s, -(int(p)), i+1])\nlst.sort()\nfor i in range(n):\n print((lst[i][2]))\n", "n = int(input())\n\nrest = []\n\nfor x in range(n):\n a,b = input().split()\n b = int(b)\n rest.append([a,b])\n \n \nrest2 = list(sorted(rest, key=lambda x:(x[1]), reverse=True))\nrest3 = list(sorted(rest2,key=lambda x:x[0]))\n\nfor i in rest3:\n print((rest.index(i)+1))\n", "N = int(input())\nr_list = []\nfor i in range(N):\n item = input().split()\n item[1] = int(item[1])\n item.insert(0, i + 1)\n r_list.append(item)\n\nr_list.sort(key = lambda x: x[2], reverse = True)\nr_list.sort(key = lambda x: x[1])\nfor item in r_list:\n print(item[0])", "n = int(input())\nx = [input().split() for i in range(n)]\nfor i in range(n):\n x[i][1] = int(x[i][1])\n x[i].append(i+1)\n\nx.sort(key= lambda a: a[1])\nx.reverse()\nx.sort(key= lambda b: b[0])\n\nfor i in range(n):\n print(x[i][2])", "n=int(input())\nsp=[list(input().split()) for _ in range(n)]\nfor i in sp:\n i[1]=100-int(i[1])\nfor i in range(n):\n sp[i].append(i+1)\nsp.sort()\nfor i in sp:\n print((i[2]))\n", "N = int(input())\nrestaurants = []\nfor i in range(N):\n name, rating = input().split()\n restaurants.append([name, -int(rating), i])\nrestaurants.sort()\nfor i in restaurants:\n print((i[2] + 1))\n", "N = int(input())\nSP = []\nfor i in range(N):\n S, P = input().split()\n SP.append([i+1, S, int(P)])\n\nsort_SP = sorted(SP, key = lambda x: (x[1], -x[2]))\n\nfor ans in sort_SP:\n print((ans[0]))\n\n", "from operator import itemgetter\nN = int(input())\nl = []\ns = []\nfor i in range(1, N+1):\n k, v = input().split()\n l.append([k, int(v), i])\n s.append(k)\nl = sorted(l)\ns = sorted(list(set(s)))\n\nfor t in s:\n for n in range(N-1, -1, -1):\n k, v, i = l[n]\n if t == k:\n print(i)\n", "\nurl = \"https://atcoder.jp//contests/abc128/tasks/abc128_b\"\n\ndef main():\n n = int(input())\n town = {}\n rate = []\n for i in range(n):\n t = list(input().split())\n town.setdefault(t[0], {})\n town[t[0]][i+1] = int(t[1])\n town = sorted(list(town.items()), key=lambda x:x[0])\n for k in town:\n sort_town = sorted(list(k[1].items()), key=lambda x:x[1], reverse=True)\n for v in sort_town:\n print((v[0]))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nX = [[input().split(), i + 1] for i in range(N)]\n\nX = sorted(X , key = lambda x:(x[0][0], -int(x[0][1])))\n\nfor i in range(N):\n print(X[i][1])", "n=int(input())\ndata=[]\nfor i in range(n):\n s,p=input().split()\n tmp=[s,-int(p),i+1]\n data.append(tmp)\ndata.sort()\nfor i in range(n):\n print(data[i][2])", "from operator import itemgetter\n\nN = int(input())\nrestaurants = []\n\nfor i in range(N):\n arr = input().split()\n restaurants.append((i + 1, arr[0], -int(arr[1])))\n\nrestaurants = sorted(restaurants, key=itemgetter(1, 2))\n\nfor i in range(N):\n print(restaurants[i][0])", "N = int(input())\ncity = []\nscore = dict()\narr = []\nfor i in range(N):\n c, s = input().split()\n arr.append([c, int(s)])\n city.append(c)\n if c in score:\n score[c].append(int(s))\n else:\n score[c] = [int(s)]\ncity.sort()\nans = []\nfor i, var in enumerate(city):\n t = score[var].index(max(score[var]))\n u = score[var].pop(t)\n ans.append(arr.index([var,u]) + 1)\nfor i in ans:\n print(i)", "N=int(input())\nSP=sorted([list(input().split())+[_+1] for _ in range(N)])\ntempcity=SP[0][0]\nans=[]\ntempans=[]\nfor i in range(N):\n\t#print(tempans)\n\tif tempcity == SP[i][0]:\n\t\ttempans.append([int(SP[i][1]),SP[i][2]])\n\telse:\n\t\ttempans=sorted(tempans, reverse=True)\n\t\tfor h in range(len(tempans)):\n\t\t\tans.append(tempans[h][1])\n\t\ttempans=[]\n\t\ttempcity=SP[i][0]\n\t\ttempans.append([int(SP[i][1]),SP[i][2]])\n\tif i==N-1:\n\t\ttempans=sorted(tempans, reverse=True)\n\t\tfor h in range(len(tempans)):\n\t\t\tans.append(tempans[h][1])\n\t\t\nfor g in range(N):print(ans[g])", "N=int(input())\nx=[]\nfor i in range(N):\n S,P=map(str,input().split())\n x.append([S,int(P),i+1])\nX=sorted(x,key=lambda x:(x[0],-x[1]))\nfor i in range(N):\n print(X[i][2])", "N = int(input())\nS = []\nP = []\nfor i in range(N):\n s,p = input().split()\n S.append(s)\n P.append(int(p))\nSset = sorted(list(set(S)))\n\ndict1 = {}\nfor i in range(N):\n dict1[P[i]] = S[i]\n\nfor k in Sset:\n U = [i for i, j in dict1.items() if j == k]\n V = sorted(U,reverse=True)\n for l in V:\n print(P.index(l) + 1)", "n = int(input())\nsp = []\nfor i in range(n):\n s, p = input().split()\n p = int(p)\n sp.append((i+1, s, p))\n\nl = sorted(sp, key=lambda x: (x[1], -x[2]))\nfor a, b, c in l:\n print(a)", "n=int(input())\nl=[]\nfor i in range(n):\n city,point=input().split()\n point=int(point)\n l.append((city,-point,i+1))\n\nfor c,p,i in sorted(l):\n print(i)", "N = int(input())\nl = []\nfor i in range(N):\n s, p = input().split()\n l.append([s, -int(p), i+1])\n\n# \u5730\u540d\u306b\u95a2\u3057\u3066\u8f9e\u66f8\u9806\u306b / (-\u70b9\u6570)\u306b\u95a2\u3057\u3066\u6607\u9806\u306b\uff08\u70b9\u6570\u306b\u95a2\u3057\u3066\u964d\u9806\u306b\uff09\u4e26\u3079\u308b\nl = sorted(l, key=lambda x:(x[0], x[1]))\nfor i in range(N):\n print(l[i][2])", "n = int(input())\ndata = [input().split() for i in range(n)]\nfor i in range(n):\n data[i].append(i + 1)\n if 10 <=int(data[i][1]) < 100:\n data[i][1] = '0' + str(data[i][1])\n elif int(data[i][1]) < 10:\n data[i][1] = '00' + str(data[i][1])\ndata.sort(key = lambda x :x[1],reverse = True)\ndata.sort(key = lambda x :x[0])\nfor i in range(n):\n print(data[i][2])", "from typing import List, Tuple\n\n\ndef answer(n: int, sps: List[Tuple[str, int]]) -> List[int]:\n result = []\n numbered_sps = []\n for i, sp in enumerate(sps, start=1):\n s, p = sp\n numbered_sps.append([i, s, p])\n numbered_sps = sorted(numbered_sps, key=lambda x: (x[1], -x[2]))\n for i in numbered_sps:\n result.append(i[0])\n\n return result\n\n\ndef main():\n n = int(input())\n temp = (input().split() for _ in range(n))\n sps = []\n for s, p in temp:\n sps.append((s, int(p)))\n for i in answer(n, sps):\n print(i)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N=int(input())\nd=[input().split() for i in range(N)]\nname=[]\nfor i in range(N):\n d[i].append(i+1)\n d[i][1]=int(d[i][1])\n name.append(d[i][0])\nName=list(set(name))\nName.sort()\nd.sort()\nfor i in range(len(Name)):\n li=[]\n for j in range(N):\n if Name[i]==d[j][0]:\n li.append([d[j][1],d[j][2]])\n else:\n continue\n li.sort()\n Li=li[::-1]\n for k in range(len(li)):\n print(Li[k][1])", "n=int(input())\n\ns_list=[]\n\nfor i in range(n):\n s,p=input().split()\n p=int(p)*(-1)\n s_list.append([s,p,i+1])\n#print(s_list)\ns_list.sort()\n#print(s_list)\n\nfor i in s_list:\n print((i[2]))\n\n", "def mapt(fn, *args):\n return list(map(fn, *args))\n\n\ndef Atom(segment):\n try:\n return int(segment)\n except ValueError:\n try:\n float(segment)\n except ValueError:\n return segment\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n = int(input())\n data = [mapt(Atom, input().split(\" \")) for _ in range(n)]\n for i in range(n):\n data[i].append(i)\n data = sorted(data, key=lambda x:x[1], reverse=True)\n data = sorted(data, key = lambda x:x[0])\n for row in data:\n print(row[2]+1)\n\nmain()", "n = int(input())\nd =[]\nfor i in range(n):\n s,p = input().split()\n l = [s,-int(p),i+1]\n d.append(l)\nd.sort()\nfor x in d:\n print(x[2])", "n = int(input())\na = []\nfor i in range(n):\n s, p = input().split()\n p = int(p)\n a.append([s, -p, i])\na.sort()\n\nfor i in a:\n print((i[2] + 1))\n", "print(*[_[0] for _ in sorted([[i+1] + input().split() for i in range(int(input()))], key=lambda x:(x[1], -int(x[2])))], sep='\\n')\n", "N=int(input())\nshop=[]\nfor i in range(N):\n S,P=input().split()\n P=int(P)\n shop.append([S,100-P,i])\nshop.sort()\nfor i in range(N):\n print((shop[i][2]+1))\n", "import sys\n\ndef main():\n input = sys.stdin.readline\n N = int(input())\n restaurants = []\n for _ in range(N):\n s, p = input().split()\n restaurants.append((s.strip(), int(p)))\n\n rank = sorted(restaurants, key=lambda x: (x[0], -x[1]))\n for a in rank:\n print(int(restaurants.index(a)) + 1)\n\ndef __starting_point():\n main()\n__starting_point()", "l=int(input())\nL=[]\nfor i in range(l):\n n,k=map(str,input().split())\n c=[]\n c.append(n)\n c.append(100-int(k))\n c.append(i+1)\n L.append(c)\nL.sort()\nfor i in range(l):\n print(L[i][2])", "n = int(input())\nlist_res = []\nfor i in range(0, n):\n s, p = input().split()\n list_res.append([s, int(p), i + 1])\nlist_res_point = sorted(list_res, key=lambda x: (x[1]), reverse=True)\nlist_ans = sorted(list_res_point, key=lambda x: (x[0]))\nfor i in range(0, n):\n print(list_ans[i][2])", "n=int(input())\nrec=[]\nfor i in range(n):\n a,b=input().split()\n rec.append([a,int(b),i+1])\nrec=sorted(rec, reverse=True, key=lambda x: x[1]) \nrec=sorted(rec, key=lambda x: x[0]) \nfor i in rec:\n print(i[2])", "N = int(input())\nR = [input().split() for i in range(N)]\n\nR2 = [{'i':i+1, 's':R[i][0], 'p':int(R[i][1])} for i in range(N)] \n\nS = []\nfor r in R:\n if r[0] not in S:\n S.append(r[0])\nS.sort()\n\nfor s in S:\n rs = [r for r in R2 if r['s'] == s]\n sorted_rs = sorted(rs, key=lambda x:x['p'], reverse=True)\n for r in sorted_rs:\n print(r['i'])", "n = int(input())\nL = []\n\nfor i in range(n):\n s, p = input().split()\n L.append([s, -int(p), i+1])\n\nL.sort()\nfor i in range(n):\n print((L[i][2]))\n", "n = int(input())\nisp = []\nfor i in range(n):\n s, p = input().split()\n p = int(p)\n isp.append([i+1, s, p])\nisp = sorted(isp, key=lambda x: (x[1], -x[2]))\nfor i in isp:\n print(i[0])", "N = int(input())\nrestaurant = [[input().split(), i+1] for i in range(N)]\n\nresta_new = sorted(restaurant, key=lambda x:(x[0][0], -int(x[0][1])))\n#print(resta_new)\n\nfor j in range(N):\n print((resta_new[j][1]))\n", "n=int(input())\ndic1={}\nbokk=[]\nlist0=[]\nfor i in range(n):\n c,p=map(str,input().split())\n p=int(p)\n list0.append([c,p])\n if c not in dic1:\n dic1[c]=[]\n dic1[c].append(p)\ndic1=dict(sorted(dic1.items()))\nfor i,k in dic1.items():\n k.sort(reverse=True)\n for j in k:\n bokk.append([i,j])\nfor i in bokk:\n print(list0.index(i)+1)", "N = int(input())\nl = []\nfor i in range(N):\n s, p = input().split()\n l.append([s, int(p), i+1])\n\n# \u5730\u540d\u306b\u95a2\u3057\u3066\u8f9e\u66f8\u9806\u306b / \u70b9\u6570\u306b\u95a2\u3057\u3066\u964d\u9806\u306b\u4e26\u3079\u308b\nl = sorted(l, key=lambda x:(x[0], -x[1]))\nfor i in range(N):\n print(l[i][2])", "n = int(input())\nL = []\n\nfor i in range(n):\n s,p = input().split()\n L.append([s,int(p),i+1])\nL.sort(key=lambda L:(L[0],-L[1]))\nfor l in L:\n print(l[2])", "n = int(input())\ntbl = []\ns = []\np = []\nfor i in range(n):\n l = list(map(str,input().split()))\n l[1] = int(l[1])\n l2 = [l[1], l[0], i + 1]\n tbl.append(l2)\n s.append(l2[1])\n p.append(l2[0])\n\np.sort()\np.reverse()\ntbl2 = []\nfor i in range(n):\n for j in range(n):\n if(tbl[j][0] == p[i]):\n tbl2.append(tbl[j])\ns = list(set(s))\ns.sort()\nfor i in range(len(s)):\n for j in range(len(tbl2)):\n if (tbl2[j][1] == s[i]):\n print((tbl2[j][2]))\n", "N=int(input())\nli=[]\nfor i in range(N):\n a,b=input().split()\n b=int(b)\n li.append([a,100-b,i+1])\nli.sort()\n\nfor j in range(N):\n print((li[j][2]))\n", "#import bisect,collections,copy,heapq,itertools,math,numpy,string\nimport sys\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\nN = I()\nSPs = [LS() for _ in range(N)]\n\ntmp = 1\nfor SP in SPs:\n \n SP[1] = int(SP[1])\n SP.append(tmp)\n tmp += 1\n\nSPs = sorted(SPs, key=lambda x:(x[0],-x[1]), reverse=False)\n\nfor ans in SPs:\n print(ans[2])", "n = int(input())\nx = []\nfor i in range(n):\n s,p=input().split()\n x.append([s,int(p),i+1])\nx.sort(key=lambda x:(x[0],-x[1]))\nfor i in x:\n print(i[2])", "N = int(input())\nl = []\nfor i in range(N):\n s, p = input().split()\n l.append([i+1, s, int(p)])\n\nl = sorted(l, key=lambda x:(x[1], -x[2]))\nfor i in range(N):\n print(l[i][0])", "n=int(input())\nl=[input().split() for i in range(n)]\nl2=[x for x in range(n)]\nbase=list(zip(l2,l))\nans=sorted(base, key=lambda x: int(x[1][1]),reverse=True)\nans=sorted(ans,key=lambda x: x[1][0])\n\nfor i in range(n):\n print(1+ans[i][0])", "n = int(input())\ns = [list(input().split()) for i in range(n)]\nfor i in range(n):\n s[i][1] = int(s[i][1])\n\nq = sorted(s, key=lambda x: x[1])\nq = sorted(q, key =lambda x: x[1],reverse=True)\nq = sorted(q, key=lambda x: x[0])\n\nfor i in range(n):\n print(s.index(q[i])+1)", "N = int(input())\nl = []\nfor i in range(N):\n s, p = input().split()\n l.append([s, int(p), i+1]) \n\n# \u307e\u305a\u70b9\u6570\u3067\u964d\u9806\u306b\u4e26\u3079\u308b\nl = sorted(l, key=lambda x:(x[1]), reverse=True)\n# \u6b21\u306b\u5730\u540d\u3067\u8f9e\u66f8\u9806\u306b\u4e26\u3079\u308b\nl = sorted(l, key=lambda x:(x[0]))\nfor i in range(N):\n print(l[i][2])", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\nimport numpy as np\n\ndef main():\n restaurants=[]\n n = int(input())\n restaurants=[list(input().split()) for _ in range(n)]\n\n for idx,restaurant in enumerate(restaurants):\n restaurants[idx][1]=int(str(restaurant[1]))\n restaurants[idx].append(idx+1)\n restaurants.sort(key=lambda x:x[1],reverse=True)\n restaurants.sort(key=lambda x:x[0].lower())\n for restaurant in restaurants:\n print(restaurant[2])\n\ndef __starting_point():\n main()\n__starting_point()", "n = int(input())\nL = []\nfor i in range(n):\n c = []\n a, b = map(str, input().split())\n c.append(a)\n c.append(100-int(b))\n c.append(i+1)\n L.append(c)\nL.sort()\nfor j in range(n):\n print(L[j][2])", "n=int(input())\nl=[]\nfor i in range(n):\n city,point=input().split()\n point=int(point)\n l.append((city,-point,i+1))\n\nfor i in sorted(l):\n print(i[2])", "n=int(input())\nsp = [input().split() for _ in range(n)]\norde=sorted(sp,key=lambda sp:(sp[0],-int(sp[1])))\nfor i in orde:\n\tprint(sp.index(i)+1)", "N = int(input())\nS = [list(input().split()) for _ in range(N)]\nfor i in S:\n i[1] = 100 - int(i[1])\nfor i in range(N):\n S[i] += i+1,\nS.sort()\nfor i in S:\n print(i[2])", "#!/usr/bin/env python3\nimport sys\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef main():\n N = int(input())\n S = [0] * N\n P = [0] * N\n R = [0] * N\n for i in range(N):\n S[i] , P[i] = list(map(str, input().split()))\n for i in range(N):\n R[i] = i + 1\n for i in range(N):\n P[i] = int(P[i]) * -1\n\n\n Z = list(zip(S, P, R))\n Z = sorted(Z)\n S, P, R = list(zip(*Z))\n\n for i in R:\n print(i)\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nrestaurants = []\nfor i in range(n):\n s, p = input().split()\n restaurants.append((s, int(p)))\nsorted_list = sorted(restaurants, key=lambda x:x[1], reverse=True)\nsorted_list.sort(key=lambda x:x[0])\n\nfor i in range(n):\n print(restaurants.index(sorted_list[i]) + 1)", "n = int(input())\nrest = [list([*input().split(),i+1]) for i in range(n)]\nrest = list(sorted(rest, key = lambda x : (x[0],100 - int(x[1]))))\nfor i in rest:\n print(i[2])", "n = int(input())\nlst = []\nfor i in range(n):\n s, p = input().split()\n lst.append([s, -(int(p)), i+1])\nlst.sort()\nfor i in range(n):\n print(lst[i][2])", "n=int(input())\nl=[]\nfor i in range(n):\n city,point=input().split()\n point=int(point)\n l.append((city,point))\n\nl=sorted(enumerate(l), key=lambda x:(x[1][0],-x[1][1]))\n\nfor i,(c,p) in l:\n print(i+1)", "N = int(input())\nguidebook = []\nfor i in range(N):\n S, P = input().split()\n P = int(P)\n guidebook.append([S,P])\n\nnew_guidebook = sorted(guidebook, key=lambda x: (x[0],-x[1]))\n\nfor i in new_guidebook:\n print((guidebook.index(i)+1))\n", "n = int(input())\n\nrestaurant = []\n\nfor i in range(n):\n score_list = input().split()\n score_list.append(i+1)\n score_list[1] = int(score_list[1])\n restaurant.append(score_list)\n\nfor l in sorted(restaurant, key=lambda x: (x[0], -x[1])):\n print(l[2])", "\nurl = \"https://atcoder.jp//contests/abc128/tasks/abc128_b\"\n\ndef main():\n n = int(input())\n town = {}\n for i in range(n):\n t = list(input().split())\n town.setdefault(t[0], {})\n town[t[0]][i+1] = int(t[1])\n town = sorted(list(town.items()), key=lambda x:x[0])\n for k in town:\n sort_town = sorted(list(k[1].items()), key=lambda x:x[1], reverse=True)\n for v in sort_town:\n print((v[0]))\n\n\ndef __starting_point():\n main()\n\n__starting_point()"] | {"inputs": ["6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n", "10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n", "39\nem 22\nl 27\nasiqdflmv 24\ntmlifuzz 62\nem 64\ntmlifuzz 35\nem 8\nasiqdflmv 16\ntmlifuzz 51\nkzmww 67\nl 60\ntmlifuzz 69\nasiqdflmv 29\nasiqdflmv 80\nasiqdflmv 40\nkzmww 79\nkzmww 86\ntmlifuzz 14\nkzmww 3\ntmlifuzz 11\ntmlifuzz 47\nkzmww 39\ntmlifuzz 83\nl 9\nkzmww 15\nkzmww 89\nl 73\nl 70\nl 21\nem 38\nem 72\nl 56\nem 17\ntmlifuzz 1\nasiqdflmv 100\ntmlifuzz 32\nkzmww 88\nem 93\nkzmww 91\n", "50\nyz 58\nlzjbh 74\nxgib 33\naccve 86\nxipd 6\ngkjbd 81\nxipd 100\nlmtawiqb 85\nyzexcuvb 94\nxipd 54\nztaowejci 80\nhjrjd 21\nwddjyti 63\nyzexcuvb 53\nvlqx 99\ngdcdycrtr 89\ndynbekwg 96\ngdcdycrtr 92\nhjrjd 55\ntiktcynm 90\njvug 62\nqcvr 97\nddrolznmof 44\nvvny 13\nmmegpdfwkc 60\nsguxsilzij 35\nddrolznmof 37\nyzexcuvb 43\nlmtawiqb 49\nxgib 93\nsguxsilzij 18\nxipd 59\nyzexcuvb 82\nlmtawiqb 87\nxipd 19\nhjrjd 56\nqcvr 15\nsguxsilzij 76\nyz 38\nal 40\najyv 39\ngdcdycrtr 14\nyzexcuvb 11\nwddjyti 23\nlmtawiqb 12\ndynbekwg 30\nxipd 66\nwddjyti 1\njvug 84\nsguxsilzij 0\n", "1\nv 81\n", "100\nsjcgcvldl 23\niyzgsoes 80\nu 82\nceooyrdyri 34\nhfzlpcs 100\nykfpusci 17\nvkke 94\nqnartzvpb 86\njqxf 35\nvsemwdhc 31\njuteior 78\nbvdq 3\nocnma 84\nkidwanqdvn 52\nmjopq 57\ntqfq 38\nikrqwzh 61\nxlcbfaszw 96\nceooyrdyri 10\nrdz 98\nxxywgn 64\nfbft 74\nebh 29\npio 95\nebh 88\nph 50\naqapninv 40\ncvvpogpf 27\nwlpycdqn 36\npc 13\niwltgbpsnp 41\npc 85\nsqtea 30\nxjjz 83\nxxywgn 47\nocnma 69\ndstjyf 5\nopibl 65\nu 12\nzui 97\nduaa 55\naszjtcz 67\nnfrh 0\nhw 19\nwatros 92\nbkkimcp 99\nbhn 16\nfypezmuybz 76\nbhl 68\nhfzlpcs 26\nanx 49\nhw 75\nbu 2\nocnma 25\nycocgzdk 89\nbhl 7\nemryxddrlq 1\nmjopq 87\nqnartzvpb 90\nanx 70\nxjjz 79\nopibl 77\nalamvxysd 43\nvkke 24\nalamvxysd 15\ncudzx 62\nfwgnh 56\naszjtcz 51\nrww 66\nfypezmuybz 22\npio 42\nrdz 59\nflketqklyd 32\nemryxddrlq 63\nyejrl 9\nmjopq 46\nzui 28\nvkke 73\nzcsgsj 44\nzmmsgtpr 39\nfbft 91\nuuyiwao 53\nopibl 72\nbhl 71\nntesxc 37\nuxyte 14\nw 33\nhw 21\nbxg 81\ndstjyf 48\nyejrl 60\nu 93\nbcwwcw 58\nbxg 4\njd 11\npio 18\nw 8\nbvdq 6\ncu 45\nmjopq 20\n", "100\ny 100\ny 14\ny 57\ny 28\ny 25\nlkhva 42\ny 98\ny 78\nlkhva 56\nlkhva 31\nlkhva 86\nlkhva 24\ny 37\nlkhva 8\nlkhva 50\nlkhva 49\ny 13\nlkhva 84\ny 39\nlkhva 4\nlkhva 3\nlkhva 88\ny 75\nlkhva 69\ny 85\nlkhva 68\nlkhva 70\nlkhva 61\nlkhva 64\ny 33\nlkhva 77\ny 80\nlkhva 30\nlkhva 26\nlkhva 82\ny 52\nlkhva 47\ny 46\nlkhva 9\nlkhva 48\nlkhva 45\ny 76\nlkhva 99\ny 83\ny 54\nlkhva 73\nlkhva 41\nlkhva 35\ny 95\ny 94\nlkhva 65\ny 58\ny 16\ny 15\ny 89\nlkhva 40\ny 11\nlkhva 51\ny 6\nlkhva 0\ny 97\nlkhva 90\ny 1\ny 7\ny 36\nlkhva 21\ny 38\nlkhva 19\ny 53\ny 66\ny 91\ny 12\ny 72\ny 22\nlkhva 55\nlkhva 59\nlkhva 20\ny 2\ny 74\ny 18\nlkhva 71\ny 29\ny 93\ny 63\ny 92\ny 5\ny 87\ny 32\ny 17\nlkhva 27\nlkhva 60\nlkhva 81\ny 79\nlkhva 62\nlkhva 67\ny 34\nlkhva 44\ny 23\nlkhva 10\ny 96\n"], "outputs": ["3\n4\n6\n1\n5\n2\n", "10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n", "35\n14\n15\n13\n3\n8\n38\n31\n5\n30\n1\n33\n7\n39\n26\n37\n17\n16\n10\n22\n25\n19\n27\n28\n11\n32\n2\n29\n24\n23\n12\n4\n9\n21\n6\n36\n18\n20\n34\n", "4\n41\n40\n23\n27\n17\n46\n18\n16\n42\n6\n36\n19\n12\n49\n21\n34\n8\n29\n45\n2\n25\n22\n37\n38\n26\n31\n50\n20\n15\n24\n13\n44\n48\n30\n3\n7\n47\n32\n10\n35\n5\n1\n39\n9\n33\n14\n28\n43\n11\n", "1\n", "63\n65\n60\n51\n27\n42\n68\n93\n84\n49\n56\n47\n46\n53\n98\n12\n89\n94\n4\n19\n99\n66\n28\n90\n37\n41\n25\n23\n74\n57\n81\n22\n73\n67\n48\n70\n5\n50\n52\n88\n44\n17\n31\n2\n95\n9\n11\n14\n58\n15\n76\n100\n43\n85\n13\n36\n54\n62\n83\n38\n32\n30\n26\n24\n71\n96\n59\n8\n20\n72\n69\n1\n33\n16\n92\n3\n39\n82\n86\n7\n78\n64\n10\n87\n97\n45\n29\n34\n61\n18\n21\n35\n55\n91\n75\n6\n79\n80\n40\n77\n", "43\n62\n22\n11\n18\n35\n92\n31\n46\n81\n27\n24\n26\n95\n51\n29\n94\n28\n91\n76\n9\n75\n58\n15\n16\n40\n37\n41\n97\n6\n47\n56\n48\n10\n33\n90\n34\n12\n66\n77\n68\n99\n39\n14\n20\n21\n60\n1\n7\n61\n100\n49\n50\n83\n85\n71\n55\n87\n25\n44\n32\n93\n8\n42\n23\n79\n73\n70\n84\n52\n3\n45\n69\n36\n38\n19\n67\n13\n65\n96\n30\n88\n82\n4\n5\n98\n74\n80\n89\n53\n54\n2\n17\n72\n57\n64\n59\n86\n78\n63\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 28,502 | |
350e1843270e6bfb04b4d35aa9097b2f | UNKNOWN | Takahashi has K 500-yen coins. (Yen is the currency of Japan.)
If these coins add up to X yen or more, print Yes; otherwise, print No.
-----Constraints-----
- 1 \leq K \leq 100
- 1 \leq X \leq 10^5
-----Input-----
Input is given from Standard Input in the following format:
K X
-----Output-----
If the coins add up to X yen or more, print Yes; otherwise, print No.
-----Sample Input-----
2 900
-----Sample Output-----
Yes
Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen. | ["k,x = map(int,input().split())\nprint(\"Yes\" if k*500 >= x else \"No\")", "k,x=map(int,input().split())\nif(500*k>=x):\n print(\"Yes\")\nelse:\n print(\"No\")", "K, X = map(int, input().split())\n\nif K * 500 >= X :\n print('Yes')\nelse :\n print('No')", "K, X = map(int, input().split())\n\nif 500*K >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "#150-A\n\nK,X = list(map(int,input().split()))\n\nif 500 * K >= X:\n print(\"Yes\")\n\nelse:\n print(\"No\")\n", "k, x = map(int, input().split())\n\nif 500*k >= x:\n print('Yes')\nelse:\n print('No')", "k, x = list(map(int, input().split()))\n\nif k*500 >= x:\n print('Yes')\nelse:\n print('No')\n", "K, X=map(int, input().split(\" \"))\n\nif 500*K>=X:\n print('Yes')\nelse:\n print('No')", "K, X = map(int, input().split())\n\nif K * 500 >= X:\n print('Yes')\nelse:\n print('No')", "k,x=map(int,input().split())\nif 500*k>=x : print(\"Yes\")\nelse : print(\"No\")", "K, X = list(map(int, input().split()))\nif (X <= ( K * 500 )):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "k,x=map(int,input().split())\n\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "num500, total = map(int, input().split())\nprint('Yes' if num500 * 500 >= total else 'No')", "K, X = map(int, input().split())\nif K * 500 >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\n\nif (500 * k) >= x:\n print(\"Yes\")\n\nelse:\n print(\"No\")", "K, X = map(int, input().split())\n\nif K * 500 >= X: print('Yes')\nelse: print('No')", "k,x=map(int,input().split())\nprint(['No','Yes'][500*k>=x])", "k, x = map(int,input().split())\n\nif 500 * k >= x:\n print('Yes')\nelse:\n print('No')", "k, x = map(int, input().split())\n\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = list(map(int, input().split()))\n\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print('No')\n", "k,x = map(int,input().split())\nif 500*k >= x :\n print('Yes')\nelse :\n print('No')", "k, x = list(map(int, input().split()))\nprint('Yes') if k *500 >= x else print('No')", "k,x=(int(y) for y in input().split())\n\nif 500*k>=x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = map(int, input().split())\nif k*500 >= x:\n print('Yes')\nelse:\n print('No')", "a,b=input().split();print('YNeos'[eval(a+'*500<'+b)::2])", "k,x = [int(x) for x in input().split()]\nif k * 500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = list(map(int,input().split()))\nprint(('Yes' if 500*k>=x else 'No'))\n", "k, x = map(int, input().split())\n\nif 500 * k >= x:\n print('Yes')\nelse:\n print('No')", "import sys\nK, X = map(int, next(sys.stdin).split())\nprint('Yes' if K * 500 >= X else 'No')", "K,X=map(int,input().split())\nif K*500<X:\n print('No')\nelse:\n print('Yes')", "k,x=map(int,input().split())\nif (k*500>=x):\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\nprint(\"Yes\" if 500*k>=x else\"No\")", "k, x = map( int, input().split() )\n\nif 500 * k < x:\n print( \"No\" )\nelse:\n print( \"Yes\" )", "#!/usr/bin/env python3\n\ndef main():\n k, x = list(map(int, input().split()))\n print((\"Yes\" if 500 * k >= x else \"No\"))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "ri = lambda S: [int(v) for v in S.split()]\ndef rii(): return ri(input())\n \nK, X = rii()\n\nprint((\"Yes\" if K * 500 >= X else \"No\"))\n", "k,x = map(int, input().split())\nif k*500 < x:\n print('No')\nelse:\n print('Yes')", "K, X = list(map(int, input().split()))\nprint((\"Yes\" if 500 * K >= X else \"No\"))\n", "K,X = map(int,input().split())\nif K*500 >= X:\n print('Yes')\nelse:\n print('No')", "K,X=map(int,input().split())\nif 500*K>=X:\n print('Yes')\nelse:\n print('No')", "k, x = map(int, input().split())\nprint(\"Yes\" if 500*k >= x else \"No\")", "K, X = map(int, input().split())\nprint('Yes' if 500 * K >= X else 'No')", "k, x = map(int, input().split())\nif k*500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\nprint('Yes' if 500*k >= x else 'No')", "\ndef main():\n k, x = map(int, input().split(\" \"))\n if 500*k >= x:\n print(\"Yes\")\n else:\n print(\"No\")\n\ndef __starting_point():\n main()\n__starting_point()", "m = input().split(\" \")\nprint(\"Yes\" if ((int(m[0]) * 500 ) >= int(m[1])) else \"No\")", "k,x=map(int,input().split())\nif k*500>=x:\n print(\"Yes\")\nelse:\n print(\"No\")", "a = list(map(int,input().split()))\nif int(a[0])*500 >= int(a[1]):\n print(\"Yes\")\nelse:\n print(\"No\")", "K,X=map(int,input().split())\nif K*500>=X:\n print('Yes')\nelse:\n print('No')", "k, x = map(int,input().split())\nprint('Yes' if 500*k >= x else 'No')", "k,x=map(int,input().split())\nif 500*k>=x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = map(int, input().split())\nprint('Yes' if 500*k >= x else 'No')", "K,X = map(int,input().split())\n\n\nif K*500 >= X:\n print('Yes')\nelse:\n print('No')", "K, X = list(map(int,input().split()))\n\nif 500 * K >= X:\n print('Yes')\nelse:\n print('No')\n", "k, x = map(int, input().split())\nprint(\"YNeos\"[500*k<x::2])", "import math\nfrom collections import Counter\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nk,x = mi()\n\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "K,X= map(int,input().split())\n\nif 500*K >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "K, X = map(int, input().split())\nprint('No' if 500 * K < X else 'Yes')", "k, x = map(int, input().split())\nprint(\"Yes\") if k * 500 >= x else print(\"No\")\n", "k,x=map(int,input().split())\nmoney=k*500\nif x<=money:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = map(int, input().split())\nif 500 * k >= x:\n print('Yes')\nelse:\n print('No')", "import sys\ninput = sys.stdin.readline\n\nk, x = map(int, input().split())\nif k * 500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = list(map(int, input().split()))\nif k * 500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a,b = map(int, input().split(\" \"))\nprint(\"Yes\") if 500 * a >= b else print(\"No\")", "k,x=map(int,input().split())\nif 500*k>=x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = map(int, input().split())\nprint('Yes' if x <= 500*k else 'No')", "K, X = map(int, input().split())\n\nif K*500 >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "k , x = input().split()\nk , x = [int(k) , int(x)]\nif k*500 >= x :\n print(\"Yes\")\nelse:\n print(\"No\")", "n=input()\nx=n.split()\nif 500*int(x[0])>=int(x[1]):\n print('Yes')\nelif 500*int(x[0])<int(x[1]):\n print('No')", "def resolve():\n k,x = map(int,input().split())\n print('Yes' if k*500>=x else 'No')\nresolve()", "k, x = map(int, input().split())\nif k * 500 >= x:\n print('Yes')\nelse:\n print('No')", "K, X = map(int,input().split())\nif K * 500 >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "# coding: utf-8\n# Your code here!\nk,x=map(int,input().split())\nif 500*k>=x:\n print(\"Yes\")\nelse:\n print(\"No\")", "K,X = map(int,input().split())\nans = 500 * K\nif ans >= X:\n print(\"Yes\")\n return\nprint(\"No\")", "K, X = [int(n) for n in input().split()]\nprint(('Yes' if 500 * K >= X else 'No'))\n", "k, x = map(int, input().split())\nif k*500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "N,X = map(int,input().split())\n\nif N*500 >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\nif 500 * k < x:\n print('No')\nelse:\n print('Yes')", "k,x = map(int,input().split())\n\nif 500 * k >= x :\n print('Yes')\nelse:\n print('No')", "K, X = map(int, input().split())\nif 500 * K >= X:\n print('Yes')\n return\nelse:\n print('No')\n return", "K,X=map(int,input().split())\nif 500*K>=X:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,s=map(int, input().split())\n \nif 500*a>=s:\n print('Yes') \nelse:\n print('No')", "#ABC150A\nk,x = list(map(int,input().split()))\nprint((\"Yes\" if k*500>=x else \"No\"))\n", "k,x=map(int,input().split())\nprint('YNeos'[500*k<x::2])", "K,X = map(int,input().split())\n\nif K*500>=X:\n print ('Yes')\nelse:\n print ('No')", "k,x = map(int, input().split())\nprint(\"Yes\" if k * 500 >= x else \"No\")", "k, x = list(map(int, input().split()))\n\nif k*500 >= x:\n print('Yes')\nelse:\n print('No')\n \n", "K,X = map(int,input().split())\n\nans = K * 500\nif ans >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = list(map(int,input().split()))\n\nif(k*500>=x):\n\tprint(\"Yes\")\nelse:\n\tprint(\"No\")\n", "N,X=map(int,input().split())\nif N*500>=X:\n print('Yes')\nelse:\n print('No')", "a,s=list(map(int, input().split()))\n\nif 500*a>=s:\n print('Yes') \nelse:\n print('No')\n", "K,X = map(int,input().split())\nif 500*K >= X:\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x=map(int,input().split())\n\nif (k*500)>=x:\n print('Yes')\nelse:\n print('No')", "a,b = map(int, input().split())\n\nprint('Yes' if a*500 >= b else 'No')", "K,X = map(int,input().split())\nif(500*K >= X):\n print(\"Yes\")\nelse:\n print(\"No\")", "k,x = map(int,input().split())\nprint('Yes' if x<=k*500 else 'No')", "k,x = map(int,input().split())\nif k*500 >= x:\n print(\"Yes\")\nelse:\n print(\"No\")", "k, x = [int(i) for i in input().split()]\nif x <= 500 * k:\n print('Yes')\nelse:\n print('No')", "k,x=map(int, input().split()) \nprint(\"Yes\" if 500*k>=x else \"No\")", "k,x = map(int,input().split())\n\nif 500*k >= x:\n print(\"Yes\")\nelse:\n print(\"No\")"] | {"inputs": ["2 900\n", "1 501\n", "4 2000\n", "100 100000\n", "1 500\n", "84 42001\n", "13 6498\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 9,764 | |
70f5e6d48bc9e96d7cf742024e0583fd | UNKNOWN | Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
- Throw the die. The current score is the result of the die.
- As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
- The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
-----Constraints-----
- 1 β€ N β€ 10^5
- 1 β€ K β€ 10^5
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K
-----Output-----
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
-----Sample Input-----
3 10
-----Sample Output-----
0.145833333333
- If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.
- If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.
- If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.
Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333. | ["n,k = map(int,input().split())\n\nans = 0\n\nfor i in range(1,n+1):\n if i>=k:\n ans += (1/n)\n continue\n x = 1\n while 1:\n i *= 2\n if i>=k:\n break\n else:x+=1\n ans += (1/n)*(1/2)**x\nprint(ans)", "import math\n\nN, K = map(int, input().split())\n\nres = max(0, N - K + 1)\n\nfor i in range(1, min(N + 1, K)):\n res += 0.5**math.ceil(math.log2(K / i))\n\nprint(res / N)", "n,k=map(int,input().split())\n\nans = 0\n\nfor i in range(1,n+1):\n p = i\n r = 1\n while p < k:\n p*=2\n r/=2\n ans+=r\n\nans/=n\n\nprint(ans)", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Sep 12 23:11:33 2020\n\n@author: liang\n\"\"\"\n\nN, K = map(int, input().split())\nans = 0\nfor i in range(1,N+1):\n tmp = i\n count = 0\n while tmp< K:\n count += 1\n tmp *= 2\n ans += 1/2**count\nans /= N\nprint(ans)", "def p(n, k):\n if n >= k:\n return 1\n num = 0\n while n < k:\n n *= 2\n num += 1\n return 1 / 2 ** num\n\nN, K = map(int, input().split())\n\nans = 0\nfor n in range(1, N + 1):\n ans += p(n, K)\n\nans /= N\n\nprint(ans)", "N,K=list(map(int,input().split()))\nans=0\nfor i in range(N):\n temp=K/(i+1)\n for j in range(100):\n if 2**(j)>=temp:\n break\n ans+=(1/N)*(1/2)**j\nprint(ans)\n", "import math\n\nn, k = map(int, input().split())\n\nans = 0\nfor i in range(1, n+1):\n a = max(math.ceil(math.log2(k/i)), 0)\n ans += 0.5**a\nprint(ans/n)", "import sys\ninput = sys.stdin.readline\nn,k = list(map(int,input().split()))\n#a = list(map(int,input().split()))\n\nimport math\npar = 0\n\nfor i in range(1,n+1):\n tmp = i\n cnt = 0\n while True:\n if tmp >= k:\n break\n tmp *= 2\n cnt += 1\n if cnt == 0:par += 1/n\n else :par += 1/(2**cnt*n)\n\nprint(f'{par:.12f}')\n", "N, K = map(int, input().split())\n\nans = 0\nfor i in range(1, N+1):\n cnt = 0\n num = i\n while num < K:\n num *= 2\n cnt += 1\n ans += 1 / N * (1 / 2)**cnt\nprint(ans)", "n,k=list(map(int,input().split()))\n\nans=0\nfor i in range(1,n+1):\n num=i\n p=1/n\n if num>=k:\n ans+=p\n continue\n while num<k:\n num=num*2\n p=p*(1/2)\n ans+=p\n \nprint(ans)\n", "n, k = list(map(int, input().split()))\nrate = 0\nfor i in range(1,n+1):\n score = i\n prob = 1 / n\n while score < k:\n score *= 2\n prob /= 2\n rate += prob\nprint(rate)\n", "import math\n\nn, k = map(int, input().split())\nlog2 = math.log10( 2)\nans = 0\nfor i in range(1,n+1):\n temp = i\n num = 1/n\n while temp < k:\n num /= 2\n temp *= 2\n ans += num\n\nprint(ans)", "N, K=map(int,input().split())\nans = 0\nfor i in range(1,N+1):\n cnt = 0\n while i < K:\n i *= 2\n cnt += 1\n ans += (1/2)**cnt\nprint(ans/N)", "n,k=map(int,input().split())\nans=0\nfor i in range(1,n+1):\n cnt=0\n while i<k:\n i*=2\n cnt+=1\n ans+=(1/2)**cnt\nprint(ans/n)", "#Answer\nN, K = input().split()\nN = int(N)\nK = int(K)\n\nimport math\nM = math.log(K,2)\nP = sum([1/(2**max(math.ceil(M - math.log(i,2)), 0)) for i in range (1, N+1)])/N\nprint(P)", "N,K = map(int, input().split())\n\nans = 0\n\nfor i in range(1, N+1):\n j = 1/N\n while i < K:\n i *= 2\n j /= 2\n ans += j\n\nprint(ans)", "n, K = map(int, input().split())\n\np = 1/n\n\nans = 0\nfor result in range(1, n+1):\n # result = 1,2,3\n k = K\n k /= result\n cnt = 0\n while k > 1:\n k /= 2\n cnt += 1\n ans += p * (0.5)**cnt\nprint(ans)", "from math import ceil as c\nfrom math import log2 as l\n\nn, k = map(int,input().split())\nans, m = 0, 1 / n\n\nfor i in range(1, n+1):\n if i < k:\n ans += (0.5 ** c(l(k/i))) * m\n else:\n ans += m\n\nprint(ans)", "n,k = map(int,input().split())\n\nnum = 0\n\nfor i in range(1,n+1):\n j = 0\n while True:\n if i*(2**j) >=k:\n break\n j +=1\n \n \n num += 1/(n*(2**j))\n\nprint(num)", "n,k=map(int,input().split())\n\na=[]\nfor i in range(1,n+1):\n x=i\n b=0\n while x<k:\n x=x*2\n b+=1\n a.append((float(1/n)*(0.5)**b))\n\n\nprint(sum(a))", "def main():\n N,K = list(map(int,input().split()))\n ans = 0\n dict = {}\n cnt = 0\n tmp = 1/N\n for i in range(N,0,-1):\n i = float(i)\n if K <= i:\n ans += tmp*(0.5**cnt)\n else:\n while True:\n K = K/2\n cnt += 1\n if K <= i:\n break\n ans += tmp*(0.5**cnt)\n return ans\n\nprint((main()))\n", "n, k = map(int, input().split())\nans = 0\nfor i in range(1, n+1):\n cnt = 0\n while i < k:\n i *= 2\n cnt += 1\n ans += 1 / n / (2 ** cnt)\nprint(ans)", "import math\nn,k = map(int, input().split())\nc = 0\nfor i in range(1,n+1):\n if k//i == 0:\n c += 1/n\n else:\n t = math.ceil(math.log2(k/i))\n c += 0.5**t/n\nprint(c)", "N, K = map(int, input().split())\n\n# \u4f55\u56de2\u3092\u304b\u3051\u308b\u3068\u8d85\u3048\u308b\u304b\u3002\ndef func1(i, k):\n ans = 0\n num = i\n end = False\n if num >= k:\n return 0\n while(not end):\n ans += 1\n num *= 2\n if num >= k:\n end = True\n break\n return ans\n\n\nans = 0\nfor initial_score in range(1, N+1):\n ans += (1/N) * (1/2) ** func1(initial_score, K)\nprint(ans)", "n,k=list(map(int,input().split()))\n\nans= 0\nfrom math import ceil,log2\n\nfor i in range(1,n+1):\n if i<k:\n a = ceil(log2(k/i))\n ans +=(1/n)*(1/2)**a\n else:\n ans += (1/n)\n\nprint(ans)\n", "import math\nn,k = map(int,input().split())\nnum = 0\nfor i in range(1,n + 1):#\u30b5\u30a4\u30b3\u30ed\u306e\u51fa\u305f\u76ee\n if i >= k:\n num += 1 / n\n else:\n num += (1 / (n * (2 ** math.ceil(math.log(k / i,2)))))\nprint(num)", "n,k=map(int,input().split())\nans=0\nfor i in range(1,n+1):\n res=0\n while i<k:\n i*=2\n res+=1\n ans+=(1/2)**res\nprint(ans/n)", "#ABC126 C\n\nimport math\nN,K = map(int,input().split())\nP = 0\nfor i in range(1,N+1):\n if i >= K:\n P += 1/N\n else:\n P += (1/N)*(0.5)**(math.ceil(math.log(K/i,2)))\n \nprint(P)", "import sys\n\nN, K = map(int, sys.stdin.readline().split())\nans = 0\nfor i in range(1, N+1):\n if K <= i:\n ans += 1 / N\n else:\n count = 0\n while i < K:\n count += 1\n i *= 2\n ans += (1 / N) * 0.5 ** count\n\nprint(ans)", "n, k = map(int,input().split())\n\nper = 0\n\nfor i in range(1,n+1):\n a = 0\n while i<k:\n a += 1\n i *= 2\n per += (1/n) * (0.5**a)\n\nprint(per)", "n, k = map(int, input().split())\n\nans = 0\nfor i in range(1, n + 1):\n cnt = 0\n while i * 2**cnt < k:\n cnt += 1\n ans += 1 / (n * 2**cnt)\n\nprint(ans)", "D, P = map(int, input().split()) \nans = 0.0\ndef func(i):\n t = 0\n while(i < P):\n i *= 2\n t += 1\n return t\n\nfor i in range(1, D + 1):\n ans += float((1/D)) * float(((1 / 2) ** func(i)))\n\nprint(ans)", "#import math\n#import itertools\n#from collections import deque\n\nINT = lambda: int(input())\nINTM = lambda: map(int,input().split())\nSTRM = lambda: map(str,input().split())\nSTR = lambda: str(input())\nLIST = lambda: list(map(int,input().split()))\nLISTS = lambda: list(map(str,input().split()))\n\ndef do():\n n,k=INTM()\n ans=0\n for i in range(1,n+1):\n temp=i\n ct=0\n while temp<k:\n ct+=1\n temp*=2\n ans+=(1/(n*(2**ct)))\n \n print(ans)\n\n\ndef __starting_point():\n do()\n__starting_point()", "N,K = map(int,input().split())\nresult = 0\nfor i in range(1,N+1):\n prob = 1\n count = i \n while count < K:\n prob *= 0.5\n count *= 2\n result += prob /N\nprint(result)", "N,K = map(int,input().split())\nans = 0\nfor i in range(1,N+1):\n if i >= K:\n ans += 1/N\n else:\n x = 0\n while i < K:\n i *= 2\n x += 1\n ans += (1/N) * (1/2)**x\nprint(ans)", "import math\nn,k = map(int,input().split())\n\nans = 0\nif n < k:\n for j in range(1,n+1):\n a = math.ceil(math.log(k/j,2))\n ans += 1/n * (1/2 ** a)\n print(ans)\n\nelse:\n for j in range(1,k):\n a = a = math.ceil(math.log(k/j,2))\n ans += 1/n * (1/2 ** a)\n ans += (n-k+1)/n \n print(ans)", "def LI():\n return list(map(int, input().split()))\n\n\nN, K = LI()\nans = 0\nfor i in range(1, N+1):\n x = 1\n count = i\n while count < K:\n count *= 2\n x /= 2\n ans += x/N\nprint(ans)\n", "N, K = map(int,input().split())\nans = 0\nfor n in range(1,N+1):\n score = n\n coin = 0\n while(score < K):\n coin += 1\n score *= 2\n ans += 1/(N*2**coin)\n\nprint(ans)", "from math import log2\nimport decimal\n\nN, K = map(int, input().split())\n\ndecimal.getcontext().prec = 28\n\nans = decimal.Decimal(0)\n\nfor i in range(1, N+1):\n if i < K:\n power = -(-(log2(K) - log2(i))//1)\n prob = decimal.Decimal(1/((2**power) * N))\n else:\n prob = decimal.Decimal(1/N)\n\n #print(prob)\n ans = decimal.Decimal(ans + prob)\n #print(ans)\n\nprint(ans)", "import math\n\nN, K = [int(x) for x in input().split()]\n\nS = 0\nfor i in range(1, N + 1):\n a = 0\n while i < K:\n a += 1\n i *= 2\n S += 0.5 ** a\n\nans = S / N\nprint(ans)", "N, K = map(int, input().split())\n\nans = 0\nfor i in range(1, N+1):\n p = 1\n while i < K:\n p *= 0.5\n i *= 2\n ans += p/N\n \nprint(ans)", "r=input().split()\nN=int(r[0])\nK=int(r[1])\nans=0\nfor i in range(1,N+1):\n x=i\n n=0\n while x<=K-1:\n x=x*2\n n+=1\n ans+=(1/N)*((1/2)**n)\nprint(ans)", "N, K = map(int, input().split())\npro=0.0\nfor i in range(1,N+1):\n n=i\n j=0\n while(True):\n if n >= K:\n break\n n=n*2\n j=j+1\n pro=pro+(1/N)*(0.5)**(j)\nprint(pro)", "from math import log2, ceil\nN, K = list(map(int, input().split()))\n\nans = 0\nj = 1.0\nfor x in range(N, 0, -1):\n if x >= K:\n ans += 1.0 * (1 / N)\n else:\n while x * j < K:\n j *= 2.0\n ans += (1.0 / j) * (1 / N)\nprint(ans)\n", "N,K=map(int,input().split())\nans=max(0,(N-K+1)/N)\nfor dice in range(1,min(N,K-1)+1):\n for time in range(1,len(bin(K))+2):\n dice*=2\n if dice>=K:\n ans+=1/(N*(2**time))\n break\nprint(ans)", "from math import ceil as c\nfrom math import log2 as l\n\nn, k = map(int,input().split())\nans = 0\n\nfor i in range(1, n+1):\n if i < k:\n ans += (0.5 ** c(l(k/i))) / n\n else:\n ans += 1 / n\n\nprint(ans)", "n,k = map(int,input().split())\nans = 0\nfor i in range(1,n+1):\n prob = 1\n now = i\n while now < k:\n now = 2 * now\n prob = prob / 2\n ans += prob / n\nprint(ans)", "import math\nN, K = map(int, input().split())\nif K == 1:\n print(1)\n return\n\nans = 0\n\nfor i in range(1, N + 1):\n if i >= K:\n ans += (1 / N)\n else:\n temp = math.log(K / i, 2)\n nu = pow(2, math.ceil(temp))\n ans += (1 / (nu * N))\nprint(ans)", "N,K=map(int,input().split())\nans=0\nfor i in range(N):\n x=i+1\n ave=1/N\n while x<K:\n x*=2\n ave/=2\n ans+=ave\nprint(ans)", "n,k = map(int,input().split())\nans = 0\nfor i in range(1,n+1):\n t = 1\n x = i\n while x<k:\n t*=0.5\n x*=2\n ans+=t/n\nprint(ans)", "n, k = map(int, input().split())\nans = 0\nfor tmp in range(1,n+1):\n cnt = 0\n while tmp < k:\n tmp *= 2\n cnt += 1\n ss = n*2**cnt\n ans += 1/ss\nprint(ans)", "import math\n\nn, k = map(int, input().split())\nans = 0\nx = [max(0, math.ceil(math.log2(k / i))) for i in range(1, n + 1)]\nfor i in x:\n ans += ((2 ** i) * n) ** -1 \nprint(ans)", "n,k=map(int,input().split())\nans=0\nfor i in range(1,n+1):\n for j in range(10**5):\n if i*2**j>=k:\n ans+=(0.5)**j/n\n break\nprint(ans)", "N, K = map(int, input().split())\n \nans = 0\n\nfor i in range(1, N+1):\n # \u30b3\u30a4\u30f3\u3092\u6295\u3052\u308b\u56de\u6570t\u3092\u6c42\u3081\u308b\n t = 0\n while True:\n if i*(2**t) >= K: break\n t += 1\n # \u78ba\u7387\u3092\u8db3\u3059\n ans += (1/N)*((1/2)**t)\n \nprint(ans)", "N,K = map(int, input().split())\n \nans = 0\n \nfor i in range(1, N+1):\n j = 1/N\n while i < K:\n i *= 2\n j /= 2\n ans += j\n \nprint(ans)", "N, K = map(int, input().split())\npro=0.0\nfor i in range(1,N+1):\n n=i\n j=0\n while(True):\n if n >= K:\n break\n n=n*2\n j=j+1\n pro=pro+(1/N)*(0.5)**(j)\nprint(pro)", "n,k = map(int,input().split())\n\nsum : float = 0.0\nfor i in range(1,n+1):\n ret : float = 1/n\n tmp = i\n while(tmp < k):\n tmp *= 2\n ret /= 2\n if(tmp != 0):\n sum += ret \nprint(sum)", "N,K=map(int,input().split())\nans=0\nfor i in range(N):\n prob=1/N\n temp=i+1\n while temp<K:\n temp*=2\n prob*=0.5\n ans+=prob\n\nprint(ans)", "n,k = map(int,input().split())\nans = 0\nfor i in range(1,n+1):\n tokuten = i\n tmp = 1/n\n while tokuten<k:\n tokuten *= 2\n tmp = tmp/2\n #print(tmp)\n ans += tmp\nprint(ans)", "import math\nN,K = map(int,input().split())\nprob = 0\nfor i in range(1,N+1):\n win_seq = max(math.ceil(math.log2(K/i)),0)\n prob += (1/2)**win_seq\nprint(prob/N)", "N, K = list(map(int, input().split()))\nA = 1\nans = 0\n\n\n\nwhile (A <= N):\n count = 0\n T = A\n while (T<K):\n T = T*2\n count += 1\n ans += float((1/N)*(1/2)**count)\n A += 1\n \nprint(ans)\n", "import math\nN, K = map(int, input().split())\n \nans = 0\n\n# \u76ee\u304cK-1\u4ee5\u4e0b => \u30b3\u30a4\u30f3\u304c ceil(log2(K/i)) \u56de\u9023\u7d9a\u3067\u8868\u3067\u52dd\u3061\n# \u76ee\u304cK\u4ee5\u4e0a => \u52dd\u3061\u78ba\u5b9a\nfor i in range(1, N+1):\n if i <= K-1: ans += (1/N)*(1/2)**math.ceil(math.log2(K/i))\n else: ans += 1/N\nprint(ans)", "n, k = list(map(int, input().split()))\nans = 0\nfor i in range(1, n+1):\n cnt = 0\n while True:\n if 2**cnt >= k/i:\n break\n cnt += 1\n ans += (1/n)*(1/2)**cnt\nprint(ans)\n", "N,K=list(map(int,input().split()))\nans=0\nfor i in range(1,N+1):\n x=i\n p=1\n while x<K:\n p/=2\n x<<=1\n ans+=p\nprint((ans/N))\n", "N, K = map(int, input().split())\n\nans = 0.0\nfor i in range(1, N + 1):\n x = 0\n while i * (2 ** x) < K:\n x += 1\n\n ans += 1 / (N * 2 ** x)\n\nprint(ans)", "\nN, K = list(map(int, input().split()))\nanswer = 0\nfor i in range(1, N+1):\n cnt = 0\n while i < K:\n i *= 2\n cnt += 1\n answer += (1/2)**cnt\n\nprint((answer/N))\n", "N,K=map(int,input().split())\nans=0\nfor i in range(1,N+1):\n j=0\n while True:\n if K<=i*2**j:\n ans+=(1/N)*(1/2)**j\n break\n j+=1\nprint(ans)", "N,K = map(int,input().split())\ntmp = 1\nnum_cnt = 0\nwhile K > tmp :\n tmp *= 2\n num_cnt +=1\nnums_list = []\nfor i in range(1,N+1):\n for j in range(num_cnt+1):\n if i*(2**j) >= K:\n nums_list.append(((1/2)**j))\n break\nprint(sum(nums_list)*(1/N))", "import math\nN, K =map(int, input().split())\nans = 0\nfor i in range(1,N+1):\n success_num = max(0,(math.ceil(math.log2(K/i))))\n ans += (1/2)**success_num\nprint(ans/N)", "n, k = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(1, n+1):\n count = 0\n p = i\n while p<k:\n p = p*2\n count +=1\n ans += (1/n)*((1/2)**count)\n\nprint(ans)", "from math import ceil as c\nfrom math import log2 as l\nimport sys\ninput = sys.stdin.readline\n\nn, k = map(int,input().split())\nans = 0\n\nfor i in range(1, n+1):\n if i < k:\n ans += (0.5 ** c(l(k/i))) / n\n else:\n ans += 1 / n\n\nprint(ans)", "N, K = map(int, input().split())\nfrom math import log2, ceil\n\np = 0\n\nfor i in range(1, N+1):\n if K >= i:\n p += 2**-(ceil(log2(K / i))) / N\n else:\n p += 1 / N\n\nprint(p)", "\n\ndef main():\n n, k = list(map(int, input().split()))\n ans = 0.0\n for t in range(1, n + 1):\n cnt = 0\n now = t\n per = 1.0\n while now < k:\n per /= 2\n now *= 2\n ans += per / n\n print(('{:.20}'.format(ans)))\n pass\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nanswer = 0\nn,k = map(int,input().split())\nfor i in range(1,n+1):\n if(i>=k):\n answer +=1/n\n else:\n answer += 1/(2**math.ceil(math.log2(k/i)))/n\nprint(answer)", "import sys\nimport math\nfrom collections import defaultdict, deque, Counter\nfrom copy import deepcopy\nfrom bisect import bisect, bisect_right, bisect_left\nfrom heapq import heapify, heappop, heappush\n \ninput = sys.stdin.readline\ndef RD(): return input().rstrip()\ndef F(): return float(input().rstrip())\ndef I(): return int(input().rstrip())\ndef MI(): return map(int, input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int, input().split()))\ndef TI(): return tuple(map(int, input().split()))\ndef LF(): return list(map(float,input().split()))\ndef Init(H, W, num): return [[num for i in range(W)] for j in range(H)]\n \n \ndef main():\n N, K = MI()\n D = deque()\n D.append(1)\n num = 1\n index = 0\n while num <= K:\n num*=2\n index+=1\n D.append(num)\n ans = 0\n for i in range(1, N+1):\n temp = K / i\n index2 = bisect_left(D, temp)\n ans += D[index-index2]\n \n print(ans / (N * D[index]))\n\n \ndef __starting_point():\n main()\n__starting_point()", "n, k = map(int, input().split())\nans = 0\nfor i in range(1, n+1):\n cnt = 1\n while i < k:\n i *= 2\n cnt /= 2\n ans += cnt\nans /= n\nprint(ans)", "import math\nN, K = map(int, input().split())\n\nans = 0\n\nfor i in range(1,N+1):\n if i <= K:\n ans+=1/N*0.5**(math.ceil(math.log2(K/i)))\n else:\n ans+=1/N\n \nprint(ans)", "from math import ceil as c\nfrom math import log2 as l\n\nn, k = map(int,input().split())\nans = 0\n\nfor i in range(1, n+1):\n if i < k:\n ans += (0.5 ** c(l(k/i))) / n\n else:\n ans += 1 / n\n\nprint(ans)", "n, k = map(int, input().split()) \n\nimport math\n\nans = 0\nfor i in range(1, n+1):\n if i < k:\n power = math.ceil(math.log2(k/i))\n else:\n power = 0\n ans += pow(0.5, power)\nprint(ans / n)", "N, M = map(int, input().split())\n\nif M == 1:\n\tprint(1)\n\treturn\n\nimport math\n\nprob = 0\nfor i in range (1, N+1):\n\tif i>=M:\n\t\tprob+=1/N\n\telse:\n\t\tprob+=((1/N)*1/2**math.ceil(math.log(M/i, 2)))\n\nprint(prob)", "n,k = map(int,input().split())\n\nsum1 = 0\nfor i in range(1,n+1):\n p = 0\n while True:\n if (2**p)*i >= k:\n break\n p +=1\n sum1 += 1/(n*2**p)\nprint(sum1)", "N,K = map(int,input().split())\nls = [0]\nfor i in range(1,N+1):\n if i >= K:\n ls.append(1)\n else:\n p = 1\n f = K//i\n if K%i == 0:\n f -= 1\n while f != 0:\n f = f//2\n p = p/2\n ls.append(p)\nans = sum(ls)/N\nprint(ans)", "# coding: utf-8\n\n\ndef main():\n N, K = list(map(int, input().split()))\n ans = 0.0\n for i in range(1, N + 1):\n j, k = i, 0\n while j < K:\n j *= 2\n k += 1\n ans += pow(0.5, k) / N\n\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nn,k=map(int,input().split())\nans=0\nfor i in range(1,n+1):\n tmp=1/n\n while i<k:\n i=i*2\n tmp/=2\n ans+=tmp\nprint(ans)", "n, k = map(int, input().split())\nprob = [0]*n\nfor i in range(1, n+1):\n j = 0\n while i*(2**j) < k:\n j += 1\n prob[i-1] = (1/n)*(1/2)**j\n\nprint(sum(prob))", "import math\nN, K = map(int, input().split())\nans = 0\nfor i in range(1, N+1):\n a = math.log2(K/i)\n if a > 0:\n ans += 0.5**math.ceil(math.log2(K/i))/N\n else:\n ans += 1/N\nprint(ans)", "N, K = map(int, input().split())\n\nans = 0\n\nfor i in range(1, N+1):\n count = 0\n while i < K:\n i *= 2\n count += 1\n ans += 1 / (N * (2 ** count))\n\nprint(ans)", "import math\n\nN, K = list(map(int, input().split()))\n\nans = 0\nfor n in range(1, N+1):\n if n >= K:\n ans += 1/N\n continue\n x = math.ceil(math.log2(K/n))\n ans += (0.5**x)/N\n\nprint(ans)\n", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, K: int):\n ans = 0\n for n in range(1, N+1):\n b = 1\n while n * b < K:\n b <<= 1\n ans += 1 / (b * N)\n return ans\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n print((solve(N, K)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef __starting_point():\n #test()\n main()\n\n__starting_point()", "import math\nn,k=map(int,input().split())\nif n>=k:\n a=0\n for i in range(1,k):\n a+=0.5**(math.ceil(math.log2(k/i)))\n print((a+n-k+1)/n)\nelse:\n a=0\n for i in range(1,n+1):\n a+=0.5**(math.ceil(math.log2(k/i)))\n print(a/n)", "#21 C - Dice and Coin\nimport math\nN,K = map(int,input().split())\n\nans = 0\nfor i in range(1,N+1):\n if K//i != 0:\n a = math.log2(K/i)\n if a.is_integer():\n x = int(a)\n else:\n x = int(a) + 1\n ans += (1/N)*(1/2)**x\n else:\n ans += (1/N)\nprint(ans)", "n, k = map(int, input().split())\nprob = [0]*n\nfor i in range(1, n+1):\n j = 0\n while i*(2**j) < k:\n j += 1\n prob[i-1] = (1/n)*(1/2)**j\n\nprint(sum(prob))", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef func(i, k):\n count = 0\n while i < k:\n i *= 2\n count += 1\n return count\n\n\ndef main():\n n, k = Input()\n ans = 0\n for i in range(1, n+1):\n ans += 1/n * (1/2 ** func(i, k))\n print(ans)\n\n\nmain()", "n, k = map(int, input().split())\n\nans = 0\nfor i in range(1, n + 1):\n j = i\n cnt = 1\n while j < k:\n j <<= 1\n cnt /= 2\n ans += cnt / n\nprint('{:10}'.format(ans))", "N,K = map(int,input().split())\n\nans = 0\nfor n in range(1,N+1):\n k = 0\n m = n\n while m < K:\n m *= 2\n k += 1\n ans += 2**(-k)\nprint(ans / N)", "N, K = [int(n) for n in input().split()]\nans = 0\nfor n in range(1, N+1):\n tmp = 1.0/N\n now = n\n while now < K:\n now *=2\n tmp /=2\n ans += tmp\nprint(('{:.12}'.format(ans)))\n", "n, k = map(int, input().split())\nprob = [0]*(n+1)\nfor i in range(1, n+1):\n j = 0\n while i*(2**j) < k:\n j += 1\n prob[i] = (1/n)*(1/2)**j\n\nprint(sum(prob))", "from math import *\n\nn, k = map(int, input().split())\n\nans = 0\nfor i in range(1, n+1):\n tmp = 1 / n\n if i < k:\n tmp *= 0.5 ** ceil(log2(k/i))\n ans += tmp\n\nprint(ans)", "import math\nn,k = map(int, input().split())\ns = 0\nans = 0\nfor x in range(1,n+1):\n if x >= k:\n a = 0\n else:\n a = math.ceil(math.log2(k/x))\n b = (1 / n) * ((0.5) ** a) \n ans += b\n \n \nprint(ans)"] | {"inputs": ["3 10\n", "100000 5\n", "3904 16384\n", "97392 33\n", "1 1\n", "10000 100000\n", "1 100000\n"], "outputs": ["0.145833333333\n", "0.999973749998\n", "0.081316166237\n", "0.999781007423\n", "1.000000000000\n", "0.036463721466\n", "0.000007629395\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 23,723 | |
18536f759a4fc4af5fe6ee5a2ad30c33 | UNKNOWN | Given is a string S representing the day of the week today.
S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
-----Constraints-----
- S is SUN, MON, TUE, WED, THU, FRI, or SAT.
-----Input-----
Input is given from Standard Input in the following format:
S
-----Output-----
Print the number of days before the next Sunday.
-----Sample Input-----
SAT
-----Sample Output-----
1
It is Saturday today, and tomorrow will be Sunday. | ["S = input()\nW = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nprint(7-W.index(S))", "S = str(input())\n\nday = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\", \"SUN\"]\nprint(7 - day.index(S))", "print(['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1].index(input())+1)", "S = input()\nweek = [\"SUN\",\"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]\nfor i in range(7):\n if week[i] == S:\n print(7 - i)", "week = [\"SAT\",\"FRI\",\"THU\",\"WED\",\"TUE\",\"MON\",\"SUN\"]\nday = input()\nprint(week.index(day)+1)", "s=input()\nif s==\"SUN\":\n print(7)\nelif s==\"MON\":\n print(6)\nelif s==\"TUE\":\n print(5)\nelif s==\"WED\":\n print(4)\nelif s==\"THU\":\n print(3)\nelif s==\"FRI\":\n print(2)\nelse:\n print(1)", "S = input()\n\n# \u8f9e\u66f8\u578b\u3092\u4f7f\u3046\u3068\u30b9\u30c3\u30ad\u30ea\u66f8\u3051\u308b\uff01\ndic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}\nprint(dic[S])", "S = input()\nDAY = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nfor num in range(7):\n if DAY[num] == S:\n print((7-num))\n", "S=['SUN','MON','TUE','WED','THU','FRI','SAT']\nprint(7-S.index(input()))", "s=input()\nif s==\"SUN\":\n print(7)\nelif s==\"SAT\":\n print(1)\nelif s==\"FRI\":\n print(2)\nelif s==\"THU\":\n print(3)\nelif s==\"WED\":\n print(4)\nelif s==\"TUE\":\n print(5)\nelif s==\"MON\":\n print(6)", "s=input()\nif 'SU' in s:\n print('7')\nif 'MO' in s:\n print('6')\nif 'TU' in s:\n print('5')\nif 'WE' in s:\n print('4')\nif 'TH' in s:\n print('3')\nif 'FR' in s:\n print('2')\nif 'SA' in s:\n print('1')\n", "week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\ns = input()\nans = 7 - week.index(s)\nans = ans if ans != 0 else 7\nprint(ans)", "days = [\"SUN\",\n \"MON\",\n \"TUE\",\n \"WED\",\n \"THU\",\n \"FRI\",\n \"SAT\"]\n\nS = input()\n\nprint(7-days.index(S))", "S = input()\n\nif S == \"SUN\":\n print(7)\nelif S == \"MON\":\n print(6)\nelif S == \"TUE\":\n print(5)\nelif S == \"WED\":\n print(4)\nelif S == \"THU\":\n print(3)\nelif S == \"FRI\":\n print(2)\nelse:\n print(1)", "import sys\nstdin=sys.stdin\n\nip=lambda: int(sp())\n\nlp=lambda:list(map(int,stdin.readline().split()))\nsp=lambda:stdin.readline().rstrip()\n\ns=sp()\n\nif s=='SUN':\n print((7))\nelif s=='MON':\n print((6))\n \nelif s=='TUE':\n print((5))\nelif s=='WED':\n print((4))\nelif s=='THU':\n print((3))\n \nelif s=='FRI':\n print((2))\nelse:\n print((1))\n", "s=input()\nif(s==\"SUN\"):\n print((7))\nelif(s==\"MON\"):\n print((6))\nelif(s==\"TUE\"):\n print((5))\nelif(s==\"WED\"):\n print((4))\nelif(s==\"THU\"):\n print((3))\nelif(s==\"FRI\"):\n print((2))\nelif(s==\"SAT\"):\n print((1))\n", "# \u554f\u984c\uff1ahttps://atcoder.jp/contests/abc146/tasks/abc146_a\n\nweek = ['SUN','MON','TUE','WED','THU','FRI','SAT']\ns = input()\nfor i, day in enumerate(week):\n if day == s:\n res = 7 - i\n break\nres = 7 - i\nprint(res)\n", "s = input()\n\nweek = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\n\nidx = week.index(s)\nprint(7-idx)", "s=input()\na=[\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nprint((7-a.index(s)))\n", "a = input()\n\nif a == \"SUN\":\n print(\"7\")\n\nelif a == \"MON\":\n print(\"6\")\n\nelif a == \"TUE\":\n print(\"5\")\n\nelif a == \"WED\":\n print(\"4\")\n\nelif a == \"THU\":\n print(\"3\")\n\nelif a == \"FRI\":\n print(\"2\")\n\nelif a == \"SAT\":\n print(\"1\")", "Week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\nS = input()\nprint(7 - Week.index(S))", "S = input()\nif S == 'SUN': print(7)\nelif S == 'MON': print(6)\nelif S == 'TUE': print(5)\nelif S == 'WED': print(4)\nelif S == 'THU': print(3)\nelif S == 'FRI': print(2)\nelif S == 'SAT': print(1) ", "ls = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nS = input()\nprint(7-ls.index(S))", "S = input()\nl = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\",\"SAT\"]\nprint((7 - l.index(S)))\n", "s = input()\n\nif s == 'SAT':\n print(1)\nif s == 'FRI':\n print(2)\nif s == 'THU':\n print(3)\nif s == 'WED':\n print(4)\nif s == 'TUE':\n print(5)\nif s == 'MON':\n print(6)\nif s == 'SUN':\n print(7)", "T = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']\nS = input()\nprint(6-T.index(S) if S!='SUN' else 7)", "\ns = str(input())\nif s == \"SUN\":\n print((7))\n return()\nif s == \"MON\":\n print((6))\n return()\nif s == \"TUE\":\n print((5))\n return()\nif s == \"WED\":\n print((4))\n return()\nif s == \"THU\":\n print((3))\n return()\nif s == \"FRI\":\n print((2))\n return()\nif s == \"SAT\":\n print((1))\n return()\n", "S=input()\nday=[\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nfor i in range(7):\n if day[i]==S:\n print((7-i))\n", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\nd = {\n \"SAT\": 1,\n \"FRI\": 2,\n \"THU\": 3,\n \"WED\": 4,\n \"TUE\": 5,\n \"MON\": 6,\n \"SUN\": 7,\n}\n\n\ndef solve():\n S = ins()\n return d[S]\n\n\nprint(solve())\n", "S=input()\nl=[\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\n\nfor i in range(len(l)):\n\tif S==l[i]:\n\t\tprint(7-i)\n\t\tbreak", "S = input()\nif S == 'SUN': print(7)\nelif S == 'MON': print(6)\nelif S == 'TUE': print(5)\nelif S == 'WED': print(4)\nelif S == 'THU': print(3)\nelif S == 'FRI': print(2)\nelse: print(1) ", "s = input()\ndl = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nfor i in range(7):\n if s == dl[i]:\n print(7-i)", "S = input()\nif(S == \"SUN\"):\n print(7)\nif(S == \"MON\"):\n print(6)\nif(S == \"TUE\"):\n print(5)\nif(S == \"WED\"):\n print(4)\nif(S == \"THU\"):\n print(3)\nif(S == \"FRI\"):\n print(2)\nif(S == \"SAT\"):\n print(1)", "list = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\n\ns = input()\n\ni = list.index(s)\nanswer = 7 - i\n\nprint(answer)", "d=dict()\nd[\"SUN\"]=7\nd[\"MON\"]=6\nd[\"TUE\"]=5\nd[\"WED\"]=4\nd[\"THU\"]=3\nd[\"FRI\"]=2\nd[\"SAT\"]=1\ns=input()\nprint(d[s])", "S = input()\nyoubi = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']\nprint(youbi.index(S) + 1)", "n = str(input())\ndic = {\"SUN\":7,\n \"MON\":6,\n \"TUE\":5,\n \"WED\":4,\n \"THU\":3,\n \"FRI\":2,\n \"SAT\":1}\nprint(dic[str(n)])", "s=input()\n\nif s==\"SUN\":\n print(7)\nelif s==\"MON\":\n print(6)\nelif s==\"TUE\":\n print(5)\nelif s==\"WED\":\n print(4)\nelif s==\"THU\":\n print(3)\nelif s==\"FRI\":\n print(2)\nelif s==\"SAT\":\n print(1)", "a = input()\nif a == 'SUN':\n print((7))\nelif a == 'MON':\n print((6))\nelif a == 'TUE':\n print((5))\nelif a == 'WED':\n print((4))\nelif a == 'THU':\n print((3))\nelif a == 'FRI':\n print((2))\nelse:\n print((1))\n\n", "yobi = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]\n\nS = input()\n\nprint(7 - yobi.index(S))", "day = ['SUN','MON','TUE','WED','THU','FRI','SAT']\ns = input()\nfor i in range(7):\n if s == day[i]:\n print(7-i)", "S=input()\nif S==\"SUN\":\n print(7)\nelif S==\"MON\":\n print(6)\nelif S==\"TUE\":\n print(5)\nelif S==\"WED\":\n print(4)\nelif S==\"THU\":\n print(3)\nelif S==\"FRI\":\n print(2)\nelif S==\"SAT\":\n print(1)", "s = input()\nl = [\"SAT\",\"FRI\",\"THU\",\"WED\",\"TUE\",\"MON\",\"SUN\"]\nprint(l.index(s) + 1)", "#ABC146A\ns = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nss = input()\nprint(7-s.index(ss))", "S = input()\nweek = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\",\"FRI\",\"SAT\"]\n\nprint(7 - week.index(S))", "S = input()\n\nd = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}\nprint((d[S]))\nreturn()\n\n", "s = input()\na = {\"SUN\":7, \"MON\":6, \"TUE\":5, \"WED\":4, \"THU\":3, \"FRI\":2, \"SAT\":1}\nprint(a[s])", "S = str(input())\n\nif S == 'SUN':\n print(7)\nelif S == 'MON':\n print(6)\nelif S == 'TUE':\n print(5)\nelif S == 'WED':\n print(4)\nelif S == 'THU':\n print(3)\nelif S == 'FRI':\n print(2)\nelse:\n print(1)", "s=input()\n\nif s=='SUN':\n print((7))\nif s=='MON':\n print((6))\nif s=='TUE':\n print((5))\nif s=='WED':\n print((4))\nif s=='THU':\n print((3))\nif s=='FRI':\n print((2))\nif s=='SAT':\n print((1))\n", "s = input()\nl = [\"SAT\", \"FRI\", \"THU\", \"WED\", \"TUE\", \"MON\", \"SUN\"]\nprint(l.index(s)+1)", "#!/usr/bin/env python3\n\nwd = \"SUN MON TUE WED THU FRI SAT\".split()\nwd = list(reversed(wd))\n\ndef solve(S: str):\n idx = wd.index(S)\n return idx+1\n\n\ndef main():\n S = input().strip()\n answer = solve(S)\n print(answer)\n\ndef __starting_point():\n main()\n\n__starting_point()", "l = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\ns = input()\nprint((7 - l.index(s)))\n", "import sys\n\n\ndef resolve(in_):\n S = next(in_).strip()\n _weekday = {0: 'SUN', 1: 'MON', 2: 'TUE', 3: 'WED', 4: 'THU', 5: 'FRI', 6: 'SAT'}\n weekday = {v: 7 - k for k, v in list(_weekday.items())}\n\n return weekday[S]\n\n\ndef main():\n answer = resolve(sys.stdin)\n print(answer)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "d={'SUN':1,'MON':2,'TUE':3,'WED':4,'THU':5,'FRI':6,'SAT':7}\ntoday_key = input()\ntoday_value = d[today_key]\nnextsunday_value = 8-today_value\nprint(nextsunday_value)", "s = input()\nif s==\"SUN\":\n print(7)\nelif s==\"MON\":\n print(6)\nelif s==\"TUE\":\n print(5)\nelif s==\"WED\":\n print(4)\nelif s==\"THU\":\n print(3)\nelif s==\"FRI\":\n print(2)\nelse:\n print(1)", "S=str(input())\n\nif S=='SUN':\n print(int(7-0))\nelif S=='MON':\n print(int(7-1))\nelif S=='TUE':\n print(int(7-2))\nelif S=='WED':\n print(int(7-3))\nelif S=='THU':\n print(int(7-4))\nelif S=='FRI':\n print(int(7-5))\nelif S=='SAT':\n print(int(7-6))", "week=[\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\na=input()\nprint(7-week.index(a))", "S=input()\nD=['SUN','MON','TUE','WED','THU','FRI','SAT']\ni=D.index(S)\nprint((7-i))\n", "s = input()\ns_list = ['SUN','MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\nprint(7 - s_list.index(s))", "S = input()\nls = [0,'SAT','FRI','THU','WED','TUE','MON','SUN']\nprint(ls.index(S))", "S={\"SUN\":7,\"MON\":6,\"TUE\":5,\"WED\":4,\"THU\":3,\"FRI\":2,\"SAT\":1}\ni=input()\nprint((S[i]))\n", "days = [\"SUN\", 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\ndays.reverse()\nd = input()\nprint((days.index(d)+1))\n", "week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\ns = input()\ni = week.index(s)\nprint(7 - i)", "w=['SUN','MON','TUE','WED','THU','FRI','SAT']\nprint(7-w.index(input()))", "S = input()\nday_of_the_week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\nfor i in range(len(day_of_the_week)):\n if S == day_of_the_week[i]:\n answer = 7 - i\nprint(answer)", "def resolve():\n week = ['SUN','MON','TUE','WED','THU','FRI','SAT']\n s = input()\n print(7-week.index(s))\nresolve()", "week = \"MON,TUE,WED,THU,FRI,SAT,SUN\".split(',')\nS = input()\nprint(7) if S==\"SUN\" else print(6-week.index(S))", "N_List=[\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nprint(7 - N_List.index(str(input())))", "s = input()\narr = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nfor i in range(7):\n if s==arr[i]:\n print(7-i)", "week = ['SUN','MON','TUE','WED','THU','FRI','SAT']\ns = input()\nn = week.index(s)\nprint(7-n)", "lis = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nS = input()\nx = lis.index(S)\nprint(7-x)", "#!/usr/bin/env python3\ns = str(input())\nif s == \"SUN\":\n print((7))\n return()\nif s == \"MON\":\n print((6))\n return()\nif s == \"TUE\":\n print((5))\n return()\nif s == \"WED\":\n print((4))\n return()\nif s == \"THU\":\n print((3))\n return()\nif s == \"FRI\":\n print((2))\n return()\nif s == \"SAT\":\n print((1))\n return()\n", "li = ['MON','TUE','WED','THU','FRI','SAT','SUN']\n\nn = input()\n\nif n == 'SUN':\n print(7)\nelse:\n print(6 - li.index(n))", "s = input()\nS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\nprint(7-S.index(s))", "print(7 - ['SUN','MON','TUE','WED','THU','FRI','SAT'].index(input()))", "S=str(input())\nst=['SUN','MON','TUE','WED','THU','FRI','SAT']\nprint((7-st.index(S)))\n", "day = {\"SUN\":7,\"MON\":6,\"TUE\":5,\"WED\":4,\"THU\":3,\"FRI\":2,\"SAT\":1}\nprint(day[input()])", "s = input()\nlst = ['SUN','MON','TUE', 'WED', 'THU', 'FRI', 'SAT' ]\nif s == 'SUN':\n print(7)\n return()\nfor i in range(7):\n if s == lst[i]:\n print(7-i)\n return()", "\ns=input()\nif s=='SUN':\n print('7')\nelif s=='MON':\n print('6')\nelif s=='TUE':\n print('5')\nelif s=='WED':\n print('4')\nelif s=='THU':\n print('3')\nelif s=='FRI':\n print('2')\nelse:\n print('1')", "S=input()\ndays=['MON','TUE','WED','THU','FRI','SAT','SUN']\ncnt =days.index('SUN')-days.index(S)\nif cnt==0:\n print(7)\nelse:\n print(cnt)", "import math\nfrom collections import Counter\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\na = input()\nday = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nfor i in range(len(day)):\n if day[i] == a:\n print(7-i)", "s = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]\nt = input()\ni = s.index(t)\nprint(7 - i)", "S = input()\nday = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]\nprint(7 - day.index(S))", "w =['SUN','MON','TUE','WED','THU','FRI','SAT','SUN']\nd = input()\n\ni = w.index(d)\nprint((7-i))\n", "s = input()\n\nweek = ['SUN','MON','TUE','WED','THU','FRI','SAT']\nn = week.index(s)\n\nprint(7-n)", "s = input()\n\nt = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\nprint(7 - t.index(s))", "s=str(input())\ndic={'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1 }\nprint(dic[s])", "s = input()\n\nif s == 'SUN':\n print(7)\nelif s == 'MON':\n print(6)\nelif s == 'TUE':\n print(5)\nelif s == 'WED':\n print(4)\nelif s == 'THU':\n print(3)\nelif s == 'FRI':\n print(2)\nelif s == 'SAT':\n print(1)", "S = input()\n\nlst = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']\ndct = {}\nfor i, j in enumerate(lst):\n dct[j] = i\nprint(7 - dct[S])", "#!/usr/bin/env python3\nfrom collections import defaultdict, Counter\nfrom itertools import product, groupby, count, permutations, combinations\nfrom math import pi, sqrt\nfrom collections import deque\nfrom bisect import bisect, bisect_left, bisect_right\nfrom string import ascii_lowercase\nfrom functools import lru_cache\nimport sys\nsys.setrecursionlimit(10000)\nINF = float(\"inf\")\nYES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"\ndy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]\ndy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]\n\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndef ceil(a, b):\n return (a + b - 1) // b\n\n\ndef sum_of_arithmetic_progression(s, d, n):\n return n * (2 * s + (n - 1) * d) // 2\n\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef lcm(a, b):\n g = gcd(a, b)\n return a / g * b\n\n\ndef solve():\n S = input()\n i = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"].index(S)\n print((7 - i))\n\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "S = input()\nW = ['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']\n\nprint(W.index(S))", "S = input()\nif S == \"SUN\":\n print(7)\nif S == \"MON\":\n print(6)\nif S == \"TUE\":\n print(5)\nif S == \"WED\":\n print(4)\nif S == \"THU\":\n print(3)\nif S == \"FRI\":\n print(2)\nif S == \"SAT\":\n print(1)", "s = str(input())\nif s == \"SUN\":\n print((7))\n return()\nif s == \"MON\":\n print((6))\n return()\nif s == \"TUE\":\n print((5))\n return()\nif s == \"WED\":\n print((4))\n return()\nif s == \"THU\":\n print((3))\n return()\nif s == \"FRI\":\n print((2))\n return()\nif s == \"SAT\":\n print((1))\n return()\n", "store = {\"SUN\":7,\"MON\":6,\"TUE\":5,\"WED\":4,\"THU\":3,\"FRI\":2,\"SAT\":1}\ns = input()\nprint(store[s])", "s=input()\ndic={\"SUN\":0,\"MON\":1,\"TUE\":2,\"WED\":3,\"THU\":4,\"FRI\":5,\"SAT\":6}\nprint(7-dic[s])", "D = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']\nS = input()\nfor i, d in enumerate(D):\n if d == S:\n print(i+1)\n return()", "d={'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}\nprint(d[input()])", "day = [\"\",\"SAT\",\"FRI\",\"THU\",\"WED\",\"TUE\",\"MON\",\"SUN\"]\nprint(day.index(input()))", "s = input()\nres = 0\nif s == \"SUN\":\n res = 7\nelif s == \"MON\":\n res = 6\nelif s == \"TUE\":\n res = 5\nelif s == \"WED\":\n res = 4\nelif s == \"THU\":\n res = 3\nelif s == \"FRI\":\n res = 2\nelif s == \"SAT\":\n res = 1\nprint(res)", "s=input()\nL=['SUN','MON','TUE','WED','THU','FRI','SAT']\n\nprint((7-L.index(s)))\n"] | {"inputs": ["SAT\n", "SUN\n", "FRI\n", "MON\n", "THU\n", "TUE\n", "WED\n"], "outputs": ["1\n", "7\n", "2\n", "6\n", "3\n", "5\n", "4\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 17,381 | |
7d480aac38d4384d1ac0e3ba5188915b | UNKNOWN | The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram. For iβ₯2000, the following formula holds:
- x_{i+1} = rx_i - D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order.
-----Constraints-----
- 2 β€ r β€ 5
- 1 β€ D β€ 100
- D < x_{2000} β€ 200
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
r D x_{2000}
-----Output-----
Print 10 lines. The i-th line (1 β€ i β€ 10) should contain x_{2000+i} as an integer.
-----Sample Input-----
2 10 20
-----Sample Output-----
30
50
90
170
330
650
1290
2570
5130
10250
For example, x_{2001} = rx_{2000} - D = 2 \times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \times 30 - 10 = 50. | ["r, D, x = map(int, input().split())\n\nfor i in range(10):\n x = r * x - D\n print(x)", "r, D, x = map(int, input().split())\n\n\nfor i in range(10):\n x = r*x-D\n print(x)", "# unihernandez22\n# https://atcoder.jp/contests/abc127/tasks/abc127_b\n# implementation\n\nr, d, x = map(int, input().split())\n\nfor _ in range(10):\n x = r*x-d\n print(x)", "r,d,x = map(int,input().split())\nfor i in range(10):\n ans = r*x - d\n print(ans)\n x = ans", "r ,D, x = list(map(int,input().split()))\n\nfor i in range(10):\n xi = r*x - D\n print(xi)\n x = r*x - D\n", "r, D, x = map(int, input().split())\n\nfor i in range(10):\n x = r*x-D\n print(x)", "r,d,x = map(int,input().split())\n\nweight = x\n\nfor i in range(10):\n weight = r*weight-d\n print(weight)", "r, D, x = list(map(int, input().split()))\n\nfor i in range(10):\n x = r*x - D\n print(x)\n", "r, d, s = list(map(int, input().split()))\n\nfor i in range(10):\n s = r * s - d\n print(s)\n", "R, D, x2000 = map(int, input().split())\n\nprev = x2000\nfor i in range(10):\n x = prev * R - D\n print(x)\n prev = x", "r, d, x =list(map(int, input().split()))\nans = []\nfor i in range(10):\n x = r*x -d\n ans.append(x)\n\nfor i in ans:\n print(i)\n", "r, D, x = map(int,input().split())\n\ndef function(y):\n y = r * y - D\n\n return y\n\nz = 1\nwhile z <= 10:\n z += 1\n ans = function(x)\n x = function(x)\n print(ans)", "r, D, x = map(int, input().split())\n\nfor i in range(10):\n x = r * x - D\n print(x)", "r, d, x = list(map(int, input().split()))\n\nfor i in range(10):\n x = r*x - d\n print(x)", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r*x-d\n print(x)", "r, D, x = list(map(int, input().split()))\n\nfor i in range(10):\n x = r*x - D\n print(x)\n", "r, D, x2000 = map(int, input().split())\n\nx = r * x2000 - D\n\nfor i in range(1, 10 + 1):\n print(x)\n x = r * x - D", "r,d,x=map(int, input().split())\nfor i in range(10):\n x=r*x-d\n print(x)", "r, d, x = map(int, input().split())\n\nfor _ in range(10):\n x = x*r - d\n print(x)", "r, D, x2000 = map(int, input().split())\nn = x2000\nfor i in range(10):\n x = r * n -D\n print(x)\n n = x", "r,D,x = map(int,input().split())\n\nfor i in range(1,11):\n x = x * r - D\n print(x)", "r, d, x = map(int, input().split())\n\nweights = []\nfor i in range(10):\n if i == 0:\n weights.append(r * x - d)\n print(weights[i])\n else:\n weights.append(r * weights[i - 1] - d)\n print(weights[i])", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r*x-d\n print(x)", "r,d,x = map(int, input().split())\n\nfor _ in range(10):\n x *= r\n x -= d\n print(x)", "r,D,x2000=map(int, input().split())\n\nans=[x2000]\n\nfor i in range(10):\n\tans.append(r*ans[i]-D)\n\nfor h in range(1,11):print(ans[h])", "r,D,x=map(int,input().split())\n\nfor i in range(10):\n\tx=r*x-D\n\tprint(x)", "r,D,x = map(int, input().split())\nfor i in range(1,11):\n x = r*x - D\n print(x)", "R, D, x = map(int, input().split())\nfor _ in range(10):\n x = R*x - D\n print(x)", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r*x-d\n print(x)", "r, d, x = list(map(int, input().strip().split()))\n\nfor i in range(10):\n x = r * x - d\n print(x)\n\n", "r,D,x=map(int,input().split())\nfor i in range(10):\n x=r*x-D\n print(x)", "r,d,x=map(int,input().split())\nfor i in range(10):\n x=r*x-d\n print(x)", "r,D,x=list(map(int,input().split()))\n\nfor i in range(10):\n x=r*x-D\n print(x)\n", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r* x - d\n print(x)", "r, d, x = map(int, input().split())\n\nweights = []\nfor i in range(10):\n try:\n weights.append(r * weights[i - 1] - d)\n print(weights[i])\n except:\n weights.append(r * x - d)\n print(weights[i])", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r*x - d\n print(x)", "r,d,x= map(int,input().split())\n\nfor _ in range(10):\n print(r*x-d)\n x = r*x-d", "r,D,x = list(map(int,input().split()))\n\nfor i in range(10):\n x = r*x - D\n print(x)\n", "# B Algea\nr, D, x = list(map(int, input().split()))\nfor i in range(10):\n x = r * x - D\n print(x)\n", "x=[]\nr,D,a=map(int,input().split())\nx.append(a)\nfor i in range(10):\n x.append(r*x[i]-D)\n print(x[i+1])", "r, D, x = map(int, input().split())\nfor i in range(10):\n\tx = r * x - D\n\tprint(x)", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r * x - d\n print(x)", "r,D,x=list(map(int,input().split()))\nfor _ in range(10):\n x=r*x-D\n print(x)\n", "\ndetails = list(map(int,input().split()))\n\nr = details[0]\nD = details[1]\nxtemp = details[2]\n\nfor i in range(0,10):\n x_next = xtemp * r - D\n print(x_next)\n xtemp = x_next\n\n", "r, D, x = map(int, input().split())\nfor i in range(10):\n x = r*x - D\n print(x)", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n r, d, x = Input()\n for _ in range(10):\n x = x * r - d\n print(x)\n\nmain()", "r, D, a_2000 = input().split()\nr = int(r)\nD = int(D)\na_2000 = int(a_2000)\nb = D / (r-1)\n \nfor i in range (1, 11) :\n print(int((r**i)*(a_2000 - b) + b))", "a,b,c = map(int,input().split())\n#print(a*c-b)\nfor i in range(10):\n c = a*c-b\n print(c)", "r,D,x=map(int,input().split())\nnow=x\nfor i in range(10):\n x=x*r-D\n print(x)", "r, D, x = map(int, input().split())\n\nans = x\nfor _ in range(10):\n ans = r * ans - D\n print(ans)", "r,d,x = map(int,input().split())\nA = x\n\nfor _ in range(10):\n A = r*A-d\n print(A)", "from typing import List\n\n\ndef answer(r: int, d: int, x: int) -> List[int]:\n result = []\n for _ in range(10):\n x = r * x - d\n result.append(x)\n\n return result\n\n\ndef main():\n r, x, d = list(map(int, input().split()))\n for i in answer(r, x, d):\n print(i)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "r, d, x = map(int, input().split())\nfor i in range(10):\n x = r*x-d\n print(x)", "r, d, x = map(int,input().split())\nfor i in range(10):\n x = r*x - d\n print(x)", "r, d, ans = list(map(int, input().split()))\nfor i in range(10):\n ans = r * ans - d\n print(ans)\n", "r,d,x2000 = map(int,input().split())\n\na = x2000\n\nfor x in range(10):\n a = r * a - d\n print(a)", "r, d, x = list(map(int, input().split()))\n\nfor i in range(1, 11):\n x = r * x - d\n print(x)\n", "r,d,x=map(int,input().split())\n\nfor i in range(1,11):\n x=r*x-d\n print(x)", "r, D, x = map(int, input().split())\nfor i in range(10):\n x = r * x -D\n print(x)", "r,D,x = list(map(int,input().split()))\nfor i in range(10):\n x = r*x-D\n print(x)\n", "r, d, x = list(map(int, input().split()))\n\nfor i in range(10):\n x = r * x - d\n print(x)\n", "r,D,X2000 = list(map(int,input().split()))\nfor i in range(10):\n X2000=r*X2000-D\n print(X2000)\n", "r, D, x2000 = map(int, input().split())\n\nfor i in range(10):\n x = r * x2000 - D\n print(x)\n x2000 = x", "r, d, x = map(int, input().split())\noutput = r*x - d\nfor i in range(10):\n print(output)\n output = output * r - d", "[r,D,x]=[int(_) for _ in input().split()]\nfor i in [0]*10:\n print(x:=r*x-D)", "r,d,x=map(int,input().split())\nfor alg in range(10):\n x*=r\n x-=d\n print(x)", "r, D, x = list(map(int, input().split()))\n\nfor i in range(10):\n next_x = (r * x) - D\n print(next_x)\n x = next_x\n", "r, d, x = list(map(int, input().split()))\nprint((r*x-d))\nfor _ in range(9):\n x = r*x-d\n print((r*x-d))\n \n", "r, D, x = list(map(int, input().split()))\n\nfor i in range(10):\n x= r*x - D\n print(x)\n", "r, D, x_2000 = map(int, input().split())\n\nx = [x_2000] * 11\n\nfor i in range(10):\n x[i+1] = r * x[i] - D\n \nprint(*x[1:], sep='\\n')", "a,b,c=input().split()\na=int(a)\nb=int(b)\nc=int(c)\ni=0\nwhile i<10:\n i=i+1\n c=a*c-b\n print(c)", "r, d, x = map(int, input().split())\nfor i in range(10):\n x = r * x - d\n print(x)", "r,D,x = map (int, input ().split ())\nfor i in range (10):\n x = r*x-D\n print (x)", "r, d, x = map(int, input().split())\nfor i in range(10):\n ans = r * x - d\n print(ans)\n x = ans", "r, d, x = map(int, input().split())\nfor i in range(10):\n x = r*x - d\n print(x)", "r,d,x=map(int,input().split())\nl=[]\nfor i in range(10):\n x = r*x-d\n print(x,\"\\n\")", "r,D,x=map(int,input().split())\n\nc=0\nwhile c<10:\n x=r*x-D\n print(x)\n c+=1", "r,D,x = map(int,input().split())\n\nX = []\nX.append(x)\n\nfor i in range(10):\n x = r*X[i] - D\n X.append(x)\n print(x)", "r,d,x=[int(num) for num in input().split(\" \")]\nfor i in range(10):\n x=r*x-d\n print(x)\n", "r,d,x = map(int, input().split())\nfor i in range(10):\n y = r*x - d\n print(y)\n x = y", "r, D, x = map(int, input().split())\nfor i in range(10):\n x = r*x - D\n print(x)", "a, b, x = map(int, input().split())\nfor i in range(10):\n x = a*x-b\n print(x)", "r,d,x=map(int,input().split())\ntmp=x\nfor i in range(10):\n print(r*tmp-d)\n tmp=r*tmp-d", "lst = input()\nlst = lst.split()\n\n\nfor i in range(len(lst)):\n lst[i]= int(lst[i])\nr = lst[0]\nD = lst[1]\nx = lst[2]\n\nfor i in range(10):\n x = r*x-D\n print(x)", "#ABC127 B\n\nr,D,x = map(int,input().split())\nA = []\nfor i in range(11):\n if i == 0:\n A.append(x)\n else:\n A.append(r*(A[i-1])-D)\n\nfor j in range(10):\n print(A[j+1])", "d=input().split()\nr=int(d[0])\nD=int(d[1])\nx=int(d[2])\nfor i in range(10):\n x=x*r-D\n print(x)", "r, d, x = list(map(int, input().split()))\nfor i in range(10):\n x = r * x - d\n print(x)\n", "r,d,x = map(int,input().split())\nfor i in range(10):\n x = r*x-d\n print(x)", "r,d,x=list(map(int, input().split()))\n\nfor i in range(10):\n x=r*x-d\n print(x)\n", "r,d,x=map(int,input().split())\nans = x\nfor i in range(10):\n ans = r*ans-d\n print(ans)", "r, d, x = (int(i) for i in input().split())\nans = x\nfor i in range(0, 10):\n ans = r * ans - d\n print(ans)", "r, D, x = list(map(int, input().split()))\n\nfor i in range(10):\n x = r*x - D\n print(x)\n\n", "r,D,x0=map(int,input().split())\n\nans=x0\n\nfor i in range(10):\n ans=r*ans-D\n print(ans)", "r,d,x=map(int,input().split())\nans=x\nfor _ in range(10):\n ans=r*ans-d\n print(ans)", "r,d,x = list(map(int,input().split()))\nsu = 0\nfor i in range(10):\n su = r*x - d\n print(su)\n x = su\n su = 0\n", "r, d, x = map(int, input().split())\nfor _ in range(10):\n x = r * x - d\n print(x)", "r, D, x = map(int, input().split())\ndef f(r, D, x):\n return r * x - D\n\nfor i in range(10):\n x = f(r, D, x)\n print(x)", "r, D, x = map(int, input().split())\n\nfor i in range(10):\n if i == 0:\n weight = r*x - D\n print(weight)\n else:\n weight = r*weight - D\n print(weight)", "r,D,x=map(int, input().split())\nfor i in range(10):\n x=r*x-D\n print(x)", "details = list(map(int, input().split()))\nr = details[0]\nD = details[1]\nx = details[2]\ncurrent = x\nfor i in range(10):\n thing = r * current - D\n print(thing)\n current = thing"] | {"inputs": ["2 10 20\n", "4 40 60\n", "2 1 2\n", "2 100 105\n", "3 1 2\n", "4 49 188\n", "5 1 200\n"], "outputs": ["30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560\n", "3\n5\n9\n17\n33\n65\n129\n257\n513\n1025\n", "110\n120\n140\n180\n260\n420\n740\n1380\n2660\n5220\n", "5\n14\n41\n122\n365\n1094\n3281\n9842\n29525\n88574\n", "703\n2763\n11003\n43963\n175803\n703163\n2812603\n11250363\n45001403\n180005563\n", "999\n4994\n24969\n124844\n624219\n3121094\n15605469\n78027344\n390136719\n1950683594\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,372 | |
745938232d7233dbefd15f1e1b33d4cc | UNKNOWN | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) β the elements of the array $d$.
-----Output-----
Print a single integer β the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
-----Examples-----
Input
5
1 3 1 1 4
Output
5
Input
5
1 3 2 1 4
Output
4
Input
3
4 1 2
Output
0
-----Note-----
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | ["input()\nnum = list(map(int, input().split()))\nmaxn = 0\nl, r = 0, len(num)-1\nj1, j2 = num[l], num[r]\nwhile l < r:\n if j1 == j2:\n maxn = max(j1, maxn)\n l += 1\n j1 += num[l]\n elif j1 < j2:\n l += 1\n j1 += num[l]\n else:\n r -= 1\n j2 += num[r]\nprint(maxn)\n", "\ndef mi():\n\treturn map(int, input().split())\n\nn = int(input())\na = list(mi())\n\ni1 = 0\ni2 = n-1\n\ncand = []\n\ns1 = s2 = 0\ns1 += a[i1]\ns2 += a[i2]\nwhile i1<i2:\n\tif s1==s2:\n\t\tcand.append(s1)\n\t\ti1+=1\n\t\ti2-=1\n\t\tif i1==n or i2==-1:\n\t\t\tbreak\n\t\ts1 += a[i1]\n\t\ts2 += a[i2]\n\telif s1<s2:\n\t\ti1+=1\n\t\tif i1==n or i2==-1:\n\t\t\tbreak\n\t\ts1 += a[i1]\n\telse:\n\t\ti2-=1\n\t\tif i1==n or i2==-1:\n\t\t\tbreak\n\t\ts2 += a[i2]\nif len(cand):\n\tprint (cand[-1])\nelse:\n\tprint (0)", "length = int(input())\nnumbers = list(map(int, input().split(\" \")))\n\nmaxTotal = 0\ntotalLeft = 0\nindexLeft = 0\ntotalRight = 0\nindexRight = length - 1\n\nwhile indexLeft <= indexRight:\n if totalLeft > totalRight:\n totalRight += numbers[indexRight]\n indexRight -= 1\n else:\n totalLeft += numbers[indexLeft]\n indexLeft += 1\n if totalRight == totalLeft:\n maxTotal = max(maxTotal, totalLeft)\nprint(maxTotal)\n", "n = int(input())\n\nnumbers = [int(i) for i in input().split(\" \")]\n\ns = 0\na = 0\nsum1 = 0\nb = n - 1\nsum2 = 0\nwhile a <= b:\n if sum1 < sum2:\n sum1 += numbers[a]\n a += 1\n else:\n sum2 += numbers[b]\n b -= 1\n\n if sum1 == sum2:\n s = sum1\n\nprint(s)\n\n", "n = int(input())\nl = list(map(int,input().split()))\nl_sum = sum(l)\nc_sum = [0 for _ in range(n)]\ntotal = 0\n\nmid = None\nfor i, x in enumerate(l): \n total += x\n c_sum[i] = total\n if mid is None and total >= l_sum//2:\n mid = i\n\npoint_left = mid\npoint_right = mid + 1\nsum_left = c_sum[mid]\nsum_right = total-c_sum[mid]\n\nwhile sum_left != sum_right:\n if point_left<0:break\n if point_right>=n:break\n\n\n if sum_left>sum_right:\n sum_left -= l[point_left]\n point_left -= 1\n else:\n sum_right -= l[point_right]\n point_right += 1\n\n\nprint (min(sum_left,sum_right))", "n = int(input())\na = list(map(int, input().split()))\n\ns1, s3 = 0, 0\nmax_s = 0\nl, r = 0, n-1\nwhile l <= r:\n if s1 > s3:\n s3 += a[r]\n r -= 1\n else:\n s1 += a[l]\n l += 1\n\n if s1 == s3:\n max_s = s1\n\nprint(max_s)", "n=int(input())\nL=list(map(int,input().split()))\nsmax=0\ni=0\nj=n-1\nt1=0\nt3=0\nt1+=L[i]\nt3+=L[j]\nwhile(i<j):\n if(t1==t3):\n smax=max(smax,t1)\n i+=1\n t1+=L[i]\n elif(t1>t3):\n j-=1\n t3+=L[j]\n else:\n i+=1\n t1+=L[i]\nprint(smax)\n", "n = int(input())\nD = list(map(int, input().split()))\nsums1, sums2 = {}, {}\n\ns = 0\nfor i, d in enumerate(D):\n s += d\n if s not in sums1:\n sums1[s] = i\n\ns = 0\nfor i, d in enumerate(D[::-1]):\n s += d\n if s not in sums2:\n sums2[s] = i\n\nsums1 = sorted(list(sums1.items()), reverse=True)\nanswer = 0\nfor s, i in sums1:\n if s in sums2 and sums2[s]+i+2 <= n:\n answer = s\n break\nprint(answer)\n", "n = int(input())\nls = [int(i) for i in input().split()]\n\nif n == 1:\n print(0);return\n\nf1, f2 = 0, n - 1\n\nans = 0\nsum1, sum2 = ls[0], ls[n-1]\nif sum1 == sum2:\n ans = sum1\n f1 += 1\n sum1 += ls[f1]\n\nwhile True:\n while sum1 != sum2 and f1 + 1 < f2:\n if sum1 < sum2:\n f1 += 1\n sum1 += ls[f1]\n else:\n f2 -= 1\n sum2 += ls[f2]\n\n if sum1 == sum2:\n ans = sum1\n if f1 + 1 >= f2:\n break\n f1 += 1\n sum1 += ls[f1]\n else:\n break\n\nprint(ans)\n\n\n", "from itertools import accumulate\n\nn = int(input())\nd = list(map(int, input().split()))\n\nleft = list(accumulate([0] + d))\nright = list(accumulate([0] + d[::-1]))\n\nans = 0\ni, j = 0, 0\n\nwhile i + j <= n:\n le, ri = left[i], right[j]\n\n if le == ri:\n ans = le\n i += 1\n j += 1\n\n elif le < ri:\n i += 1\n\n elif le > ri:\n j += 1\n\n else:\n return\n\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\nb = a[::-1]\nsa = [0] * n\nsb = [0] * n\nsa[0] = a[0]\nsb[0] = b[0]\nfor i in range(1, n):\n sa[i] = sa[i - 1] + a[i]\n sb[i] = sb[i - 1] + b[i]\ni, j = 1, 1\nrec = []\nwhile i + j <= n:\n if sa[i - 1] == sb[j - 1]:\n rec.append(sa[i - 1])\n i += 1\n elif sa[i - 1] < sb[j - 1]:\n i += 1\n else:\n j += 1\n\nif len(rec) == 0:\n print(0)\nelse:\n print(max(rec))", "n = int(input())\na = list(map(int, input().split()))\n\nx = 0\ny = 0\nz = sum(a)\npos = -1\n\nfor i in range(n):\n x += a[i]\n z -= a[i]\n if x >= z:\n pos = i\n break\n\nl, r = pos, pos + 1\n\nwhile True:\n # print(l, r)\n if x > z and l >= 0:\n x -= a[l]\n l -= 1\n elif x < z and r < n:\n z -= a[r]\n r += 1\n elif x == z:\n print(x)\n return\n elif l < 0 or r >= n:\n print(0)\n return", "n = int(input())\na = [int(x) for x in input().split()]\n\nleft = 0\nright = n - 1\nleft_sum = 0\nright_sum = 0\nequal = 0\nwhile left <= right and left < n and right >= 0 :\n if left_sum > right_sum:\n right_sum += a[right]\n right -= 1\n else:\n left_sum += a[left]\n left += 1\n if left_sum == right_sum:\n equal = left_sum\n\nprint(equal)\n\n", "#from math import ceil, log\n\nt = 1#int(input())\nfor test in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n l = -1\n h = n\n curMax = 0\n sum1 = 0\n sum3 = 0\n while l<h:\n \tif sum1==sum3:\n \t\tcurMax = max(curMax, sum1)\n \t\tl+=1\n \t\tsum1+=arr[l]\n \telif sum1<sum3:\n \t\tl+=1\n \t\tsum1+=arr[l]\n \telse:\n \t\th-=1\n \t\tsum3+=arr[h]\n print(curMax)\n\n\n", "n = int(input())\na = list(map(int, input().split()))\ni = -1\nj = n\ns1, s2 = 0, 0\nans = 0\nwhile i < j:\n if s1 == s2:\n ans = max(ans, s1)\n if s1 >= s2:\n j -= 1\n s2 += a[j]\n\n\n else:\n i += 1\n s1 += a[i]\n\nprint(ans)", "n = int(input())\n\ndata = list(map(int,input().split()))\n\n\nind_l = 0\nind_r = n - 1\n\nsum_l = 0\nsum_r = 0\n\nanswer = 0\nwhile ind_l <= ind_r:\n sum_l+=data[ind_l]\n ind_l+=1\n\n while (sum_l > sum_r) and ind_l <= ind_r:\n sum_r += data[ind_r]\n ind_r -= 1\n\n \n if (sum_l == sum_r):\n answer = sum_l\n\nprint(answer)\n", "R = lambda: map(int, input().split())\n\nn = int(input())\na = list(R())\n\nans = 0\ni = 0\nj = n - 1\ns1 = 0\ns3 = 0\n\nwhile i < j:\n if s1 + a[i] == s3 + a[j]:\n s1 += a[i]\n s3 += a[j]\n i += 1\n j -= 1\n ans = s1\n elif s1 + a[i] < s3 + a[j]:\n s1 += a[i]\n i += 1\n else:\n s3 += a[j]\n j -= 1\nprint(ans)", "n = int(input())\nl = list(map(int, input().split()))\n\nmx = 0\nleft = 0\nright = n - 1\nsl = 0\nsr = 0\nwhile left <= right:\n\tif sl == sr:\n\t\tmx = sl\n\t\tsl += l[left]\n\t\tleft += 1\n\telif sl > sr:\n\t\tsr += l[right]\n\t\tright -= 1\n\telif sl < sr:\n\t\tsl += l[left]\n\t\tleft += 1\nif sl == sr:\n\tmx = sl\nprint(mx)", "n = int(input())\na = [int(i) for i in input().split()]\ni = -1\nj = n\nsum1 = 0\nsum2 = 0\nans = 0\nwhile i < j:\n while (sum1 <= sum2) and (i < j):\n i += 1\n if i == j:\n break\n sum1 += a[i]\n if (sum1 == sum2) and (sum1 > ans):\n ans = sum1\n# print(i, j, sum1, sum2)\n while (sum2 <= sum1) and (j > i):\n j -= 1\n if i == j:\n break\n sum2 += a[j]\n if (sum1 == sum2) and (sum1 > ans):\n ans = sum1\n# print(i, j, sum1, sum2)\n\nprint(ans)\n\n", "import bisect\n\nn = int(input())\na = list(map(int, input().split(' ')))\n\nprefs = [a[0]] * n\nsuffs = [a[n - 1]] * n\nfor i in range(1, len(a)):\n\tprefs[i] = prefs[i - 1] + a[i]\nfor i in reversed(list(range(0, len(a) - 1))):\n\tsuffs[i] = suffs[i + 1] + a[i]\n\nans = 0\nfor i in range(len(a)):\n\ts = suffs[i]\n\tind = bisect.bisect_left(prefs, s)\n\tif prefs[ind] == s and ind < i:\n\t\tans = s\n\t\tbreak\n\nprint(ans)\n", "n=int(input())\na=list(map(int,input().split()))\nsuma=i=0\nflag=0\nsum1=0\nsum3=0\nj=n-1\nidxs=i\nidxe=j\nwhile(True):\n if((sum1==0 and sum3==0) or (sum1<sum3)):\n sum1+=a[i]\n i+=1\n elif(sum3<sum1):\n sum3+=a[j]\n j-=1\n elif(sum1==sum3):\n suma+=sum1\n flag=1\n sum1=0\n sum3=0\n if(j<i-1):\n break\n \n\nif(flag):\n print(suma)\nelse:\n print(0)\n", "#!/usr/bin/env python3\n\nn = int(input())\nx = [int(i) for i in input().split()]\n\nS1, S3, L, R = 0, 0, -1, n\nMaxS = 0\nwhile L < R:\n if S1 == S3:\n MaxS = S1\n L += 1\n S1 += x[L]\n elif S1 > S3:\n R -= 1\n S3 += x[R]\n else:\n L += 1\n S1 += x[L]\nprint(MaxS)\n\n\n", "length = int(input())\n\nnumbers = list(map(int, input().split(' ')))\n\nlastResult = 0\n\nsum1, sum3 = 0, 0\ni1, i3 = 0, length-1\n\nwhile True:\n if i1 > i3:\n break\n if sum1 < sum3:\n sum1 += numbers[i1]\n i1 += 1\n elif sum1 > sum3:\n sum3 += numbers[i3]\n i3 -= 1\n else:\n lastResult = sum1\n sum1 += numbers[i1]\n i1 += 1\n\nprint(sum1 if sum1 == sum3 else lastResult)", "n = int(input())\na = list(map(int, input().split()))\ni, j, si, sj, r = -1, len(a), 0, 0, 0\nwhile i < j:\n if si == sj: r = si\n if si < sj:\n i += 1\n si += a[i]\n else:\n j -= 1\n sj += a[j]\nprint( r )\n"] | {
"inputs": [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n",
"1\n1000000000\n",
"2\n1 1\n",
"5\n1 3 5 4 5\n"
],
"outputs": [
"5\n",
"4\n",
"0\n",
"0\n",
"1\n",
"9\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,950 | |
d9facbd4ddbe7d932eba1096ca3151b1 | UNKNOWN | You are given three positive (i.e. strictly greater than zero) integers $x$, $y$ and $z$.
Your task is to find positive integers $a$, $b$ and $c$ such that $x = \max(a, b)$, $y = \max(a, c)$ and $z = \max(b, c)$, or determine that it is impossible to find such $a$, $b$ and $c$.
You have to answer $t$ independent test cases. Print required $a$, $b$ and $c$ in any (arbitrary) order.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The only line of the test case contains three integers $x$, $y$, and $z$ ($1 \le x, y, z \le 10^9$).
-----Output-----
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $a$, $b$ and $c$ ($1 \le a, b, c \le 10^9$) in the second line. You can print $a$, $b$ and $c$ in any order.
-----Example-----
Input
5
3 2 3
100 100 100
50 49 49
10 30 20
1 1000000000 1000000000
Output
YES
3 2 1
YES
100 100 100
NO
NO
YES
1 1 1000000000 | ["for testcase in range(int(input())):\n vals = list(map(int, input().split()))\n \n ans = None\n for a in vals:\n for b in vals:\n for c in vals:\n if max(a, b) == vals[0] and max(a, c) == vals[1] and max(b, c) == vals[2]:\n ans = [a, b, c]\n \n if ans is None:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*ans)\n \n", "def check(a, b, c, x, y, z):\n ok = True\n ok &= x == max(a, b)\n ok &= y == max(a, c)\n ok &= z == max(b, c)\n return ok\n\ndef solve():\n x,y,z = map(int,input().split())\n l = [x, y, z, 1, 10 ** 9]\n for a in l:\n for b in l:\n for c in l:\n if check(a, b, c, x, y, z):\n print('YES')\n print(a, b, c)\n return\n print('NO')\n\nt = int(input())\nfor _ in range(t):\n solve()", "def solve():\n x, y, z = map(int, input().split())\n for s in range(1 << 3):\n a = x if s & 1 else y\n b = x if s & 2 else z\n c = y if s & 4 else z\n if x == max(a, b) and y == max(a, c) and z == max(b, c):\n print('YES')\n print(a, b, c)\n return\n print('NO')\n\nt = int(input())\nfor _ in range(t):\n solve()", "for _ in range(int(input())):\n a = sorted(list(map(int, input().split())))\n if (a[1] != a[2]):\n print(\"NO\")\n else:\n print(\"YES\")\n print(a[0], a[0], a[2])\n\n", "t=int(input())\nfor _ in range(t):\n a=list(map(int,input().split()))\n a.sort()\n if a[1]==a[2]:\n print('YES')\n ans=[]\n ans.append(str(a[1]))\n ans.append(str(a[0]))\n ans.append(str(a[0]))\n print(' '.join(ans))\n else:\n print('NO')\n", "t=int(input())\ndef fun(x,y,z):\n a=-1\n b=-1\n c=-1\n flag=0\n l=[x,y,z]\n for i in l:\n for j in l:\n for k in l:\n if x==max(i,j) and y==max(i,k) and z==max(j,k):\n flag=1\n a=i\n b=j\n c=k\n break\n if flag:\n break\n if flag:\n break\n if flag:\n print(\"YES\")\n print(a,b,c)\n else:\n print(\"NO\")\nwhile t:\n t-=1\n x,y,z=list(map(int,input().split()))\n fun(x,y,z)\n", "\ntt = int(input())\n\nfor loop in range(tt):\n\n x,y,z = list(map(int,input().split()))\n\n if x == y == z:\n print (\"YES\")\n print(x,y,z)\n elif x == y and x > z:\n print (\"YES\")\n print(x,z,z)\n elif x == z and x > y:\n print (\"YES\")\n print(y,x,y)\n elif y == z and y > x:\n print (\"YES\")\n print(x,x,y)\n else:\n print (\"NO\")\n \n", "\"\"\"\n pppppppppppppppppppp\n ppppp ppppppppppppppppppp\n ppppppp ppppppppppppppppppppp\n pppppppp pppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp pppppppp\n ppppppppppppppppppppp ppppppp\n ppppppppppppppppppp ppppp\n pppppppppppppppppppp\n\"\"\"\n\n\nimport sys\nfrom functools import lru_cache, cmp_to_key\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque, Counter as C\nfrom itertools import combinations as comb, permutations as perm\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nfrom time import perf_counter\nfrom fractions import Fraction\nfrom decimal import Decimal\n# sys.setrecursionlimit(pow(10, 6))\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"output.txt\", \"w\")\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef data(): return sys.stdin.readline().strip()\ndef out(var): sys.stdout.write(str(var)+\"\\n\")\ndef outa(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var)) + end)\ndef l(): return list(sp())\ndef sl(): return list(ssp())\ndef sp(): return list(map(int, data().split()))\ndef ssp(): return list(map(str, data().split()))\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\n\n\nfor _ in range(int(data())):\n a = l()\n a.sort()\n if a[0] == a[1] == a[2]:\n out(\"YES\")\n outa(*a)\n continue\n if a[1] == a[2]:\n out(\"YES\")\n outa(a[2], a[0], a[0])\n continue\n out(\"NO\")\n", "import sys\n#q=1\nq=int(input())\nfor i in range(q):\n #n,m=[int(j) for j in sys.stdin.readline().split()]\n #n=int(sys.stdin.readline())\n a=[int(j) for j in sys.stdin.readline().split()]\n a.sort()\n if a[1]==a[2]:\n print('YES')\n print(a[0],a[0],a[2])\n else:\n print('NO')", "import math as mt \nimport sys,string\ninput=sys.stdin.readline\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : list(map(int,input().split()))\nI=lambda :int(input())\nfrom collections import defaultdict\n\n\n\nt=I()\nfor i in range(t):\n x,y,z=M()\n d=[x,y,z]\n p=max(x,y,z)\n c=0\n for j in d:\n if(j==p):\n c+=1\n if(c>=2):\n print(\"YES\")\n if(c==2):\n print(min(x,y,z),min(x,y,z),p)\n else:\n print(p,p,p)\n else:\n print(\"NO\")\n", "for u in range(int(input())):\n x, y, z = map(int, input().split())\n \n t = max(x, y, z)\n ans = 0\n if t == x:\n ans += 1\n if t ==y:\n ans += 1\n if t == z:\n ans += 1\n \n if ans >=2:\n print(\"YES\")\n print(min(x,y,z), min(x, y, z), t)\n else:\n print('NO')", "def solve(x, y, z):\n x, y, z = sorted([x, y, z])\n if x == y == z:\n return [x, x, x]\n elif x < y and y == z:\n return [x, x, z]\n return None\n\nt = int(input())\nfor _ in range(t):\n # n = int(input())\n x, y, z = map(int, input().split())\n # c = list(map(int, input().split()))\n sol = solve(x, y, z)\n if sol:\n print('YES')\n print(' '.join(map(str, sol)))\n else:\n print('NO')", "import sys\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\ndef mint():\n\treturn int(minp())\n\ndef mints():\n\treturn list(map(int, minp().split()))\n\ndef solve():\n\ta = list(mints())\n\ta.sort()\n\tif a[-1] != a[-2]:\n\t\tprint(\"NO\")\n\t\treturn\n\telse:\n\t\tprint(\"YES\")\n\t\tprint(a[0],a[0],a[1])\n\nfor i in range(mint()):\n\tsolve()\n", "T, = list(map(int, input().split()))\nfor _ in range(T):\n x, y, z = list(map(int, input().split()))\n if x == z and z>=y:\n print(\"YES\")\n print(y, x, y)\n elif y == z and z>=x:\n print(\"YES\")\n print(x, x, z)\n elif x == y and x>=z:\n print(\"YES\")\n print(x, z, z)\n else:\n print(\"NO\")\n\n\n", "for _ in range(int(input())):\n l = list(map(int,input().split()))\n l.sort()\n if l[1]==l[2]:\n print(\"YES\")\n print(l[0],l[0],l[2])\n else:\n print(\"NO\")", "for _ in range(int(input())):\n x,y,z=map(int,input().split())\n a,b,c=min(x,y),min(x,z),min(y,z)\n if x==max(a,b) and y==max(a,c) and z==max(b,c):print('YES');print(a,b,c)\n else:print('NO')", "import sys\ninput = sys.stdin.readline\nfor f in range(int(input())):\n x,y,z=map(int,input().split())\n a=min(x,y)\n b=min(x,z)\n c=min(y,z)\n if max(a,b)!=x or max(a,c)!=y or max(b,c)!=z:\n print(\"NO\")\n else:\n print(\"YES\")\n print(a,b,c)", "from itertools import *\nfor i in range(int(input())):\n x, y, z = list(map(int ,input().split()))\n a = [x, y, z, min(x, y, z), max(x, y, z)]\n ha = False\n for p in permutations(a):\n if max(p[0], p[1]) == x and max(p[0], p[2]) == y and max(p[1], p[2]) == z:\n print(\"YES\")\n print(*p[:3])\n ha = True\n break\n if not ha:\n print(\"NO\")\n"] | {
"inputs": [
"5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000\n",
"2\n5 7 7\n6 7 3\n",
"1\n127869 127869 127869\n",
"1\n12789 12789 12789\n",
"1\n78738 78738 78738\n",
"1\n78788 78788 78788\n"
],
"outputs": [
"YES\n2 2 3\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000\n",
"YES\n5 5 7\nNO\n",
"YES\n127869 127869 127869\n",
"YES\n12789 12789 12789\n",
"YES\n78738 78738 78738\n",
"YES\n78788 78788 78788\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,574 | |
c79d5d89fb0e94e6790b9052276d023d | UNKNOWN | Maksim has $n$ objects and $m$ boxes, each box has size exactly $k$. Objects are numbered from $1$ to $n$ in order from left to right, the size of the $i$-th object is $a_i$.
Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to right through the objects, and if the $i$-th object fits in the current box (the remaining size of the box is greater than or equal to $a_i$), he puts it in the box, and the remaining size of the box decreases by $a_i$. Otherwise he takes the new empty box and continues the process above. If he has no empty boxes and there is at least one object not in some box then Maksim cannot pack the chosen set of objects.
Maksim wants to know the maximum number of objects he can pack by the algorithm above. To reach this target, he will throw out the leftmost object from the set until the remaining set of objects can be packed in boxes he has. Your task is to say the maximum number of objects Maksim can pack in boxes he has.
Each time when Maksim tries to pack the objects into the boxes, he will make empty all the boxes he has before do it (and the relative order of the remaining set of objects will not change).
-----Input-----
The first line of the input contains three integers $n$, $m$, $k$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \le k \le 10^9$) β the number of objects, the number of boxes and the size of each box.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the size of the $i$-th object.
-----Output-----
Print the maximum number of objects Maksim can pack using the algorithm described in the problem statement.
-----Examples-----
Input
5 2 6
5 2 1 4 2
Output
4
Input
5 1 4
4 2 3 4 1
Output
1
Input
5 3 3
1 2 3 1 1
Output
5
-----Note-----
In the first example Maksim can pack only $4$ objects. Firstly, he tries to pack all the $5$ objects. Distribution of objects will be $[5], [2, 1]$. Maxim cannot pack the next object in the second box and he has no more empty boxes at all. Next he will throw out the first object and the objects distribution will be $[2, 1], [4, 2]$. So the answer is $4$.
In the second example it is obvious that Maksim cannot pack all the objects starting from first, second, third and fourth (in all these cases the distribution of objects is $[4]$), but he can pack the last object ($[1]$).
In the third example Maksim can pack all the objects he has. The distribution will be $[1, 2], [3], [1, 1]$. | ["n, m, k = [int(_) for _ in input().split()]\na = [int(_) for _ in input().split()]\n\nb = k\ncount = 0\nfor obj in a[::-1]:\n if obj > k:\n break\n if obj > b:\n if m > 1:\n m -= 1\n b = k - obj\n count += 1\n else:\n break\n else:\n b -= obj\n count += 1\n\nprint(count)\n\n", "n,m,k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\na = a[::-1]\nboxes = 0\nans = 0\nloc = 0\nfor i in range(n):\n loc += a[i]\n if loc > k:\n boxes += 1\n loc = a[i]\n if boxes == m:\n break\n ans += 1\n # print(ans,boxes,loc)\nprint(ans)\n\n", "n,m,k = list(map(int, input().split()))\nlist_a = list(map(int, input().split()))\nlist_a.reverse()\ncount_b = 0\nsum_now = 0\nans = 0\ni = 0\nwhile i < n:\n\tif count_b >= m:\n\t\tans = i - 1\n\t\tbreak\n\tsum_now += list_a[i]\n\tif sum_now > k:\n\t\tsum_now = 0\n\t\tcount_b +=1\n\telse:\n\t\ti += 1\nelse:\n\tans = n-1\nprint(ans+1)\n", "n, m, k = map(int, input().split())\na = list(map(int, input().split()))\n\n# left = -1\n# right = n-1\n\n# while right - left > 1:\n# \tmid = (right+left)//2\n\t\n# \tcount = 0\n# \tcurr = 0\n# \tfor i in range(mid, n):\n# \t\tif curr + a[i] <= k:\n# \t\t\tcurr += a[i]\n# \t\telse:\n# \t\t\tcount += 1\n# \t\t\tcurr = a[i]\n# \tcount += 1\n\t\n# \tif count > m:\n# \t\tleft = mid\n# \telse:\n# \t\tright = mid\n\n# print(n-right)\n\ncount = 0\ncurr = 0\ni = n\nwhile count < m and i >= 0:\n\ti -= 1\n\tif curr + a[i] <= k:\n\t\tcurr += a[i]\n\telse:\n\t\tcount += 1\n\t\tcurr = a[i]\n\nprint(n-i-1)", "def fit(a, m, k, res):\n\tk1 = k\n\tfor ai in a[-res:]:\n\t\tif ai <= k1:\n\t\t\tk1 -= ai\n\t\telse:\n\t\t\tk1 = k-ai\n\t\t\tif m == 1:\n\t\t\t\treturn False\n\t\t\telse:\n\t\t\t\tm -= 1\n\treturn True\n\t# \u0421 \u043d\u0435\u043a. \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0451 \u0432\u043e\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c (\u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e)\n\n\ndef bisect(n, m, k, a):\n\tleft, right = 0, n+1\n\twhile left + 1 < right:\n\t\tmiddle = (left + right) // 2\n\t\tif fit(a, m, k, middle):\n\t\t\tleft = middle\n\t\telse:\n\t\t\tright = middle\n\treturn left\n\n\ndef main():\n\tn, m, k = list(map(int, input().split()))\n\ta = tuple(map(int, input().split()))\n\tprint(bisect(n, m, k, a))\nmain()\n", "n,m,k = [int(s) for s in input().split()]\na = [int(s) for s in input().split()]\nans = 0\nboxi = 0\nrem_size = k\nfor i in range(n-1, -1, -1):\n if a[i] > k:\n break\n if a[i] > rem_size:\n if boxi >= m-1:\n break\n else:\n boxi += 1\n rem_size = k\n rem_size -= a[i]\n ans += 1\n\nprint(ans)", "from sys import stdin\nn,m,k=list(map(int,stdin.readline().strip().split()))\ns=tuple(map(int,stdin.readline().strip().split()))\nx=0\ny=0\nans=0\nfor i in range(n-1,-1,-1):\n if x==m:\n break\n if y+s[i]>k:\n if s[i]>k:\n break\n x+=1\n if x==m:\n break\n ans+=1\n y=s[i]\n else:\n y+=s[i]\n ans+=1\n \nprint(ans)\n", "n,m,k=[int(x)for x in input().split()]\nns=[int(x)for x in input().split()]\nns.reverse()\nrem=k\nnum=0\nans=[]\nfor i in range(n):\n if rem>=ns[i]:\n rem-=ns[i]\n num+=1\n else:\n ans.append(num)\n rem=k-ns[i]\n num=1\nif num>0:\n ans.append(num)\n\n# print(ans)\n\nif len(ans)<=m:\n print(sum(ans))\nelse:\n a=[sum(ans[:m])]\n # for i in range(m,len(ans)):\n # a.append(a[-1]+ans[i]-ans[i-m])\n print(max(a))", "def main():\n nobj, nbox, boxsize = list(map(int, input().split()))\n obj = list(map(int, input().split()))\n box = boxsize\n curr = 0\n ans = 0\n i = nobj - 1\n while i >= 0:\n o = obj[i]\n #print('box: ' + str(box) + ' i = ' + str(i) + ', o = ' + str(o))\n if o <= box:\n box -= o\n ans += 1\n else:\n curr += 1\n box = boxsize\n if curr >= nbox:\n break\n continue\n i -= 1\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "# coding=utf-8\n\nn, m, k = map(int, input().split())\n\na = [int(i) for i in input().split()]\n\ncur = 0\nans = 0\nbox = k\ni = n - 1\n\nwhile i >= 0:\n obj = a[i]\n if obj <= box:\n box -= obj\n ans += 1\n else:\n cur += 1\n box = k\n if cur >= m:\n break\n continue\n i -= 1\n\nprint(ans)", "# coding=utf-8\n\nn, m, k = map(int, input().split())\n\na = [int(i) for i in input().split()]\n\ncur = 0\nans = 0\nbox = k\ni = n - 1\n\nwhile i >= 0:\n obj = a[i]\n if obj <= box:\n box -= obj\n ans += 1\n else:\n cur += 1\n box = k\n if cur >= m:\n break\n continue\n i -= 1\n\nprint(ans)", "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\na = a[::-1]\n\nres = 0\nweight = 0\n\nfor i in range(n):\n weight += a[i]\n if weight > k:\n weight = a[i]\n m -= 1\n if m <= 0:\n break\n res += 1\n\nprint(res)\n", "import sys\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\nn,mm,k = map(int,minp().split())\na = list(map(int,minp().split()))\ndef tt(x):\n\tm = mm-1\n\tc = 0\n\tfor j in range(x,n):\n\t\ti = a[j]\n\t\tif c + i > k:\n\t\t\tif m == 0 or i > k:\n\t\t\t\treturn False\n\t\t\tc = i\n\t\t\tm -= 1\n\t\t\t#if i == k:\n\t\t\t#\tif m == 0:\n\t\t\t#\t\treturn False\n\t\t\t#\tm -= 1\n\t\t\t#\tc = 0\n\t\telse:\n\t\t\tc += i\n\treturn True\nl = 0\nr = n\nwhile l < r:\n\tc = (l+r)//2\n\tif tt(c):\n\t\tr = c\n\telse:\n\t\tl = c+1\nprint(n-r)", "import sys\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\nn,mm,k = list(map(int,minp().split()))\na = list(map(int,minp().split()))\ndef tt(x):\n\tm = mm-1\n\tc = 0\n\tres = 0\n\tfor i in reversed(a):\n\t\tif c + i > k:\n\t\t\tif m == 0 or i > k:\n\t\t\t\treturn res\n\t\t\tc = i\n\t\t\tm -= 1\n\t\t\t#if i == k:\n\t\t\t#\tif m == 0:\n\t\t\t#\t\treturn False\n\t\t\t#\tm -= 1\n\t\t\t#\tc = 0\n\t\telse:\n\t\t\tc += i\n\t\tres += 1\n\treturn res\nprint(tt(0))\n#l = 0\n#r = n\n#while l < r:\n#\tc = (l+r)//2\n#\tif tt(c):\n#\t\tr = c\n#\telse:\n#\t\tl = c+1\n#print(n-r)\n", "import sys\ninput = sys.stdin.readline\n\ndef main():\n n, m, k = map(int, input().split())\n a = list(map(int, input().split()))\n if min(a) > k:\n return 0\n a = a[::-1]\n current = 0\n answer = 0\n for i in range(n):\n if current + a[i] <= k:\n current += a[i]\n answer += 1\n else:\n current = 0\n m -= 1\n if m == 0:\n break\n else:\n if current + a[i] < k:\n current += a[i]\n answer += 1\n elif current + a[i] == k:\n answer += 1\n m -= 1\n if m == 0:\n break\n else:\n continue\n return answer\ndef __starting_point():\n print(main())\n__starting_point()", "n,m,k=list(map(int,input().split()))\narr=list(map(int,input().split()))\narr1=[0]*n\ni=n-1\nprevval=0\nans=0\nwhile(i>=0 and m>0):\n\tif(prevval+arr[i]<=k):\n\t\tprevval+=arr[i]\n\telse:\n\t\tm-=1\n\t\tprevval=arr[i]\n\ti-=1\n\tans+=1\nif(m==0):\n\tans-=1\nprint(ans)\n", "n,m,k=list(map(int,input().split()))#object,\u7bb1,size,\nA=list(map(int,input().split()))#size\n\n\nA.reverse()\ninb=0\nbox=0\ni=0\nwhile box<m and i<n:\n if inb+A[i]<=k:\n inb+=A[i]\n i+=1\n else:\n box+=1\n inb=0\n \nprint(i)\n", "import sys\nimport math\n\nn,m,k=map(int,input().split())\njobs=[int(x) for x in input().strip().split()]\nsteve=jobs[:]\nnade=steve[::-1]\nsuma,con,kik=0,0,0\nfor i in range(n):\n if(nade[i]>k):\n break\n if(suma+nade[i]<k):\n #print(\"A\")\n suma+=nade[i]\n kik+=1\n if(i<n-1):\n if(suma+nade[i+1]>k):\n suma=0\n con+=1\n elif(suma+nade[i]==k):\n #print(\"B\")\n #print(\"SPC CASE\",suma,nade[i],suma+nade[i])\n con+=1\n kik+=1\n suma=0\n elif(suma+nade[i]>k):\n #print(\"C\")\n con+=1\n suma=0\n #print(suma,kik)\n if(con>=m):\n break\nprint(kik)", "import math\nimport sys\nn,m,k = map(int, sys.stdin.readline().split())\na =[int(x) for x in sys.stdin.readline().split()]\na.reverse()\nans = 0\nbag = m - 1\nsize = k\nfor x in a:\n if size < x:\n if bag > 0:\n bag -= 1\n size = k - x\n else: break\n else: size -= x\n ans += 1\nsys.stdout.write(str(ans))", "def bS(alist, item):\n first = 0\n last = len(alist)-1\n found = False\n posi=-1\t\n while (first<=last+1) and (not found):\n midpoint = (first + last)//2\n #print(midpoint,alist[midpoint-1] )\n if (alist[midpoint]>=item):#and (alist[midpoint+1] <= item):\n found = True\n posi=midpoint\n else:\n if item < alist[midpoint]:\n last = midpoint-1\n else:\n first = midpoint+1\n\t\n return posi\n\n\nn,m,k=list(map(int,input().split()))\na=list(input().split())\nmaxi=0\ncc=0\nnow=-1\nalr=0\nalfa=[0]*n\nlast=0\nfor ii in range(n):\n i=n-ii-1\n alfa[ii]=int(a[i])+last\n last=alfa[ii]\n\n#print(alfa)\nif alfa[-1]>m*k:\n pos=bS(alfa,m*k)\nelse:\n pos=n-1\n\n#print(pos)\nii=n-pos-1\n#b=a[ii+1:].copy()\nb=a\nb.reverse()\nmaxi=0\nstart=0\n#for start in range(n):\nif (1==1):\n #if n-start<maxi:\n # break\n alr=0\n cc=0\n for i in b[start:]:\n alr+=int(i)\n cc+=1\n \n if alr>k:\n alr=int(i)\n if alr>k:\n cc-=1\n m-=1\n if m==0:\n cc-=1\n break\n if cc>maxi:\n maxi=cc\n \n \nprint(maxi) \n\n\n\n\n \n\n \n", "def go():\n n, m, k = [int(i) for i in input().split(' ')]\n a = [int(i) for i in input().split(' ')]\n current_box = k\n m -= 1\n c = 0\n for i in range(n - 1, -1, -1):\n if a[i] <= current_box:\n current_box -= a[i]\n c += 1\n elif a[i] > current_box:\n current_box = k - a[i]\n if m == 0:\n break\n m -= 1\n c += 1\n return c\n\nprint(go())\n", "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na.reverse()\nlast = 0\nfor i in range(n):\n if a[i] > last:\n if m == 0:\n print(i)\n return\n else:\n m -= 1\n last = k - a[i]\n else:\n last -= a[i]\nprint(n)\n", "n,m,k=list(map(int,input().split()))\ncnt=0\ncount=0\nsum=0\na=[int(s) for s in input().split()]\nfor i in range(n-1,-1,-1):\n sum+=a[i]\n if sum>k:\n sum=a[i]\n count+=1\n if count>=m:\n break\n cnt+=1\nprint(cnt)\n", "\nn,k,m=list(map(int,input().split()))\nl=[int(i) for i in input().split()]\ndef ispzbl(l,n,m,k,mid):\n z=l[mid:]\n if not z:\n return True \n s=0\n box=1\n for i in z:\n s+=i \n if s>m:\n box+=1 \n s=i\n return box<=k\nlow=0 \nhigh=n-1 \nwhile low<=high:\n mid=(low+high)//2\n # print(mid)\n if ispzbl(l,n,m,k,mid):\n ans=mid \n high=mid-1 \n else:\n low=mid+1 \n#print(ans)\nprint(n-ans)\n"] | {
"inputs": [
"5 2 6\n5 2 1 4 2\n",
"5 1 4\n4 2 3 4 1\n",
"5 3 3\n1 2 3 1 1\n",
"5 4 2\n1 2 1 2 1\n",
"1 1 1\n1\n",
"5 5 5\n5 5 5 5 5\n"
],
"outputs": [
"4\n",
"1\n",
"5\n",
"4\n",
"1\n",
"5\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 11,945 | |
53b3d0fa65ab0c6c27be8ad8555af2ef | UNKNOWN | Recently, Norge found a string $s = s_1 s_2 \ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$. Yes, all $\frac{n (n + 1)}{2}$ of them!
A substring of $s$ is a non-empty string $x = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}$ ($1 \leq a \leq b \leq n$). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only $k$ Latin letters $c_1, c_2, \ldots, c_k$ out of $26$.
After that, Norge became interested in how many substrings of the string $s$ he could still type using his broken keyboard. Help him to find this number.
-----Input-----
The first line contains two space-separated integers $n$ and $k$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq k \leq 26$) β the length of the string $s$ and the number of Latin letters still available on the keyboard.
The second line contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
The third line contains $k$ space-separated distinct lowercase Latin letters $c_1, c_2, \ldots, c_k$ β the letters still available on the keyboard.
-----Output-----
Print a single number β the number of substrings of $s$ that can be typed using only available letters $c_1, c_2, \ldots, c_k$.
-----Examples-----
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
-----Note-----
In the first example Norge can print substrings $s[1\ldots2]$, $s[2\ldots3]$, $s[1\ldots3]$, $s[1\ldots1]$, $s[2\ldots2]$, $s[3\ldots3]$, $s[5\ldots6]$, $s[6\ldots7]$, $s[5\ldots7]$, $s[5\ldots5]$, $s[6\ldots6]$, $s[7\ldots7]$. | ["n, k = map(int, input().split())\ns = set()\nst = input()\ninp = input().split()\nfor x in inp:\n s.add(x)\ncurrent, ans = 0, 0\nfor x in st:\n if x in s:\n current += 1\n else:\n ans += (current * (current + 1)) // 2\n current = 0\nans += (current * (current + 1)) // 2\nprint(ans)", "n,k=map(int,input().split())\ns=input()\nans1=0\nans=0\na=list(input())\nfor i in range(n):\n if s[i] in a:\n ans+=1\n else:\n ans1+=(ans*(ans+1)//2)\n ans=0\nans1+=(ans*(ans+1))//2 \nprint(ans1) ", "from math import *\nimport os, sys\nfrom io import BytesIO\n\n#input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nn, k = list(map(int, input().split()))\ns = input()\na = set(input().split())\nn += 1\ncan1 = [0] * n\ncan2 = [0] * n\nn -= 1\nans = 0\nfor i in range(n):\n if s[i] in a:\n can1[i + 1] = can1[i] + 1\n ans += can1[i + 1]\nprint(ans)\n", "import sys\nimport math\nn, k = list(map(int, input().split()))\ns = list(input())\nword = set((input().split()))\nlenArr = []\nsum = 0\nfor i in range(len(s)):\n if s[i] not in word:\n if sum != 0:\n lenArr.append(sum)\n sum = 0\n else:\n sum += 1\n\nif sum != 0:\n lenArr.append(sum)\n sum = 0\n\nans = 0\nfor i in range(len(lenArr)):\n ans += (lenArr[i] * (lenArr[i]+1)) // 2\nprint(ans)", "import sys\n\nn, k = map(int, sys.stdin.readline().strip().split(' '))\ns = sys.stdin.readline().strip()\nletters = sys.stdin.readline().strip().split(' ')\n\n#print(n, k, s, letters)\n#print(len(s))\n\ncurrent_counter = 0\nresult = 0\nfor c in s:\n\tif c in letters:\n\t\tcurrent_counter += 1\n\telse:\n\t\tresult += current_counter * (current_counter + 1) // 2\n\t\tcurrent_counter = 0\n\nresult += current_counter * (current_counter + 1) // 2\nprint(result)", "def f(n):\n return n*(n+1)//2\na,m = map(int,input().split())\ns = list(input())\nt = set(input().split())\np = 0\ni = 0\nans = 0\nwhile p<len(s):\n if s[p] not in t:\n ans+=f(i)\n i = 0\n else:\n i+=1\n p+=1\nans+=f(i)\nprint(ans)", "n,k=list(map(int,input().split()))\ns = input()\np=[]\nq=[]\nx=input().split()\nk=\"\"\nt=0\nfor i in s:\n if i in x:\n k+=i\n t+=1\n else:\n p.append(k)\n q.append(t)\n k=\"\"\n t=0\np.append(k)\nq.append(t)\nres = 0\nfor i in q:\n res+=(i*(i+1))//2\nprint(res)\n", "n, k = tuple(map(int, input().split()))\ns = input() + '!'\nlets = set(input().split())\n\nans = 0\ncnt = 0\nfor i in s:\n if i in lets:\n cnt += 1\n else:\n ans += cnt * (cnt + 1) // 2\n cnt = 0\n\nprint(ans)\n", "n, k = list(map(int, input().strip().split()))\nstring = input().strip()\nforbidden = input().strip().split()\n\nforbidden = set(forbidden)\n\nstring = list(string)\nfor i in range(len(string)):\n if string[i] not in forbidden:\n string[i] = None\n\ncnt = 0\ni = 0\nwhile i < len(string):\n if string[i] == None:\n i += 1\n else:\n j = i\n while j < len(string) and string[j] != None:\n j += 1\n diff = j - i\n cnt += (diff*(diff+1))//2\n i = j\n\nprint(cnt)", "n = input()\ns = input()\ns += \"-\"\navailable = input().split()\n\nlength = 0\nans = 0;\nfor i in s:\n if (i in available):\n length += 1\n else:\n ans += length*(length+1) // 2\n length = 0\n \nprint(ans)", "#!/usr/bin/env python3\n# coding: utf-8\n# Last Modified: 12/Dec/19 07:21:47 PM\n\n\nimport sys\n\n\ndef main():\n n, k = get_ints()\n s = input()\n d = set(input().split())\n ans = 0\n curr = 0\n for i in range(len(s)):\n if s[i] in d:\n curr += 1\n else:\n ans += (curr * (curr + 1)) // 2\n curr = 0\n ans += (curr * (curr + 1)) // 2\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()", "import sys, math\n\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef main():\n n, k = list(map(int,input().split()))\n s = input()\n c = set(input().split())\n prev = 0\n ans = 0\n for k in range(n):\n if s[k] not in c:\n l = k-prev\n ans += (l*(l+1))//2\n prev = k+1\n l = k-prev+1\n ans += (l*(l+1))//2\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "a, b = map(int, input().split())\ns = input()\nl = list(input().split(\" \"))\nmass = [0 for i in range(300)]\nfor i in range(b):\n mass[ord(l[i])] = 1\nresm = []\np = 0\nfor i in range(a):\n if mass[ord(s[i])] == 1:\n p += 1\n else:\n resm += [p]\n p = 0\nresm += [p]\nres = 0\nfor i in range(len(resm)):\n res += (resm[i] * (resm[i] + 1)) // 2\nprint(res)", "n,k=list(map(int,input().strip().split()))\nx=list(input())\na=input().strip().split()\nxx=0\nop=0\nfor i in x:\n if(i in a):\n xx+=1\n else:\n op=op+(xx*(xx+1)//2)\n xx=0\nop=op+(xx*(xx+1)//2) \n# xx=xx-len(x)+xx-1\n# print(xx*(xx+1)//2,xx,op)\nprint(op)", "n, k = map(int, input().split())\ns = input()\nchars = set(map(str, input().split()))\n\ntotal = 0\n\ncur = 0\nfor i in s:\n if i in chars:\n cur += 1\n else:\n if cur != \"\":\n total += cur*(cur+1) // 2\n cur = 0\n\nif cur != 0:\n total += cur*(cur+1) // 2\n\n\nprint(total)"] | {
"inputs": [
"7 2\nabacaba\na b\n",
"10 3\nsadfaasdda\nf a d\n",
"7 1\naaaaaaa\nb\n",
"200 13\nvgfjhgkgwkftaeqejmbgildembgxdbskxfndwmcckjfkbeekxkgakmcjhclqsecpnkaigcxxhfghgegfadjktckftdhtifriemfifakygoesjfginnddjjklwiwlbjsgftwhtjdxmcadpvhaeddxwnmguwhetwbmffbmvdvuhecgjckddrbikgwkrfwfhdhqolidgkfm\na b c d e f g h i j k l m\n",
"200 13\nqownuutwuwqnrxxtnlvnqtroztwpnvunynwrzzpsotnrqwxqstxnnzosszovtznquvxwvunpvxqzvyrwxwpxvxnnzzuzarepcqxzrseqqorwpuntzvwqnwuvvuygnpgrrznvootrtcvtxnoowywptwzvwrqwpxusuxqznvoqpnxsrquuzorkxvuwvpxyntrqywqvotuf\na b c d e f g h i j k l m\n",
"200 13\nuzqrruuwunntqnotxvtyzoqooznonqyvrpnzppvtowswpyvutsyynrrsozsswrnnzsxwrqrwuqwswxnxyxwqqsssoqvoortnxvtswtuxywnrnzutstvnqyutptxxtrzvxuwxstqqqvztqtnzrynwzuvosonnvquvpxunwpstpxvuqropxynytvvsxxsvuzvsusysrxpx\na b c d e f g h i j k l m\n"
],
"outputs": [
"12\n",
"21\n",
"0\n",
"578\n",
"10\n",
"0\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 5,580 | |
1ce4bc8b7b77432c3b11d4f332f606f3 | UNKNOWN | Recall that the sequence $b$ is a a subsequence of the sequence $a$ if $b$ can be derived from $a$ by removing zero or more elements without changing the order of the remaining elements. For example, if $a=[1, 2, 1, 3, 1, 2, 1]$, then possible subsequences are: $[1, 1, 1, 1]$, $[3]$ and $[1, 2, 1, 3, 1, 2, 1]$, but not $[3, 2, 3]$ and $[1, 1, 1, 1, 2]$.
You are given a sequence $a$ consisting of $n$ positive and negative elements (there is no zeros in the sequence).
Your task is to choose maximum by size (length) alternating subsequence of the given sequence (i.e. the sign of each next element is the opposite from the sign of the current element, like positive-negative-positive and so on or negative-positive-negative and so on). Among all such subsequences, you have to choose one which has the maximum sum of elements.
In other words, if the maximum length of alternating subsequence is $k$ then your task is to find the maximum sum of elements of some alternating subsequence of length $k$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of elements in $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9, a_i \ne 0$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the maximum sum of the maximum by size (length) alternating subsequence of $a$.
-----Example-----
Input
4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000
Output
2
-1
6
-2999999997
-----Note-----
In the first test case of the example, one of the possible answers is $[1, 2, \underline{3}, \underline{-1}, -2]$.
In the second test case of the example, one of the possible answers is $[-1, -2, \underline{-1}, -3]$.
In the third test case of the example, one of the possible answers is $[\underline{-2}, 8, 3, \underline{8}, \underline{-4}, -15, \underline{5}, \underline{-2}, -3, \underline{1}]$.
In the fourth test case of the example, one of the possible answers is $[\underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}]$. | ["for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n a=[]\n lis=[]\n prevsign=-1\n if l[0]>0:\n prevsign=1\n else:\n prevsign=0\n i=0\n for i in l:\n if (i>0 and prevsign==1) or (i<0 and prevsign==0):\n lis.append(i)\n else:\n if prevsign==1:\n a.append(max(lis))\n lis=[]\n lis.append(i)\n prevsign=0\n else:\n a.append(max(lis))\n lis=[]\n lis.append(i)\n prevsign=1\n \n if prevsign==1:\n a.append(max(lis))\n lis=[]\n lis.append(i)\n prevsign=0\n else:\n a.append(max(lis))\n lis=[]\n lis.append(i)\n prevsign=1\n print(sum(a))\n \n", "t = int(input())\nfor _ in range(t):\n n = int(input())\n a = list(map(int,input().split()))\n b = [a[0]]\n ans = 0\n for i in range(1,n):\n if b[0] < 0 and a[i] < 0:\n b.append(a[i])\n if b[0] > 0 and a[i] > 0:\n b.append(a[i])\n if b[0] < 0 and a[i] > 0:\n ans += max(b)\n b = [a[i]]\n if b[0] > 0 and a[i] < 0:\n ans += max(b)\n b = [a[i]]\n if len(b) >= 1:\n ans += max(b)\n print(ans)\n\n# a = list(map(int,input().split()))\n# n,m = map(int,input().split())\n\n\n", "from math import *\ntest = int(input())\nfor test_case in range(test):\n\tn = int(input())\n\ta = list(map(int,input().split()))\n\tif(a[0] > 0):\n\t\tf = 1\n\telse:\n\t\tf = 0\n\ti = 0\n\tans = 0\n\twhile(i < n):\n\t\tm = a[i]\n\t\tif(f == 1):\n\t\t\twhile(i < n and a[i] > 0):\n\t\t\t\tm = max(m,a[i])\n\t\t\t\ti += 1\n\t\telse:\n\t\t\twhile(i < n and a[i] < 0):\n\t\t\t\tm = max(m,a[i])\n\t\t\t\ti += 1\n\t\tf = f^1\n\t\t#print(m)\n\t\tans += m\n\tprint(ans)\n", "for i in range(int(input())):\n\tn=int(input())\n\ta=[int(j) for j in input().split()]\n\ts=0\n\tmx=a[0]\n\tfor j in range(n):\n\t\tif(a[j]*mx<0):\n\t\t\ts+=mx\n\t\t\tmx=a[j]\n\t\telse:\n\t\t\tmx=max(mx, a[j])\n\tprint(s+mx)", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n\n i = 1\n b, tmp = [], [a[0]]\n while i < n:\n if a[i] * tmp[0] > 0:\n tmp.append(a[i])\n else:\n b.append(tmp)\n tmp = [a[i]]\n i += 1\n\n b.append(tmp)\n\n s = 0\n for bb in b:\n s += max(bb)\n\n print(s)\n", "import sys\nlines = sys.stdin.readlines()\nT = int(lines[0].strip())\nfor t in range(T):\n n = int(lines[2*t+1].strip())\n nums = list(map(int, lines[2*t+2].strip().split(\" \")))\n res = []\n tmp = nums[0]\n for i in range(1, len(nums)):\n if nums[i] * nums[i-1] > 0:\n tmp = max(tmp, nums[i])\n else:\n res.append(tmp)\n tmp = nums[i]\n res.append(tmp)\n print(sum(res))\n", "from sys import stdin\ninput = stdin.readline\nt = int(input())\nfor rew in range(t):\n\tn = int(input())\n\tl = list(map(int,input().split()))\n\twyn = 0\n\tlistka = []\n\tcur = [l[0]]\n\tfor i in range(1,n):\n\t\tif cur and l[i] * cur[-1] < 0:\n\t\t\tlistka.append(cur)\n\t\t\tcur = [l[i]]\n\t\telse:\n\t\t\tcur.append(l[i])\n\tlistka.append(cur)\n\tfor i in listka:\n\t\twyn += max(i)\n\tprint(wyn)", "t = int(input())\nfor tt in range(t):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\ts = a[0]\n\tl = a[0]\n\tfor i in range(1, n):\n\t\tif a[i] > 0 and l < 0 or a[i] < 0 and l > 0:\n\t\t\tl = a[i]\n\t\t\ts += l\n\t\telif l < a[i]:\n\t\t\ts += a[i] - l\n\t\t\tl = a[i]\n\tprint(s)", "from sys import stdin, exit\nfrom bisect import *\nfrom heapq import heappush, heappop\nfrom itertools import combinations\nfrom collections import deque\ninput = stdin.readline\nlmi = lambda: list(map(int, input().split()))\nmi = lambda: map(int, input().split())\nsi = lambda: input().strip('\\n')\nssi = lambda: input().strip('\\n').split()\n\nfor _ in range(int(input())):\n n = int(input())\n arr = lmi()\n i = 0\n tmp = []\n ans = 0\n while i < n:\n tmp.append(arr[i])\n i+= 1\n if i >=n or (arr[i] > 0) != (arr[i-1] > 0):\n ans += max(tmp)\n tmp = []\n print(ans)", "t=int(input())\nfor pp in range(0,t):\n n=int(input())\n ip=list(map(int,input().split()))\n if(ip[0]>0):\n arr=[]\n curr=ip[0]\n sign=1\n for i in range(1,len(ip)):\n num=ip[i]\n if(num>0 and sign==1 and num>curr):\n curr=num\n elif(num<0 and sign==1):\n arr.append(curr)\n curr=num\n sign=-1\n elif(sign==-1):\n if(num<0 and num>curr):\n curr=num\n if(num>0):\n arr.append(curr)\n curr=num\n sign=1\n arr.append(curr)\n else:\n arr=[]\n curr=ip[0]\n sign=-1\n for i in range(1,len(ip)):\n num=ip[i]\n if(num>0 and sign==1 and num>curr):\n curr=num\n elif(num<0 and sign==1):\n arr.append(curr)\n curr=num\n sign=-1\n elif(sign==-1):\n if(num<0 and num>curr):\n curr=num\n if(num>0):\n arr.append(curr)\n curr=num\n sign=1\n arr.append(curr)\n ss=sum(arr)\n print(ss)", "t = int(input())\nfor i in range(t):\n n = int(input())\n a = [int(i) for i in input().split()]\n ans = 0\n index = 0\n now = a[0]\n mx = a[0]\n while index < n:\n while index < n and now * a[index] > 0:\n mx = max(mx, a[index])\n index += 1\n ans += mx\n if index == n:\n break\n now = a[index]\n mx = a[index]\n print(ans)\n", "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = [int(x) for x in input().strip().split()]\n i = 0\n res = 0\n while i<n:\n if a[i]>0:\n pi = 0 \n while i<n and a[i]>0:\n pi = max(pi, a[i])\n i+=1\n \n res+=pi\n else:\n ni = -10**10\n while i<n and a[i]<0:\n ni = max(ni,a[i])\n i+=1\n res+=ni\n print(res)", "t = int(input())\nfor i in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n ind = 0\n ans = 0\n while ind < n:\n cur = -10000000001\n if a[ind] < 0:\n while ind < n and a[ind] < 0:\n cur = max(a[ind], cur)\n ind += 1\n else:\n while ind < n and a[ind] > 0:\n cur = max(a[ind], cur)\n ind += 1\n ans += cur\n print(ans)", "t=int(input())\nfor i in range(t):\n n=int(input())\n nums=list(map(int,input().split()))\n currentmax=nums[0]\n ans=0\n if nums[0]>0:\n pos=1\n else:\n pos=-1\n for j in range(1,n):\n if nums[j]>0:\n if pos==1:\n if nums[j]>currentmax:\n currentmax=nums[j]\n else:\n ans=ans+currentmax\n currentmax=nums[j]\n pos=1\n else:\n if pos==-1:\n if nums[j]>currentmax:\n currentmax=nums[j]\n else:\n ans=ans+currentmax\n currentmax=nums[j]\n pos=-1\n ans=ans+currentmax\n print(ans)"] | {
"inputs": [
"4\n5\n1 2 3 -1 -2\n4\n-1 -2 -1 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n",
"2\n2\n1 2\n1\n1\n",
"2\n4\n1 2 3 4\n3\n1 2 3\n",
"4\n5\n1 2 3 -1 -1\n4\n-4 -2 -4 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n",
"2\n2\n-1 -1\n1\n-2\n",
"10\n10\n-1 5 6 2 -8 -7 -6 5 -3 -1\n10\n1 2 3 4 5 6 7 8 9 10\n1\n6\n1\n-7\n11\n5 -4 1 2 3 -5 -7 -10 -2 1 12\n4\n-4 -5 -6 1\n7\n1 2 6 3 2 -6 -2\n5\n-1 -5 4 -2 -9\n1\n9\n3\n1 -1 1\n"
],
"outputs": [
"2\n-1\n6\n-2999999997\n",
"2\n1\n",
"4\n3\n",
"2\n-2\n6\n-2999999997\n",
"-1\n-2\n",
"3\n10\n6\n-7\n14\n-3\n4\n1\n9\n1\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 7,728 | |
504c85ecfe8d129426ae07d68edb9515 | UNKNOWN | You are given a board of size $n \times n$, where $n$ is odd (not divisible by $2$). Initially, each cell of the board contains one figure.
In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell $(i, j)$ you can move the figure to cells: $(i - 1, j - 1)$; $(i - 1, j)$; $(i - 1, j + 1)$; $(i, j - 1)$; $(i, j + 1)$; $(i + 1, j - 1)$; $(i + 1, j)$; $(i + 1, j + 1)$;
Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.
Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. $n^2-1$ cells should contain $0$ figures and one cell should contain $n^2$ figures).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 200$) β the number of test cases. Then $t$ test cases follow.
The only line of the test case contains one integer $n$ ($1 \le n < 5 \cdot 10^5$) β the size of the board. It is guaranteed that $n$ is odd (not divisible by $2$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$ ($\sum n \le 5 \cdot 10^5$).
-----Output-----
For each test case print the answer β the minimum number of moves needed to get all the figures into one cell.
-----Example-----
Input
3
1
5
499993
Output
0
40
41664916690999888 | ["a=int(input())\n\nfor ufui in range(a):\n val=int(input())\n\n num=val//2 + 1\n count=0\n\n for i in range(num):\n count=count+i*((2*i+1)**2 - (2*i-1)**2)\n\n print (count)\n \n", "import sys\ninput = sys.stdin.readline\nrInt = lambda: int(input())\nmInt = lambda: list(map(int, input().split()))\nrLis = lambda: list(map(int, input().split()))\n\nt = rInt()\nfor _ in range(t):\n n = rInt()\n center = n//2\n out = 0\n for i in range(1, n // 2 + 1):\n out += i * i * 8\n print(out)\n", "import sys\n\nreadline = sys.stdin.readline\nreadall = sys.stdin.read\nns = lambda: readline().rstrip()\nni = lambda: int(readline().rstrip())\nnm = lambda: map(int, readline().split())\nnl = lambda: list(map(int, readline().split()))\nprn = lambda x: print(*x, sep='\\n')\n\n\ndef solve():\n n = ni()\n c = 0\n for i in range(n//2):\n c += (i+1)*(i+1)*2*4\n print(c)\n return\n\n# solve()\n\nT = ni()\nfor _ in range(T):\n solve()\n", "\nt = int(input())\n\nfor loop in range(t):\n\n n = int(input())\n\n ans = 0\n for i in range(n//2+1):\n ans += i * ( (i*2+1)**2 - (i*2-1)**2 )\n\n print (ans)\n", "for _ in range(int(input())):\n n=int(input())\n x=n//2\n res=0\n for i in range(1,x+1):\n res+=8*i*i\n print(res)\n", "from sys import stdin, stdout, setrecursionlimit\nfor _ in range(int(input())):\n n = int(input())\n summa = 0\n while n > 0:\n summa += 4 * (n // 2) + 4 * (n - 2) * (n // 2)\n n -= 2\n print(summa)\n\n\n\n\n\n\n", "t = int(input())\nfor i in range(t):\n n = int(input())\n s = 0\n for j in range(1, (n + 1) // 2):\n s += j * ((2*j + 1) * 4 - 4)\n print(s)", "\n\ndef solve():\n n = int(input())\n iters = n // 2\n out = 0\n for i in range(iters + 1):\n out += 8 * i * i\n print(out)\n\ndef __starting_point():\n t = int(input())\n for tc in range(t):\n solve()\n__starting_point()", "for _ in range(int(input())):\n n = int(input())\n print(sum(i * ((2 * i + 1) ** 2 - (2 * (i - 1) + 1) ** 2) for i in range(1, n // 2 + 1)))\n", "import math\nimport time\nfrom collections import defaultdict,deque\nfrom sys import stdin,stdout\nfrom bisect import bisect_left,bisect_right\nt=1\nt=int(input())\nfor _ in range(t):\n n=int(input())\n ans=0\n for i in range(1,(n+1)//2):\n ans+=i*8*i \n print(ans)\n", "import sys\ninput = sys.stdin.readline\nfrom itertools import accumulate\nS=[i*4*(2*i) for i in range(5*10**5+2)]\nANS=list(accumulate(S))\n\nt=int(input())\nfor tests in range(t):\n n=int(input())\n print(ANS[n//2])\n", "def getN():\n return int(input())\ndef getNM():\n return list(map(int, input().split()))\ndef getList():\n return list(map(int, input().split()))\n\nfrom collections import defaultdict, deque\nimport math\nimport copy\nfrom bisect import bisect_left\n\nimport sys\n# sys.setrecursionlimit(1000000)\nINF = 10 ** 17\nMOD = 998244353\n\ndef solve():\n n = getN()\n ans = 0\n radius = n // 2\n for r in range(radius):\n ra = r + 1\n ans += ra *((ra * 2 + 1) ** 2 - (ra * 2 - 1) ** 2)\n print(ans)\n\ndef main():\n n = getN()\n for _ in range(n):\n solve()\ndef __starting_point():\n main()\n\n\n__starting_point()", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tk = n//2\n\tsu = k*(k+1)//2\n\tsu += (2*k*(k*(k+1)//2))\n\tsu *= 4\n\tprint(su*2//3)\n", "for f in range(int(input())):\n n=int(input())\n m=n//2\n prev=1\n cur=3\n mov=0\n for i in range(m):\n mov+=(i+1)*(cur**2-prev**2)\n prev+=2\n cur+=2\n print(mov)", "import math \ndef ri():\n return map(int,input().split())\ndef li():\n return list(map(int,input().split()))\ndef inp():\n return int(input())\ndef si():\n return input()\ndef pYes():\n print(\"YES\")\ndef pNo():\n print(\"NO\")\ndef plist(l):\n print(\"\".join(l))\nt = int(input())\nfor i in range(t):\n n = int(input())\n ans=0\n t=1\n for k in range(3,n+1,2):\n \n ans+=(2*k + (k-2)*2)*t\n t=t+1\n print(ans)", "from collections import defaultdict as dd\nfrom collections import deque\nimport bisect\nimport heapq\n\ndef ri():\n return int(input())\n\ndef rl():\n return list(map(int, input().split()))\n\n\ndef solve():\n n = ri()\n answer = 0\n half = (n + 1) // 2\n for i in range(1, half):\n ring = (2 * i + 1)**2 - (2 * i - 1)**2\n answer += i * ring\n print (answer)\n\n\n\n\n\nmode = 'T'\n\nif mode == 'T':\n t = ri()\n for i in range(t):\n solve()\nelse:\n solve()\n", "t=int(input())\nfor _ in range(t):\n n=int(input())\n s=0\n for i in range(n//2):\n s=s+8*(i+1)*(i+1)\n print(s)", "N = 5*(10**5)+1\ndp = [0 for i in range(N)]\ndp[1] = 0\nfor i in range(3,N,2):\n\tdp[i] = dp[i-2]+8*(i//2)*(i//2)\nt = int(input())\nfor y in range(t):\n\tn = int(input())\n\tprint(dp[n])\n\t\n", "# encoding: utf-8\nimport sys\nsys.setrecursionlimit(10**6)\n\n\ndef __starting_point():\n # sys.stdin = open('1.std.in', 'r')\n nofkase = int(input())\n for kase in range(nofkase):\n n = int(input())\n n = n // 2\n print(n*(n+1)*(n+n+1)*8//6)\n\n__starting_point()", "t=int(input())\nfor i in range(t):\n n=int(input())\n ans=(n//2)*n**2\n for j in range(n//2):\n ans-=(2*j+1)**2\n print(ans)", "t=int(input())\nfor _ in range(t):\n\tn=int(input())\n\tans=0\n\tfor i in range(1,n//2+1):\n\t\tans+=8*i*i\n\tprint(ans)", "def solve(k):\n res = 0\n for i in range((k+1)//2):\n res += 4*2*i**2\n return res\n\nstrr = input()\nfor _ in range(int(strr)):\n k = int(input())\n print(solve(k))\n", "import sys\nimport os\nimport time\nimport collections\nfrom collections import Counter, deque\nimport itertools\nimport math\nimport timeit\nimport random\nimport string\n\n#########################\n# imgur.com/Pkt7iIf.png #\n#########################\n\ndef sieve(n):\n if n < 2: return list()\n prime = [True for _ in range(n + 1)]\n p = 3\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 += 2\n r = [2]\n for p in range(3, n + 1, 2):\n if prime[p]:\n r.append(p)\n return r\n\ndef divs(n, start=1):\n divisors = []\n for i in range(start, int(math.sqrt(n) + 1)):\n if n % i == 0:\n if n / i == i:\n divisors.append(i)\n else:\n divisors.extend([i, n // i])\n return divisors\n\ndef divn(n, primes):\n divs_number = 1\n for i in primes:\n if n == 1:\n return divs_number\n t = 1\n while n % i == 0:\n t += 1\n n //= i\n divs_number *= t\n\ndef flin(d, x, default=-1):\n left = right = -1\n for i in range(len(d)):\n if d[i] == x:\n if left == -1: left = i\n right = i\n if left == -1:\n return default, default\n else:\n return left, right\n\ndef ceil(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=' ', end='\\n'): print(sep.join(map(str, a)), end=end)\ndef dd(): return collections.defaultdict(int)\ndef ddl(): return collections.defaultdict(list)\n\n########################################################################################################################\n# input = sys.stdin.readline\n\nfor _ in range(ii()):\n n = ii()\n res = 0\n cs = 8\n for i in range(1, n//2 + 1):\n res += cs * i\n cs += 8\n print(res)\n\n", "t = int(input())\nwhile t:\n n = int(input())\n ans = 0\n if n==1: print(0)\n else:\n for i in range(1, n//2 + 1):\n ans += 8*i*i\n print(ans)\n t -= 1", "# ========= /\\ /| |====/|\n# | / \\ | | / |\n# | /____\\ | | / |\n# | / \\ | | / |\n# ========= / \\ ===== |/====| \n# code\n\ndef main():\n t = int(input())\n for _ in range(t):\n n = int(input())\n ans = 0\n for i in range(1,n + 1,2):\n ans += (4 * i - 4) * (i // 2)\n print(ans)\n return\n\ndef __starting_point():\n main()\n__starting_point()", "import sys\ninput=sys.stdin.readline\nfrom collections import defaultdict as dd\nt=int(input())\nwhile t:\n n=int(input())\n a=8\n res=0\n for i in range(1,n//2+1):\n res+=a*i*i\n print(res)\n t-=1", "for _ in range(int(input())):\n n = int(input())\n c = n // 2, n // 2\n\n s = 0\n\n for j in range(n):\n s += max(abs(c[0] - 0), abs(c[1] - j))\n\n ts = s\n\n for i in range(1, n // 2 + 1):\n s -= n - 2 * i\n ts += s\n\n print(ts * 2 - s)", "T = int(input())\n\nfor t in range(T):\n N = int(input())\n\n answer = 0\n i = 0\n moves = 0\n nb = 0\n while i < N//2:\n i += 1\n nb += 8\n answer += nb * i\n print(answer)\n", "from sys import stdin\n\ndef func(n):\n if n == 1:\n return 0\n x = n//2\n m = 0\n while(x > 0):\n m += 4*(n -1)*x\n x -= 1\n n -= 2\n return m\n\nfor _ in range(int(input())):\n n = int(input())\n #l = list(map(int, stdin.readline().split()))\n #n, k = map(int, input().split())\n print(func(n))\n"] | {
"inputs": [
"3\n1\n5\n499993\n",
"1\n499999\n",
"1\n69791\n",
"3\n5\n3005\n3005\n",
"1\n214541\n",
"1\n214145\n"
],
"outputs": [
"0\n40\n41664916690999888\n",
"41666416667000000\n",
"113312287936960\n",
"40\n9045074040\n9045074040\n",
"3291619655775960\n",
"3273426253628160\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,613 | |
b817d727a616e93ab386729bde11d7ab | UNKNOWN | You are given an array $a$ consisting of $n$ integers. In one move, you can jump from the position $i$ to the position $i - a_i$ (if $1 \le i - a_i$) or to the position $i + a_i$ (if $i + a_i \le n$).
For each position $i$ from $1$ to $n$ you want to know the minimum the number of moves required to reach any position $j$ such that $a_j$ has the opposite parity from $a_i$ (i.e. if $a_i$ is odd then $a_j$ has to be even and vice versa).
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of elements in $a$.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
Print $n$ integers $d_1, d_2, \dots, d_n$, where $d_i$ is the minimum the number of moves required to reach any position $j$ such that $a_j$ has the opposite parity from $a_i$ (i.e. if $a_i$ is odd then $a_j$ has to be even and vice versa) or -1 if it is impossible to reach such a position.
-----Example-----
Input
10
4 5 7 6 7 5 4 4 6 4
Output
1 1 1 2 -1 1 1 3 1 1 | ["from heapq import heappush, heappop\n\nn = int(input())\na = list(map(int, input().split()))\nedge = [[] for _ in range(n)]\nrev = [[] for _ in range(n)]\ninf = 10**9\ncost = [inf]*n\nhq = []\n\nfor i, x in enumerate(a):\n if i+x < n:\n edge[i].append(i+x)\n rev[i+x].append(i)\n if (a[i] ^ a[i+x]) & 1:\n cost[i] = 1\n if i-x >= 0:\n edge[i].append(i-x)\n rev[i-x].append(i)\n if (a[i] ^ a[i-x]) & 1:\n cost[i] = 1\n\n if cost[i] == 1:\n hq.append((1, i))\n\nwhile hq:\n c, v = heappop(hq)\n if cost[v] < c:\n continue\n c += 1\n for dest in rev[v]:\n if cost[dest] > c:\n cost[dest] = c\n heappush(hq, (c, dest))\n\nfor i in range(n):\n if cost[i] == inf:\n cost[i] = -1\n\nprint(*cost)\n", "import sys\nfrom itertools import chain, permutations\n\nn = int(sys.stdin.readline())\na = list(map(int, sys.stdin.readline().split(' ')))\n\n\nresult = [-1 for _ in a]\njumps_to = [[] for _ in a]\n\nfor i in range(len(a)):\n\tleft = i - a[i] \n\tright = i + a[i]\n\tif left >= 0:\n\t\tjumps_to[left].append(i)\n\t\tif (a[left] % 2) != (a[i] % 2):\n\t\t\tresult[i] = 1\n\tif right < n:\n\t\tjumps_to[right].append(i)\n\t\tif (a[right] % 2) != (a[i] % 2):\n\t\t\tresult[i] = 1\n\nqueue = []\nqueue_ptr = 0\nfor i in range(n):\n\tif result[i] == 1:\n\t\tqueue.append(i)\n\nwhile queue_ptr < len(queue):\n\tcurrent = queue[queue_ptr]\n\tfor to in jumps_to[current]:\n\t\tif result[to] == -1 or result[to] > result[current] + 1:\n\t\t\tqueue.append(to)\n\t\t\tresult[to] = result[current] + 1\n\tqueue_ptr += 1\n\n\n#print(jumps_to)\n\nprint(\" \".join(map(str, result)))", "n = int(input())\n\na = list(map(int, input().split()))\n\nadj = []\nfor _ in range(n):\n adj.append([])\ndist = [-1] * n\nq = []\n\nfor i, x in enumerate(a):\n for dx in [+x, -x]:\n if 0 <= i + dx < n:\n if a[i+dx]%2==x%2:\n adj[i+dx].append(i)\n else:\n dist[i] = 1\n q.append(i)\n\nq_index = 0\nwhile q_index < len(q):\n top = q[q_index]\n q_index += 1\n \n for nei in adj[top]:\n if dist[nei] == -1:\n dist[nei] = dist[top]+1\n q.append(nei)\n \nprint(*dist)\n", "from collections import deque\nn = int(input())\na = list(map(int,input().split()))\nans = [-1 for _ in range(n)]\ngraph = [[] for _ in range(n)]\n\nque = deque([])\nfor i,x in enumerate(a):\n t = False\n if i+x < n:\n if (a[i+x]%2) != (a[i]%2):\n ans[i] = 1\n t = True\n graph[i+x].append(i)\n if i-x >= 0:\n if (a[i-x]%2)!= (a[i]%2):\n ans[i] = 1\n t = True\n graph[i-x].append(i)\n if t:\n que.append(i)\n#print(graph)\nwhile len(que) > 0:\n now = que.popleft()\n for ne in graph[now]:\n if ans[ne] == -1:\n ans[ne] = ans[now]+1\n que.append(ne)\n \n\nprint(*ans)"] | {
"inputs": [
"10\n4 5 7 6 7 5 4 4 6 4\n",
"100\n10 3 10 3 5 4 10 9 9 8 7 10 3 10 8 9 7 7 8 10 7 8 3 10 4 5 10 10 3 9 10 6 9 9 7 6 10 4 3 8 7 7 3 9 9 8 7 5 4 5 3 8 4 4 5 3 9 6 9 9 6 9 3 4 5 6 5 10 5 4 6 10 3 4 4 8 8 3 9 7 8 10 6 5 8 3 4 6 8 9 8 9 4 3 10 8 8 10 7 3\n",
"100\n12 18 18 10 13 13 20 14 20 13 12 13 18 13 14 13 14 20 16 14 14 11 11 17 20 13 18 14 15 19 15 18 13 14 11 18 12 13 18 10 20 11 11 15 12 15 18 14 20 14 18 14 14 19 10 11 19 19 15 19 14 16 11 14 17 18 15 20 19 19 10 10 15 12 19 11 16 13 11 19 15 13 10 15 17 12 13 15 18 12 10 16 14 14 11 16 17 10 15 19\n",
"100\n7 9 5 3 5 3 3 7 4 3 5 7 9 7 3 9 5 3 7 5 5 9 3 3 3 9 5 7 3 5 7 3 5 3 9 7 7 7 5 7 7 7 7 9 9 7 3 3 3 3 9 5 7 9 9 3 3 9 9 9 9 5 5 7 9 5 9 5 3 3 7 7 5 5 9 9 5 3 3 5 9 7 9 5 4 9 7 9 7 7 7 9 5 3 3 3 3 3 9 3\n",
"100\n11 15 15 11 17 15 15 15 13 17 19 11 15 11 17 19 11 13 11 13 13 17 15 15 13 13 17 19 19 13 19 19 13 11 11 19 13 17 17 11 19 17 13 19 13 11 17 15 17 13 17 19 19 17 10 13 11 19 19 19 19 15 19 17 11 19 15 11 19 17 15 17 17 19 13 11 11 15 19 11 11 17 15 15 13 11 13 15 11 19 17 19 19 19 15 17 11 13 11 11\n",
"150\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2\n"
],
"outputs": [
"1 1 1 2 -1 1 1 3 1 1 \n",
"1 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 3 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 1 1 3 1 3 2 3 2 2 1 \n",
"2 2 2 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 2 2 1 2 1 1 1 2 1 1 2 1 1 1 2 1 2 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 1 1 1 2 1 2 1 2 1 3 2 1 1 1 1 1 3 1 2 1 3 2 \n",
"14 3 14 13 12 1 12 13 1 11 2 11 10 11 12 11 10 11 10 11 10 9 10 11 10 9 10 9 10 9 8 9 8 9 8 9 8 7 8 9 8 9 8 7 6 7 8 7 8 7 6 7 6 5 8 7 6 3 6 5 4 3 4 7 4 5 2 5 4 3 6 3 6 3 4 1 4 5 2 1 4 5 4 3 1 5 2 3 6 5 4 5 4 5 6 5 6 7 6 7 \n",
"4 7 6 7 10 5 10 3 10 5 8 3 8 3 6 9 6 5 4 9 4 9 2 9 2 9 4 7 6 7 4 5 8 3 8 1 6 1 8 5 6 3 8 3 6 7 6 5 4 5 4 9 2 7 1 7 6 5 4 5 4 5 4 5 4 3 6 5 6 3 8 1 8 1 6 3 4 3 4 3 4 5 4 7 2 7 2 9 4 9 2 9 2 7 4 5 8 3 10 5 \n",
"149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 1 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 3,007 | |
98bcbde98b8f0d955aa61ec19098bd3c | UNKNOWN | You are given one integer number $n$. Find three distinct integers $a, b, c$ such that $2 \le a, b, c$ and $a \cdot b \cdot c = n$ or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The next $n$ lines describe test cases. The $i$-th test case is given on a new line as one integer $n$ ($2 \le n \le 10^9$).
-----Output-----
For each test case, print the answer on it. Print "NO" if it is impossible to represent $n$ as $a \cdot b \cdot c$ for some distinct integers $a, b, c$ such that $2 \le a, b, c$.
Otherwise, print "YES" and any possible such representation.
-----Example-----
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | ["#-------------Program--------------\n#----Kuzlyaev-Nikita-Codeforces----\n#-------------Round615-------------\n#----------------------------------\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=[]\n for i in range(2,int(n**0.5)+2):\n if len(a)==2:\n a.append(n)\n break \n if n%i==0:\n a.append(i)\n n//=i\n a=list(set(a))\n if len(a)==3 and a.count(1)==0:\n print('YES')\n a.sort()\n print(a[0],a[1],a[2])\n else:\n print('NO')\n", "def Fenjie(n):\n k = {}\n if (n == 1):\n return {}\n a = 2\n while (n >= 2):\n b = n%a\n if (a*a > n):\n if (n in k):\n k[n] += 1\n else:\n k[n] = 1\n break\n if (b == 0):\n if (a in k):\n k[a] += 1\n else:\n k[a] = 1\n n = n//a\n else:\n a += 1\n return k\n\nn = int(input())\nfor _ in range(n):\n m = int(input())\n k = Fenjie(m)\n s = 0\n le = len(k)\n l = [i for i in k]\n if (le >= 3):\n print(\"YES\")\n flag = 0\n print(l[0], l[1], m//l[0]//l[1])\n elif (le==2):\n if (k[l[0]]+k[l[1]] >= 4):\n print(\"YES\")\n print(l[0], l[1], m//l[0]//l[1])\n else:\n print(\"NO\")\n else:\n if (k[l[0]] >= 6):\n print(\"YES\")\n print(l[0], l[0]*l[0], m//l[0]//l[0]//l[0])\n else:\n print(\"NO\")", "t = int(input())\nfor _ in range(t):\n n = int(input())\n test = 2\n out = []\n while len(out) < 2 and test * test < n:\n if n % test == 0:\n out.append(test)\n n //= test\n test += 1\n \n if len(out) == 2 and n > out[1]:\n print('YES')\n print(out[0], out[1], n)\n else:\n print('NO')\n", "from math import sqrt as S \ndef div(x):\n d=[]\n if x==1:\n return [1]\n if x==2:\n return [1,2]\n cnt=[1,n]\n for i in range(2,int(S(x))+1):\n if x %i==0:\n cnt.append(i) \n return cnt \ndef check(arr):\n if 1 in arr or 0 in arr:\n return 0 \n return len(set(arr))==3 \n\nimport sys \ninput=sys.stdin.readline \nt=int(input())\nans=[]\nfor i in range(t): \n n=int(input()) \n f=0 \n cnt=div(n)\n for x in cnt : \n y=n//x\n if f: break \n for z in div(y):\n if check([x,z,y//z]):\n ans=[x,z,y//z]\n f=1 \n break \n if f:\n print('YES')\n print(*ans)\n else:\n print('NO')", "from math import sqrt\n\ndef divide(n, start):\n for k in range(start, int(sqrt(n)) + 1):\n if n % k == 0:\n return k\n return n\n\n\nfor _ in range(int(input())):\n n = int(input())\n a = divide(n, 2)\n if a == n:\n print('NO')\n continue\n n //= a\n b = divide(n, a + 1)\n if b == n:\n print('NO')\n continue\n n //= b\n if n <= b:\n print('NO')\n continue\n print('YES')\n print(a, b, n)\n", "import sys\ninput = sys.stdin.readline\n\nt=int(input())\n\nimport math\n\ndef f(x):\n \n xr=math.ceil(math.sqrt(x))\n\n LIST=[]\n for i in range(1,xr+1):\n if x%i==0:\n LIST.append(i)\n LIST.append(x//i)\n\n return sorted(set(LIST))[1:]\n\n\nfor test in range(t):\n n=int(input())\n L=f(n)\n\n A=L[0]\n\n for i in f(n):\n if i!=A and i*A<n and n%(i*A)==0 and n//(i*A)!=i and n//(i*A)!=A and n//(i*A)!=1:\n print(\"YES\")\n print(A,i,n//(i*A))\n break\n\n else:\n print(\"NO\")\n \n \n", "import sys\ninput = sys.stdin.readline\n\ndef factors(n):\n\tret = set()\n\tfor i in range(2, int(n**.5) + 1):\n\t\tif n%i == 0:\n\t\t\tret.add(i)\n\t\t\tret.add(n//i)\n\treturn ret\n\ndef solve(n):\n\tfor i in range(2, int(n**.5)+1):\n\t\tif n%i == 0 and i != n//i:\n\t\t\ta, b = i, n//i\n\t\t\tfa, fb = factors(a), factors(b)\n\t\t\t# option 1\n\t\t\tif len(fa) > 0:\n\t\t\t\tfor fac in fa:\n\t\t\t\t\tif len(set([fac, a//fac, b])) == 3:\n\t\t\t\t\t\treturn [fac, a//fac, b]\n\t\t\t# option 2\n\t\t\tif len(fb) > 0:\n\t\t\t\tfor fac in fb:\n\t\t\t\t\tif len(set([fac, b//fac, a])) == 3:\n\t\t\t\t\t\treturn [fac, b//fac, a]\n\treturn 'NO'\n\n\nfor _ in range(int(input())):\n\tn = int(input())\n\tans = solve(n)\n\tif ans == 'NO':\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n\t\tprint(*sorted(ans))", "def main():\n n = int(input())\n a = 2\n while a * a * a < n:\n if n % a == 0:\n b = a + 1\n while b * b < n // a:\n if (n // a) % b == 0:\n c = n // a // b\n if a != c and b != c:\n print(\"YES\")\n print(a, b, n // a // b)\n return 0\n b += 1\n a += 1\n print(\"NO\")\np = int(input())\nfor i in range(p):\n main()", "from math import sqrt\nT = int(input())\nfor z in range(T):\n N = int(input())\n num = N\n i = 2\n nums = []\n found = 0\n s = int(sqrt(N))\n while i<= s:\n if num % i == 0:\n nums.append(i)\n num = num //i\n found += 1\n if found == 2:\n if num not in nums:\n found = 3\n nums.append(num)\n break\n i += 1\n if found == 3:\n print(\"YES\")\n print(*nums)\n else:\n print(\"NO\")\n\n", "from functools import reduce\ndef factors(n):\n k = sorted(list(set(reduce(list.__add__,\n ([i,n//i] for i in range(1,int(n**0.5+1)) if n%i == 0)))))\n return k[1:]\nt = int(input())\nfor _ in range(0,t):\n n = int(input())\n f = factors(n)\n if len(f) < 3:\n print('NO')\n else:\n ans = 'NO'\n a,b,c = -1,-1,-1\n for i in range(0,len(f)):\n for j in range(i+1,len(f)):\n temp = n//f[i]\n temp //= f[j]\n if temp in f and temp != f[i] and temp != f[j]:\n a,b,c = f[i],f[j],temp\n ans = 'YES'\n break\n if ans == 'YES':\n break\n if ans == 'YES':\n print(ans)\n print(a,b,c)\n else:\n print(ans)\n\n\n", "t = int(input())\nfor a in range(t):\n n = ori = int(input())\n num = []\n for b in range(2,int(ori**0.5)+1):\n # print(n)\n if n % b == 0:\n num.append(b)\n n = n//b\n if len(num) == 2:\n if n != 1:\n num.append(n)\n break\n num = list(set(num))\n if len(num) == 3:\n print(\"YES\")\n print(\" \".join(map(str, num)))\n else:\n print(\"NO\")"] | {"inputs": ["5\n64\n32\n97\n2\n12345\n", "21\n719\n5039\n39916801\n479001599\n28657\n514229\n433494437\n66047\n263167\n16785407\n999999757\n999999761\n999999797\n999999883\n999999893\n999999929\n999999937\n991026973\n985062919\n979134757\n971230541\n", "1\n128\n", "6\n10\n10\n10\n10\n10\n10\n", "1\n1112\n", "1\n162\n"], "outputs": ["YES\n2 4 8 \nNO\nNO\nNO\nYES\n3 5 823 \n", "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\n983 991 997 \n", "YES\n2 4 16 \n", "NO\nNO\nNO\nNO\nNO\nNO\n", "YES\n2 4 139 \n", "YES\n2 3 27 \n"]} | INTRODUCTORY | PYTHON3 | CODEFORCES | 7,023 | |
b001a1aa7f2bb35c872de21b1b0c12ff | UNKNOWN | Nikolay got a string $s$ of even length $n$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $1$ to $n$.
He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.
The prefix of string $s$ of length $l$ ($1 \le l \le n$) is a string $s[1..l]$.
For example, for the string $s=$"abba" there are two prefixes of the even length. The first is $s[1\dots2]=$"ab" and the second $s[1\dots4]=$"abba". Both of them have the same number of 'a' and 'b'.
Your task is to calculate the minimum number of operations Nikolay has to perform with the string $s$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.
-----Input-----
The first line of the input contains one even integer $n$ $(2 \le n \le 2\cdot10^{5})$ β the length of string $s$.
The second line of the input contains the string $s$ of length $n$, which consists only of lowercase Latin letters 'a' and 'b'.
-----Output-----
In the first line print the minimum number of operations Nikolay has to perform with the string $s$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.
In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.
-----Examples-----
Input
4
bbbb
Output
2
abba
Input
6
ababab
Output
0
ababab
Input
2
aa
Output
1
ba
-----Note-----
In the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'.
In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'. | ["import sys\ninput = sys.stdin.readline\n\nn=int(input())\ns=list(input().strip())\n\nANS=0\nfor i in range(0,n,2):\n if s[i]==s[i+1]:\n ANS+=1\n if s[i]==\"a\":\n s[i]=\"b\"\n else:\n s[i]=\"a\"\n\nprint(ANS)\nprint(\"\".join(s))\n", "'''input\n2\naa\n\n\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\nfrom heapq import heappush as hpush\nfrom heapq import heappop as hpop\nmod=10**9+7\n\ndef ri(flag=0):\n\tif flag==0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n\n\n\nn = ri(1)\na = list(input())\nans =0\n\nfor i in range(0,n,2):\n\tif a[i]!=a[i+1]:\n\t\tpass\n\telse:\n\t\tif a[i]==\"a\":\n\t\t\ta[i]=\"b\"\n\t\telse:\n\t\t\ta[i]=\"a\"\n\t\tans+=1\n\nprint(ans)\nprint(\"\".join(a))\n", "import sys\ninput = lambda: sys.stdin.readline().strip()\n\ndef opp(s):\n if s=='a': return 'b'\n else: return 'a'\n\nn = int(input())\ns = list(input())\ncnt = 0\nfor i in range(0, n, 2):\n if s[i]!=opp(s[i+1]):\n cnt+=1\n s[i] = opp(s[i+1])\nprint(cnt)\nprint(''.join(s))\n", "n = int(input())\ns = input()\nnew_s = [0] * len(s)\nans = 0\nfor i in range(0, len(s), 2):\n if s[i] == s[i + 1]:\n ans += 1\n new_s[i] = s[i]\n new_s[i+1] = 'b' if s[i] == 'a' else 'a'\n else:\n new_s[i] = s[i]\n new_s[i+1] = s[i + 1]\nprint(ans)\nprint(''.join(new_s))", "n = int(input())\ns = input()\na = []\nd = 0\nfor i in range(0,n,2):\n if s[ i ] == s[ i + 1 ]:\n a.append( 'a' )\n a.append( 'b' )\n d += 1\n else:\n a.append( s[ i ] )\n a.append( s[ i + 1 ] )\n\nprint( d )\nprint( \"\".join(a) )\n", "n=int(input())\na=input()\nres=0\nres2=''\nfor i in range (0,len(a),2):\n if a[i]==a[i+1]:\n res+=1\n res2+='ab'\n else:\n res2+=a[i]\n res2+=a[i+1]\nprint(res)\nprint(res2)", "from sys import stdin, stdout \n\n\n\ninput()\n\nS = list(input())\n\nct = 0\n\nfor i in range(0, len(S), 2):\n if S[i] == S[i+1]:\n ct += 1\n if S[i] == 'a':\n S[i] = 'b'\n else:\n S[i] = 'a'\n \n\nprint(ct)\n\nprint(\"\".join(S))", "n = int(input())\ns = list(input())\ncnt = 0\nfor i in range(0, n, 2):\n if s[i] == 'a' and s[i + 1] == 'a':\n cnt += 1\n s[i] = 'b'\n elif s[i] == 'b' and s[i + 1] == 'b':\n cnt += 1\n s[i] = 'a'\nprint(cnt)\nprint(''.join(s))\n", "n = int(input())\nl = [*input()]\na = b = 0\ncnt = 0\nfor i in range(n):\n if l[i] == 'a': a += 1\n else: b += 1\n if i & 1 and a != b:\n cnt += 1\n if a > b: l[i], a = 'b', b\n else: l[i], b = 'a', a\nprint(cnt)\nprint(''.join(l))", "n = int(input())\na = list(map(lambda x: 0 if x == \"a\" else 1, input()))\nbal = 0\nfor i in range(1, n, 2):\n if a[i] == a[i - 1]:\n bal += 1\n a[i] = (a[i - 1] + 1) % 2\nprint(bal)\nprint(''.join(\"a\" if a[i] == 0 else \"b\" for i in range(n)))", "n = int(input())\ns = str(input())\nk = 0\nnew = ''\n\nfor i in range(0, n-1, 2):\n if s[i:i + 2] == 'ab':\n new += 'ab'\n continue\n if s[i:i + 2] == 'ba':\n new += 'ba'\n continue\n else:\n k += 1\n new += 'ab'\n\nprint(k)\nprint(new)\n", "N = int(input())\nS = list(input())\nk = N//2\nans = 0\nT = ''\nfor i in range(k):\n if S[2*i] == S[2*i+1]:\n ans += 1\n T += 'ab'\n else:\n T += S[2*i] + S[2*i+1]\nprint(ans)\nprint(T)", "n = int(input())\nli = list(input())\n\nans = []\ncnt = 0\nfor i in range(n//2):\n if li[2*i] == li[2*i + 1]:\n if li[2*i] == \"a\":\n ans.append(\"b\")\n ans.append(li[2*i + 1])\n cnt += 1\n if li[2*i] == \"b\":\n ans.append(\"a\")\n ans.append(li[2*i + 1])\n cnt += 1 \n else:\n ans.append(li[2*i])\n ans.append(li[2*i + 1])\nprint(cnt)\nprint(\"\".join(map(str, ans)))\n \n\n", "from bisect import *\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nfrom decimal import *\nfrom copy import *\nfrom heapq import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 10**6+1\nMOD = 10**9+7\nspf = [i for i in range(MAXN)]\ndef sieve():\n for i in range(2,MAXN,2):\n spf[i] = 2\n for i in range(3,int(MAXN**0.5)+1):\n if spf[i]==i:\n for j in range(i*i,MAXN,i):\n if spf[j]==j:\n spf[j]=i\n\ndef mhd(a,b):\n return abs(a[0]-b[0])+abs(b[1]-a[1])\n\ndef charIN(x= ' '):\n return(sys.stdin.readline().strip().split(x))\n\ndef arrIN(x = ' '):\n return list(map(int,sys.stdin.readline().strip().split(x)))\n\ndef eld(x,y):\n a = y[0]-x[0]\n b = x[1]-y[1]\n return (a*a+b*b)**0.5\n\ndef lgcd(a):\n g = a[0]\n for i in range(1,len(a)):\n g = math.gcd(g,a[i])\n return g\n\ndef ms(a):\n msf = -MAX\n meh = 0\n st = en = be = 0\n for i in range(len(a)):\n meh+=a[i]\n if msf<meh:\n msf = meh\n st = be\n en = i\n if meh<0:\n meh = 0\n be = i+1\n return msf,st,en\n\ndef ncr(n,r):\n num=den=1\n for i in range(r):\n num = (num*(n-i))%MOD\n den = (den*(i+1))%MOD\n\n return (num*(pow(den,MOD-2,MOD)))%MOD\n\n\n\ndef flush():\n return sys.stdout.flush()\n\n'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''\nn = int(input())\ns = '.'+input()\nans = 0\ns = [i for i in s]\nfor i in range(2,n+1,2):\n if i%2==0:\n if s[i]==s[i-1]:\n if s[i]=='a':\n s[i-1]='b'\n else:\n s[i-1] = 'a'\n ans+=1\nprint(ans)\nprint(''.join(s[1:]))", "n = int(input())\ns = list(input())\npref = [0]\nk = 0\nfor i in range(0,n-1,2):\n if s[i]==s[i+1]:\n k+=1\n if s[i]=='b':\n s[i]='a'\n else:\n s[i]='b'\n\nprint(k)\nprint(''.join(s))", "n = int(input())\na = list(input())\n# ans = a.copy()\nl = 0\nfor i in range(1, n, 2):\n if a[i] == a[i - 1]:\n l += 1\n a[i] = 'a' if a[i - 1] == 'b' else 'b'\n\nprint(l)\nprint(''.join(a))", "elem = int(input())\nstring = input()\nar = []\nfor x in range(len(string)):\n ar.append(string[x])\n\nfirst = 'a'\nsecond = 'a'\ncount = 0\nnew_ar = []\nfor x in range(len(ar)):\n if x%2==0:\n first = ar[x]\n second = ar[x+1]\n if first != second:\n new_ar.append(first)\n new_ar.append(second)\n else:\n count=count+1\n new_ar.append('a')\n new_ar.append('b')\nprint(count)\nprint(''.join(str(i) for i in new_ar))", "input()\ns = input()\n\nchanges = 0\nbalance = 0\nres = []\n\nfor i in range(len(s)):\n balance += 1 if s[i] == 'a' else -1\n res.append(s[i])\n\n if i % 2 == 1 and balance != 0:\n changes += 1\n res[-1] = chr(ord('a') + ord('b') - ord(res[-1]))\n balance = 0\n\nprint(changes)\nprint(\"\".join(res))", "n = int(input())\ns = list(input())\nc = 0\nfor i in range(0,n-1,2):\n\tif(s[i] == s[i+1] and s[i] == 'a'):\n\t\ts[i] = 'b'\n\t\tc+=1\n\telif(s[i] == s[i+1] and s[i] == 'b'):\n\t\ts[i] = 'a'\n\t\tc+=1\nprint(c)\nprint(''.join(s))\n", "n = int(input())\ns = [i for i in input()]\ntemp = ''\nans = 0\nfor i,j in enumerate(s):\n if i % 2:\n if temp == 'a':\n if j == 'a':\n ans += 1\n s[i] = 'b'\n else:\n if j == 'b':\n ans += 1\n s[i] = 'a'\n else:\n temp = j\nprint(ans)\nprint(''.join(s))\n\n", "l = int(input())\ns = [char for char in input()]\ncc = 0\n\nother_char = {'a': 'b', 'b': 'a'}\n\nfor i in range(0, l, 2):\n if s[i] == s[i+1]:\n cc += 1\n s[i] = other_char[s[i]]\n\nprint(cc)\nprint(''.join(s))", "input()\nsmth = list(input())\ncnt=0\nfor i in range(len(smth)//2):\n if smth[i*2]==smth[i*2+1]:\n cnt+=1\n if smth[i*2]=='a':\n smth[i*2]='b'\n else:\n smth[i*2]='a'\nsmth=''.join(smth)\nprint(cnt)\nprint(smth)"] | {
"inputs": [
"4\nbbbb\n",
"6\nababab\n",
"2\naa\n",
"6\nbbbbba\n",
"8\nbbbabbba\n",
"8\nbbabbbaa\n"
],
"outputs": [
"2\nabab\n",
"0\nababab\n",
"1\nba\n",
"2\nababba\n",
"2\nabbaabba\n",
"3\nabababba\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,384 | |
c1a0dacf470a4858903c9ed9d1cc1fed | UNKNOWN | Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B are both wrong.
Print the correct choice for this problem.
-----Constraints-----
- Each of the numbers A and B is 1, 2, or 3.
- A and B are different.
-----Input-----
Input is given from Standard Input in the following format:
A
B
-----Output-----
Print the correct choice.
-----Sample Input-----
3
1
-----Sample Output-----
2
When we know 3 and 1 are both wrong, the correct choice is 2. | ["a = int(input())\nb = int(input())\n\nc = 1+2+3\n\nprint((c - (a+b)))\n", "A = input()\nB = input()\ncandidate = set(('1', '2', '3'))\nexclude = set((A, B))\nprint((candidate - exclude).pop())", "A=int(input())\nB=int(input())\nif A==1 and B==2 or A==2 and B==1:\n print(3)\nelif A==3 and B==2 or A==2 and B==3:\n print(1)\nelif A==1 and B==3 or A==3 and B==1:\n print(2)", "a=int(input())\nb=int(input())\nans=6-a-b\nprint(ans)", "# -*- coding: utf-8 -*-\na = int(input())\nb = int(input())\nif a + b == 3:\n print((3))\nelif a + b == 4:\n print((2))\nelse:\n print((1))\n", "a = int(input())\nb = int(input())\nprint(6-a-b)", "n = [1, 2, 3]\na = input()\nb = input()\nn.remove(int(a))\nn.remove(int(b))\nprint(n[0])", "a=int(input())\nb=int(input())\nif a+b==3:\n print(3)\nelif a+b==4:\n print(2)\nelif a+b==5:\n print(1)", "A = int(input())\nB = int(input())\nfor i in range(1, 4):\n if i not in [A, B]:\n print(i)", "a = int(input())\nb = int(input())\nprint(6-a-b)", "A = int(input())\nB = int(input())\nprint(6 - A - B)", "ans = [1, 2, 3]\nans.remove(int(input()))\nans.remove(int(input()))\nprint(ans[0])", "A = int(input())\nB = int(input())\n\nans = [1,2,3]\nans.remove(A)\nans.remove(B)\nprint(ans[0])", "a=int(input())\nb=int(input())\nprint(6-a-b)", "#!/usr/bin/env python3\nfrom collections import defaultdict, Counter\nfrom itertools import product, groupby, count, permutations, combinations\nfrom math import pi, sqrt\nfrom collections import deque\nfrom bisect import bisect, bisect_left, bisect_right\nfrom string import ascii_lowercase\nfrom functools import lru_cache\nimport sys\nsys.setrecursionlimit(10000)\nINF = float(\"inf\")\nYES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"\ndy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]\ndy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]\n\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndef ceil(a, b):\n return (a + b - 1) // b\n\n\ndef sum_of_arithmetic_progression(s, d, n):\n return n * (2 * s + (n - 1) * d) // 2\n\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef lcm(a, b):\n g = gcd(a, b)\n return a / g * b\n\n\ndef solve():\n A = int(input())\n B = int(input())\n for i in range(1, 4):\n if i != A and i != B:\n print(i)\n break\n\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a = int(input())\nb = int(input())\nprint(6-a-b)", "ls = [1,2,3]\nls.remove(int(input()))\nls.remove(int(input()))\nprint(ls[0])", "a = int(input())\nb = int(input())\n\nfor i in range(1,4):\n # 1...3\n if a != i and b != i:\n print(i)", "print(int(input())^int(input()))", "l = [1,2,3]\nl.remove(int(input()))\nl.remove(int(input()))\nprint((l[0]))\n", "print(6-int(input())-int(input()))", "a = int(input())\nb = int(input())\nfor i in range(1,4):\n if i not in [a,b]:\n print(i)", "#!/usr/bin/env python3\nimport sys\nfrom itertools import chain\n\n\ndef solve(A: int, B: int):\n answer = 6 - A - B\n return answer\n\n\ndef main():\n tokens = chain(*(line.split() for line in sys.stdin))\n A = int(next(tokens)) # type: int\n B = int(next(tokens)) # type: int\n answer = solve(A, B)\n print(answer)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a=int(input())\nb=int(input())\nif (a==1 and b==2) or (a==2 and b==1):\n print(\"3\")\nelif (a==2 and b==3) or (a==3 and b==2):\n print(\"1\")\nelse:\n print(\"2\")", "print(*set([1,2,3])^set([int(input()),int(input())]))", "A=int(input())\nB=int(input())\nprint((6-A-B))\n", "a=int(input())\nb=int(input())\n\nprint((6-a-b))\n", "A = int(input())\nB = int(input())\nprint((6-A-B))\n", "A = int(input())\nB = int(input())\n \n# \u982d\u3044\u3044\u65b9\u6cd5\uff01\nprint(6-A-B)", "a = int(input())\nb = int(input())\nif a == 1:\n if b == 2:\n print(3)\n else:\n print(2)\nelif a == 2:\n if b == 1:\n print(3)\n else:\n print(1)\nelse:\n if b == 2:\n print(1)\n else:\n print(2)", "A=int(input())\nB=int(input())\nfor i in range(1,4):\n if (i!=A) and (i!=B):\n print(i)\n", "A = int(input())\nB = int(input())\n \nl = [1,2,3]\nl.remove(A)\nl.remove(B)\n \nprint(l[0])", "a = int(input())\nb = int(input())\nprint(6 - a-b)", "print(6-int(input())-int(input()))", "a = int(input())\nb = int(input())\nfor i in range(1, 4):\n if i != a and i != b:\n print(i)", "A=int(input())\nB=int(input())\nif A==1 and B==2 or A==2 and B==1:\n print((3))\nelif A==3 and B==2 or A==2 and B==3:\n print((1))\nelif A==1 and B==3 or A==3 and B==1:\n print((2))\n \n", "a=int(input())\nb=int(input())\n\nans_list=[1,2,3]\nans_list.remove(a)\nans_list.remove(b)\n\nprint(ans_list[0])", "a = int(input())\nb = int(input())\nans_set = [1,2,3]\nans_set.remove(a)\nans_set.remove(b)\nprint(ans_set[0])", "L = [1,2,3]\na = int(input())\nb = int(input())\nL.remove(a)\nL.remove(b)\nprint(L[0])", "a = int(input())\nb = int(input())\nl = [1,2,3]\nif a>b:\n l.pop(a-1)\n l.pop(b-1)\nelse:\n l.pop(b-1)\n l.pop(a-1)\nprint(l[0])", "A = int(input())\nB = int(input())\nlis = [1, 2, 3]\nx = lis.index(A)\ny = lis.index(B)\nlis[x] = 0\nlis[y] = 0\nans = sum(lis)\nprint(ans)", "print(1^2^3^int(input())^int(input()))", "a = int(input())\nb = int(input())\nprint(6-a-b)", "a=int(input())\nb=int(input())\nprint('1' if a+b==5 else'2' if a+b==4 else '3' )", "A = int(input())\nB = int(input())\nprint(6-A-B)", "print(6-int(input())-int(input()))", "A=int(input())\nB=int(input())\n\nab={A,B}\nAll={1,2,3}\n\nAns=list(All-ab)\n\nprint((Ans[0]))\n", "print(6-int(input())-int(input()))", "a=int(input())\nb=int(input())\n\nif (a==1 and b==2) or (a==2 and b==1):\n print((3))\nelif (a==2 and b==3) or (a==3 and b==2):\n print((1))\nelse:\n print((2))\n\n", "print((6 - int(input()) - int(input())))\n", "u = {1,2,3}\nd = {int(input()) for i in range(2)}\nprint(list(u-d)[0])", "L=[1,2,3]\n\nd=int(input())\nL.remove(d)\nd=int(input())\nL.remove(d)\n\n\nprint(L[0])", "A=int(input())\nB=int(input())\nans=[1,2,3]\nans.remove(A)\nans.remove(B)\nprint(ans[0])", "a = int( input() )\nb = int( input() )\n\nif a * b == 6:\n print( 1 )\nelif a * b == 3:\n print( 2 )\nelse:\n print( 3 )", "a = int(input())\nb = int(input())\n\nans = {1,2,3} - {a,b}\nprint(ans.pop())", "A = int(input())\nB = int(input())\n\nprint(6 - A - B)", "a=int(input())\nb=int(input())\nprint(6-a-b)", "ans=list(range(1,4))\nfor i in range(2):\n ans.remove(int(input()))\n\nprint(ans[0])", "A = int(input())\nB = int(input())\nif(A == 1):\n if(B == 2):\n print(3)\n if(B == 3):\n print(2)\nif(A == 2):\n if(B == 1):\n print(3)\n if(B == 3):\n print(1)\nif(A == 3):\n if(B == 1):\n print(2)\n if(B == 2):\n print(1)", "a= int(input())\n\nb = int(input())\n\nprint(6 - a - b)", "X = {1,2,3}\na = {int(input())}\nb = {int(input())}\nprint(list(X-a-b)[0])", "A = int(input())\nB = int(input())\nprint(6 - A - B)", "a = int(input())\nb = int(input())\nprint(6-a-b)", "A = int(input())\nB = int(input())\n\nprint(6 - A - B)", "a = int(input())\nb = int(input())\n\nprint(6-a-b)", "a = int(input())\nb = int(input())\nans = [1,2,3]\nans.remove(a)\nans.remove(b)\nprint(ans[0])", "A = int(input())\nB = int(input())\n\nif (A == 1 and B == 2) or (A == 2 and B == 1):\n print(3)\nelif (A == 1 and B == 3) or (A == 3 and B == 1):\n print(2)\nelif (A == 2 and B == 3) or (A == 3 and B == 2):\n print(1)", "A = int(input())\nB = int(input())\nprint(6-(A+B))", "A = int(input())\nB = int(input())\n\nprint(6 - A - B)", "A,B = [int(input()) for _ in range(2)]\nprint(list(set([1,2,3])-set([A,B]))[0])", "a=[int(input()) for i in range(2)]\nb=[1,2,3]\nb.remove(a[0])\nb.remove(a[1])\nprint(b[0])", "a = int(input())\nb = int(input())\n\nif (a == 1 and b == 2) or (a == 2 and b == 1) :\n print(3)\nelif (a == 2 and b == 3) or (a == 3 and b == 2) :\n print(1)\nelif (a == 1 and b == 3) or (a == 3 and b == 1) :\n print(2)", "a=int(input())\nb = int(input())\ns = set([1,2,3])\ns.remove(a)\ns.remove(b)\nprint(*s)", "A = int(input())\nB = int(input())\nprint((6 - A - B))\n", "a = int(input())\nb = int(input())\n\nprint(6-a-b)", "num_l = [1, 2, 3]\nnum_l.remove(int(input()))\nnum_l.remove(int(input()))\nprint(num_l.pop())", "A=int(input())\nB=int(input())\n\nfor i in range(1,4):\n\tif i !=A and i != B:\n\t\tprint(i)\n\n", "a=int(input())\nb=int(input())\nprint((6-a-b))\n", "A=int(input())\nB=int(input())\nprint(6-A-B)", "A = int(input())\nB = int(input())\n\nprint(6-A-B)", "A=int(input())\nB=int(input())\nif A==1 and B==2 or A==2 and B==1:\n print(3)\nelif A==3 and B==2 or A==2 and B==3:\n print(1)\nelif A==1 and B==3 or A==3 and B==1:\n print(2)", "s = int(input())\na = int(input())\n\nprint(6-s-a)", "a=int(input())\nb=int(input())\nprint('1' if a+b==5 else'2' if a+b==4 else '3' )", "ab=[int(input()) for i in range(2)]\nprint(*{1,2,3}-set(ab))", "Ans = [\"1\", \"2\", \"3\"]\n\nfor i in range(2):\n a = input()\n Ans.remove(a)\n\nprint(Ans[0])", "a=int(input())\nb=int(input())\nprint(6-a-b)", "a = int(input())\nb = int(input())\nprint(6-a-b)", "A = int(input())\nB = int(input())\n\nfor i in range(1,4):\n if i != A and i != B:\n print(i)", "A = int(input())\nB = int(input())\nC = 6 - A - B\nprint(C)", "num = [1, 2, 3]\nnum.remove(int(input()))\nnum.remove(int(input()))\nprint(num.pop())\nreturn", "a=int(input())\nb=int(input())\n\nif a+b==3:\n print(3)\nelif a+b==5:\n print(1)\nelse:\n print(2)", "a = int(input())\nb = int(input())\nif a + b ==3:\n print(3)\nelif a + b ==4:\n print(2)\nelse:\n print(1)", "a = int(input())\nb = int(input())\n\nprint(6 - a - b)", "A = int(input())\nB = int(input())\nans = [1, 2, 3]\nans.remove(A)\nans.remove(B)\n\nprint(ans[0])", "a = int(input())\nb = int(input())\n\nif a + b == 3:\n print(3)\nelif a + b == 4:\n print(2)\nelse:\n print(1)", "a=int(input())\nb=int(input())\nif (a==1 and b==2) or (a==2 and b==1):\n print(\"3\")\nelif (a==2 and b==3) or (a==3 and b==2):\n print(\"1\")\nelse:\n print(\"2\")", "a = int(input())\nb = int(input())\n\nfor i in range(1,4):\n if i !=a and i!= b:\n print(i)", "x = int(input())\ny = int(input())\nif (x == 1 and y == 2) or (x == 2 and y == 1):\n print((3))\nif (x == 1 and y == 3) or (x == 3 and y == 1):\n print((2))\nif (x == 3 and y == 2) or (x == 2 and y == 3):\n print((1))\n", "a = int(input())\nb = int(input())\n\nif a == 1:\n if b == 2:\n print(\"3\")\n \n elif b == 3:\n print(\"2\")\n\nelif a == 2:\n if b == 1:\n print(\"3\")\n \n elif b == 3:\n print(\"1\")\n\nelif a == 3:\n if b == 1:\n print(\"2\")\n \n elif b == 2:\n print(\"1\")"] | {"inputs": ["3\n1\n", "1\n2\n", "1\n3\n", "3\n2\n", "2\n1\n", "2\n3\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "3\n", "1\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 10,791 | |
76adb487d5ae20ac4d23f1c9d4a5321a | UNKNOWN | Given is a positive integer L.
Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
-----Constraints-----
- 1 β€ L β€ 1000
- L is an integer.
-----Input-----
Input is given from Standard Input in the following format:
L
-----Output-----
Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.
-----Sample Input-----
3
-----Sample Output-----
1.000000000000
For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.
On the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater. | ["L = int(input())\n\nans = (L / 3) ** 3\n\nprint(ans)", "def resolve():\n L = int(input())\n a = L/3\n print(a**3)\nresolve()", "s=int(input())\nb=s/3\nprint(b**3)", "L = int(input())\nprint((L ** 3) / 27)", "from math import *\nl = int(input())\nprint((l/3)**3)", "print((int(input())/3)**3)", "L = int(input())\n\nprint(((L / 3) ** 3))\n", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n L = ini()\n return (L / 3) ** 3\n\n\nprint(solve())\n", "L = int(input())\nprint((L**3)/27)", "import math\nimport sys\n##### graph implementation with adjacancy list#####\nclass Graph:\n def __init__(self,Nodes,is_directed=False):\n self.nodes=Nodes\n self.adj_list={}\n self.is_directed=is_directed\n \n for node in self.nodes:\n self.adj_list[node]=[]\n \n def add_edge(self,u,v):\n self.adj_list[u].append(v)\n if self.is_directed==False:\n self.adj_list[v].append(u)\n \n def print_graph(self):\n for node in self.nodes:\n print((node,\"->\",self.adj_list[node]))\n \n def degree_node(self,node):\n return len(self.adj_list[node])\n \n def dfsUTIL(self,v,visited,parents=[]):\n #print(v,end=\" \")\n visited[v]=True\n for i in self.adj_list[v]:\n if visited[i]==False:\n self.dfsUTIL(i,visited,parents)\n parents.append(i) \n \n def dfs(self,v):\n visited=[False]*(max(self.adj_list)+1)\n parents=[v]\n self.dfsUTIL(v,visited,parents)\n return len(parents)\n \n#####sorting a dictionary by the values#####\ndef dict_sort(ans):\n ans=sorted(list(ans.items()),reverse=True,key=lambda kv:(kv[1]))\n \n##### naive method for testing prime or not O(n^.5)#####\ndef is_prime(n):\n if n==1:\n return 0\n for i in range(2,int(math.sqrt(n))+1):\n if n%i==0:\n return False\n return True\n\n#####swap function#####\ndef swap(a,b):\n temp=a\n a=b\n b=temp\n return a,b\n\n#####Primes till Nth O(n)#####\ndef seive_primes(n):\n flag=[0]*(n+10)\n flag[1]=flag[0]=1\n i=2\n while i*i<=n+1:\n if flag[i]==0:\n j=i*i\n while j<=n+1:\n flag[j]=1\n j+=i\n i+=1\n return flag\n\n#####all the prime factors of a number#####\ndef factors(n):\n d={}\n while(n%2==0):\n if 2 in d:\n d[2]+=1\n else:\n d[2]=1\n n/=2\n for i in range(3,int(n**0.5)+1,2):\n while(n%i==0):\n if i in d:\n d[i]+=1\n else:\n d[i]=1\n n/=i\n n=int(n)\n if n>1:\n d[n]=1\n return d\n\n#####greatest common divisor of two numbers#####\ndef gcd(a,b):\n if b==0:\n return a\n return gcd(b,a%b)\n\n#####least common multiplyer of two numbers#####\ndef lcm(a,b):\n return (a*b)//gcd(a,b)\n\n#####function that return all the letters#####\ndef alphabates():\n return \"abcdefghijklmnopqrstuvwxyz\"\n\n#####binary search O(logN)#####\ndef binary_search(ls,n,flag):\n low=0\n hi=n-1\n while(low<=hi):\n mid=(low+hi)//2\n if ls[mid]==flag:\n return mid\n elif ls[mid]>flag:\n hi=mid-1\n else:\n low=mid+1\n return -1\n\n#####quadratic roots#####\ndef qdrt(a,b,c):\n chk=b*b-4*a*c\n if chk>=0:\n ans1=(-b+chk**0.5)/(2*a)\n ans2=(-b-chk**0.5)/(2*a)\n return [int(ans1),int(ans2)]\n return -1\n#####permutations#####\ndef permutation(n,r):\n if n<r:\n return 0\n ans=1\n for i in range(n-r+1,n+1):\n ans*=i\n return ans\n\n#####combinations#####\ndef combination(n,r):\n if n<r:\n return 0\n ans=1\n for i in range(r):\n ans*=(n-i)\n div=1\n for i in range(2,r+1):\n div*=i\n return ans//div\n \n#####taking an array/list as input#####\ndef arinp():\n ls=list(map(int,input().split()))\n return ls\n\n#####taking multiple inputs#####\ndef mult_inp():\n return list(map(int,input().split()))\n\n#####Main function starts from here#####\ndef main():\n n=int(input())/3\n print((n**3))\ndef __starting_point():\n main()\n \n\n \n \n \n \n \n \n\n__starting_point()", "from decimal import *\nl = int(input())\nprint(Decimal((l/3)**3))", "l=int(input(\"\"))\nv=l*l*l\nd=int(v/27)\nprint((v%27)/27+d)", "L=float(input())\n\nprint((L/3)**3)", "print(((int(input())/3)**3))\n", "from decimal import Decimal\nl=int(input())\nnum = Decimal(l/3)\nprint((num**3))\n", "l = int(input())\nprint((l/3) ** 3)", "print(((int(input())/3)**3))\n", "l=int(input())\nprint((l/3)**3)", "print((int(input())/3)**3)", "l = int(input())\n\nans = (l / 3) ** 3\n\nprint(ans)\n", "l = int(input())\nprint((l/3)**3)", "def main():\n L = int(input())\n l = L/3\n print((l*l*l))\n\n\nmain()\n", "L = int(input())\n\nx = L/3\nprint((x*x*x))\n", "L = int(input())\nprint((L/3)**3)", "l=int(input())\nprint(l**3/27)", "print((int(input())/3)**3)", "L = int(input())\n\nans = pow(L / 3, 3)\nprint(ans)", "l = int(input())\n\nprint(pow(l/3,3))", "def main():\n l = int(input())\n oneThirds = l / 3\n return oneThirds*oneThirds*oneThirds\n \n\n\ndef __starting_point():\n print(main())\n__starting_point()", "l = int(input())\n\nl = float(l / 3)\nprint((l ** 3))\n", "l = int(input())\n\nx= l/3\n\nans= x**3\n\nprint(ans)", "print(pow(int(input())/3,3))", "l = int(input())\na = l / 3\nl = l - a\nb = l / 2\nc = l - b\nprint(a * b * c)", "n = int(input())\n\nx = n/3\ny = n/3\nz = (n-x-y)\n\nprint(x*y*z)", "# import math\n# import statistics\n# import itertools\na=int(input())\n# b=input()\n# c=[]\n# for i in a:\n# c.append(int(i))\n# N,S,T= map(int,input().split())\n# f = list(map(int,input().split()))\n# g = [int(input()) for _ in range(N)]\n# h = []\n# for i in range(a):\n# h.append(list(map(int,input().split())))\n# a = [[0] for _ in range(H)]#nizigen\n\nprint((a/3)**3)", "l = int(input())\nprint((l/3)**3)", "l = int(input())\nprint((l/3)**3)", "print((int(input()) / 3) ** 3)", "a = int(input())\n\nb = a/3\n\nsub = b**3\n\nprint(sub)", "L = int(input())\nx = L / 3.0\nz = L - 2.0 * x\nprint((x * x * z))\n", "l = int(input())\nprint((l/3)**3)", "l = int(input())\ne = l/3\nprint(\"{:.10}\".format(e**3))", "l = int(input())\n\nprint((l/3)**3)", "L=int(input())\nprint(pow(L/3,3))", "L = int(input())\nans = (L/3)**3\nprint(ans)", "L= int(input())\n\nprint ((L/3)**3)", "L = int(input())\nS = (L/3)**3\nprint(S)", "L = int(input())\nprint(pow(L/3, 3))", "L = int(input())\nprint((L/3)**3)", "l = int(input())\n\nprint(((l / 3) ** 3))\n", "import os, sys, re, math\n\nL = int(input())\n\nprint(((L / 3) ** 3))\n", "l = int(input())\nprint((l**3 / 27))\n", "l = int(input())\nprint(((l/3)**3))\n", "L = int(input())\nn = L/3\nprint((n**3))\n", "num = int(input())\n\nnumber = num / 3\nprint(number * number * number)", "print((int(input())/3)**3)", "L = int(input())\n\nprint((L ** 3) / 27)", "L=int(input())\nx=L/3\ny=L/3\nz=L/3\nprint(x*y*z)", "import sys\nimport math\nfrom collections import defaultdict, deque, Counter\nfrom copy import deepcopy\nfrom bisect import bisect, bisect_right, bisect_left\nfrom heapq import heapify, heappop, heappush\n \ninput = sys.stdin.readline\ndef RD(): return input().rstrip()\ndef F(): return float(input().rstrip())\ndef I(): return int(input().rstrip())\ndef MI(): return map(int, input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int, input().split()))\ndef TI(): return tuple(map(int, input().split()))\ndef LF(): return list(map(float,input().split()))\ndef Init(H, W, num): return [[num for i in range(W)] for j in range(H)]\n \n \ndef main():\n L = I()\n print(pow(L/3, 3))\ndef __starting_point():\n main()\n__starting_point()", "print((int(input())/3)**3)", "l = int(input())\nprint((l/3)**3)", "L=int(input())\nprint((L/3)**3)", "l = int(input())\n\nL = l**3 / 27\nprint(L)", "l = int(input())\nprint((l / 3)**3)", "L = int(input())\nprint(L **3 / 27)", "l = int(input())\nans = (l/3)**3\nprint(ans)", "l=int(input())\nprint((l/3)**3)", "print(int(input())**3/27)", "l = int(input())\nprint((l / 3)**3)", "L = int(input())\n\nedge = L/3\n\nprint(edge**3)", "l = int(input())\nprint((l/3)**3)", "print((int(input()) / 3) ** 3)", "l = int(input())\nprint((l/3) ** 3)", "import sys\n\nsys.setrecursionlimit(10 ** 7)\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef resolve():\n l = int(input())\n res = pow(l / 3, 3)\n print(res)\n\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "L = int(input())\nret = L ** 3 / 3 ** 3\nprint(ret)\n\n", "L = int(input())\nn = L/3\nprint(n*n*n)", "print((int(input()) / 3) ** 3)", "k=float(input())\nvolume=(k/3)*(k/3)*(k/3)\nprint(volume)", "print((int(input()) / 3) ** 3)", "\ndef i_input(): return int(input())\ndef i_map(): return map(int, input().split())\ndef i_list(): return list(map(int, input().split()))\ndef i_row(N): return [int(input()) for _ in range(N)]\ndef i_row_list(N): return [list(map(int,input().split())) for _ in range(N)]\n\nl=i_input()\nprint((l/3)**3)", "l = int(input())\nv = (float(l/3))**3\nprint(v)", "l = int(input())\nprint(l ** 3 / 27)", "L = int(input())\na = L/3\nans = pow(a,3)\nprint(ans)", "l = int(input())\nprint(l**3/27)", "L = int(input())\n\nl = L/3\nans = l**3\nprint(ans)", "l = int(input())\nprint((l/3.0)**3.0)", "# coding=utf-8\n\ndef __starting_point():\n L = int(input())\n\n print((L/3)**3)\n__starting_point()", "L = int(input())\n\nprint((L / 3) ** 3)", "L = int(input())\nl = L / 3\nprint(l ** 3)", "l = int(input())\nprint((l/3) * (l/3) * (l/3))", "print(int(input())**3/27)", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect\nfrom operator import itemgetter\n#from heapq import heappush, heappop\n#import numpy as np\n#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson\n#from scipy.sparse import csr_matrix\n#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nnf = lambda: float(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nnb = lambda: list(map(float, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nL = ni()\nprint(((L/3)**3))\n\n \n\n", "L=int(input())\nprint((L/3)**3)", "l = int(input()) / 3\nprint(('{:.9}'.format(l**3)))\n", "import sys\n\nL = int(sys.stdin.readline())\nprint(L**3 / 27)", "L = int(input())\nL = L/3\nV=1\nfor i in range (3):\n V*=L\nprint (V)\n \n", "def answer(l: int) -> float:\n return pow(l / 3, 3)\n\n\ndef main():\n l = int(input())\n print(answer(l))\n\n\ndef __starting_point():\n main()\n__starting_point()", "L = int(input())\nprint(L**3/27)", "l = int(input())\n\nans = l * l * l / 27\n\nprint(ans)\n", "L=int(input())\nprint(pow(L/3,3))"] | {"inputs": ["3\n", "999\n", "430\n", "1\n", "1000\n", "392\n"], "outputs": ["1.000000000000\n", "36926037.000000000000\n", "2944703.703703703824\n", "0.037037037037\n", "37037037.037037037313\n", "2230973.629629629664\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,372 | |
80bcbe21c5b67cf5282269bdaa231723 | UNKNOWN | In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
-----Constraints-----
- N is 1 or 2.
- A is an integer between 1 and 9 (inclusive).
- B is an integer between 1 and 9 (inclusive).
-----Input-----
Input is given from Standard Input in one of the following formats:
1
2
A
B
-----Output-----
If N=1, print Hello World; if N=2, print A+B.
-----Sample Input-----
1
-----Sample Output-----
Hello World
As N=1, Takahashi is one year old. Thus, we should print Hello World. | ["n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "N = int(input())\nprint(\"Hello World\") if N==1 else print(sum([int(input()) for _ in range(2)]))", "n = int(input())\n\nif n == 1:\n print(\"Hello World\")\nelse:\n A = int(input())\n B = int(input())\n print(A+B)", "a = int(input())\nif a == 1:\n print('Hello World')\nelse:\n a = [int(input()) for i in range(2)]\n print(a[0] + a[1])", "n=int(input())\nif n ==1:\n print('Hello World')\nelse:\n a=int(input())\n b=int(input())\n print(a+b)", "N = int(input())\nif N == 1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n print(A+B)", "n= int(input())\nif n == 1:\n print(\"Hello World\")\n return\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "a = int(input())\nif a == 1:\n print('Hello World')\nelse:\n a = [int(input()) for i in range(2)]\n print((a[0] + a[1]))\n", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n=int(input())\n\nif(n==1):\n print(\"Hello World\")\nelif(n==2):\n a=int(input())\n b=int(input())\n print(int(a+b))", "if input() == '1':\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print((a+b))\n", "n = int(input())\n\nif n == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "\ndef main():\n n = int(input())\n if n == 1:\n print('Hello World')\n else:\n a = int(input())\n b = int(input())\n print((a + b))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "#k = int(input())\n#s = input()\n#a, b = map(int, input().split())\n#s, t = map(str, input().split())\n#l = list(map(int, input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\n#a = [list(input()) for _ in range(n)]\n#a = [input() for _ in range(n)]\n\nn = int(input())\n\nif n == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print((a+b))\n", "n = int(input())\nif n == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a + b)", "n=int(input())\nif n==1:print(\"Hello World\")\nelse:\n print(int(input())+int(input()))", "n=int(input())\nif n==1:\n print(\"Hello World\")\nif n==2:\n print(int(input())+int(input()))", "N = int(input())\n\nif N == 1:\n print('Hello World')\nelse:\n print((int(input())+int(input())))\n", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print((a + b))\n", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print((a + b))\n", "N=int(input())\nif N==1:\n print('Hello World')\n return\nelse:\n A=int(input())\n B=int(input())\n print(A+B)", "N=input()\nif N==\"1\":\n print(\"Hello World\")\nelse:\n print(int(input())+int(input())) ", "print(\"Hello World\") if input() == \"1\" else print(int(input()) + int(input()) )", "n = int(input())\nif n == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "N = int(input())\n\nif N == 1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n print(A + B)", "if input()==\"1\":print(\"Hello World\")\nelse:print(int(input())+int(input()))", "\nn = int(input())\nif n==1:\n print('Hello World')\nif n==2:\n a = int(input())\n b = int(input())\n print(a+b)", "n = int(input())\nif n == 2:\n a = int(input())\n b = int(input())\n print(a + b)\nelse:\n print(\"Hello World\")", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a, b = [int(input()) for _ in range(2)]\n print(a + b)", "import sys\n\n\nstdin = sys.stdin\ndef ns(): return stdin.readline().rstrip()\ndef ni(): return int(stdin.readline().rstrip())\ndef nm(): return list(map(int, stdin.readline().split()))\ndef nl(): return list(map(int, stdin.readline().split()))\n\n\ndef main():\n print(('Hello World' if ni() == 1 else ni() + ni()))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "x=int(input())\nif x==1:\n print(\"Hello World\")\nelse:\n A=int(input())\n B=int(input())\n print(A+B)", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n a=int(input())\n b=int(input())\n print(a+b)", "if int(input()) == 1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n print(A + B)", "n = int(input())\nprint(\"Hello World\" if n==1 else int(input())+int(input()))", "print(\"Hello World\"if input()==\"1\"else sum(map(int,[input(),input()])))", "a = int(input())\nif a == 1:\n print(\"Hello World\")\nelse:\n print(int(input())+int(input()))", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n A=int(input())\n B=int(input())\n print(A+B)", "n = int(input())\n\nif n == 1:\n print('Hello World')\nif n == 2:\n a = int(input())\n b = int(input())\n print(a + b)", "a = input()\n\nif a == \"1\":\n print(\"Hello World\")\nelif a == \"2\":\n b = int(input())\n c = int(input())\n print(b + c)", "N = int(input())\nif N == 2:\n A = int(input())\n B = int(input())\n print(A+B)\nif N == 1:\n print('Hello World')", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n a=int(input())\n b=int(input())\n print(a+b)", "N = int(input())\nif N == 1:\n print(\"Hello World\")\nelse:\n A = int(input())\n B = int(input())\n print((A + B))\n", "if int(input()) == 1:\n print(\"Hello World\")\nelse:\n b = int(input())\n c = int(input())\n print(b+c)", "n = int(input())\n\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print((a + b))\n", "a = input()\nif a == \"1\":\n print(\"Hello World\")\nelse:\n print(int(input()) + int(input()))", "n=input()\nif n=='1':\n print(\"Hello World\")\nelse:\n a=[int(input()) for i in range(2)]\n print(a[0]+a[1])", "if input()=='1':\n print('Hello World')\nelse:\n print(int(input())+int(input()))", "n = int (input ())\nif n == 1:\n print ('Hello World')\nelse:\n a = int (input ())\n b = int (input ())\n print (a+b)", "N=int(input())\n\nif N==1:\n print(\"Hello World\")\nelse:\n A=int(input())\n B=int(input())\n print((A+B))\n", "a = int(input())\nif a == 1:\n print('Hello World')\nelse:\n print(int(input()) + int(input()))", "a=int(input())\nif a==1:\n print(\"Hello World\")\nif a==2:\n b=int(input())\n c=int(input())\n print((int(b+c)))\n", "N = int(input())\n\nif N == 1:\n print('Hello World')\n \nelif N == 2:\n print((int(input()) + int(input())))\n", "n=int(input())\n\nif n==1:\n print(\"Hello World\")\n \nelse:\n a=int(input())\n b=int(input())\n print((a+b))\n", "N= int(input())\nif N==1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n print(A+B)", "n = int(input())\n\nif n == 1:\n print('Hello World')\nelif n == 2:\n a = int(input())\n b = int(input())\n print(a + b)", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n a=int(input())\n b=int(input())\n print((a+b))\n", "def __starting_point():\n\tn = int(input())\n\t\n\tif n == 1:\n\t\tprint(\"Hello World\")\n\telse:\n\t\tans = 0\n\t\tfor i in range(2):\n\t\t\tans += int(input())\n\t\tprint(ans)\n__starting_point()", "N = input()\nif N == '1':\n print('Hello World')\n return\nelse:\n A = int(input())\n B = int(input())\n print(A+B)", "N = int(input())\n\nif N == 1:\n print('Hello World')\nelif N == 2:\n A = int(input())\n B = int(input())\n print((A + B))\n", "com=int(input())\nif com==1:\n print(\"Hello World\")\nelse:\n a=int(input());b=int(input())\n print((a+b))\n", "N = int(input())\nif N == 2:\n A = int(input())\n B = int(input())\n print((A+B))\nelse:\n print('Hello World')\n", "\n\ndef main():\n n = int(input())\n if n == 1:\n print(\"Hello World\")\n else:\n a = int(input())\n b = int(input())\n print(a+b)\n \n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nif N==1:\n print('Hello World')\nelse:\n print(sum(int(input()) for T in range(0,2)))", "if int(input()) == 2:\n A = int(input())\n B = int(input())\n print(A + B)\nelse:\n print('Hello World')", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n print(A+B)", "n=int(input())\nif n==1:print('Hello World')\nelse:\n a,b=int(input()),int(input())\n print(a+b)", "n = int(input())\nif n == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n a=int(input())\n b=int(input())\n print(a+b)", "N=int(input())\nif N==1 :\n print(\"Hello World\")\nelse :\n A=int(input())\n B=int(input())\n print(A+B)", "a = int(input())\nif a == 1:\n print(\"Hello World\")\nelse:\n b = int(input())\n c = int(input())\n print(int(b + c))", "n=int(input())\nif n==1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print(a + b)", "n = int(input())\n\nif n == 2:\n a = int(input())\n b = int(input())\n print(a+b)\nelse:\n print('Hello World')", "N = int(input())\nif N == 1:\n print(\"Hello World\")\nelse:\n print((sum([int(input()) for _ in range(2)])))\n", "n = int(input())\n\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n = int(input())\n\nif n ==1:\n print(\"Hello World\")\n\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n=int(input())\nif n==1:\n print('Hello World')\nelse:\n print((int(input())+int(input())))\n", "N = int(input())\nif N == 1:\n print(\"Hello World\")\nelse:\n A = int(input())\n B = int(input())\n print(A + B)", "n=int(input())\nprint(\"Hello World\" if n==1 else int(input())+int(input()))", "n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = [int(input()) for i in range(2)]\n print(a[0] + a[1])", "n=int(input())\nif n==1:print(\"Hello World\")\nelse:print(int(input())+int(input()))", "if int(input()) == 1:\n print(\"Hello World\")\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "n = int(input())\nif n ==1 :\n print(\"Hello World\")\nelse : \n a = int(input())\n b = int(input())\n print((a+b))\n", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N = int(readline())\n\n if N == 1:\n print('Hello World')\n else:\n A, B = list(map(int, read().split()))\n print((A + B))\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "age = int(input())\n\nif age == 1:\n print('Hello World')\nelif age == 2:\n a = int(input())\n b = int(input())\n print(a + b)", "x = int(input())\nif x==1:\n print(\"Hello World\")\nelse:\n x=int(input())\n y=int(input())\n print(x+y)", "n=int(input())\nif n==1:\n print('Hello World')\nif n!=1:\n a=int(input())\n b=int(input())\n print(a+b)", "N = int(input())\n\nif N ==1:\n print('Hello World')\nelse:\n print(int(input())+int(input()))", "n = int(input())\n\nif n == 1: print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print((a+b))\n", "# author: Taichicchi\n# created: 11.10.2020 10:50:47\n\nimport sys\n\nif input() == \"1\":\n print(\"Hello World\")\nelse:\n A = int(input())\n B = int(input())\n print((A + B))\n", "n = int(input())\nif n == 2:\n a = int(input())\n b = int(input())\n print(a+b)\nelse:\n print(\"Hello World\")", "a = int(input())\nif a == 1:\n print(\"Hello World\")\nelse:\n b = int(input())\n c = int(input())\n print(b+c)", "\nn=int(input())\nif n==1:\n print('Hello World')\nelse:\n a=int(input())\n b=int(input())\n print(a+b)", "def main():\n n = int(input())\n a, b = \"Hello \", \"World\"\n if n == 2:\n a, b = [int(input()) for _ in range(n)]\n print(a+b)\n\n\nmain()", "N=input()\nif N==\"1\":\n print(\"Hello World\")\nelse:\n a,b=int(input()),int(input())\n print(a+b)", "a = int(input())\nif a == 1:\n print('Hello World')\nelse:\n b = int(input())\n c = int(input())\n print(b + c)", "n=int(input())\nif n==1:\n print('Hello World')\nelse:\n print(int(input())+int(input()))", "N = int(input())\n\nif N == 1:\n print('Hello World')\nelse:\n A = int(input())\n B = int(input())\n\n print(A + B)", "print('Hello World' if input() == '1' else int(input()) + int(input()))", "if input()=='1':\n print(\"Hello World\")\nelse:\n print((sum(int(input()) for _ in range(2))))\n"] | {"inputs": ["1\n", "2\n3\n5\n", "2\n1\n1\n", "2\n8\n5\n", "2\n9\n9\n", "2\n5\n6\n"], "outputs": ["Hello World\n", "8\n", "2\n", "13\n", "18\n", "11\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 13,029 | |
33d53b82248d7ae514fcf98791c17a51 | UNKNOWN | Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?
-----Constraints-----
- 1 \leq a \leq 9
- 1 \leq b \leq 9
- a and b are integers.
-----Input-----
Input is given from Standard Input in the following format:
a b
-----Output-----
Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)
-----Sample Input-----
4 3
-----Sample Output-----
3333
We have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller. | ["a, b = map(int, input().split())\n\nif a <= b:\n ans = str(a) * b\nelse:\n ans = str(b) * a\nprint(ans)\nreturn", "a, b = map(int, input().split())\n\nprint((f\"{a}\" * b, f\"{b}\" * a)[b <= a])", "a,b = map(int, input().split())\n\n\nif a < b:\n print(str(a)*b)\nelse:\n print(str(b)*a)", "a, b = map(int, input().split())\n\nif a < b:\n print(str(a) * b)\nelse:\n print(str(b) * a)", "a,b = input().split()\nprint(max(int(a*int(b)),int(b*int(a))))", "a,b = map(int,input().split())\n\nans =[]\nans.append(a)\nans.append(b)\nans = sorted(ans)\n\nanser = ''\nfor i in range(ans[1]):\n anser+=str(ans[0])\n \nprint (anser)", "a, b = map(int, input().split())\n\nans = 0\nif a >= b:\n for i in range(a):\n ans += b * 10**i\nelse:\n for i in range(b):\n ans += a * 10**i\nprint(ans)", "a, b = list(map(int, input().split()))\nprint((min(str(b)*a, str(a)*b)))\n", "a, b = map(int, input().split())\nc = str(a) * b\nd = str(b) * a\nif int(c[0]) >= int(d[0]):\n print(d)\nelse:\n print(c)", "a,b = map(int,input().split())\nif a > b:\n print(int(str(b)*a))\nelse:\n print(int(str(a)*b))", "a, b = map(int, input().split())\n\nif a > b:\n print(str(b) * a)\nelse:\n print(str(a) * b)", "a, b = [s for s in input().split()]\nprint((min(a * int(b), b * int(a))))\n", "a,b = map(int,input().split())\n# a,b\u3092\u6587\u5b57\u5217\u5316\na_str = str(a)\nb_str = str(b)\n# a*b\u3068b*a\u3092\u6607\u9806\u3067\u306a\u3089\u3079\u3066\u30ea\u30b9\u30c8\u5316\nab_list = sorted([a_str * b, b_str * a])\n# \u30ea\u30b9\u30c8\u306e1\u756a\u76ee\u3092\u51fa\u529b\nprint(ab_list[0])", "a, b = map(int, input().split())\n\na_b = str(a) * b\nb_a = str(b) * a\n\nif int(a_b[0]) >= int(b_a[0]):\n print(b_a)\nelse:\n print(a_b)", "a, b = map(int, input().split())\n\na1 = a * str(b)\na2 = b * str(a)\nprint(min(a1, a2))", "a, b = map(int,input().split())\n\nab = str(a) * b\nba = str(b) * a\n\nif ab > ba:\n ans = ba\nelse:\n ans = ab\n\nprint(ans)", "a,b = input().split()\nab = a*int(b)\nba = b*int(a)\ns = max(len(ab),len(ba))\n\nif s == len(ab) :\n print(ab)\nelse :\n print(ba)", "def answer(a: int, b: int) -> str:\n return min(str(a) * b, str(b) * a)\n\n\ndef main():\n a, b = map(int, input().split())\n print(answer(a, b))\n\n\ndef __starting_point():\n main()\n__starting_point()", "a,b = input().split()\nprint(sorted([a*int(b),b*int(a)])[0])", "a,b = input().split()\n\nA = (a*int(b))\nB = (b*int(a))\n\nif A < B:\n print(A)\nelse:\n print(B)", "def main():\n\ta, b = list(map(int, input().split()))\n\tf = str(a)*b\n\ts = str(b)*a\n\tans = [f, s]\n\tans.sort()\n\treturn ans[0]\n\n\ndef __starting_point():\n print((main()))\n\n__starting_point()", "a, b = input().split()\nc = a * int(b)\nd = b * int(a)\nprint(min(c, d))", "a,b=list(map(int,input().split()))\nc=0\nif a>=b:\n for i in range(a):\n c=c*10+1\n print((b*c))\nelse:\n for i in range(b):\n c=c*10+1\n print((a*c))\n", "a, b = input().split()\nstr = ''\nif int(a)<=int(b):\n for _ in range(int(b)):\n str += a\nelse:\n for _ in range(int(a)):\n str += b\n\nprint(str)", "a, b = map(str,input().split())\nA = a*int(b)\nB = b*int(a)\nx = [A , B]\nx.sort()\nprint(x[0])", "def resolve():\n a,b = map(int,input().split())\n A = str(a)*b\n B = str(b)*a\n print(A if A<B else B)\nresolve()", "a, b = map(int, input().split())\naa = str(a)*b\nbb = str(b)*a\n\naa = ''.join(aa)\nbb = ''.join(bb)\n\nif aa > bb:\n print(bb)\nelse:\n print(aa)", "a, b = input().split()\na1 = a * int(b)\nb1 = b * int(a)\nif int(a) <= int(b):\n print(a1)\nelse:\n print(b1)", "a, b = list(map(int, input().split()))\nprint((min(str(a) * b, str(b) * a)))\n", "a,b = input().split()\n\nprint(min(a*int(b),b*int(a)))", "a,b = map(int,input().split())\n\n#\u6574\u6570\u540c\u58eb\u306e\u305f\u3060\u306e\u8a08\u7b97\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u578b\u3092\u6307\u5b9a\u3059\u308b\u3002\nA = str(a) * b\nB = str(b) * a\n\nif a > b:\n print(B)\nelse:\n print(A)", "a,b=list(map(int,input().split()))\n\nif a<b:\n print((str(a)*b))\nelif a>b:\n print((str(b)*a))\nelif a==b:\n print((str(a)*b))\n", "a,b = map(str,input().split())\nA = a*int(b)\nB = b*int(a)\nprint(sorted([A,B])[0])", "a,b = map(int, input().split())\nif a < b:\n print(str(a)*b)\nelse:\n print(str(b)*a)", "a, b = map(int, input().split())\nminValue = min(a,b)\nmaxValue = max(a,b)\nprint(str(minValue)*maxValue)", "a,b = map(int,input().split())\nc = str(a)*b\nd = str(b)*a\nprint(min(c,d))", "a, b = list(map(int, input().split()))\n\n# \u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3046\nA = str(a)\nB = str(b)\n\naaa = A * b\nbbb = B * a\n\n# \u8f9e\u66f8\u9806\u3067\u5c0f\u3055\u3044\u65b9\u3092\u51fa\u529b\nlists = sorted([aaa, bbb])\nprint((lists[0]))\n", "a, b = map(int, input().split())\n\nif a > b:\n print(str(b) * a)\nelif a < b:\n print(str(a) * b)\nelse:\n print(str(a) * a)", "a,b = map(int,input().split())\n\n\nif a > b:\n print(str(b) * a)\n\nelif b > a:\n print(str(a) * b)\nelse:\n print(str(a) * b)", "a, b = map(int, input().split())\n\nprint(str(min(a, b))*max(a, b))", "a,b = list(map(int,input().split()))\n\nif a <= b:\n a = str(a)\n print((a*b))\n\nelse:\n b = str(b)\n print((b*a))\n", "ls = list(map(int,input().split()))\nprint(str(min(ls))*max(ls))", "a, b = map(int, input().split())\nif a > b:\n print(str(b) * a)\nelif a < b:\n print(str(a) * b)\nelse:\n print(str(a) * a)", "import numpy as np\n\na,b=map(int,input().split())\n\nA=(''.join([str(a)]*b))\nB=(''.join([str(b)]*a))\n\nprint(min(A,B))", "# \u5165\u529b\u3092\u53d7\u3051\u53d6\u308b\na,b = input().split()\n\n#a\u3092b\u500b\u3001b\u3092a\u500b\u4e26\u3079\u305f\u3082\u306e\u3092\u4f5c\u308b\nstr_a = a*int(b)\nstr_b = b*int(a)\n\n#a\u3068b\u3092\u6bd4\u8f03\u3057\u3066\u3001\u8f9e\u66f8\u9806\u306b\u5c0f\u3055\u3044\u65b9\u3092\u51fa\u529b\u3059\u308b\nprint(str_a if str_a < str_b else str_b)", "a,b=input().split()\nprint(min(a*int(b),b*int(a)))", "a,b=map(int,input().split())\ns=[a]*b\nt=[b]*a\nab=map(str,s)\nba=map(str,t)\nif a<=b:\n print(''.join(ab))\nelse:\n print(''.join(ba))", "a,b = map(int,input().split())\nL = [str(a)*b, str(b)*a]\n\n\nL = sorted(L)\nprint(L[0])", "a, b = list(map(int, input().split()))\nif a > b:\n print((str(b) * a))\nelse:\n print((str(a) * b))\n", "a,b = input().split()\nif a < b:\n print(a*int(b))\nelse:\n print(b*int(a))", "from sys import setrecursionlimit, exit\nsetrecursionlimit(1000000000)\n\ndef main():\n a, b = map(int, input().split())\n if a <= b:\n print(str(a) * b)\n else:\n print(str(b) * a)\n\nmain()", "a, b = map(int,input().split())\nlist = []\nif a > b:\n for i in range(a):\n list.append(b)\nelse:\n for j in range(b):\n list.append(a)\n\n\nlist = [str(a) for a in list]\nlist = \"\".join(list)\nprint(list)", "a,b = map(int,input().split())\nif a >= b:\n print(str(b) * a) \nelse:\n print(str(a) * b)", "a, b = input().split()\nif a < b:\n print(a * int(b))\nelse:\n print(b * int(a))", "a,b = input().split()\n\nprint(sorted([a*int(b), b*int(a)])[0])", "a, b = map(int, input().split())\n\nif a > b:\n b = str(b)\n print(b * a)\nelse:\n a = str(a)\n print(a * b)", "a = input()\na = a.split()\nb = a[1]\na = a[0]\nif a < b:\n d = a\n for c in range(int(b)-1):\n d = d + a\nelse:\n d = b\n for c in range(int(a)-1):\n d = d + b\nprint(int(d))", "a,b=input().split();print(min(a*int(b),b*int(a)))", "a,b=map(int,input().split())\nA=0\nB=0\nfor i in range(a):\n A += b*10**i\nfor i in range(b):\n B += a*10**i\nif a>b:\n print (A)\nelse:\n print (B)", "input_line=input().rstrip().split()\nnum1 = int(input_line[0])\nnum2 = int(input_line[1])\n \nif (num1 > num2):\n print(str(num2)*num1)\nelif (num1 < num2):\n print(str(num1)*num2)\nelif (num1 == num2):\n print(str(num1)*num2)", "a,b=map(int,input().split())\n\ndef ans152(a:int, b:int):\n listab=[str(a)*b,str(b)*a]\n listab.sort()\n return int(listab[0])\n\nprint(ans152(a,b))", "a, b = map(int, input().split())\n\nif a <= b:\n print(str(a) * b)\nelif a > b:\n print(a * str(b))", "a, b = input().split()\nprint(min(a * int(b), b * int(a)))", "f = list(map(int, input().split()))\nprint(str(min(f)) * max(f))", "a, b = map(str, input().split())\n\nlist = []\ndef Repetition(x:str, y:str):\n list.append(x * int(y))\n return\n\nRepetition(a, b)\nRepetition(b, a)\n\n\nlist.sort()\nprint(list[0])", "a, b = map(int, input().split())\n\nif a <= b:\n ans = a\n for i in range(b-1):\n ans = ans * 10 + a\nelse: \n ans = b \n for i in range(a-1):\n ans = ans * 10 + b\n\nprint(ans)", "x, y = list(map(int, input().split()))\n\nif x > y:\n print((str(y) * x))\nelse:\n print((str(x) * y))\n", "a, b = map(int,input().split())\n\nA = str(a) * int(b)\nB = str(b) * int(a)\nprint(min(A, B))", "A,B = list(map(int,input().split()))\nans = [str(A)*B,str(B)*A]\nans.sort()\nprint((ans[0]))\n", "a, b = list(map(int,input().split()))\n\nmy_list = []\n\nif a > b:\n for i in range(a):\n my_list.append(b)\nelif b > a:\n for i in range(b):\n my_list.append(a)\nelse:\n for i in range(a):\n my_list.append(b)\n \nprint(''.join([str(n) for n in my_list]))", "a,b=map(int,input().split())\nif a<=b:\n print(str(a)*b)\nelse:\n print(str(b)*a)", "a, b = map(int, input().split())\n\n# \u6574\u6570a \u3092b\u56de\u7e70\u308a\u8fd4\u3057\u3066\u3067\u304d\u308b\u6587\u5b57\u5217\u3068 \u6574\u6570b \u3092a\u56de\u7e70\u308a\u8fd4\u3057\u3066\u3067\u304d\u308b\u6587\u5b57\u5217\u306e\u3046\u3061\u3001\n# \u8f9e\u66f8\u9806\u3067\u5c0f\u3055\u3044\u65b9\u3092\u51fa\u529b\u305b\u3088\u3002\n# (2\u3064\u306e\u6587\u5b57\u5217\u304c\u7b49\u3057\u3044\u3068\u304d\u306f\u3001\u305d\u306e\u3046\u3061\u3069\u3061\u3089\u304b\u3092\u51fa\u529b\u305b\u3088\u3002)\n\nif a > b:\n b = str(b)\n print(b * a)\nelse:\n a = str(a)\n print(a * b)", "a, b = map(int, input().split())\n\nab = str(a) * b\nba = str(b) * a\n\nif ab > ba:\n answer = ba\nelse:\n answer = ab\n \nprint(answer)", "a, b = map(int, input().split())\n\nlists = []\nlists.append(str(a) * b)\nlists.append(str(b) * a)\nlists.sort()\n\nprint(lists[0])", "a,b = map(int,input().split())\nprint(str(min(a,b))*max(a,b))", "# a, b\u3092\u6570\u5024\u578b\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\nvals = list(map(int, input().split()))\n\n# \u5c0f\u3055\u3044\u5024\u306e\u65b9\u3092\u5224\u5b9a\nmin_val, max_val = sorted(vals)\n\n# \u5c0f\u3055\u3044\u5024\u306e\u65b9\u3092\u3082\u3046\u4e00\u65b9\u306e\u5024\u306e\u5206\u3060\u3051\u7e70\u308a\u8fd4\u3057\u6587\u5b57\u5217\u7d50\u5408\u3055\u305b\u308b\nret = ''\nfor i in range(max_val):\n ret += str(min_val)\n\n# \u7d50\u679c\u3092\u8868\u793a\nprint(ret)", "a, b = map(int, input().split())\n \nif a > b:\n print(str(b) * a)\nelse:\n print(str(a) * b)", "\na,b = list(map(int, input().split()))\nc=str(a)*b\nd=str(b)*a\n\nif c>d:\n print(d)\nelse:\n print(c)\n", "a, b = map(int, input().split())\n\nstr1 = str(a) * b\nstr2 = str(b) * a\n\nprint(min(str1, str2))", "a,b = map(int,input().split())\n\nif a > b:\n print(str(b) * a)\n\nelif b > a:\n print(str(a) * b)\n\nelse:\n print(str(a) * b)", "n, m = list(map(int, input().split()))\nif n > m:\n n, m = m, n\nres = str(n)\nprint((res * m))\n", "a, b = map(int, input().split())\nif a <= b:\n print(str(a) * b)\nelse:\n print(str(b) * a)", "a, b = map(int, input().split())\n\ndef dic():\n a_str, b_str = str(a), str(b)\n a_moji = a_str*b\n b_moji = b_str*a\n dic={a_moji:1,b_moji:2}\n dic = sorted(dic.items())\n\n\n return dic[0][0]\n\nprint(dic())", "\na, b = map(int, input().split())\n\na_b = str(a) * b\nb_a = str(b) * a\n\nif int(a_b[0]) >= int(b_a[0]):\n print(b_a)\nelse:\n print(a_b)", "a, b = map(int, input().split())\nans = \"\"\n\nif a <= b:\n for i in range(b):\n ans += str(a)\nelif b < a:\n for i in range(a):\n ans += str(b)\n\nprint(ans)", "num, num1 = input(\"\").split()\nnum = int(num)\nnum1 = int(num1)\n\nif num <= num1:\n for i in range(num1):\n print(num, end='')\nelse:\n for i in range(num):\n print(num1, end='')", "a,b=input().split()\nprint(min(a*int(b),b*int(a)))", "#!/usr/bin/env python3\ndef main():\n a, b = list(map(int, input().split()))\n\n can_a = str(a) * b\n can_b = str(b) * a\n if can_a < can_b:\n print(can_a)\n else:\n print(can_b)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a,b=map(int, input().split())\nA=str(a)*b\nB=str(b)*a\n\nprint(A if A<=B else B)", "a, b = list(map(int, input().split()))\n\nlists = [str(a) * b, str(b) * a]\nsort_list = sorted(lists)\n\nprint((sort_list[0]))\n", "a,b = input().split()\na,b = a*int(b),b*int(a)\nprint(sorted([a,b])[0])", "a,b = map(int,input().split())\nf = str(a)*b\nn = str(b)*a\nif f > n:\n print(n)\nelse:\n print(f)", "a, b = input().split()\nprint(a*int(b) if a*int(b)<b*int(a) else b*int(a))", "a, b = input().split()\n\nprint(min(a*int(b), b*int(a)))", "a,b = list(map(int, input().split()))\n\nif str(a)*b < str(b)*a:\n print((str(a)*b))\nelse:\n print((str(b)*a))\n", "a,b=sorted(input().split());print(a*int(b))", "a, b = input().split()\nab = a * int(b)\nba = b * int(a)\n\nif int(a) <= int(b):\n print(ab)\nelse:\n print(ba)", "a,b=map(int,input().split())\nif a>b:\n print(str(b)*a)\nelse:\n print(str(a)*b)", "a, b = map(int, input().split())\n\n(x, y) = (a, b) if a<=b else (b, a)\n\nfor _ in range(y):\n print(x, end='')", "# a, b\u3092\u6570\u5024\u578b\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\nvals = list(map(int, input().split()))\n\n# \u6607\u9806\u306b\u30bd\u30fc\u30c8\u3057\u3066\u5404\u5024\u3092\u53d6\u5f97\nmin_val, max_val = sorted(vals)\n\n# \u5c0f\u3055\u3044\u5024\u306e\u65b9\u3092\u3082\u3046\u4e00\u65b9\u306e\u5024\u306e\u5206\u3060\u3051\u7e70\u308a\u8fd4\u3057\u6587\u5b57\u5217\u7d50\u5408\u3055\u305b\u308b\nret = str(min_val)*max_val\n\n# \u7d50\u679c\u3092\u8868\u793a\nprint(ret)"] | {"inputs": ["4 3\n", "7 7\n", "1 1\n", "9 1\n", "6 8\n", "5 4\n"], "outputs": ["3333\n", "7777777\n", "1\n", "111111111\n", "66666666\n", "44444\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 14,174 | |
52723a182b6b1a0e01591aea33f33acd | UNKNOWN | Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.
-----Constraints-----
- C is a lowercase English letter that is not z.
-----Input-----
Input is given from Standard Input in the following format:
C
-----Output-----
Print the letter that follows C in alphabetical order.
-----Sample Input-----
a
-----Sample Output-----
b
a is followed by b. | ["C = input()\nC = ord(C)\nC = C+1\nprint(chr(C))", "C = input()\nword = [chr(i) for i in range(97, 97+26)]\ncount = 0\nfor i in range( len(word) ):\n if C == word[i]:\n count = i\nprint(word[count+1])", "C =input()\nprint(chr(ord(C)+1))", "asd=input()\ndfg=[\"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\nprint(dfg[dfg.index(asd)+1])", "c = input()\nprint((chr(ord(c) + 1)))\n", "S = 'abcdefghijklmnopqrstuvwxyz'\nprint(S[S.index(input())+1])", "print(chr(ord(input())+1))", "c = ord(input())\nprint(chr(c + 1))", "print(chr(ord(input())+1))", "C = input()\nn = chr(ord(C)+1)\nprint(n)", "C = input()\na = ord(C)\nprint(chr(a+1))", "print('abcdefghijklmnopqrstuvwxyz'['abcdefghijklmnopqrstuvwxyz'.find(input())+1])", "c = input()\nprint((chr(ord(c)+1)))\n", "ls = ['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','a']\nprint(ls[ls.index(input())+1])", "C = input()\n \n# \u6587\u5b57\u5217\u3068\u6570\u5024\u306e\u5909\u63db\n# ord('\u6587\u5b57') / chr(\u6570\u5024) \u3067\u5909\u63db\nprint(chr(ord(C)+1))", "S = input()\nalphabet = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\nx = alphabet.index(S)\nprint(alphabet[x+1])", "s=input()\nprint(chr(ord(s)+1))", "print(chr(ord(input())+1))", "print(chr(ord(input())+1))", "c = input()\ns = list('abcdefghijklmnopqrstuvwxyz')\n\nfor i in range(25):\n if c == s[i]:\n print(s[i+1])\n return", "c = input()\ns = list('abcdefghijklmnopqrstuvwxyz')\n\nfor i in range(len(s)):\n if c == s[i]:\n print(s[i+1])\n return", "import string\nsl = string.ascii_lowercase\nprint(sl[sl.find(input())+1])", "c = input()\nprint(chr(ord(c)+1))", "print(chr(ord(input()) + 1))", "a = input()\nprint(chr(ord(a)+1))", "print(chr(ord(input())+1))", "c=ord(input())\n\nprint(chr(c+1))", "c = ord(input())\nprint((chr(c + 1)))\n", "C = input()\n\nl = list('abcdefghijklmnopqrstuvwxyz')\nprint(l[l.index(C)+1])", "a = input()\nprint(chr(ord(a) + 1))", "c=input()\nletters=\"abcdefghijklmnopqrstuvwxyz\"\nfor i in range(26):\n if c==letters[i]:\n print(letters[i+1])", "#!/usr/bin/env python3\n\n\ndef solve(C: str):\n return chr(ord(C) + 1)\n\n\ndef main():\n C = input().strip()\n answer = solve(C)\n print(answer)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "c = input()\n\na = \"abcdefghigklmnopqrstuvwxyz\"\n\nprint((a[a.index(c) + 1]))\n", "print(chr(ord(input())+1))", "C=input()\n\na=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\n \"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\n \"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n\nprint(a[a.index(C)+1])", "c = input()\nl = [chr(ord('a') + i) for i in range(26)]\nprint(l[l.index(c)+1])", "c=input()\nprint(chr(ord(c)+1))", "s = input()\nprint(chr(ord(s)+1))", "C=input()\n\nA=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"\n ,\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\"\n ,\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n\na1=A.index(C)+1\n\nprint(A[a1])", "c = input()\nprint(chr(ord(c)+1))", "C = input()\nalpha = list('abcdefghijklmnopqrstuvwxyz')\n\nprint(alpha[alpha.index(C) + 1])", "print(chr(ord(input())+1))", "C = input()\n\nprint(chr(ord(C)+1))", "# coding: utf-8\n# Your code here!\ns=input()\nans=ord(s)+1\nprint((chr(ans)))\n", "a=input()\nprint(chr(ord(a)+1))", "n = input()\na = ord(n)\nprint(chr(a+1))", "c = input()\nprint(chr(ord(c) + 1))", "C = input()\nabc = \"abcdefghijklmnopqrstuvwxyz\"\nprint(abc[abc.index(C) + 1])", "c = input()\nprint((chr(ord(c)+1)))\n", "print(chr(ord(input())+1))", "ans = chr(ord(input())+1)\nprint(ans)", "# coding: utf-8\n# Your code here!\ns = input()\n\nord_s = ord(s)\nans = ord_s + 1\n\nprint(chr(ans))", "ri = lambda S: [int(v) for v in S.split()]\ndef rii(): return ri(input())\n \nC = input()\nprint(chr(ord(C)+1))", "print(chr(ord(input())+1))", "c = input()\n\nans = chr(ord(c)+1)\nprint(ans)", "alp = 'abcdefghijklmnopqrstuvwxyz'\n\nprint((alp[alp.index(input())+1]))\n", "C=input()\nst='abcdefghijklmnopqrstuvwxyz'\n\nprint(st[st.find(C)+1])", "print(chr(ord(input())+1))", "l=list(\"abcdefghijklmnopqrstuvwxyz\")\nans=input()\nfor i in range(len(l)):\n if l[i]==ans:\n print(l[i+1])\n break", "c=input()\nnum=ord(c)\nif num!=122:\n print(chr(num+1))\nelse:\n print('a')", "print(chr(ord(input()) + 1))", "c=input()\nans=chr(ord(c)+1)\nprint(ans)", "al =[\"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\nC = input()\n\nkk = al.index(C)\n\nprint((al[kk+1]))\n", "C = input()\n\n# \u6587\u5b57\u5217\u3068\u6570\u5024\u306e\u5909\u63db\n# ord('\u6587\u5b57') / chr(\u6570\u5024) \u3067\u5909\u63db\u3067\u304d\u308b\nord_s = ord(C)\nchr_s = chr(ord_s + 1)\n\nprint(chr_s)", "print(chr(ord(input())+1))", "next_ord = ord(input()) + 1\nprint(chr(next_ord))", "\ndef main():\n c = input()\n print(chr(ord(c)+1))\n\ndef __starting_point():\n main()\n__starting_point()", "C = input()\nword = 'abcdefghijklmnopqrstuvwxyz'\ni = word.find(C)\nprint(word[i+1])", "import string\nC = input()\nalpha = string.ascii_lowercase\nprint(alpha[alpha.index(C)+1])", "C = input()\n\nalpha = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n\nj = 0\nfor i in alpha:\n if i == C:\n print(alpha[j+1])\n j += 1", "print(chr(ord(str(input()))+1))", "C=input()\nal=[]\nfor idx in range(97,123):\n al.append(chr(idx))\nidx = al.index(C)\nprint(al[idx+1])", "import string\nc = input()\nabc=list(string.ascii_lowercase)\ni = abc.index(c)\n\nprint(abc[i+1])", "C = input()\n\nif C == 'z':\n print('z')\nelse:\n print(chr(ord(C) + 1))", "print(chr(int(ord(input()))+1))", "x = ord(input())\nprint(chr(x+1))", "C = input()\n\nprint(chr(ord(C) + 1))", "C = input()\n\ntempnum= ord(C)\nans = chr(tempnum+1)\nprint (ans)", "c = input()\ncl =[chr(ord(\"a\")+i) for i in range(26)]\nprint(cl[cl.index(c)+1])", "import math\nimport collections\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\ns = input()\nprint(chr(ord(s)+1))", "c = input()\nprint(chr(ord(c)+1))", "c = input()\nal = \"abcdefghijklmnopqrstuvwxyz\"\nprint(al[al.index(c)+1])", "print(chr(ord(input()) + 1))", "c=input()\nchr=\"abcdefghijklmnopqrstuvwxyz\"\nfor i in range(len(chr)):\n if c==chr[i]:\n print(chr[i+1])", "n = input()\n\nord_s = ord(n)\n\nchr_s = chr(ord_s + 1)\n\nprint(chr_s)", "c = input()\nabc = 'abcdefghijklmnopqrstuvwxyz'\nprint(abc[abc.index(c)+1])", "c = input()\n\nc = chr(ord(c)+1)\n\nprint(c)", "a=input()\ncode=ord(a)\ncode+=1\nmoji=chr(code)\nprint(moji)", "C = str(input())\ndata = 'abcdefghijklmnopqrstuvwxyz'\n\nfor i in range(len(data)):\n if C == data[i]:\n print(data[i+1])\n return", "c=input()\nprint(chr(ord(c)+1))", "print(chr(ord(input())+1))", "C = str(input())\n\nprint(chr(ord(C)+1))", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n s = input()\n return chr(ord(s) + 1)\n\n\nprint(solve())\n", "s = input()\nx = ord(s)\nx += 1\nprint(chr(x))", "C = input()\nprint((chr(ord(C) + 1)))\n", "c = input()\nprint(chr(ord(c) + 1))", "def resolve():\n c = input()\n print(chr(ord(c)+1))\nresolve()", "S = input()\n\nX = \"abcdefghijklmnopqrstuvwxyz\"\n\nM = X.index(S)\nprint(X[M+1])", "c=input()\na=\"abcdefghijklmnopqrstuvwxyz\"\nb=a.index(c)\nprint(a[b+1])", "c=input()\nprint(chr(ord(c)+1))"] | {"inputs": ["a\n", "y\n", "c\n", "p\n", "d\n", "t\n"], "outputs": ["b\n", "z\n", "d\n", "q\n", "e\n", "u\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 8,062 | |
eb3b52d146270bcef84c4378d8832c8c | UNKNOWN | Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.
-----Constraints-----
- S and T are strings consisting of lowercase English letters.
- The lengths of S and T are between 1 and 100 (inclusive).
-----Input-----
Input is given from Standard Input in the following format:
S T
-----Output-----
Print the resulting string.
-----Sample Input-----
oder atc
-----Sample Output-----
atcoder
When S = oder and T = atc, concatenating T and S in this order results in atcoder. | ["S,T = map(str,input().split())\nprint(T + S)", "s, t = map( str, input().split() )\nprint( t + s )", "S,T = input().split()\n\nans = T+S\nprint(ans)", "S,T=input().split()\nprint((T+S))\n", "s, t = input().split()\n\nu = t + s\n\nprint(u)\n\n", "s,t=map(str,input().split())\nprint(t+s)", "S,T=map(str,input().split())\nprint(T+S)", "s, t = input().split()\nprint(t + s)", "s, t = input().split()\nprint(t + s)", "#149-A\n\nS,T = list(map(str,input().split()))\n\nprint((T+S))\n", "s,t = input().split()\nprint(t+s)", "a,b=input().split()\nprint(b+a)", "S,T =input().split()\nprint (str(T)+str(S))", "S, T = input().split()\nprint(T+S)", "S,T = input().split()\n\nprint(T + S)", "#!/usr/bin/env python3\nfrom collections import defaultdict, Counter\nfrom itertools import product, groupby, count, permutations, combinations\nfrom math import pi, sqrt\nfrom collections import deque\nfrom bisect import bisect, bisect_left, bisect_right\nfrom string import ascii_lowercase\nfrom functools import lru_cache\nimport sys\nsys.setrecursionlimit(10000)\nINF = float(\"inf\")\nYES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"\ndy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]\ndy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]\n\n\ndef inside(y, x, H, W):\n return 0 <= y < H and 0 <= x < W\n\n\ndef ceil(a, b):\n return (a + b - 1) // b\n\n\ndef sum_of_arithmetic_progression(s, d, n):\n return n * (2 * s + (n - 1) * d) // 2\n\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef lcm(a, b):\n g = gcd(a, b)\n return a / g * b\n\n\ndef solve():\n S, T = input().split()\n print((T + S))\n\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "s,t = input().split()\n\nprint(t+s)", "s,t = input().split()\nprint(t+s)", "s,t = input().split()\n\nprint(t + s)", "a, b = map(str, input().split())\nprint('{}{}'.format(b, a))", "S,T = map(str,input().split())\nprint(T+S)", "s, t = input().split()\nu = t + s\nprint(u)", "s, t = map(str, input().split())\nprint(t+s)", "s, t = input().split()\nprint(\"\".join([t, s]))", "s, t = input().split()\nprint(t+s)", "s, t = map(str, input().split())\nprint(t + s)", "s,t = input().split()\nprint(t+s)", "s,t=input().split()\nprint(t+s)", "s, t = input().split()\n\nprint(t + s)", "#!/usr/bin/env python3\nimport sys\nfrom itertools import chain\n\n\ndef solve(S: str, T: str):\n answer = T + S\n return answer\n\n\ndef main():\n tokens = chain(*(line.split() for line in sys.stdin))\n S = next(tokens) # type: str\n T = next(tokens) # type: str\n answer = solve(S, T)\n print(answer)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nfrom collections import Counter\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\ns,t = input().split()\nprint(t+s)", "s,t=input().split()\nprint(t+s)", "s,t = input().split()\nprint(t,s,sep=\"\")", "#!/usr/bin/env python3\ns,t=input().split()\nprint(t+s)", "S,T = map(str,input().split())\n\nprint(T+S)", "s, t = input().split()\nprint(t + s)", "# coding: utf-8\n# Your code here!\n\ns,t = input().split()\nprint(t+s)", "print(*input().split()[::-1],sep='')", "S, T = input().split()\nans = T + S\nprint(ans)", "S,T = input().split()\nprint(T+S)", "s,t=input().split()\nprint (t+s)", "S, T = map(str, input().split())\n\nprint(T+S)", "s, t = input().split()\nprint((t + s))\n", "s,t = input().split()\nprint(t+s)", "s,t = input().split()\n\nanswer = t + s\nprint(answer)", "s,t = input().split()\nprint(t+s)", "s,t=input().split()\n\nprint(t+s)", "s,t = input().split()\n\nprint(t + s)", "s,t=input().split()\n\nr=t+s\n\nprint(r)\n", "s, t = map(str, input().split())\n\nprint(t+s)", "s,t = input().split()\nprint(t,s,sep='')", "s, t = input().split()\nprint(t+s)", "S, T = input().split()\nprint(T+S)", "S, T = map(str, input().split())\n\nprint(T+S)", "s,t = input().split()\nprint(t+s)", "s, t = input().split()\nprint(t+s)", "s,t=input().split()\nprint(t+s)", "s,t=input().split()\n\nr=t+s\n\nprint(r)", "x,y = input().split()\nprint(y+x)", "import sys\n \nS, T = next(sys.stdin).strip().split()\nprint(T + S)", "s, t = map(list, input().split())\nt.extend(s)\nprint(''.join(t))", "s,t=input().split()\nprint(t+s)", "s,t = input().split()\nprint(t+s)", "S, T = input().split()\n\nprint(T + S)", "b,a = input().split()\nprint(a + b)", "s,t = input().split()\nprint((t+s))\n", "s,t = map(str, input().split())\nprint(t+s)", "s,t = input().split()\nprint((t + s))\n", "s,t = map(str,input().split())\nprint(t+s)", "a, b = input().split()\nprint((b + a))\n", "S, T = map(str, input().split())\nprint(T + S)", "s,t = map(str,input().split())\nprint(t+s)", "s, t = input().split()\nprint(t+s)", "s, t = input().split()\nprint(t+s)", "s,t = input().split()\nprint(t+s)", "a,b=input().split()\nfor i in b,a:\n print(i,end=\"\")\n", "s,t = input().split()\n \nprint(t+s)", "S, T = input().split()\nprint(T+S)", "s,t = input().split()\nprint(t+s)", "s,t=input().split()\nprint(t+s)", "#!/usr/bin/env python3\n\ndef main():\n s, t = input().split()\n print((t + s))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "s,t = list(map(str,input().split()))\nprint(( t+s ))\n", "s,t = input().split()\nprint(t,s,sep='')", "S,T=input().split()\nprint(T+S)", "S, T = input().split()\nprint(T + S)", "S,T=map(str,input().split())\nprint(T+S)", "s,t=input().split()\nprint(t+s)", "S , T = input().split()\nprint((T+S))\n\n", "S, T = input().split()\nprint(T + S)", "\ns,t=map(str,input().split())\nprint(t+s,sep='')", "s, t = list(input().split())\n\nprint((t + s))\n", "S, T = [s for s in input().split()]\nprint(''.join([T, S]))", "s,t = input().split()\nprint(t+s)", "S,T = input().split()\n\nprint(T + S)", "s, t = input().split()\nprint(t, s, sep='')", "str_l = list(map(str, input().split()))\nprint(''.join(list(reversed(str_l))))", "s, t = input().split()\nprint((t+s))\n", "s,t=input().split()\nprint(t+s)", "s,t=list(map(str ,input().split()))\nans_str=\"\"\nfor i in range(0,len(t)):\n ans_str+=t[i] \n\nans_str1=\"\"\nfor j in range(0,len(s)):\n ans_str1+=s[j]\n\nprint(ans_str+ans_str1)", "s,t=input().split()\nprint(t+s,sep=\"\")"] | {"inputs": ["oder atc\n", "humu humu\n", "c a\n", "oekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahjekkengkfoekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahj yowkymbmhkkgjjeokdlakbndkkworqotkfnblgpnkkrogjrfnvmbjisnbkzvmbnrrrigeoibgpefjobvmovpqosqoqrgrkengrlk\n", "dttd dttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttd\n", "mmkmkmkmkkkmkkkmmmkkkmkmkmmkkkmmkkkkmmmkkkmmkmmkmkmkmmkmkkmkmkmmmmkkkmkkkmmmkkkkkkmkmmmkmmmk zk\n"], "outputs": ["atcoder\n", "humuhumu\n", "ac\n", "yowkymbmhkkgjjeokdlakbndkkworqotkfnblgpnkkrogjrfnvmbjisnbkzvmbnrrrigeoibgpefjobvmovpqosqoqrgrkengrlkoekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahjekkengkfoekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahj\n", "dttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttddttd\n", "zkmmkmkmkmkkkmkkkmmmkkkmkmkmmkkkmmkkkkmmmkkkmmkmmkmkmkmmkmkkmkmkmmmmkkkmkkkmmmkkkkkkmkmmmkmmmk\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 6,315 | |
11f0eb68bff1e39cbcb63bcfe6e63b56 | UNKNOWN | Polycarp has an array $a$ consisting of $n$ integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally: If it is the first move, he chooses any element and deletes it; If it is the second or any next move: if the last deleted element was odd, Polycarp chooses any even element and deletes it; if the last deleted element was even, Polycarp chooses any odd element and deletes it. If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 2000$) β the number of elements of $a$.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^6$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
Print one integer β the minimum possible sum of non-deleted elements of the array after end of the game.
-----Examples-----
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | ["n = int(input())\na = list(map(int, input().split()))\nodd = []\neven = []\nfor i in a:\n if i%2:\n odd.append(i)\n else:\n even.append(i)\nodd.sort()\neven.sort()\nif abs(len(odd) - len(even)) <= 1:\n print(0)\nelse:\n if len(odd) > len(even):\n print(sum(odd[:len(odd)-len(even)-1]))\n else:\n print(sum(even[:len(even) - len(odd)-1]))\n", "n=int(input())\narr=list(map(int,input().split()))\narr1=[]\narr2=[]\nfor i in range(n):\n if(arr[i]%2==0):\n arr1.append(arr[i])\n else:\n arr2.append(arr[i])\narr1.sort(reverse=True)\narr2.sort(reverse=True)\nif(len(arr1)==len(arr2)):\n print(0)\nelse:\n if(len(arr1)>len(arr2)):\n l=len(arr2)\n print(sum(arr1)-sum(arr1[:l+1]))\n else:\n l=len(arr1)\n print(sum(arr2)-sum(arr2[:l+1]))\n\n", "n = int(input())\nl = list(map(int,input().split()))\npar = []\nnpar = []\nfor i in l:\n\tif i % 2 == 0:\n\t\tpar.append(i)\n\telse:\n\t\tnpar.append(i)\nif abs(len(par) - len(npar)) <= 1:\n\tprint(0)\nelse:\n\tif len(par) - len(npar) > 1:\n\t\tpar = sorted(par)\n\t\tnpar = sorted(npar)\n\t\twyn = 0\n\t\tfor i in range(len(par) - len(npar) - 1):\n\t\t\twyn = wyn + par[i]\n\t\tprint(wyn)\n\tif len(npar) - len(par) > 1:\n\t\tpar = sorted(par)\n\t\tnpar = sorted(npar)\n\t\twyn = 0\n\t\tfor i in range(len(npar) - len(par) - 1):\n\t\t\twyn = wyn + npar[i]\n\t\tprint(wyn)\n", "N = int(input())\nA = [int(a) for a in input().split()]\n\nE = []\nO = []\n\nfor a in A:\n if a % 2:\n O.append(a)\n else:\n E.append(a)\n\nE = sorted(E)\nO = sorted(O)\n\ne = len(E)\no = len(O)\n\nif e == o:\n print(0)\nelif e < o:\n print(sum(O[:o-e-1]))\nelse:\n print(sum(E[:e-o-1]))\n", "n = int(input())\nA = list(map(int, input().split()))\n\nchet = []\nnechet = []\n\nfor i in A:\n if i % 2 == 0:\n chet.append(i)\n else:\n nechet.append(i)\n\nif len(chet) == len(nechet) or abs(len(chet) - len(nechet)) == 1:\n print(0)\nelse:\n if len(chet) > len(nechet):\n print(sum(sorted(chet)[:len(chet) - len(nechet) - 1]))\n else:\n print(sum(sorted(nechet)[:len(nechet) - len(chet) - 1]))\n", "n = int(input())\nA = list(map(int, input().split()))\nq1 = []\nq2 = []\nfor i in A:\n if i % 2:\n q1.append(i)\n else:\n q2.append(i)\nif abs(len(q1) - len(q2)) <= 1:\n print(0)\n return\nif len(q1) < len(q2):\n q2.sort()\n print(sum(q2[:len(q2) - len(q1) - 1]))\nelse:\n q1.sort()\n print(sum(q1[:len(q1) - len(q2) - 1]))", "n=int(input())\nA=list(map(int,input().split()))\n\nA0=[a for a in A if a%2==0]\nA1=[a for a in A if a%2==1]\n\nA0.sort()\nA1.sort()\n\nL0=len(A0)\nL1=len(A1)\n\nif abs(L0-L1)<=1:\n print(0)\n\nelif L0>L1:\n x=L0-L1-1\n print(sum(A0[:x]))\n\nelif L0<L1:\n x=L1-L0-1\n print(sum(A1[:x]))\n", "'''input\n5\n1 5 7 8 2\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\nimport heapq\nmod=10**9+7\n\ndef ri(flag=0):\n\tif flag==0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n\nn=ri(1)\na=ri()\neven=[]\nodd=[]\n\nfor i in a:\n\tif i%2==0:\n\t\teven.append(i)\n\telse:\n\t\todd.append(i)\n\neven.sort(reverse=True)\nodd.sort(reverse=True)\n\nans=0\n\ni=0\nj=0\nf=0\nwhile 1:\n\ttry:\n\t\tif f==0:\n\t\t\tf=1\n\t\t\tans+=even[i]\n\t\t\ti+=1\n\t\telse:\n\t\t\tf=0\n\t\t\tans+=odd[j]\n\t\t\tj+=1\n\texcept:\n\t\tbreak\n\nans1=0\n\ni=0\nj=0\nf=1\nwhile 1:\n\ttry:\n\t\tif f==0:\n\t\t\tf=1\n\t\t\tans1+=even[i]\n\t\t\ti+=1\n\t\telse:\n\t\t\tf=0\n\t\t\tans1+=odd[j]\n\t\t\tj+=1\n\texcept:\n\t\tbreak\n\n\n\nprint(sum(a)-max(ans,ans1))\n\n#print(even,odd)\n", "#Bhargey Mehta (Sophomore)\n#DA-IICT, Gandhinagar\nimport sys, math, queue\nsys.setrecursionlimit(1000000)\n#sys.stdin = open(\"input.txt\", \"r\")\n\nn = int(input())\na = list(map(int, input().split()))\nod = []\nev = []\nfor i in range(n):\n if a[i]%2 == 0: ev.append(a[i])\n else: od.append(a[i])\nod.sort()\nev.sort()\n\nif abs(len(od)-len(ev)) <= 1:\n print(0)\n return\n\nans = 0\nif len(od) > len(ev):\n for i in range(len(od)-len(ev)-1):\n ans += od[i]\nelse:\n for i in range(len(ev)-len(od)-1):\n ans += ev[i]\nprint(ans)", "''' CODED WITH LOVE BY SATYAM KUMAR '''\n\nfrom sys import stdin, stdout\nimport cProfile, math\nfrom collections import Counter,defaultdict\nfrom bisect import bisect_left,bisect,bisect_right\nimport itertools\nfrom copy import deepcopy\nfrom fractions import Fraction\nimport sys, threading\nimport operator as op\nfrom functools import reduce\nsys.setrecursionlimit(10**6) # max depth of recursion\nthreading.stack_size(2**27) # new thread will get stack of such size\nfac_warmup = False\nprintHeap = str()\nmemory_constrained = False\nP = 10**9+7\nimport sys\n\nclass merge_find:\n def __init__(self,n):\n self.parent = list(range(n))\n self.size = [1]*n\n self.num_sets = n\n self.lista = [[_] for _ in range(n)]\n def find(self,a):\n to_update = []\n while a != self.parent[a]:\n to_update.append(a)\n a = self.parent[a]\n for b in to_update:\n self.parent[b] = a\n return self.parent[a]\n def merge(self,a,b):\n a = self.find(a)\n b = self.find(b)\n if a==b:\n return\n if self.size[a]<self.size[b]:\n a,b = b,a\n self.num_sets -= 1\n self.parent[b] = a\n self.size[a] += self.size[b]\n self.lista[a] += self.lista[b]\n def set_size(self, a):\n return self.size[self.find(a)]\n def __len__(self):\n return self.num_sets\n\ndef display(string_to_print):\n stdout.write(str(string_to_print) + \"\\n\")\n\ndef primeFactors(n): #n**0.5 complex \n factors = dict()\n for i in range(2,math.ceil(math.sqrt(n))+1): \n while n % i== 0: \n if i in factors:\n factors[i]+=1\n else: factors[i]=1\n n = n // i \n if n>2:\n factors[n]=1\n return (factors)\n\ndef fibonacci_modP(n,MOD):\n if n<2: return 1\n #print (n,MOD)\n return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD\n\ndef factorial_modP_Wilson(n , p): \n if (p <= n): \n return 0\n res = (p - 1) \n for i in range (n + 1, p): \n res = (res * cached_fn(InverseEuler,i, p)) % p \n return res \n\ndef binary(n,digits = 20):\n b = bin(n)[2:]\n b = '0'*(20-len(b))+b\n return b\n\ndef isprime(n):\n \"\"\"Returns True if n is prime.\"\"\"\n if n < 4:\n return True\n if n % 2 == 0:\n return False\n if n % 3 == 0:\n return False\n i = 5\n w = 2\n while i * i <= n:\n if n % i == 0:\n return False\n i += w\n w = 6 - w\n return True\nfactorial_modP = []\ndef warm_up_fac(MOD):\n nonlocal factorial_modP,fac_warmup\n if fac_warmup: return\n factorial_modP= [1 for _ in range(fac_warmup_size+1)]\n for i in range(2,fac_warmup_size):\n factorial_modP[i]= (factorial_modP[i-1]*i) % MOD\n fac_warmup = True\n\ndef InverseEuler(n,MOD):\n return pow(n,MOD-2,MOD)\n\ndef nCr(n, r, MOD):\n nonlocal fac_warmup,factorial_modP\n if not fac_warmup:\n warm_up_fac(MOD)\n fac_warmup = True\n return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD\n\ndef test_print(*args):\n if testingMode:\n print(args)\n\ndef display_list(list1, sep=\" \"):\n stdout.write(sep.join(map(str, list1)) + \"\\n\")\n\ndef display_2D_list(li):\n for i in li:\n print(i)\ndef prefix_sum(li):\n sm = 0\n res = []\n for i in li:\n sm+=i\n res.append(sm)\n return res\n\ndef get_int():\n return int(stdin.readline().strip())\n\ndef get_tuple():\n return map(int, stdin.readline().split())\n\ndef get_list():\n return list(map(int, stdin.readline().split()))\nimport heapq,itertools\npq = [] # list of entries arranged in a heap\nentry_finder = {} # mapping of tasks to entries\nREMOVED = '<removed-task>' \ndef add_task(task, priority=0):\n 'Add a new task or update the priority of an existing task'\n if task in entry_finder:\n remove_task(task)\n count = next(counter)\n entry = [priority, count, task]\n entry_finder[task] = entry\n heapq.heappush(pq, entry)\n\ndef remove_task(task):\n 'Mark an existing task as REMOVED. Raise KeyError if not found.'\n entry = entry_finder.pop(task)\n entry[-1] = REMOVED\n\ndef pop_task():\n 'Remove and return the lowest priority task. Raise KeyError if empty.'\n while pq:\n priority, count, task = heapq.heappop(pq)\n if task is not REMOVED:\n del entry_finder[task]\n return task\n raise KeyError('pop from an empty priority queue')\nmemory = dict()\ndef clear_cache():\n nonlocal memory\n memory = dict()\ndef cached_fn(fn, *args):\n nonlocal memory\n if args in memory:\n return memory[args]\n else:\n result = fn(*args)\n memory[args] = result\n return result\n\ndef ncr (n,r):\n return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))\ndef binary_serach(i,li):\n #print(\"Search for \",i)\n fn = lambda x: li[x]-x//i\n x = -1\n b = len(li)\n while b>=1:\n #print(b,x)\n while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like\n x+=b\n b=b//2\n return x\n\n# -------------------------------------------------------------- MAIN PROGRAM\nTestCases = False\ntestingMode = False\nfac_warmup_size = 10**5+100\noptimiseForReccursion = True #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3\nfrom math import factorial\n\n\ndef main():\n n = get_int()\n li = get_list()\n even = [x for x in li if x%2!=0]\n odd = [x for x in li if x%2==0]\n if abs(len(even)-len(odd))<2:\n print(0)\n return\n elif len(odd)>len(even):\n odd,even = even,odd\n even.sort()\n print(sum(even[:len(even)-len(odd)-1]))\n \n# --------------------------------------------------------------------- END=\n\n\nif TestCases: \n for _ in range(get_int()): \n cProfile.run('main()') if testingMode else main() \nelse: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()", "import math\nn=int(input())\narr=list(map(int,input().split()))\neven=[]\nodd=[]\nfor i in range(n):\n\tif arr[i]%2==0:\n\t\teven.append(arr[i])\n\telse:\n\t\todd.append(arr[i])\nif abs(len(even)-len(odd))<=1:\n\tprint(0)\n\treturn\nif len(even)>len(odd):\n\teven.sort(reverse=True)\n\tans=0\n\tfor i in range(len(odd)+1,len(even)):\n\t\tans+=even[i]\n\tprint(ans)\n\treturn\nodd.sort(reverse=True)\nss=0\nfor i in range(len(even)+1,len(odd)):\n\tss+=odd[i]\nprint(ss)", "n = int(input())\nl = list(map(int,input().split()))\n\nodd = []\neven = []\nfor i in l:\n if i%2:\n odd.append(i)\n else:\n even.append(i)\n\nodd.sort()\neven.sort()\n\nlo = len(odd)\nle = len(even)\n\nif lo == le or lo == le+1 or lo == le-1:\n print(0)\nelse:\n\n if le > lo:\n diff = le - lo - 1\n ans = sum(even[:diff])\n else:\n diff = lo - le - 1\n ans = sum(odd[:diff])\n\n print(ans)\n", "from bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nimport random\nMAX = sys.maxsize\nMAXN = 10**5+10\nMOD = 10**9+7\ndef isprime(n):\n n = abs(int(n))\n if n < 2:\n return False\n if n == 2: \n return True \n if not n & 1: \n return False\n for x in range(3, int(n**0.5) + 1, 2):\n if n % x == 0:\n return False\n return True\n\ndef mhd(a,b,x,y):\n return abs(a-x)+abs(b-y)\n\ndef numIN(x = \" \"):\n return(map(int,sys.stdin.readline().strip().split(x)))\n\ndef charIN():\n return(sys.stdin.readline().strip().split())\n\ndef dis(x,y):\n a = y[0]-x[0]\n b = x[1]-y[1]\n return (a*a+b*b)**0.5\n\n\n\n\nn = int(input())\nl = list(numIN())\ne = []\no = []\nfor i in l:\n if i%2:\n o.append(i)\n else:\n e.append(i)\nif len(e)==len(o):\n print(0)\nelse:\n e.sort(reverse=True)\n o.sort(reverse=True)\n mn = min(len(e),len(o))\n x = e[mn:]\n y = o[mn:]\n if x:\n print(sum(x)-x[0])\n else:\n print(sum(y)-y[0])", "import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nevens = []\nodds = []\n\nfor i in map(int, input().split()):\n if i % 2 == 0:\n evens.append(i)\n else:\n odds.append(i)\n \nevens.sort(reverse = True)\nodds.sort(reverse = True)\n\nif len(evens) > len(odds):\n print(sum(evens[len(odds)+1:]))\nelif len(odds) > len(evens):\n print(sum(odds[len(evens)+1:]))\nelse:\n print(0)", "import heapq\n\nn = int(input())\narr = list(map(int, input().split()))\nch = []\nnc = []\n\nfor i in arr:\n if i % 2 == 0:\n ch.append(i)\n else:\n nc.append(i)\nif len(ch) > len(nc):\n ans = sum(sorted(ch)[:len(ch) - len(nc) - 1])\nelif len(ch) < len(nc):\n ans = sum(sorted(nc)[:len(nc) - len(ch) - 1])\nelse:\n ans = 0\nprint(ans)", "n = int(input())\nl = list(map(int, input().split()))\na = list()\nb = list()\nfor i in l:\n if i % 2:\n a.append(i)\n else:\n b.append(i)\na.sort()\nb.sort()\na.reverse()\nb.reverse()\nk = min(len(a), len(b))\nif abs(len(a) - len(b)) < 2:\n print(0)\nelse:\n s = 0\n if len(a) < len(b):\n for i in range(k + 1, len(b)):\n s += b[i]\n else:\n for i in range(k + 1, len(a)):\n s += a[i]\n print(s)\n \n", "GI = lambda: int(input()); GIS = lambda: list(map(int, input().split())); LGIS = lambda: list(GIS())\n\ndef main():\n GI()\n xs = GIS()\n ps = [[], []]\n for x in xs:\n ps[x % 2].append(x)\n ps.sort(key=len)\n lendiff = len(ps[1]) - len(ps[0])\n if lendiff > 1:\n large = ps[1]\n large.sort()\n print(sum(large[:lendiff-1]))\n else:\n print(0)\n\nmain()\n", "# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\neven = list([x for x in A if x % 2 == 0])\nodd = list([x for x in A if x % 2 != 0])\neven = sorted(even)\nodd = sorted(odd)\n\nevenN = len(even)\noddN = len(odd)\n\nans = -1\nif abs(evenN-oddN) <= 1:\n ans = 0\nelse:\n if evenN > oddN:\n ans = sum(even[:evenN-oddN-1])\n else:\n ans = sum(odd[:oddN-evenN-1])\nprint(ans)\n", "n = int(input())\narr = list(map(int, input().split()))\neven, odd = [], []\n\nfor i in arr:\n if i%2 == 0:\n even += [i]\n else:\n odd += [i]\n\neven = sorted(even)\nodd = sorted(odd)\n\nif len(even) == len(odd):\n print(0)\n return\n\nelif len(even) < len(odd):\n even, odd = odd, even\n\n#print(even, odd)\n\neven.pop()\nwhile even and odd:\n even.pop()\n odd.pop()\n\n#print(even, odd)\nprint(sum(even))\n", "n = int(input())\nints = list(map(int, input().split()))\n\neven = []\nodd = []\n\nfor i in ints:\n if i % 2 == 1:\n odd.append(i)\n else:\n even.append(i)\n\neven.sort()\nodd.sort()\n\nif len(even) < len(odd):\n diff = len(odd) - len(even) - 1\n if diff > 0:\n print(sum(odd[0:diff]))\n else:\n print(0)\nelse:\n diff = len(even) - len(odd) - 1\n if diff > 0:\n print(sum(even[0:diff]))\n else:\n print(0)", "import sys\nimport math\nimport heapq\nimport bisect\nfrom collections import defaultdict as dd\n\nn = int(input())\nl = [int(i) for i in input().split()]\no = []\ne = []\nfor i in l:\n if i%2==0:\n e.append(i)\n else:\n o.append(i)\no.sort()\ne.sort()\nif len(e) > len(o):\n o, e = e, o #o\nfor i in range(len(e)):\n e.pop(-1)\n o.pop(-1)\nif o:\n o.pop(-1)\nprint(sum(o))"] | {
"inputs": [
"5\n1 5 7 8 2\n",
"6\n5 1 2 4 6 3\n",
"2\n1000000 1000000\n",
"5\n2 1 1 1 1\n",
"5\n1 1 1 1 1\n"
],
"outputs": [
"0\n",
"0\n",
"1000000\n",
"2\n",
"4\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 16,453 | |
04631f6c093cd288b2c10f6e84fdc71c | UNKNOWN | There are $n$ monsters standing in a row numbered from $1$ to $n$. The $i$-th monster has $h_i$ health points (hp). You have your attack power equal to $a$ hp and your opponent has his attack power equal to $b$ hp.
You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $0$.
The fight with a monster happens in turns. You hit the monster by $a$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $b$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster.
You have some secret technique to force your opponent to skip his turn. You can use this technique at most $k$ times in total (for example, if there are two monsters and $k=4$, then you can use the technique $2$ times on the first monster and $1$ time on the second monster, but not $2$ times on the first monster and $3$ times on the second monster).
Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.
-----Input-----
The first line of the input contains four integers $n, a, b$ and $k$ ($1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique.
The second line of the input contains $n$ integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 10^9$), where $h_i$ is the health points of the $i$-th monster.
-----Output-----
Print one integer β the maximum number of points you can gain if you use the secret technique optimally.
-----Examples-----
Input
6 2 3 3
7 10 50 12 1 8
Output
5
Input
1 1 100 99
100
Output
1
Input
7 4 2 1
1 3 5 4 2 7 6
Output
6 | ["n, a, b, k = map(int, input().split())\nH = list(map(int, input().split()))\nfor i in range(n):\n H[i] %= (a + b)\n if H[i] == 0:\n H[i] = a + b\nH.sort()\nans = 0\nfor x in H:\n if x <= a:\n ans += 1\n else:\n tok = (x + a - 1) // a - 1\n if k >= tok:\n k -= tok\n ans += 1\nprint(ans)", "from sys import stdin\ninput = stdin.readline\nn,a,b,k = map(int,input().split())\nl = list(map(int,input().split()))\ndef cost(h):\n\th -= (a+b)*((h-(a+b))//(a+b))\n\tif h > (a+b):\n\t\th-=(a+b)\n\treturn (h-1)//a\npyk = []\nfor i in range(n):\n\tpyk.append(cost(l[i]))\npyk.sort()\nwyn = 0\nsu = 0\nfor i in range(n):\n\tsu += pyk[i]\n\tif su <= k:\n\t\twyn += 1\nprint(wyn)", "#!/usr/bin/env python3\nimport os\nimport sys\nfrom atexit import register\nfrom io import StringIO\n\n# Buffered output, at least 2x faster.\nsys.stdout = StringIO()\nregister(lambda: os.write(1, sys.stdout.getvalue().encode()))\n\n###############################################################################\nimport math\n###############################################################################\nn,a,b,k = [int(k) for k in sys.stdin.readline().split()]\nhs = [int(k) for k in sys.stdin.readline().split()]\n\ndef uses(h):\n r = h % (a+b)\n if r == 0:\n r = a+b\n return int(math.ceil(r/a) - 1)\n\nus = [uses(h) for h in hs]\nus.sort()\nret = 0\nfor u in us:\n if u > k:\n break\n k -= u\n ret += 1\nprint(ret)\n", "n, a, b, k = map(int, input().split())\nh = list(map(int, input().split()))\n\nhow_much_to_spend = [0 for _ in range(n)]\nfor i in range(n):\n\tif h[i] % (a+b) == 0:\n\t\thow_much_to_spend[i] = (a+b -1 ) // a\n\telse:\n\t\thow_much_to_spend[i] = ( (h[i] % (a+b)) - 1) // a\n\nhow_much_to_spend = sorted(how_much_to_spend)\nans = 0\nfor item in how_much_to_spend:\n\tif item <= k:\n\t\tans += 1\n\t\tk -= item\n\nprint(ans)", "from math import ceil\n\n(n, a, b, k) = map(int, input().split())\nh = list(map(int, input().split()))\nfor i in range(n):\n h[i] -= (h[i]//(a+b))*(a+b)\n if h[i] == 0:\n h[i] += a+b\nh.sort()\nans = 0\ni = 0\nwhile k > 0 and i < n:\n if ceil(h[i]/a) - 1 <= k:\n k -= ceil(h[i]/a) - 1\n ans += 1\n else:\n k = -1\n i += 1\n\nprint(ans)", "n, a, b, k = list(map(int, input().split()))\nar = list(map(int, input().split()))\nkek = []\nans = 0\nfor elem in ar:\n x = elem % (a + b)\n if x == 0 or x > a:\n if x == 0:\n x = a + b\n kek.append((x + a - 1) // a - 1)\n else:\n ans += 1\nkek.sort()\ni = 0\nwhile i < len(kek) and k > 0:\n if k - kek[i] >= 0:\n k -= kek[i]\n i += 1\n ans += 1\n else:\n break\nprint(ans)", "n, a, b, k = map(int, input().split())\nl1 = list(map(int, input().split()))\nnew = []\nfor x in l1:\n x = x%(a + b)\n if x > 0 and x <= a:\n new.append(0)\n else :\n if x == 0:\n x = a+b\n x-=a\n temp = x//a\n x = x-temp*a\n if x > 0:\n temp+=1\n new.append(temp)\nnew.sort()\nanswer = 0\nfor item in new:\n if k - item >=0:\n k -= item\n answer+=1\n else : \n break\nprint(answer)", "from math import *\n\nn, a, b, k = list(map(int, input().split()))\nh = [int(i) for i in input().split()]\n\nans = n\nnh = []\nfor m in h:\n tr = max(0, (m - 1) // (a+b))\n m -= tr*(a+b)\n m -= a\n if m > 0:\n nh.append(m)\n ans -= 1\n\nnh.sort()\ni = 0\nwhile k > 0 and i < len(nh):\n k -= ceil(nh[i]/a)\n if k < 0:\n break\n i += 1\n ans += 1\n\nprint(ans)\n", "from math import *\nn,a,b,k = list(map(int,input().split()))\nl = list(map(int,input().split()))\nfor i in range(n):\n\tl[i] %= (a+b)\n\tif(l[i] == 0): l[i] = a+b\nl.sort()\nct = 0\n#print(l)\nfor i in range(n):\n\tl[i] -= a\n\tif(l[i] <= 0): ct += 1\n\telse:\n\t\tk -= ceil(l[i]/a)\n\t\tif(k < 0):\n\t\t\tbreak\n\t\tct += 1\nprint(ct)\n\t\n", "import sys\nimport math\nimport heapq\nimport bisect\nimport re\nfrom collections import deque\nfrom decimal import *\nfrom fractions import gcd\n \ndef YES_NO(flag):\n if flag:\n print(\"YES\")\n else:\n print(\"NO\")\n \n \ndef main():\n # q = [int(i) for i in sys.stdin.readline().split()]\n n, a, b, k = [int(i) for i in sys.stdin.readline().split()]\n q = [int(i) for i in sys.stdin.readline().split()]\n t = [0 for i in range(n)]\n for i in range(n):\n w = (a + b) * (q[i] % (a + b) == 0) + q[i] % (a + b)\n if w <= a:continue\n else: t[i] = ((w + a - 1) // a) - 1\n t = sorted(t)\n res = 0\n for i in range(n):\n if t[i] > k: break\n res += 1\n k -= t[i]\n print(res)\nfor i in range(1):\n main()", "n, a, b, k = list(map(int, input().split()))\nhp = sorted([((int(x) % (a+b) or a+b) + a - 1) // a - 1 for x in input().split()])\n\nscore = 0\n\nfor h in hp:\n if h <= k:\n k -= h\n score += 1\n\nprint(score)\n", "n, a, b, k = map(int, input().split())\nH = list(map(int,input().split()))\nans = 0\n\nTQ = []\n\nfor h in H:\n h %= a + b\n if not h:\n h += a + b\n x = (h - 1) // a\n if x: TQ.append(x)\n else: ans += 1\n\nTQ.sort()\n\nfor tq in TQ:\n if k >= tq:\n k -= tq\n ans += 1\n else:\n break\n\nprint(ans)", "import math\n\nn, a, b, k = list(map(int, input().split()))\nh = list(map(int, input().split()))\nska = []\nfor i in range (0, n) :\n totm = h[i] % (a + b)\n if totm == 0 :\n totm = a + b\n ska.append(math.ceil(totm / a) - 1)\nska.sort()\n# print(ska)\ncnt = 0\nans = 0\ni = 0\nwhile i < n and cnt + ska[i] <= k :\n ans += 1\n cnt += ska[i]\n i += 1\nprint(ans)", "import sys \ninput=sys.stdin.readline \nn,a,b,k=map(int,input().split())\nfrom math import ceil \narr=[int(i) for i in input().split()]\nif a<= b:\n req=[]\n sm=0 \n sm+=sum(i<=a for i in arr)\n arr=[i for i in arr if i>a]\n tot=a+b\n chance=k \n for x in arr:\n now =x%tot \n if now>0 and now<=a:\n sm+=1 \n else: \n curr=now \n if curr==0:\n curr=tot \n curr-=a \n req.append(ceil(curr/a))\n req.sort() \n # print(req)\n for x in req:\n if x<=chance:\n sm+=1 \n chance-=x \n else:\n break \n print(sm)\n \nelse:\n sm=0 \n sm+=sum(i<=a for i in arr)\n arr=[i for i in arr if i>a]\n tot=a+b \n chance=k \n for x in arr:\n now=x%tot \n if now>0 and now<=a: \n sm+=1 \n else: \n if chance:\n sm+=1 \n chance-= 1 \n print(sm)", "n,a,b,k=map(int,input().split())\nh=input().split()\nfor i in range(n):\n h[i]=int(h[i])\nls=[] \nfor i in range(n):\n if(h[i]%(a+b)==0):\n h[i]=a+b\n if(h[i]%a==0):mauka=h[i]//a\n else:mauka=h[i]//a+1\n ls.append(mauka-1)\n else:\n h[i]=h[i]%(a+b)\n if(h[i]<=a):ls.append(0)\n else:\n if(h[i]%a==0):mauka=h[i]//a\n else:mauka=h[i]//a+1\n ls.append(mauka-1)\nls.sort()\ncount=0\nfor i in range(n):\n if(ls[i]<=k):\n k-=ls[i]\n count+=1\nprint(count) ", "import math\nimport sys\ninput = sys.stdin.readline\nN, a, b, k = list(map(int, input().split()))\nh = list(map(int, input().split()))\n\nans = 0\ntmp = []\nfor i in range(N):\n j = h[i] % (a+b)\n if j > 0 and j <= a:\n ans += 1\n else:\n if j == 0:\n j += b\n else:\n j -= a\n tmp.append(j)\n\ntmp.sort()\nfor x in tmp:\n if k >= math.ceil(x / a):\n k -= math.ceil(x / a)\n ans += 1\n else:\n break\nprint(ans)\n", "# def red(x,a,b):\n# x%=a+b\n# if(x==0):\n# x=a+b\n# return \n\ndef main():\n n,a,b,k = list(map(int,input().split()))\n arr = [ (a+b-1)//a if x%(a+b)==0 else (x%(a+b)-1)//a for x in map(int,input().split()) ]\n arr.sort()\n ans = 0\n for x in arr:\n if(k<x):\n break\n k-=x\n ans+=1\n print(ans)\n \ndef __starting_point():\n main()\n\n__starting_point()"] | {
"inputs": [
"6 2 3 3\n7 10 50 12 1 8\n",
"1 1 100 99\n100\n",
"7 4 2 1\n1 3 5 4 2 7 6\n",
"2 1 49 2\n50 50\n",
"2 1 100 2\n1 101\n"
],
"outputs": [
"5\n",
"1\n",
"6\n",
"0\n",
"1\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,278 | |
7040c0c037b2832037107d49b5df3940 | UNKNOWN | You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's calculate $c_r$ ($0 \le r \le m-1)$ β the number of elements having remainder $r$ when divided by $m$. In other words, for each remainder, let's find the number of corresponding elements in $a$ with that remainder.
Your task is to change the array in such a way that $c_0 = c_1 = \dots = c_{m-1} = \frac{n}{m}$.
Find the minimum number of moves to satisfy the above requirement.
-----Input-----
The first line of input contains two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le n$). It is guaranteed that $m$ is a divisor of $n$.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), the elements of the array.
-----Output-----
In the first line, print a single integer β the minimum number of moves required to satisfy the following condition: for each remainder from $0$ to $m - 1$, the number of elements of the array having this remainder equals $\frac{n}{m}$.
In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed $10^{18}$.
-----Examples-----
Input
6 3
3 2 0 6 10 12
Output
3
3 2 0 7 10 14
Input
4 2
0 1 2 3
Output
0
0 1 2 3 | ["import bisect\n\nn, m = map(int, input().split())\nls = list(map(int, input().split()))\n\nmls = []\nfor i in range(0, n):\n mls.append((ls[i] % m, i))\n\nmls.sort()\n# print(mls)\n\nbk1 = set()\nbk2 = set()\n\naim = n // m\ncnt = 0\n\nmis = []\nfor i in range(m):\n for j in range(aim):\n mis.append(i)\n\np1 = 0\np2 = 0\n\nwhile p2 < n:\n if mls[p1][0] > mis[p2]:\n p2 += 1\n else:\n a = mis[p2] - mls[p1][0]\n ls[mls[p1][1]] += a\n cnt += a\n bk2.add(p2)\n p1 += 1\n p2 += 1\n\nif p1 < n and p2 == n:\n p1 = n\n for i in range(p2):\n if i not in bk2:\n p1 -= 1\n a = m - mls[p1][0] + mis[i]\n ls[mls[p1][1]] += a\n cnt += a\n\nprint(cnt)\nfor i in ls:\n print(i, end=' ')\n\n", "n, m = map(int,input().split())\na = list(map(int,input().split()))\nf = [[] for i in range(m)]\nl = [0 for i in range(m)]\nfor i in range(n):\n f[a[i] % m].append(i)\n l[a[i] % m] += 1\nk = n // m\nj = 0\ntot = 0\nfor i in range(m):\n while l[i] > k:\n while l[j] >= k:\n j = (j + 1) % m\n tot += (j + m - i) % m\n l[j] += 1\n a[f[i][-1]] += (j + m - i) % m\n f[i].pop()\n l[i] -= 1\n if i == j:\n j += 1\nprint(tot)\nfor i in a:\n print(i,end=' ')\n", "n,m = list(map(int, input().split()))\nassert n % m == 0\nk = n // m\na = [*list(map(int, input().split()))]\ninds = [[] for r in range(m)]\nfor i,v in enumerate(a):\n inds[v%m].append(i)\nextras = []\nfor r in range(2*m):\n r %= m\n if len(inds[r]) == k: continue\n elif len(inds[r]) > k:\n extras.extend(inds[r][k:])\n inds[r] = inds[r][:k]\n elif len(inds[r]) < k:\n for _ in range(min(k-len(inds[r]), len(extras))):\n inds[r].append(extras.pop())\n else: assert False\nres = 0\nfor r in range(m):\n for i in inds[r]:\n if a[i] % m > r:\n res += m - (a[i] % m)\n a[i] += m - (a[i] % m)\n res += (r - a[i] % m)\n a[i] += (r - a[i] % m)\nprint(res)\nprint(' '.join(map(str, a)))\n", "k=int(input().split()[1])\nl=list()\nsc=[0]*k\nfor i in input().split():\n l.append(int(i))\ngoal=len(l)/k\ncpt=0\ns=\"\"\ndict={}\nfor i in range(len(l)):\n ok=0\n init=l[i]%k\n ltc=list()\n while(not ok):\n div=l[i]%k\n if(sc[div]<goal):\n sc[div]+=1\n ok=1\n for j in ltc:\n dict[j]=div\n else:\n ltc.append(div)\n #chercher dans la map si on a d\u00e9j\u00e0 \u00e9t\u00e9 ici\n if(div in dict.keys()):\n nd=dict[div]\n diff=(nd-div)%k\n cpt+=diff\n l[i]+=diff\n else:\n cpt+=1\n l[i]+=1\n s+=str(l[i])+\" \"\nprint(cpt)\nprint(s[:len(s)-1])", "3\n\n\nfrom queue import Queue\nimport sys\nimport math\nimport os.path\n\n\ndef log(*args, **kwargs):\n print(*args, file=sys.stderr, **kwargs)\n\n\n# INPUT\ndef ni():\n return list(map(int, input().split()))\n\n\ndef nio(offset):\n return [int(x) + offset for x in input().split()]\n\n\ndef nia():\n return list(map(int, input().split()))\n\n# CONVERT\n\n\ndef toString(aList, sep=\" \"):\n return sep.join(str(x) for x in aList)\n\n\ndef toMapInvertIndex(aList):\n return {k: v for v, k in enumerate(aList)}\n\n\n# MAIN\n\nn,m = ni()\na = nia()\n\nnm = n // m\n\nmmap = [[] for _ in range(m)]\n\nfor i in range(n) :\n xx = a[i] % m\n mmap[xx].append(i)\n\n# log(n,m)\n# log(mmap)\n\nmove = []\ndestination = []\n\nfor i in range(m):\n ddu = mmap[i]\n x = len(ddu)\n destination.extend([i]*(nm-x))\n move.extend(ddu[nm:x])\n \n# log(\"move\",move)\n# log(\"dest\",destination)\n\nssum = 0\nlenmove = len(move)\nsMoveId = sorted(list(range(lenmove)), key=lambda k: a[move[k]] % m)\n\n# log(\"smId\",sMoveId)\ndi = 0\nfor i in range(lenmove):\n moveId = sMoveId[i]\n s = a[move[moveId]] % m \n while destination[di] < s:\n destination.append(destination[di]+m)\n di += 1 \n d = destination[di]\n di += 1\n ssum += d-s\n\n # log(\"move \", move[moveId],\"as\",a[move[moveId]],s,\" to \", d, ssum)\n a[move[moveId]] += d-s\n\nprint(ssum)\nprint(toString(a))\n \n", "import sys\nfrom collections import Counter\n\ndef i_ints():\n return list(map(int, sys.stdin.readline().split()))\n\nn, m = i_ints()\na = list(i_ints())\n\nr = [x % m for x in a]\nc = Counter(r)\nc = [c[i] for i in range(m)]\n\nrem2ind = [[] for i in range(m)]\nfor i, x in enumerate(r):\n rem2ind[x].append(i)\n \n\nR = n // m\n\nfor i, inds in enumerate(rem2ind):\n if len(inds) > R:\n next_big = i\n break\nelse:\n next_big = m\nnext_small = next_big + 1\n#for i in range(next_big + 1, next_big + m):\n# if len(rem2ind[i%m]) < R:\n# next_small = i\n# break\n\nmoves = 0\nwhile next_big < m:\n next_small = max(next_small, next_big + 1)\n num = max(c[next_big] - R, 0)\n while num > 0:\n num2 = max(R - c[next_small%m], 0)\n delta = min(num, num2)\n num -= delta\n c[next_small%m] += delta\n step = next_small - next_big\n for i in rem2ind[next_big][num:num+delta]:\n a[i] += step\n moves += delta * step\n if c[next_small%m] >= R:\n next_small += 1\n# print(next_big, next_small, delta, step, moves)\n next_big += 1\n \nprint(moves)\nprint( \" \".join(map(str, a)))\n\n\n\n#def distribute(k, i):\n# \"\"\" distribute i elements from position k to the following positions, not exceeding R\"\"\"\n# while i > 0:\n# c[k] -= i\n# moves[k] += i\n# k = (k+1) % m\n# c[k] += i\n# i = max(0, c[k] - R)\n# \n#moves = [0] * m\n# \n#for k in range(m):\n# if c[k] > R:\n# distribute(k, c[k] - R)\n# \n#print(sum(moves))\n#\n#for k, x in enumerate(a):\n# while moves[x%m]:\n# moves[x%m] -= 1\n# x += 1\n# a[k] = x\n#\n#print( \" \".join(map(str, a)))\n", "n,m = list(map(int, input().split()))\nnums = list(map(int, input().split()))\n\n# 0 to m-1 remainders\nremainder = [0]*m\nlimit = n//m\nmoves = 0\n\nfor i in nums:\n remainder[i%m] += 1\n\nfor i in range(m):\n remainder[i] -= limit\n\ndeficit = set() \nfor i in range(m):\n if remainder[i] < 0:\n deficit.add(i)\n\n#print(remainder)\n#print(deficit)\nspare = []\nconvert = {}\n\ni = 0\nwhile len(deficit) > 0:\n i = i%m\n\n if remainder[i] > 0:\n spare.append([i, remainder[i]])\n remainder[i] = 0\n elif remainder[i] < 0:\n if len(spare) > 0:\n while len(spare) > 0 and remainder[i] < 0:\n rem = min(spare[-1][1],abs(remainder[i]))\n\n if spare[-1][0] in list(convert.keys()):\n convert[spare[-1][0]].append([(i - spare[-1][0])%m, rem]) \n else:\n convert[spare[-1][0]] = [[(i - spare[-1][0])%m,rem]]\n\n spare[-1][1] -= rem\n remainder[i] += rem\n\n if spare[-1][1] == 0:\n spare.pop()\n \n if remainder[i] == 0:\n deficit.remove(i)\n \n i += 1\n\nfor i in range(n):\n rem = nums[i]%m\n\n if rem in list(convert.keys()):\n moves += convert[rem][-1][0]\n nums[i] += convert[rem][-1][0]\n convert[rem][-1][1] -= 1\n\n if convert[rem][-1][1] == 0:\n convert[rem].pop()\n \n if len(convert[rem]) == 0:\n del convert[rem]\n#print(convert)\nprint(moves)\nprint(*nums)\n", "n,m = list(map(int, input().split()))\nnums = list(map(int, input().split()))\n\n# 0 to m-1 remainders\nremainder = [0]*m\nlimit = n//m\nmoves = 0\n\nfor i in nums:\n remainder[i%m] += 1\n\nfor i in range(m):\n remainder[i] -= limit\n\ndeficit = set() \nfor i in range(m):\n if remainder[i] < 0:\n deficit.add(i)\n\n#print(remainder)\n#print(deficit)\nspare = []\nconvert = {}\n\ni = 0\nwhile len(deficit) > 0:\n i = i%m\n\n if remainder[i] > 0:\n spare.append([i, remainder[i]])\n remainder[i] = 0\n elif remainder[i] < 0:\n if len(spare) > 0:\n while len(spare) > 0 and remainder[i] < 0:\n rem = min(spare[-1][1],abs(remainder[i]))\n\n if spare[-1][0] in list(convert.keys()):\n convert[spare[-1][0]].append([(i - spare[-1][0])%m, rem]) \n else:\n convert[spare[-1][0]] = [[(i - spare[-1][0])%m,rem]]\n\n spare[-1][1] -= rem\n remainder[i] += rem\n\n if spare[-1][1] == 0:\n spare.pop()\n \n if remainder[i] == 0:\n deficit.remove(i)\n \n i += 1\n\nfor i in range(n):\n rem = nums[i]%m\n\n if rem in list(convert.keys()):\n moves += convert[rem][-1][0]\n nums[i] += convert[rem][-1][0]\n convert[rem][-1][1] -= 1\n\n if convert[rem][-1][1] == 0:\n convert[rem].pop()\n \n if len(convert[rem]) == 0:\n del convert[rem]\n#print(convert)\nprint(moves)\nprint(*nums)\n", "n, m = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = sum(a)\nx = [[] for i in range(m)]\nfor i in range(n): x[a[i] % m].append(i)\nj = 0\nfor i in range(m):\n while len(x[i]) > n // m:\n while j < i or len(x[j % m]) >= n // m: j += 1\n k = x[i].pop()\n a[k] += (j - i) % m\n x[j % m].append(k)\nprint(sum(a) - s)\nprint(*a)\n", "n,m=map(int,input().split())\na=list(map(int,input().split()))\nd={}\nfor i in range(m):\n\td[i]=[]\nfor i in range(len(a)):\n\tr=a[i]%m\n\td[r].append((a[i],i))\n# print(d)\nstep=0\nx=n//m\nstack=[]\n# print(d)\nfor i in range(2*m):\n\ti=i%m\n\t# print(i,stack)\n\twhile(len(d[i])>x):\n\t\tstack.append(d[i].pop())\n\twhile(len(d[i])<x and len(stack)):\n\t\tz=list(stack.pop())\n\t\tdelta=(i+m-(z[0]%m))%m\n\t\tz[0]+=delta\n\t\td[i].append((z[0],z[1]))\n\t\tstep+=delta\narr=[]\n# print(d)\nfor i in d:\n\tfor j in d[i]:\n\t\tarr.append(j)\narr.sort(key=lambda i: i[1])\nprint(step)\nfor i in arr:\n\tprint(i[0],end=\" \")\nprint()", "import collections\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\nmd = n // m\nc = [[] for _ in range(m)]\nmx, ind, moves = (0,) * 3\nmovable = collections.deque()\nchange = []\n\nfor i in range(n):\n c[a[i] % m].append(i)\n\nfor i in range(m):\n req = md - len(c[i])\n if req <= 0:\n for j in range(-req):\n movable.append(i)\n else:\n while req > 0:\n if len(movable) == 0:\n change.append([i, req])\n break\n old = movable[0]\n add = i - old\n a[c[old][-1]] += add\n moves += add\n\n c[i].append(c[old][-1])\n del c[old][-1]\n movable.popleft()\n req -= 1\n\nfor obj in change:\n i, req = obj[0], obj[1]\n while req > 0:\n old = movable[0]\n add = i + m - old\n a[c[old][-1]] += add\n moves += add\n\n c[i].append(c[old][-1])\n del c[old][-1]\n movable.popleft()\n req -= 1\n\n# print(c)\nans = [0 for _ in range(n)]\n\nfor i in range(m):\n for j in range(md):\n ans[c[i][j]] = a[c[i][j]]\n\nprint(moves)\nprint(*ans)", "n, m = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = sum(a)\nx = [[] for i in range(m)]\nfor i in range(n): \n x[a[i] % m].append(i)\nj = 0\nfor i in range(m):\n while len(x[i]) > n // m:\n while j < i or len(x[j % m]) >= n // m: \n j += 1\n k = x[i].pop()\n a[k] += (j - i) % m\n x[j % m].append(k)\nprint(sum(a) - s)\nprint(*a)\n", "import collections\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nd = collections.defaultdict(set)\nkr = [-n//k] * k\n\nfor i in range(n):\n ri = a[i] % k\n kr[ri] += 1\n d[ri].add(i)\n\nkrs = [0] * k\nkrs[0] = kr[0]\nfor i in range(1, k):\n krs[i] = krs[i-1] + kr[i]\n\norg = (krs.index(min(krs))+1)%k\ncnt = sum(abs(i) for i in kr) // 2\naa = [0] * cnt\nbb = [0] * cnt\nai = bi = 0\n\nfor ii in range(org, org+k):\n i = ii % k\n if kr[i] > 0:\n for _ in range(kr[i]):\n aa[ai] = i\n ai += 1\n elif kr[i] < 0:\n for _ in range(-kr[i]):\n bb[bi] = i\n bi += 1\n\nans = 0\nfor ai, bi in zip(aa,bb):\n diff = (bi-org)%k - (ai-org)%k\n ans += diff\n i = d[ai].pop()\n a[i] += diff\n\nprint(ans)\nprint(' '.join(map(str, a)))\n", "n, m = map(int, input().split())\na = list(map(int, input().split()))\ns = sum(a)\nx = [[] for i in range(m)]\nfor i in range(n): x[a[i] % m].append(i)\nj = 0\nfor i in range(m):\n while len(x[i]) > n // m:\n while j < i or len(x[j % m]) >= n // m: j += 1\n k = x[i].pop()\n a[k] += (j - i) % m\n x[j % m].append(k)\nprint(sum(a) - s)\nprint(*a)", "from collections import defaultdict\n\nn,m = map(int,input().split())\nk = n//m\nl = list(map(int,input().split()))\ns = sum(l)\n#mod_list = []\nocc = defaultdict(list)\nfor i,a in enumerate(l):\n rem = a%m\n occ[rem].append(i)\n #mod_list.append(rem)\n\nj = 0\nfor i in range(m):\n while len(occ[i]) > k:\n while j < i or len(occ[j % m]) >= k: j += 1\n key = occ[i].pop()\n l[key] += (j - i) % m\n occ[j % m].append(k)\nprint(sum(l) - s)\nprint(*l)", "n, m = list(map(int, input().split()))\naa = list(map(int, input().split()))\nres, cnt = sum(aa), [-n // m] * m\nacc = [[] for _ in range(m)]\nfor i, a in enumerate(aa):\n r = a % m\n cnt[r] += 1\n acc[r].append(i)\nicnt, a = [], 0\nfor c in cnt:\n a += c\n icnt.append(a)\nstart = (min(range(m), key=icnt.__getitem__) + 1) % m\nexcess, scarce = [], []\nfor r in range(start, m), range(start):\n for i in r:\n if cnt[i] > 0:\n for _ in range(cnt[i]):\n excess.append(i)\n elif cnt[i] < 0:\n for _ in range(-cnt[i]):\n scarce.append(i)\nfor e, s in zip(excess, scarce):\n aa[acc[e].pop()] += (s - e) % m\nprint(sum(aa) - res)\nprint(' '.join(map(str, aa)))", "n, m = map(int, input().split())\naa = list(map(int, input().split()))\nres, q = sum(aa), n // m\nacc = [[] for _ in range(m)]\nfor i in range(n):\n acc[aa[i] % m].append(i)\nj = -m\nfor i, l in enumerate(acc):\n if len(l) > q:\n if j <= i - m:\n j = i - m + 1\n while len(l) > q:\n while len(acc[j]) >= q:\n j += 1\n aa[l.pop()] += j + m - i\n acc[j].append(0)\nprint(sum(aa) - res)\nprint(' '.join(map(str, aa)))", "from collections import deque\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\n\nn_m = n // m\nc = m * [0]\nindices = [deque() for r in range(m)]\n\nfor i, ai in enumerate(a):\n r = ai % m\n c[r] += 1\n indices[r].append(i)\n\nn_moves = 0\nqueue = deque()\n\nfor i in range(0, 2 * m):\n r = i % m\n \n while c[r] > n_m:\n queue.append((i, indices[r].pop()))\n c[r] -= 1\n \n while c[r] < n_m and queue:\n j, index = queue.popleft()\n indices[r].append(index)\n c[r] += 1\n a[index] += i - j\n n_moves += i - j\n\nprint(n_moves)\nprint(*a)", "n,m = map(int,input().split())\na = list(map(int,input().split()))\nk = int(n/m)\nlis = [ [] for i in range(m+1)]\n\nfree = list()\n\nfor i in range(n):\n ele = a[i]%m\n lis[ele].append(i)\n\nans = 0\n\nfor i in range(2*m):\n cur = i%m\n \n while len(lis[cur])>k:\n ele = lis[cur].pop()\n free.append([ele,i])\n \n while len(lis[cur])<k and free!=[]:\n ele,mm = free.pop()\n #print(ele,mm)\n lis[cur].append(ele)\n a[ele]+=(i-mm)\n ans+=(i-mm)\nprint(ans)\nfor item in a:\n print(item,end=\" \")\n\n \n \n ", "n, m = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = [[] for _ in range(m)]\n\nfor i in range(n):\n s[a[i] % m].append(i)\n\nf = []\nc = 0\n\nfor _ in range(2):\n for i in range(m):\n while len(s[i]) > n // m:\n f.append((s[i].pop(), i))\n while len(s[i]) < n // m and f:\n v, p = f.pop()\n s[i].append(v)\n if i > p:\n d = i - p\n else:\n d = i + m - p\n a[v] += d\n c += d\n\nprint(c)\nprint(*a)\n", "import sys\ninput = sys.stdin.readline\nout = sys.stdout\n\ndef main():\n n, m = map(int, input().split())\n a = list(map(int, input().split()))\n query = n//m\n data = {i: 0 for i in range(n)}\n data_stat = {i: set() for i in range(m)}\n for i in range(n):\n data[i] = a[i]\n data_stat[a[i] % m].add(i)\n free = []\n answer = {i: 0 for i in range(n)}\n result = 0\n for i in range(2*m):\n cur = i % m\n while len(data_stat[cur]) > query:\n elem = data_stat[cur].pop()\n free.append((elem, i))\n while len(data_stat[cur]) < query and free != []:\n elem, mmod = free.pop()\n data_stat[cur].add(elem)\n a[elem] += i - mmod\n result += i - mmod \n print(result)\n for j in a:\n out.write(str(j) + ' ')\n\ndef __starting_point():\n main()\n__starting_point()", "import collections\nn,m = [int(x) for x in input().split()]\n\nL = [int(x) for x in input().split()]\n\nJ = [0]*m\nD = []\nfor i in range(m):\n D.append([])\nx = n//m\ns = 0\nfor i in range(m):\n D[i] = []\nfor i in range(n):\n J[L[i]%m] += 1\n D[L[i]%m].append(i)\n\nFree = collections.deque([])\nF = 0\nfor i in range(2*m-1):\n j = i%m\n if J[j] > x:\n t = J[j] - x\n F += t\n for A in range(t):\n Free.append((j,D[j][A]))\n J[j] = x\n elif J[j] < x:\n while (F > 0) and (J[j] < x):\n F -= 1\n J[j] += 1\n a,b = Free.popleft()\n s += (j-a)%m\n L[b] += (j-a)%m\nprint(s)\nfor i in L:\n print(i, end = ' ')", "n, m = map(int, input().split())\na = list(map(int, input().split()))\nk, c, free = n // m, [[] for _ in range(m)], []\nfor i, ai in enumerate(a):\n\tc[ai % m].append(i)\nans = 0\nfor _ in range(2 * m):\n\ti = _ % m\n\tlci = len(c[i])\n\tfor j in range(k, lci)[::-1]:\n\t\tfree.append((c[i][j], i))\n\t\tc[i].pop()\n\tfor j in range(k - lci):\n\t\tif free:\n\t\t\tto_add = (i - free[-1][1]) % m\n\t\t\tans += to_add\n\t\t\ta[free[-1][0]] += to_add\n\t\t\tc[i].append(free[-1][0])\n\t\t\tfree.pop()\nprint(ans)\nprint(*a)"] | {
"inputs": [
"6 3\n3 2 0 6 10 12\n",
"4 2\n0 1 2 3\n",
"1 1\n1000000000\n",
"6 3\n3 2 0 6 10 11\n",
"100 25\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 5794 4486 626 971 6731 6618 887 6354 4814 7307 7681 6160 9351 2579 411 3436 5570 2812 2726 4433 3220 577 5891 3861 528 2183 127 5579 6979 4005 9953 5038 9937 4792 3003 9417 8796 1565 11 2596 2486 3494 4464 9568 5512 5565 9822 9820 4848 2889 9527 2249 9860 8236 256 8434 8038 6407 5570 5922 7435 2815\n"
],
"outputs": [
"3\n3 2 0 7 10 14 \n",
"0\n0 1 2 3 \n",
"0\n1000000000 \n",
"1\n3 2 0 7 10 11 \n",
"88\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 5794 4486 626 971 6731 6618 887 6354 4814 7307 7681 6160 9351 2579 411 3436 5570 2812 2726 4433 3220 577 5891 3863 528 2183 127 5579 6979 4005 9953 5038 9937 4792 3005 9417 8796 1565 24 2596 2505 3494 4464 9568 5513 5566 9822 9823 4848 2899 9530 2249 9860 8259 259 8434 8038 6408 5573 5922 7435 2819 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 18,751 | |
9cad0fd51d1b1ecdba8c3e4b737b54c4 | UNKNOWN | The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β and he won't start playing until he gets all of them.
Each day (during the morning) Ivan earns exactly one burle.
There are $n$ types of microtransactions in the game. Each microtransaction costs $2$ burles usually and $1$ burle if it is on sale. Ivan has to order exactly $k_i$ microtransactions of the $i$-th type (he orders microtransactions during the evening).
Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for $1$ burle and otherwise he can buy it for $2$ burles.
There are also $m$ special offers in the game shop. The $j$-th offer $(d_j, t_j)$ means that microtransactions of the $t_j$-th type are on sale during the $d_j$-th day.
Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β the number of types of microtransactions and the number of special offers in the game shop.
The second line of the input contains $n$ integers $k_1, k_2, \dots, k_n$ ($0 \le k_i \le 1000$), where $k_i$ is the number of copies of microtransaction of the $i$-th type Ivan has to order. It is guaranteed that sum of all $k_i$ is not less than $1$ and not greater than $1000$.
The next $m$ lines contain special offers. The $j$-th of these lines contains the $j$-th special offer. It is given as a pair of integers $(d_j, t_j)$ ($1 \le d_j \le 1000, 1 \le t_j \le n$) and means that microtransactions of the $t_j$-th type are on sale during the $d_j$-th day.
-----Output-----
Print one integer β the minimum day when Ivan can order all microtransactions he wants and actually start playing.
-----Examples-----
Input
5 6
1 2 0 2 0
2 4
3 3
1 5
1 2
1 5
2 3
Output
8
Input
5 3
4 2 1 3 2
3 5
4 2
2 5
Output
20 | ["import collections\n\n\ndef 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 def enough(days):\n bought = [] # (type, amount)\n bought_total = 0\n used_from = days\n for d in range(days, 0, -1):\n used_from = min(d, used_from)\n for t in offers.get(d, []):\n if K[t] > 0:\n x = min(K[t], used_from)\n K[t] -= x\n bought.append((t, x))\n bought_total += x\n used_from -= x\n if not used_from:\n break\n remaining_money = days - bought_total\n ans = (total_transaction - bought_total) * 2 <= remaining_money\n for t, a in bought:\n K[t] += a\n return ans\n\n n, m = read_int_array()\n K = read_int_array()\n total_transaction = sum(K)\n offers = collections.defaultdict(list)\n for _ in range(m):\n d, t = read_int_array()\n offers[d].append(t-1)\n\n low = total_transaction\n high = low * 2\n ans = high\n while low <= high:\n mid = (low + high) // 2\n if enough(mid):\n ans = mid\n high = mid - 1\n else:\n low = mid + 1\n write(ans)\n\n\nmain()\n", "import sys\nimport bisect\nimport copy\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\nK=[0]+list(map(int,input().split()))\nSP=[list(map(int,input().split())) for i in range(m)]\n\nSP2=[[] for i in range(n+1)]\n\nfor d,t in SP:\n SP2[t].append(d)\n\nfor i in range(n+1):\n SP2[i].sort()\n\nSUM=sum(K)\nMIN=SUM\nMAX=SUM*2\nMAXBUY=0\n\nfor day in range(MIN,MAX+1):\n\n DAYS=[[] for i in range(day+1)]\n\n for i in range(n+1):\n x=bisect.bisect_right(SP2[i],day)-1\n if x>=0:\n DAYS[SP2[i][x]].append(i)\n\n GOLD=0\n SUMK=SUM\n K2=copy.deepcopy(K)\n\n for d in range(1,day+1):\n GOLD+=1\n\n for t in DAYS[d]:\n DBUY=min(K2[t],GOLD,SUMK)\n K2[t]-=DBUY\n GOLD-=DBUY\n\n\n if GOLD>=sum(K2)*2:\n print(day)\n break\n\n\n\n\n \n \n", "import sys\nimport bisect\nimport copy\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\nK=[0]+list(map(int,input().split()))\nSP=[list(map(int,input().split())) for i in range(m)]\n\nSP2=[[] for i in range(n+1)]\n\nfor d,t in SP:\n SP2[t].append(d)\n\nfor i in range(n+1):\n SP2[i].sort()\n\nSUM=sum(K)\nMIN=SUM\nMAX=SUM*2\nMAXBUY=0\n\nwhile MIN!=MAX:\n day=(MIN+MAX)//2\n\n DAYS=[[] for i in range(day+1)]\n\n for i in range(n+1):\n x=bisect.bisect_right(SP2[i],day)-1\n if x>=0:\n DAYS[SP2[i][x]].append(i)\n\n GOLD=0\n SUMK=SUM\n K2=copy.deepcopy(K)\n\n for d in range(1,day+1):\n GOLD+=1\n\n for t in DAYS[d]:\n DBUY=min(K2[t],GOLD,SUMK)\n K2[t]-=DBUY\n GOLD-=DBUY\n\n\n if GOLD>=sum(K2)*2:\n MAX=day\n else:\n MIN=day+1\n\nprint(MIN)\n\n\n\n\n \n \n", "import math\nfrom collections import defaultdict\nimport sys\n#input = sys.stdin.readline\n\n\ndef main():\n n, m = list(map(int, input().split()))\n k = list(map(int, input().split()))\n sales = [(0, 0)] * m\n for i in range(m):\n a, b = list(map(int, input().split()))\n sales[i] = (b, a)\n\n def check(days):\n last_sale = {}\n for sale in sales:\n if sale[1] <= days:\n if sale[0] not in last_sale or sale[1] > last_sale[sale[0]]:\n last_sale[sale[0]] = sale[1]\n\n date_last_sales = {}\n for t, d in list(last_sale.items()):\n if d not in date_last_sales:\n date_last_sales[d] = [t]\n else:\n date_last_sales[d].append(t)\n\n balance = 0\n required = [0] + k.copy()\n\n end = 0\n for d in range(1, days+1):\n balance += 1\n if d in date_last_sales:\n for t in date_last_sales[d]:\n if required[t] > 0:\n if required[t] > balance:\n end += required[t] - balance\n balance -= min(required[t], balance)\n required[t] = 0\n if d == days: # last day\n for r in required:\n if r > 0:\n end += r\n\n return 2*end <= balance\n\n total = sum(k)\n for i in range(1, 2*total+1):\n if check(i):\n print(i)\n break\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys\n\nDEBUG = False\n\nif DEBUG:\n inf = open(\"input.txt\")\nelse:\n inf = sys.stdin\n\nN, M = list(map(int, inf.readline().split(' ')))\nn_items = list(map(int, inf.readline().split(' ')))\nsales = []\nfor _ in range(M):\n sale = list(map(int, inf.readline().split(' ')))\n sales.append(sale)\n\nsales = sorted(sales, key=lambda x: x[0])\n\n# print(N, M)\n# print(n_items)\n# print(sales)\n# last_sales = [0 for _ in range(N)] # last sale day\nlast_sales = {k: -1 for k in range(N+1)} # for convenience ...\nfinal_sol = 99999999\n\nfor i in range(M):\n sale_day, sale_type = sales[i]\n last_sales[sale_type] = sale_day\n if i != M-1: # not last sale\n if sales[i+1][0] == sale_day: # same sale day\n continue\n \n total = 0\n lasts = last_sales.items()\n lasts = sorted(lasts, key=lambda x: x[1]) # sort by day\n burle = 0\n before_lastday = -1\n for stype, last_sday in lasts:\n if stype == 0:\n continue\n if last_sday == -1:\n # non-sale item\n total += n_items[stype-1]*2\n continue\n \n if before_lastday == -1:\n burle = last_sday\n else:\n burle += last_sday - before_lastday\n before_lastday = last_sday\n\n bought = min(burle, n_items[stype-1])\n left = n_items[stype-1] - bought\n burle -= bought\n total += bought + 2*left\n \n # print(sale_day, total)\n sol = max(sale_day, total)\n if final_sol > sol:\n final_sol = sol\n\nprint(final_sol)", "import sys\n\nDEBUG = False\n\nif DEBUG:\n inf = open(\"input.txt\")\nelse:\n inf = sys.stdin\n\nN, M = list(map(int, inf.readline().split(' ')))\nn_items = list(map(int, inf.readline().split(' ')))\nsales = []\nfor _ in range(M):\n sale = list(map(int, inf.readline().split(' ')))\n sales.append(sale)\n\nsales = sorted(sales, key=lambda x: x[0])\n\n# print(N, M)\n# print(n_items)\n# print(sales)\n# last_sales = [0 for _ in range(N)] # last sale day\nlast_sales = {k: -1 for k in range(N+1)} # for convenience ...\nfinal_sol = 99999999\n\nfor i in range(M):\n sale_day, sale_type = sales[i]\n last_sales[sale_type] = sale_day\n if i != M-1: # not last sale\n if sales[i+1][0] == sale_day: # same sale day\n continue\n \n total = 0\n lasts = last_sales.items()\n lasts = sorted(lasts, key=lambda x: x[1]) # sort by day\n burle = 0\n before_lastday = -1\n for stype, last_sday in lasts:\n if stype == 0:\n continue\n if last_sday == -1:\n # non-sale item\n total += n_items[stype-1]*2\n continue\n \n if before_lastday == -1:\n burle = last_sday\n else:\n burle += last_sday - before_lastday\n before_lastday = last_sday\n\n bought = min(burle, n_items[stype-1])\n left = n_items[stype-1] - bought\n burle -= bought\n total += bought + 2*left\n \n # print(sale_day, total)\n sol = max(sale_day, total)\n if final_sol > sol:\n final_sol = sol\n\nprint(final_sol)", "import sys\nimport copy\n\nDEBUG = False\n\nif DEBUG:\n inf = open(\"input.txt\")\nelse:\n inf = sys.stdin\n\nN, M = list(map(int, inf.readline().split(' ')))\nn_items = list(map(int, inf.readline().split(' ')))\nsales = []\nfor _ in range(M):\n sale = list(map(int, inf.readline().split(' ')))\n sales.append(sale) # sale_day, sale_type\n\nsales = sorted(sales, key=lambda x: x[0], reverse=True) # sort by day\n\ndef can_buy_in(dday):\n used = 0\n money_left = dday\n items = copy.deepcopy(n_items)\n for sale_day, sale_type in sales:\n if sale_day > dday:\n continue\n \n if money_left > sale_day:\n money_left = sale_day\n can_buy = min(items[sale_type-1], money_left)\n # buy it\n used += can_buy\n items[sale_type-1] -= can_buy\n money_left -= can_buy\n\n if money_left == 0:\n break\n \n need_money_for_rest = sum(items) * 2\n return need_money_for_rest + used <= dday\n\ntotal_items = sum(n_items)\nlow = total_items\nhigh = total_items * 2\n\n# find minimum can_buy day\nwhile low <= high:\n mid = (low + high) // 2\n if can_buy_in(mid):\n high = mid-1\n else:\n low = mid+1\n\nprint(low)", "n, m = input().split()\nn = int(n)\nm = int(m)\nnList = input().split()\nbList = [0] * len(nList)\nfor i in range(len(nList)):\n nList[i] = int(nList[i])\nshopD = {}\nshopT = {}\noHis = []\nmHis = []\nmaxD = 0\nfor i in range(m):\n d, t = input().split()\n if nList[int(t) - 1] != 0:\n maxD = max(maxD, int(d))\n if d not in shopD.keys():\n shopD.update({d: [int(t)]})\n else:\n if int(t) not in shopD[d]:\n shopD[d].append(int(t))\n if t not in shopT.keys():\n shopT.update({t: [int(d)]})\n else:\n if int(d) not in shopT[t]:\n shopT[t].append(int(d))\nfor i, j in shopT.items():\n j = list(dict.fromkeys(j))\n j.sort()\n shopT[i] = j\nfor i, j in shopD.items():\n j = list(dict.fromkeys(j))\n shopD[i] = j\ntotal = sum(nList)\ncoin = 0\nday = 0\ndef modifyMis(t, left):\n if left == 0:\n for ii in range(len(mHis))[::-1]:\n if mHis[ii]['t'] == t:\n mHis.pop(ii)\n else:\n for ii in range(len(mHis))[::-1]:\n if mHis[ii]['t'] == t:\n mHis[ii]['n'] = left\nwhile total > 0 and day < maxD:\n coin += 1\n day += 1\n oHis.append({'t': [], 'n': []})\n if str(day) in shopD.keys():\n for t in shopD[str(day)]:\n if nList[t - 1] > 0:\n if bList[t - 1] > 0 and shopT[str(t)][0] != day and coin > nList[t - 1] - bList[t - 1] and len(mHis) > 0 and coin > 0:\n i = 0\n j = 0\n while shopT[str(t)][i] < day:\n extraC = 0\n d = shopT[str(t)][i]\n if t in oHis[d - 1]['t']:\n indexT = oHis[d - 1]['t'].index(t)\n extraC += oHis[d - 1]['n'][indexT]\n bList[t - 1] -= oHis[d - 1]['n'][indexT]\n total += oHis[d - 1]['n'][indexT]\n oHis[d - 1]['t'].pop(indexT)\n oHis[d - 1]['n'].pop(indexT)\n while j < len(mHis) and mHis[j]['d'] < d:\n j += 1\n while extraC > 0 and len(mHis) > j:\n thisT = mHis[j]['t']\n thisD = mHis[j]['d']\n change = min(extraC, mHis[j]['n'])\n bList[thisT - 1] += change\n total -= change\n extraC -= change\n mHis[j]['n'] -= change\n modifyMis(thisT, nList[thisT - 1] - bList[thisT - 1])\n if thisT in oHis[thisD - 1]['t']:\n oHis[thisD - 1]['n'][oHis[thisD - 1]['t'].index(thisT)] += change\n else:\n oHis[thisD - 1]['t'].append(thisT)\n oHis[thisD - 1]['n'].append(change)\n i += 1\n coin += extraC\n buy = min(nList[t - 1] - bList[t - 1], coin)\n if buy != 0:\n oHis[day - 1]['t'].append(t)\n oHis[day - 1]['n'].append(buy)\n total -= buy\n bList[t - 1] += buy\n modifyMis(t, nList[t - 1] - bList[t - 1]) \n coin -= buy\n if nList[t - 1] - bList[t - 1] > 0:\n mHis.append({'d': day, 't': t, 'n': nList[t - 1] - bList[t - 1]}) \n if coin >= total * 2:\n break\nday += max(total * 2 - coin, 0)\nprint(day)", "n, m = input().split()\nn = int(n)\nm = int(m)\nnList = input().split()\nbList = [0] * len(nList)\nfor i in range(len(nList)):\n nList[i] = int(nList[i])\nshopD = {}\nshopT = {}\noHis = []\nmHis = []\nmaxD = 0\nfor i in range(m):\n d, t = input().split()\n if nList[int(t) - 1] != 0:\n maxD = max(maxD, int(d))\n if d not in list(shopD.keys()):\n shopD.update({d: [int(t)]})\n else:\n if int(t) not in shopD[d]:\n shopD[d].append(int(t))\n if t not in list(shopT.keys()):\n shopT.update({t: [int(d)]})\n else:\n if int(d) not in shopT[t]:\n shopT[t].append(int(d))\nfor i, j in list(shopT.items()):\n j = list(dict.fromkeys(j))\n j.sort()\n shopT[i] = j\nfor i, j in list(shopD.items()):\n j = list(dict.fromkeys(j))\n shopD[i] = j\ntotal = sum(nList)\ncoin = 0\nday = 0\ndef modifyMis(t, left):\n if left == 0:\n for ii in range(len(mHis))[::-1]:\n if mHis[ii]['t'] == t:\n mHis.pop(ii)\n else:\n for ii in range(len(mHis))[::-1]:\n if mHis[ii]['t'] == t:\n mHis[ii]['n'] = left\nwhile total > 0 and day < maxD:\n coin += 1\n day += 1\n oHis.append({'t': [], 'n': []})\n if str(day) in list(shopD.keys()):\n for t in shopD[str(day)]:\n if nList[t - 1] > 0:\n if bList[t - 1] > 0 and shopT[str(t)][0] != day and coin > nList[t - 1] - bList[t - 1] and len(mHis) > 0 and coin > 0:\n i = 0\n j = 0\n while shopT[str(t)][i] < day:\n extraC = 0\n d = shopT[str(t)][i]\n if t in oHis[d - 1]['t']:\n indexT = oHis[d - 1]['t'].index(t)\n extraC += oHis[d - 1]['n'][indexT]\n bList[t - 1] -= oHis[d - 1]['n'][indexT]\n total += oHis[d - 1]['n'][indexT]\n oHis[d - 1]['t'].pop(indexT)\n oHis[d - 1]['n'].pop(indexT)\n while j < len(mHis) and mHis[j]['d'] < d:\n j += 1\n while extraC > 0 and len(mHis) > j:\n thisT = mHis[j]['t']\n thisD = mHis[j]['d']\n change = min(extraC, mHis[j]['n'])\n bList[thisT - 1] += change\n total -= change\n extraC -= change\n mHis[j]['n'] -= change\n modifyMis(thisT, nList[thisT - 1] - bList[thisT - 1])\n if thisT in oHis[thisD - 1]['t']:\n oHis[thisD - 1]['n'][oHis[thisD - 1]['t'].index(thisT)] += change\n else:\n oHis[thisD - 1]['t'].append(thisT)\n oHis[thisD - 1]['n'].append(change)\n i += 1\n coin += extraC\n buy = min(nList[t - 1] - bList[t - 1], coin)\n if buy != 0:\n oHis[day - 1]['t'].append(t)\n oHis[day - 1]['n'].append(buy)\n total -= buy\n bList[t - 1] += buy\n modifyMis(t, nList[t - 1] - bList[t - 1]) \n coin -= buy\n if nList[t - 1] - bList[t - 1] > 0:\n mHis.append({'d': day, 't': t, 'n': nList[t - 1] - bList[t - 1]}) \n if coin >= total * 2:\n break\nday += max(total * 2 - coin, 0)\nprint(day)\n", "#binary search reconstructure\n \n\ndef BinarySearch(my_list,key):\n l = 0\n r = len(my_list)- 1 \n #print(l,r)\n while r > l :\n mid = (l+r)//2\n if my_list[mid+1] <= key :\n l = mid + 1 \n else :\n r = mid \n #print(l,r)\n return l\n\ndef weather_can_buy(day,total,req_list,sale_days):\n tmp_buy = []\n last_day = []\n # money = day\n # bug anything that is on sale\n d = day\n my_total = total\n for i in range(len(req_list)) : \n last_day.append(0)\n for i in range(d):\n tmp_buy.append(0) \n for i in range(len(sale_days)) : \n if len(sale_days[i]) > 0 : \n index = BinarySearch(sale_days[i],day)\n last_day[i] = sale_days[i][index]\n for i in range(len(last_day)) :\n if last_day[i]-1 > -1 :\n tmp_buy[last_day[i]-1] += req_list[i]\n # buying\n money = 0\n for i in range(d):\n money += 1\n my_total -= min(money,tmp_buy[i])\n money -= min(money,tmp_buy[i]) \n if my_total < 0 :\n return True\n elif money >= my_total * 2:\n return True\n else :\n return False\n \ndef function():\n tmp = input().split(\" \")\n n = int(tmp[0]) # The number of type\n m = int(tmp[1]) \n req_list = input().split(\" \")\n req_list = list(map(int,req_list)) \n total = sum(req_list)\n sale_days = []\n # sale days for acceleration\n for i in range(len(req_list)):\n sale_days.append([0]) \n for i in range(m) :\n tmp = input().split(\" \")\n dj,tj = (int(tmp[0]),int(tmp[1]))\n sale_days[tj-1].append(dj)\n for i in range(len(sale_days)) :\n sale_days[i] = sorted(sale_days[i])\n # optimized by sorting\n for i in range(len(sale_days)) :\n sale_days[i] = sorted(sale_days[i]) \n #day = 0\n\n l = 1\n r = 2*total\n while r > l :\n mid = (l+r)//2\n if weather_can_buy(mid,total,req_list,sale_days) :\n r = mid\n else :\n l = mid + 1 \n print(r)\n \nfunction()\n", "import copy\nfrom collections import defaultdict\n\nBIG = 10**9\nN, M = [int(i) for i in input().split()]\n\nK = [0] + [int(i) for i in input().split()]\n\nsumK = sum(K)\nmax_days = 2*sum(K)\n\nday_at_sale_per_item = defaultdict(list)\nfor i in range(M):\n day, item = [int(i) for i in input().split()]\n day_at_sale_per_item[item].append(day)\n\nsales_per_day = defaultdict(list)\nfor item, days in list(day_at_sale_per_item.items()):\n for day in days:\n sales_per_day[day].append(item)\n\nL, R = 0, max_days\nanswer = 0\nwhile L <= R:\n m = (L+R)//2\n\n def get_best_sales(m):\n best_sales = defaultdict(list)\n for item, days in list(day_at_sale_per_item.items()):\n best_day = 0\n for day in days:\n if day <= m:\n best_day = max(best_day, day)\n if best_day:\n best_sales[best_day].append(item)\n return best_sales\n\n def available_sales(m):\n available_money = 0\n nb_sales = 0\n cK = copy.deepcopy(K)\n\n best_sales = get_best_sales(m)\n\n for day in range(1, m+1):\n available_money += 1\n for item in best_sales[day]:\n buy = min(cK[item], available_money)\n if buy:\n cK[item] -= buy\n available_money -= buy\n nb_sales += buy\n return nb_sales\n\n def possible(m):\n total_money = m\n needed_money = 2 * sumK - available_sales(m)\n return total_money >= needed_money\n\n if possible(m):\n answer = m\n R = m-1\n else:\n L = m+1\nprint(answer)\n", "from collections import defaultdict\n\ndef possible(days):\n nonlocal events, k\n \n latest_ev = defaultdict(int)\n for d, t in events:\n if d <= days:\n latest_ev[t] = max(latest_ev[t], d)\n \n earned = days\n offers_needed = 2 * sum(k) - earned\n\n offers = 0 \n cur_day = 0\n cur_val = 0\n for t, d in sorted(list(latest_ev.items()), key=lambda x: x[1]):\n cur_val += d - cur_day\n cur_day = d\n offers_to_take = min(k[t], cur_val)\n offers += offers_to_take\n cur_val -= offers_to_take\n return offers >= offers_needed\n \n\nn, m = list(map(int, input().split()))\n\nk = list(map(int, input().split()))\n\nevents = []\nfor _ in range(m):\n d, t = list(map(int, input().split()))\n t -= 1\n events.append((d, t))\n \nlo = 0\nhi = 4*10**5\n\nwhile lo + 1 < hi:\n mid = (lo+hi)//2\n \n if possible(mid):\n hi = mid\n else:\n lo = mid\n \nprint(hi)\n", "from collections import defaultdict\n\ndef possible(days):\n nonlocal events, k\n \n latest_ev = defaultdict(int)\n for d, t in events:\n if d <= days:\n latest_ev[t] = max(latest_ev[t], d)\n \n earned = days\n offers_needed = 2 * sum(k) - earned\n\n offers = 0 \n cur_day = 0\n cur_val = 0\n for t, d in sorted(list(latest_ev.items()), key=lambda x: x[1]):\n cur_val += d - cur_day\n cur_day = d\n offers_to_take = min(k[t], cur_val)\n offers += offers_to_take\n cur_val -= offers_to_take\n if offers >= offers_needed:\n return True\n return offers >= offers_needed\n \n\nn, m = list(map(int, input().split()))\n\nk = list(map(int, input().split()))\n\nevents = []\nfor _ in range(m):\n d, t = list(map(int, input().split()))\n t -= 1\n events.append((d, t))\n \nlo = sum(k) - 1\nhi = 2 * sum(k)\n\nwhile lo + 1 < hi:\n mid = (lo+hi)//2\n \n if possible(mid):\n hi = mid\n else:\n lo = mid\n \nprint(hi)\n", "def check(mid):\n\tl = [0 for i in range(n)]\n\tfor i in b:\n\t\tif(i[0] > mid): break\n\t\tl[i[1]-1] = i[0]\n\tv = [0 for i in range(mid+1)]\n\tfor i in range(n):\n\t\tv[l[i]] += a[i]\n\tct = 0\n\tfor i in range(1,mid+1):\n\t\tct += 1\n\t\tif(ct >= v[i]):\n\t\t\tct -= v[i]\n\t\t\tv[i] = 0\n\t\telse:\n\t\t\tv[i] -= ct\n\t\t\tct = 0\n\treturn ct >= 2*sum(v)\n\ndef bs():\n\tl = 0\n\tr = 5*10**5\n\twhile(l <= r):\n\t\tmid = (l+r)//2\n\t\tif(check(mid)):\n\t\t\tr = mid-1\n\t\telse:\n\t\t\tl = mid+1\n\treturn r+1\n\nn,m = map(int,input().split())\na = list(map(int,input().split()))\nb = []\nfor i in range(m):\n\tb.append(list(map(int,input().split())))\nb.sort()\nprint(bs())", "import sys\ninput = sys.stdin.readline\ndef check(num):\n\tlast = [0 for i in range(n)]\n\tfor i in o:\n\t\tif i[0]>num:\n\t\t\tbreak\n\t\telse:\n\t\t\tlast[i[1]-1] = i[0]\n\tb = [0 for i in range(num+1)]\n\tfor i in range(n):\n\t\tb[last[i]] += a[i]\n\n\ti = 0\n\tc = 0\n\td = 0\n\tfor i in range(1,num+1):\n\t\tc += 1\n\t\tif(c >= b[i]):\n\t\t\tc -= b[i]\n\t\t\tb[i] = 0\n\t\telse:\n\t\t\tb[i] -= c\n\t\t\tc = 0\n\n\ts = sum(b)\n\tif s*2<=c:\n\t\treturn True\n\treturn False\n\n\n\nn,m = map(int,input().split())\na = list(map(int,input().split()))\no = []\nfor i in range(m):\n\tx,y = map(int,input().split())\n\to.append((x,y))\no.sort()\nlow = 1\nhigh = sum(a)*2\nwhile low<high:\n\tmid = (low+high)//2\n\tif check(mid):\n\t\thigh = mid - 1\n\telse:\n\t\tlow = mid + 1\nif check(low):\n\tprint (low)\nelse:\n\tprint (low+1)", "def check(x):\n last=[0]*(n+1)\n for i in tmp:\n if i[0]>x:\n break\n else:\n last[i[1]]=i[0]\n sal=[0]*(x+1)\n for i in range(1,n+1):\n sal[last[i]]+=lis[i-1]\n c=0\n for i in range(1,x+1):\n c+=1\n if sal[i]>=c:\n sal[i]-=c\n c=0\n else:\n c-=sal[i]\n sal[i]=0\n if sum(sal)*2<=c:\n return True\n else:\n return False \nn,m = list(map(int,input().split()))\nlis = list(map(int,input().split()))\ntmp=[]\nfor _ in range(m):\n a,b = list(map(int,input().split()))\n tmp.append([a,b])\ntmp.sort()\nl=0\nr=sum(lis)*2\nwhile l<=r:\n mid = l + (r-l)//2\n if check(mid):\n r = mid-1\n else:\n l = mid+1\nif check(r):\n print(r)\nelif check(l):\n print(l)\nelse:\n print(l+1) \n\n\n\n", "from collections import deque\n\n\ndef main():\n n, m = list(map(int, input().split()))\n wanted_cnt = list(map(int, input().split()))\n Order = [tuple(map(int, input().split())) for i in range(m)]\n #count the maximum number which you can buy on sales day.\n S = sum(wanted_cnt)\n\n def ispossible_within(Day):\n sale_get_cnt = 0\n last_sale = [0]*n\n for day, good in Order:\n if day > Day:\n continue\n last_sale[good-1] = max(last_sale[good-1], day)\n Que = []\n for i in range(n):\n if wanted_cnt[i] > 0 and last_sale[i] > 0:\n Que.append((last_sale[i], wanted_cnt[i]))\n Que.sort()\n que = deque(Que)\n while que:\n sale_day, wanted = que.popleft()\n money_left = sale_day - sale_get_cnt\n if money_left >= wanted:\n sale_get_cnt += wanted\n elif money_left < wanted:\n sale_get_cnt += money_left\n left_money = Day - sale_get_cnt\n left = S - sale_get_cnt\n\n return left_money >= 2*left\n\n impossible = 0\n possible = 2020\n while possible - impossible > 1:\n m = (impossible + possible)//2\n if ispossible_within(m):\n possible = m\n else:\n impossible = m\n print(possible)\n return\n\n\ndef __starting_point():\n main()\n\n\n__starting_point()"] | {
"inputs": [
"5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n",
"5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n",
"78 36\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 1 0 0 0 0 0 0 0 0 0 0\n1 52\n2 6\n9 43\n10 52\n4 63\n9 35\n10 67\n9 17\n3 43\n4 38\n1 27\n9 44\n6 74\n7 3\n8 18\n1 52\n1 68\n5 51\n5 2\n7 50\n1 72\n1 37\n8 64\n10 30\n2 68\n1 59\n5 12\n9 11\n10 23\n2 51\n10 56\n6 17\n1 49\n3 20\n10 62\n10 40\n",
"10 47\n1 0 0 1 2 1 1 3 1 3\n4 9\n15 5\n6 2\n4 1\n23 3\n9 10\n12 2\n5 10\n2 4\n2 4\n18 4\n23 5\n17 1\n22 3\n24 4\n20 5\n7 3\n17 10\n3 10\n12 10\n4 6\n3 10\n24 2\n12 1\n25 9\n12 5\n25 2\n13 5\n6 5\n4 9\n6 10\n7 2\n7 9\n11 7\n9 4\n1 1\n7 2\n8 1\n11 9\n25 9\n7 8\n9 9\n8 1\n6 4\n22 8\n16 6\n22 6\n",
"4 7\n23 78 12 46\n100 1\n41 3\n213 2\n321 3\n12 2\n87 1\n76 2\n"
],
"outputs": [
"8\n",
"20\n",
"1\n",
"13\n",
"213\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 26,886 | |
4a6b4d29b0f03cf3a77a10ba466f41dc | UNKNOWN | You are given $4n$ sticks, the length of the $i$-th stick is $a_i$.
You have to create $n$ rectangles, each rectangle will consist of exactly $4$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides $a$ and $b$ is $a \cdot b$.
Your task is to say if it is possible to create exactly $n$ rectangles of equal area or not.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 500$) β the number of queries. Then $q$ queries follow.
The first line of the query contains one integer $n$ ($1 \le n \le 100$) β the number of rectangles.
The second line of the query contains $4n$ integers $a_1, a_2, \dots, a_{4n}$ ($1 \le a_i \le 10^4$), where $a_i$ is the length of the $i$-th stick.
-----Output-----
For each query print the answer to it. If it is impossible to create exactly $n$ rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
-----Example-----
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | ["for _ in range(int(input())):\n n = int(input())\n A = list(map(int, input().split()))\n B = {}\n for i in A:\n if i not in B:\n B[i] = 0\n B[i] += 1\n ans = 'YES'\n J = []\n for i in B:\n if B[i] % 2:\n ans = 'NO'\n break\n else:\n for _ in range(B[i] // 2):\n J.append(i)\n if ans == 'YES':\n J.sort()\n s = set()\n for i in range(n):\n s.add(J[i] * J[-i-1])\n if len(s) != 1:\n ans = 'NO'\n print(ans)", "from sys import stdin\nfrom collections import deque\nq=int(stdin.readline().strip())\nfor i in range(q):\n n=int(stdin.readline().strip())\n s=list(map(int,stdin.readline().strip().split()))\n s.sort()\n s=deque(s)\n t=True\n A=s[0]*s[-1]\n while len(s)>0:\n a1=s[0]*s[-1]\n if a1!=A or s[0]!=s[1] or s[-1]!=s[-2]:\n t=False\n break\n s.popleft()\n s.popleft()\n s.pop()\n s.pop()\n if t :\n print(\"YES\")\n else:\n print(\"NO\")\n \n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\ta.sort()\n\tfor i in range(0, 2 * n, 2):\n\t\tif a[i] != a[i + 1] or a[-i-1] != a[-i-2]:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif i == 0:\n\t\t\tarea = a[i] * a[-i-1]\n\t\telse:\n\t\t\tif area != a[i] * a[-i-1]:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tprint('YES')\n\n", "T = int(input())\nfor t in range(T):\n n = int(input())\n A = [int(i) for i in input().split()]\n A.sort()\n ok = 1\n areas = []\n left = 0\n\n right = 4*n - 1\n for i in range(n):\n l1 = left\n l2 = left + 1\n\n r1 = right\n r2 = right - 1\n \n if not (A[l1] == A[l2] and A[r1] == A[r2]):\n ok = 0 \n areas.append(A[l1]*A[r1])\n\n left += 2\n right -= 2\n \n #print(areas, ok)\n if len(set(areas)) == 1 and ok:\n print('YES')\n else:\n print('NO')\n", "q = int(input())\nfor _ in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n a.sort()\n pos = True\n for i in range(0, 4 * n, 2):\n if a[i] != a[i + 1]:\n pos = False\n break\n area = a[0] * a[-1]\n if pos:\n for i in range(2, 2 * n, 2):\n pos = pos and a[i] * a[-i - 1] == area\n print('YES' if pos else 'NO')\n", "for _ in range(int(input())):\n n = int(input())\n a = [int(i) for i in input().split()]\n a.sort()\n i = 1\n j = len(a)-2\n ans = \"YES\"\n area = a[0]*a[-1]\n while i<j:\n if a[i] == a[i-1] and a[j] == a[j+1] and a[i]*a[j]==area:\n i+=2\n j-=2\n else:\n ans = \"NO\"\n break\n print(ans)", "for _ in range(int(input())):\n n = int(input())\n a = list(sorted(map(int, input().split())))\n b = []\n for i in range(0, len(a), 2):\n if a[i + 1] != a[i]:\n print(\"NO\")\n break\n b.append(a[i])\n else:\n s = b[0] * b[-1]\n for j in range(1, len(a) // 2):\n if b[j] * b[-j-1] != s:\n print(\"NO\")\n break\n else:\n print(\"YES\")", "def main():\n q = int(input())\n for _ in range(q):\n n = int(input())\n slist = list(sorted(map(int, input().split())))\n li, ri = 0, 4*n-1\n ans = None\n for j in range(n):\n if slist[li] != slist[li+1] or slist[ri] != slist[ri-1]:\n print('NO')\n break\n if ans is None:\n ans = slist[li]*slist[ri]\n li += 2\n ri -= 2\n else:\n if ans != slist[li]*slist[ri]:\n print('NO')\n break\n else:\n li += 2\n ri -= 2\n else:\n print('YES')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "Q = int(input())\nfor q in range(Q):\n N = int(input())\n A = sorted([int(a) for a in input().split()])\n S = A[0] * A[-1]\n i, j = 0, 4*N-1\n for _ in range(N):\n if not(A[i] == A[i+1] and A[j] == A[j-1] and A[i] * A[j] == S):\n print(\"NO\")\n break\n i += 2\n j -= 2\n else:\n print(\"YES\")\n", "q=int(input())\nfor i in range(q):\n t=int(input())\n arr=[int(x) for x in input().split()]\n arr.sort()\n pos=True\n lengths=[]\n for j in range(2*t):\n if arr[2*j]!=arr[2*j+1]:\n pos=False\n break\n lengths.append(arr[2*j])\n if pos==True:\n area=lengths[0]*lengths[2*t-1]\n for j in range(t-1):\n if lengths[1+j]*lengths[2*t-2-j]!=area:\n pos=False\n break\n if pos==True:\n print(\"YES\")\n else:\n print(\"NO\")\n \n", "def gns():\n return list(map(int,input().split()))\n\nt=int(input())\n\n\nfor i in range(t):\n n=int(input())\n ns=gns()\n ns.sort()\n a=ns[0]*ns[-1]\n f=True\n for i in range(4*n):\n if i%2==1:\n continue\n if ns[i]!=ns[i+1]:\n f=False\n break\n if not f:\n print('NO')\n continue\n for i in range(4*n):\n if ns[i]*ns[4*n-1-i]!=a:\n f=False\n break\n if not f:\n print('NO')\n continue\n print('YES')\n\n\n\n", "#579_B\n\nimport sys\n\nq = int(input())\n\nfor i in range(0, q):\n n = int(input())\n ln = [int(j) for j in sys.stdin.readline().rstrip().split(\" \")]\n ln = sorted(ln)\n f = True\n for j in range(1, len(ln), 2):\n if ln[j] != ln[j - 1]:\n f = False\n\n ind1 = 0\n ind2 = len(ln) - 2\n sm = ln[ind1] * ln[ind2]\n while ind1 < ind2:\n ind1 += 2\n ind2 -= 2\n if ln[ind1] * ln[ind2] != sm:\n f = False\n break\n if f:\n print(\"YES\")\n else:\n print(\"NO\")\n", "q = int(input())\nfor _ in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n\n def solve(a):\n from collections import Counter\n c = Counter(a)\n keys = sorted(c)\n for key in keys:\n if c[key] % 2 != 0:\n return False\n temp = [[k]*c[k] for k in keys]\n keys = []\n for t in temp:\n keys += t\n area = keys[0] * keys[-1]\n head = 0\n tail = len(keys) - 1\n if len(keys) % 2 != 0:\n return False\n while head < tail:\n if keys[head] * keys[tail] != area:\n return False\n head += 1\n tail -= 1\n return True\n print(\"YES\" if solve(a) else \"NO\")\n", "import sys\ninput=sys.stdin.readline\ndef query(n,A):\n A.sort()\n B=[]\n for i in range(0,n*4,2):\n if A[i]!=A[i+1]:\n return 'NO'\n B.append(A[i])\n s=B[0]*B[-1]\n for i in range(n*2):\n if B[i]*B[-i-1]!=s:\n return 'NO'\n return 'YES'\n\nq=int(input())\nfor _ in range(q):\n n=int(input())\n A=list(map(int,input().split()))\n print(query(n,A))", "for _ in range(int(input())):\n\tn=int(input())\n\tl=list(map(int,input().split()))\n\td1={}\n\tfor i in l:\n\t\tif i in d1:\n\t\t\td1[i]+=1\n\n\t\telse:\n\t\t\td1[i]=1\n\n\tf=True\n\tli=[]\n\tfor i in d1:\n\t\tif d1[i]%2!=0:\n\t\t\tf=False\n\t\t\tbreak\n\t\telse:\n\t\t\tli.extend([i]*(d1[i]//2))\n\n\tif f:\n\t\tli.sort()\n\t\tc=li[0]*li[-1]\n\t\ti=1\n\t\tj=len(li)-2\n\t\twhile i<j:\n\t\t\tif c!=li[i]*li[j]:\n\t\t\t\tf=False\n\t\t\t\tbreak\n\n\t\t\telse:\n\t\t\t\ti+=1\n\t\t\t\tj-=1\n\t\tif f:\n\t\t\tprint(\"YES\")\n\n\t\telse:\n\t\t\tprint(\"NO\")\n\n\telse:\n\t\tprint(\"NO\")\n\n", "t = int(input())\nfor u in range(t):\n\tn = int(input())\n\tn = n*4\n\tx = list(map(int, input().split()))\n\tx.sort()\n\ti = 0\n\tf = []\n\twhile(i < n):\n\t\tif(x[i]==x[i+1]):\n\t\t\tf += [x[i]]\n\t\t\ti += 2\n\t\telse:\n\t\t\tbreak\n\tans = \"YES\"\n\tif(len(f)==n//2):\n\t\tar = f[0]*f[-1]\n\t\ti = 0\n\t\tj = len(f)-1\n\t\tfor k in range(n//4):\n\t\t\tif(f[i]*f[j] != ar):\n\t\t\t\tans = \"NO\"\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tj -= 1\n\telse:\n\t\tans = \"NO\"\n\tprint(ans)\n", "q = int(input())\nfor qq in range(q):\n n = int(input())\n *a, = list(map(int, input().split()))\n a = list(sorted(a))\n br = False\n for i in range(2*n):\n if a[2*i] != a[2*i+1]:\n print(\"NO\")\n br = True\n break\n if br:\n continue\n a = a[::2]\n ar = a[0]*a[-1]\n for i in range(n):\n if a[i]*a[-i-1] != ar:\n print(\"NO\")\n break\n else:\n print(\"YES\")\n", "import io, os\n#input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline\n\nq = int(input())\n\nfor i in range(q):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\td = {}\n\tmn, mx = 10 ** 18, 0\n\tfor c in a:\n\t\tif c < mn:\n\t\t\tmn = c\n\t\tif c > mx:\n\t\t\tmx = c\n\t\td[c] = d.get(c, 0) + 1\n\t\n\ts = mn * mx\n\tf = True\n\tfor c in d:\n\t\tif not(d[c] % 2 == 0 and s % c == 0 and d.get(s // c, 0) == d[c]):\n\t\t\tf = False\n\t\t\tprint(\"NO\")\n\t\t\tbreak\n\tif f:\n\t\tprint(\"YES\")\n\t\n", "q = int(input())\nfor Q in range(q):\n n = int(input())\n arr = list(map(int, input().split()))\n arr2 = []\n unused = set()\n for i in arr:\n if i not in unused:\n unused.add(i)\n else:\n arr2.append(i)\n unused.remove(i)\n\n if len(unused) != 0:\n print(\"NO\")\n else:\n flag = True\n arr2.sort()\n s = arr2[0] * arr2[-1]\n arr2 = arr2[1:-1]\n while len(arr2) != 0:\n s2 = arr2[0] * arr2[-1]\n if s2 != s:\n print(\"NO\")\n flag = False\n break\n else:\n arr2 = arr2[1:-1]\n if flag:\n print(\"YES\")\n", "N = int(input())\nfor i in range(N):\n A = int(input())\n B = list(map(int,input().split()))\n B.sort()\n flag = True\n for i in range(2*A):\n if B[2*i] != B[2*i+1]:\n flag = False\n break\n S = B[0]*B[-1]\n for i in range(A):\n if B[i*2] * B[-i*2-1] != S:\n flag = False\n break\n print([\"NO\",\"YES\"][flag])\n", "q = int(input())\nfor j in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n a = sorted(a)\n if n == 1:\n if a[0] == a[1] and a[2] == a[3]:\n print('YES')\n else:\n print('NO')\n else:\n b = []\n for i in range(0, 4 * n - 1, 2):\n if a[i] == a[i + 1]:\n b.append(a[i])\n #print(b)\n if len(b) == 2 * n:\n x = b[0] * b[2 * n - 1]\n for i in range(1, n):\n #print(x)\n if b[i] * b[2 * n - i - 1]== x:\n x = b[i] * b[2 * n - i - 1]\n else:\n x = 0\n break\n if x != 0:\n print('YES')\n else:\n print('NO')\n else:\n print('NO')\n \n", "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort()\n t=[]\n k=0\n for i in range(0,2*n,2):\n if a[i]==a[i+1] and a[4*n-i-1]==a[4*n-i-2]:\n s=a[i]*a[4*n-i-1]\n t.append(s)\n \n\n else:\n k+=1\n if k>0:\n print('NO')\n else:\n if len(list(set(t)))==1:\n print('YES')\n else:\n print('NO')\n", "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n hsh=[0]*max(a)\n for i in a:\n hsh[i-1]+=1\n flag=0\n for i in hsh:\n flag+=i%2\n if(flag):\n break\n if(flag):\n print(\"NO\")\n else:\n a.sort()\n s=a[0]*a[-1]\n for i in range(2*n):\n if(a[i]*a[4*n-1-i]!=s):\n flag=1\n break\n if(flag):\n print(\"NO\")\n else:\n print(\"YES\")\n\n", "q=int(input())\nwhile q:\n n=int(input())\n a=input().split()\n for i in range(4*n):\n a[i]=int(a[i])\n a.sort()\n count=0\n value=a[0]*a[4*n-1]\n j=0\n while j<=2*n-2:\n if(a[j]==a[j+1] and a[4*n-j-1]==a[4*n-j-2]):\n if(a[j]*a[4*n-j-1]==value):\n count+=1\n j+=2 \n if(count==n) : print(\"YES\")\n else: print(\"NO\")\n q-=1 ", "q = int(input())\nfor i in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n a.sort()\n ans = True\n S = -1\n i = 0\n for j in range(n):\n if a[i] == a[i + 1] and a[-(1 + i)] == a[-(2 + i)]:\n if S == -1 or S == a[i] * a[-(1 + i)]:\n S = a[i] * a[-(1 + i)]\n else:\n ans = False\n break\n else:\n ans = False\n break\n i += 2\n if ans:\n print(\"YES\")\n else:\n print(\"NO\")"] | {
"inputs": [
"5\n1\n1 1 10 10\n2\n10 5 2 10 1 1 2 5\n2\n10 5 1 10 5 1 1 1\n2\n1 1 1 1 1 1 1 1\n1\n10000 10000 10000 10000\n",
"1\n2\n11 1 11 1 5 2 5 2\n",
"1\n2\n1 1 3 3 5 5 10 10\n",
"1\n2\n1 11 1 11 5 2 5 2\n",
"1\n2\n3 3 4 4 4 4 6 6\n"
],
"outputs": [
"YES\nYES\nNO\nYES\nYES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 13,269 | |
9b151e59de0827f6d5aad58c038df4da | UNKNOWN | You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges.
You need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one).
More formally, if $d$ is the matrix of shortest paths, where $d_{i, j}$ is the length of the shortest path between vertices $i$ and $j$ ($1 \le i < j \le n$), then you need to print the $k$-th element in the sorted array consisting of all $d_{i, j}$, where $1 \le i < j \le n$.
-----Input-----
The first line of the input contains three integers $n, m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le \min\Big(\frac{n(n-1)}{2}, 2 \cdot 10^5\Big)$, $1 \le k \le \min\Big(\frac{n(n-1)}{2}, 400\Big)$Β β the number of vertices in the graph, the number of edges in the graph and the value of $k$, correspondingly.
Then $m$ lines follow, each containing three integers $x$, $y$ and $w$ ($1 \le x, y \le n$, $1 \le w \le 10^9$, $x \ne y$) denoting an edge between vertices $x$ and $y$ of weight $w$.
It is guaranteed that the given graph is connected (there is a path between any pair of vertices), there are no self-loops (edges connecting the vertex with itself) and multiple edges (for each pair of vertices $x$ and $y$, there is at most one edge between this pair of vertices in the graph).
-----Output-----
Print one integerΒ β the length of the $k$-th smallest shortest path in the given graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one).
-----Examples-----
Input
6 10 5
2 5 1
5 3 9
6 2 2
1 3 1
5 1 8
6 5 10
1 6 5
6 4 6
3 6 2
3 4 5
Output
3
Input
7 15 18
2 6 3
5 7 4
6 5 4
3 6 9
6 7 7
1 6 4
7 1 6
7 2 1
4 3 2
3 2 8
5 3 6
2 5 5
3 7 9
4 1 8
2 1 1
Output
9 | ["import sys\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nEDGE=[list(map(int,input().split())) for i in range(m)]\n\nEDGE.sort(key=lambda x:x[2])\nEDGE=EDGE[:k]\n\nCOST_vertex=[[] for i in range(n+1)]\nfor a,b,c in EDGE:\n COST_vertex[a].append((b,c))\n COST_vertex[b].append((a,c))\n\nfor i in range(min(m,k)):\n x,y,c=EDGE[i]\n EDGE[i]=(c,x,y)\n\n\nUSED_SET=set()\n\nANS=[-1<<50]*k\n\nimport heapq\n\nwhile EDGE:\n c,x,y = heapq.heappop(EDGE)\n\n if (x,y) in USED_SET or c>=-ANS[0]:\n continue\n\n else:\n heapq.heappop(ANS)\n heapq.heappush(ANS,-c)\n USED_SET.add((x,y))\n USED_SET.add((y,x))\n\n for to,cost in COST_vertex[x]:\n if to!=y and not((y,to) in USED_SET) and c+cost<-ANS[0]:\n heapq.heappush(EDGE,(c+cost,y,to))\n #USED_SET.add((y,to))\n #USED_SET.add((to,y))\n\n for to,cost in COST_vertex[y]:\n if to!=x and not((x,to) in USED_SET) and c+cost<-ANS[0]:\n heapq.heappush(EDGE,(c+cost,x,to))\n #USED_SET.add((x,to))\n #USED_SET.add((to,x))\n\nprint(-ANS[0])\n \n", "import sys\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nEDGE=[list(map(int,input().split())) for i in range(m)]\n\nEDGE.sort(key=lambda x:x[2])\nEDGE=EDGE[:k]\n\nCOST_vertex=[[] for i in range(n+1)]\nVERLIST=[]\n\nfor a,b,c in EDGE:\n COST_vertex[a].append((b,c))\n COST_vertex[b].append((a,c))\n VERLIST.append(a)\n VERLIST.append(b)\n\nVERLIST=list(set(VERLIST))\n\nimport heapq\n\nANS=[-1<<50]*k\n\n\nfor start in VERLIST:\n MINCOST=[1<<50]*(n+1)\n\n checking=[(0,start)]\n MINCOST[start]=0\n\n j=0\n while j<k:\n if not(checking):\n break\n \n cost,checktown=heapq.heappop(checking)\n if cost>=-ANS[0]:\n break\n\n if MINCOST[checktown]<cost:\n continue\n \n if cost!=0 and checktown>start:\n heapq.heappop(ANS)\n heapq.heappush(ANS,-cost)\n j+=1\n \n for to,co in COST_vertex[checktown]:\n\n if MINCOST[to]>cost+co:\n MINCOST[to]=cost+co\n\n heapq.heappush(checking,(cost+co,to))\n\nprint(-ANS[0])\n \n \n", "import sys\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nEDGE=[list(map(int,input().split())) for i in range(m)]\n\nEDGE.sort(key=lambda x:x[2])\nEDGE=EDGE[:k]\n\nCOST_vertex=[[] for i in range(n+1)]\nVERLIST=[]\n\nfor a,b,c in EDGE:\n COST_vertex[a].append((b,c))\n COST_vertex[b].append((a,c))\n VERLIST.append(a)\n VERLIST.append(b)\n\nVERLIST=sorted((set(VERLIST)))\n\nimport heapq\n\nANS=[-1<<50]*k\n\n\nfor start in VERLIST:\n MINCOST=[1<<50]*(n+1)\n\n checking=[(0,start)]\n MINCOST[start]=0\n\n j=0\n while j<k:\n if not(checking):\n break\n \n cost,checktown=heapq.heappop(checking)\n if cost>=-ANS[0]:\n break\n\n if MINCOST[checktown]<cost:\n continue\n \n if cost!=0 and checktown>start:\n heapq.heappop(ANS)\n heapq.heappush(ANS,-cost)\n j+=1\n \n for to,co in COST_vertex[checktown]:\n\n if MINCOST[to]>cost+co:\n MINCOST[to]=cost+co\n\n heapq.heappush(checking,(cost+co,to))\n\nprint(-ANS[0])\n \n \n", "import sys\ninput = sys.stdin.readline\nN, M, K = list(map(int, input().split()))\nX = []\nfor _ in range(M):\n x, y, w = list(map(int, input().split()))\n X.append([min(x,y), max(x,y), w])\nX = (sorted(X, key = lambda x: x[2])+[[0, 0, 10**20] for _ in range(K)])[:K]\nD = {}\nfor x, y, w in X:\n if x: D[x*10**6+y] = w\n\nflg = 1\nwhile flg:\n flg = 0\n for i in range(len(X)):\n x1, y1, w1 = X[i]\n for j in range(i+1, len(X)):\n x2, y2, w2 = X[j]\n if x1==x2: a, b = min(y1,y2), max(y1,y2)\n elif y1==y2: a, b = min(x1,x2), max(x1,x2)\n elif x1==y2: a, b = x2, y1\n elif x2==y1: a, b = x1, y2\n else: a, b = 0, 0\n if a:\n if (a*10**6+b in D and w1+w2 < D[a*10**6+b]) or (a*10**6+b not in D and w1+w2 < X[-1][2]):\n if a*10**6+b in D:\n for k in range(len(X)):\n if X[k][0] == a and X[k][1] == b:\n X[k][2] = w1+w2\n else:\n x, y, w = X.pop()\n if x: D.pop(x*10**6+y)\n X.append([a,b,w1+w2])\n D[a*10**6+b] = w1+w2\n X = sorted(X, key = lambda x: x[2])\n flg = 1\n break\n if flg:\n break\nprint(X[-1][2])\n", "import sys\ninput = sys.stdin.readline\nN, M, K = list(map(int, input().split()))\nX = []\nfor _ in range(M):\n x, y, w = list(map(int, input().split()))\n X.append([min(x,y), max(x,y), w])\nX = (sorted(X, key = lambda x: x[2])+[[0, 0, 10**20] for _ in range(K)])[:K]\nD = {}\nfor x, y, w in X:\n if x: D[x*10**6+y] = w\n\nflg = 1\nwhile flg:\n flg = 0\n for i in range(len(X)):\n x1, y1, w1 = X[i]\n for j in range(i+1, len(X)):\n x2, y2, w2 = X[j]\n if x1==x2: a, b = min(y1,y2), max(y1,y2)\n elif y1==y2: a, b = min(x1,x2), max(x1,x2)\n elif x1==y2: a, b = x2, y1\n elif x2==y1: a, b = x1, y2\n else: a, b = 0, 0\n if a:\n if (a*10**6+b in D and w1+w2 < D[a*10**6+b]) or (a*10**6+b not in D and w1+w2 < X[-1][2]):\n if a*10**6+b in D:\n for k in range(len(X)):\n if X[k][0] == a and X[k][1] == b:\n X[k][2] = w1+w2\n else:\n x, y, w = X.pop()\n if x: D.pop(x*10**6+y)\n X.append([a,b,w1+w2])\n D[a*10**6+b] = w1+w2\n X = sorted(X, key = lambda x: x[2])\n flg = 1\nprint(X[-1][2])\n", "import heapq\nn,m,k = list(map(int,input().split()))\nconnectionList = []\nfor _ in range(n):\n connectionList.append([])\nedgeList = []\nfor _ in range(m):\n x,y,w = list(map(int,input().split()))\n edgeList.append((x,y,w))\nedgeList.sort(key = lambda x: x[2])\nif k < m:\n maxDist = edgeList[min(m,k) - 1][2]\nelse:\n maxDist = sum([x[2] for x in edgeList])\ncolorList = {}\ncolorVertex = []\nfor i in range(n):\n colorList[i] = [i]\n colorVertex.append(i)\n\nfor i in range(min(m,k)):\n x,y,w = edgeList[i]\n connectionList[x-1].append((y-1,w))\n connectionList[y-1].append((x-1,w))\n if colorVertex[x-1] != colorVertex[y-1]:\n if len(colorList[colorVertex[x-1]]) >= len(colorList[colorVertex[y-1]]):\n prevColor = colorVertex[y-1]\n for elem in colorList[colorVertex[y-1]]:\n colorVertex[elem] = colorVertex[x-1]\n colorList[colorVertex[x-1]].append(elem)\n del colorList[prevColor]\n else:\n prevColor = colorVertex[x-1]\n for elem in colorList[colorVertex[x-1]]:\n colorVertex[elem] = colorVertex[y-1]\n colorList[colorVertex[y-1]].append(elem)\n del colorList[prevColor]\n\npathList = []\nfor key in colorList:\n vertexList = colorList[key]\n for mainVertex in vertexList:\n vertexPQueue = []\n isCovered = {}\n distanceDic = {}\n for elem in vertexList:\n isCovered[elem] = False\n distanceDic[elem] = maxDist\n isCovered[mainVertex] = True\n for elem in connectionList[mainVertex]:\n heapq.heappush(vertexPQueue,(elem[1],elem[0]))\n distanceDic[elem[0]] = elem[1]\n while vertexPQueue:\n distance, curVertex = heapq.heappop(vertexPQueue)\n if isCovered[curVertex]:\n continue\n elif distance >= maxDist:\n break\n for elem in connectionList[curVertex]:\n if distance + elem[1] < distanceDic[elem[0]]:\n heapq.heappush(vertexPQueue,(distance + elem[1],elem[0]))\n distanceDic[elem[0]] = distance + elem[1]\n for key in distanceDic:\n if distanceDic[key] <= maxDist and key > mainVertex:\n pathList.append(distanceDic[key])\n if len(pathList) > k:\n pathList.sort()\n pathList = pathList[0:k]\n if pathList[-1] < maxDist:\n maxDist = pathList[-1]\npathList.sort()\nprint(pathList[k-1])\n \n \n"] | {
"inputs": [
"6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n",
"7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5 5\n3 7 9\n4 1 8\n2 1 1\n",
"8 7 19\n1 2 1000000000\n2 3 999999999\n3 4 999999998\n4 5 999999997\n5 6 999999996\n6 7 999999995\n7 8 999999994\n",
"2 1 1\n1 2 123456789\n",
"28 27 378\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 1000000000\n8 9 1000000000\n9 10 1000000000\n10 11 1000000000\n11 12 1000000000\n12 13 1000000000\n13 14 1000000000\n14 15 1000000000\n15 16 1000000000\n16 17 1000000000\n17 18 1000000000\n18 19 1000000000\n19 20 1000000000\n20 21 1000000000\n21 22 1000000000\n22 23 1000000000\n23 24 1000000000\n24 25 1000000000\n25 26 1000000000\n26 27 1000000000\n27 28 1000000000\n"
],
"outputs": [
"3\n",
"9\n",
"3999999982\n",
"123456789\n",
"27000000000\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,842 | |
d3d6a9b4a86a3c94744618f68405eda8 | UNKNOWN | There are $n$ students at your university. The programming skill of the $i$-th student is $a_i$. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has $2 \cdot 10^5$ students ready for the finals!
Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of $k$ students with programming skills $a[i_1], a[i_2], \dots, a[i_k]$, then the diversity of this team is $\max\limits_{j=1}^{k} a[i_j] - \min\limits_{j=1}^{k} a[i_j]$).
The total diversity is the sum of diversities of all teams formed.
Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.
-----Input-----
The first line of the input contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) β the number of students.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the programming skill of the $i$-th student.
-----Output-----
In the first line print two integers $res$ and $k$ β the minimum total diversity of the division of students and the number of teams in your division, correspondingly.
In the second line print $n$ integers $t_1, t_2, \dots, t_n$ ($1 \le t_i \le k$), where $t_i$ is the number of team to which the $i$-th student belong.
If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.
-----Examples-----
Input
5
1 1 3 4 2
Output
3 1
1 1 1 1 1
Input
6
1 5 12 13 2 15
Output
7 2
2 2 1 1 2 1
Input
10
1 2 5 129 185 581 1041 1909 1580 8150
Output
7486 3
3 3 3 2 2 2 2 1 1 1
-----Note-----
In the first example, there is only one team with skills $[1, 1, 2, 3, 4]$ so the answer is $3$. It can be shown that you cannot achieve a better answer.
In the second example, there are two teams with skills $[1, 2, 5]$ and $[12, 13, 15]$ so the answer is $4 + 3 = 7$.
In the third example, there are three teams with skills $[1, 2, 5]$, $[129, 185, 581, 1041]$ and $[1580, 1909, 8150]$ so the answer is $4 + 912 + 6570 = 7486$. | ["import sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nB=[(a,ind) for ind,a in enumerate(A)]\nB.sort()\n \nDP=[0]*(n+1)\n\nfor i in range(3,n-2):\n DP[i]=max(DP[i-1],DP[i-3]+B[i][0]-B[i-1][0])\n\n#print(DP)\n\nMAX=max(DP)\n\nx=DP.index(MAX)\n\nREMLIST=[]\n\nwhile x>0:\n if DP[x]==DP[x-1]:\n x-=1\n else:\n REMLIST.append(x)\n x-=3\n\nREMLIST.sort()\nREMLIST.append(1<<60)\n\nprint(max(A)-min(A)-MAX,len(REMLIST))\n\nANS=[-1]*n\nremind=0\nNOW=1\n\nfor i in range(n):\n if i==REMLIST[remind]:\n NOW+=1\n remind+=1\n ANS[B[i][1]]=NOW\nprint(*ANS)\n\n\n", "n = int(input())\nl = list(map(int,input().split()))\na = [[l[i], i] for i in range(n)]\na.sort()\nll = l.copy()\nll.sort()\nif n < 6:\n\tprint(a[-1][0] - a[0][0], 1)\n\tprint(*([1] * n))\nelse:\n\tb = [ll[i] - ll[i-1] for i in range(3, n - 2)]\n\t#wybieramy najwieksza sume z b ale nie moge wybrac ziomow o mniej niz 2 od siebie\n\tdp = [[0,0] for i in range(len(b) + 5)]\n\ti = len(b) - 1\n\tdp[i] = [0, b[i]]\n\twhile i >= 0:\n\t\tdp[i][0] = max(dp[i+1])\n\t\tdp[i][1] = max(dp[i+3]) + b[i]\n\t\ti-=1\n\todp = []\n\ti = 0\n\twhile True:\n\t\tif dp[i] == [0,0]:\n\t\t\tbreak\n\t\tif dp[i][1] > dp[i][0]:\n\t\t\todp.append(i)\n\t\t\ti += 3\n\t\telse:\n\t\t\ti += 1\n\todp = [i+3 for i in odp]\n\tgrupy = [0] * n\n\tgrupa = 1\n\twsk = 0\n\tfor i in range(n):\n\t\tif wsk <= len(odp)-1:\n\t\t\tif i == odp[wsk]:\n\t\t\t\twsk += 1\n\t\t\t\tgrupa += 1\n\t\tgrupy[a[i][1]] = grupa\n\tprint(ll[-1] - ll[0] - max(dp[0]), grupa)\n\tprint(*grupy)", "n=int(input())\na=sorted((int(v),i) for i,v in enumerate(input().split()))\nINF=10**18\ndp=[-INF,-INF,0]\nfor i in range(n-1):\n dp.append(max(dp[-1],dp[i]+a[i+1][0]-a[i][0]))\ncur,t = n-1,1\no=[0]*n\nwhile cur >= 0:\n if dp[cur] == dp[cur-1]:\n o[a[cur][1]] = t\n cur -= 1\n else:\n o[a[cur][1]] = o[a[cur-1][1]] = o[a[cur-2][1]] = t\n cur -= 3\n t += 1\nprint(a[-1][0] - a[0][0] - dp[n-1], t-1)\nprint(*o)", "n=int(input())\na=sorted((int(v),i) for i,v in enumerate(input().split()))\nINF=10**18\ndp=[-INF,-INF,0]\nfor i in range(n-1):\n dp.append(max(dp[-1],dp[i]+a[i+1][0]-a[i][0]))\ncur,t = n-1,1\no=[0]*n\nwhile cur >= 0:\n if dp[cur] == dp[cur-1]:\n o[a[cur][1]] = t\n cur -= 1\n else:\n o[a[cur][1]] = o[a[cur-1][1]] = o[a[cur-2][1]] = t\n cur -= 3\n t += 1\nprint(a[-1][0] - a[0][0] - dp[n-1], t-1)\nprint(*o)", "n=int(input())\na=sorted((int(v),i) for i,v in enumerate(input().split()))\nINF=10**18\ndp=[-INF,-INF,0]\nfor i in range(n-1):\n dp.append(max(dp[-1],dp[i]+a[i+1][0]-a[i][0]))\ncur,t = n-1,1\no=[0]*n\nwhile cur >= 0:\n if dp[cur] == dp[cur-1]:\n o[a[cur][1]] = t\n cur -= 1\n else:\n o[a[cur][1]] = o[a[cur-1][1]] = o[a[cur-2][1]] = t\n cur -= 3\n t += 1\nprint(a[-1][0] - a[0][0] - dp[n-1], t-1)\nprint(*o)", "n=int(input())\na=sorted((int(v),i) for i,v in enumerate(input().split()))\nINF=10**18\ndp=[-INF,-INF,0]\nfor i in range(n-1):\n dp.append(max(dp[-1],dp[i]+a[i+1][0]-a[i][0]))\ncur,t = n-1,1\no=[0]*n\nwhile cur >= 0:\n if dp[cur] == dp[cur-1]:\n o[a[cur][1]] = t\n cur -= 1\n else:\n o[a[cur][1]] = o[a[cur-1][1]] = o[a[cur-2][1]] = t\n cur -= 3\n t += 1\nprint(a[-1][0] - a[0][0] - dp[n-1], t-1)\nprint(*o)"] | {
"inputs": [
"5\n1 1 3 4 2\n",
"6\n1 5 12 13 2 15\n",
"10\n1 2 5 129 185 581 1041 1909 1580 8150\n",
"6\n1 1 2 2 3 3\n",
"10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n"
],
"outputs": [
"3 1\n1 1 1 1 1 \n",
"7 2\n2 2 1 1 2 1 \n",
"7486 3\n3 3 3 2 2 2 2 1 1 1 \n",
"2 1\n1 1 1 1 1 1 \n",
"0 1\n1 1 1 1 1 1 1 1 1 1 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 3,408 | |
aac92eb2ab310c0ab9df061b48fa3ad6 | UNKNOWN | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from $1$ to $9$ (inclusive) are round.
For example, the following numbers are round: $4000$, $1$, $9$, $800$, $90$. The following numbers are not round: $110$, $707$, $222$, $1001$.
You are given a positive integer $n$ ($1 \le n \le 10^4$). Represent the number $n$ as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number $n$ as a sum of the least number of terms, each of which is a round number.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is a line containing an integer $n$ ($1 \le n \le 10^4$).
-----Output-----
Print $t$ answers to the test cases. Each answer must begin with an integer $k$ β the minimum number of summands. Next, $k$ terms must follow, each of which is a round number, and their sum is $n$. The terms can be printed in any order. If there are several answers, print any of them.
-----Example-----
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | ["for _ in range(int(input())):\n n = int(input())\n # arr = list(map(int, input().split()))\n # n, m = map(int, input().split())\n arr = []\n x = 1\n while n > 0:\n if (n % 10):\n arr.append((n % 10) * x)\n n //= 10\n x *= 10\n print(len(arr))\n print(*arr)", "t = int(input())\nfor _ in range(t):\n\ts = input()\n\tn = len(s)\n\tans = []\n\tfor i in range(n):\n\t\tif s[i] != \"0\":\n\t\t\tans.append(s[i] + \"0\" * (n-1-i))\n\tprint(len(ans))\n\tprint(*ans)", "for _ in range(int(input())):\n s = input()\n\n print(len(s.replace('0', '')))\n\n for i, j in enumerate(s[::-1]):\n if j != '0':\n print(j + '0' * i, end=' ')\n\n print()", "for t in range(int(input())):\n st = input()\n k = len(st) - 1\n ans = []\n for i in st:\n if i != '0':\n ans.append(i + '0' * k)\n k -= 1\n print(len(ans))\n print(*ans)", "for _ in range(int(input())):\n n = list(map(int, input()))\n ans = []\n for i in range(len(n)):\n x = str(n[i]) + '0' * (len(n) - i - 1)\n x = int(x)\n if x != 0:\n ans.append(x)\n print(len(ans))\n print(*ans)", "from math import *\n\nfor zz in range(int(input())):\n n = int(input())\n cp = 10\n ans = []\n while n > 0:\n t = (n % cp) - n % (cp//10)\n if t > 0:\n ans.append(t)\n n -= t\n cp *= 10\n #print(n, t, cp)\n\n print(len(ans))\n print(*ans)\n", "'''input\n5\n5009\n7\n9876\n10000\n10\n'''\ndef solve():\n\ts = input()\n\tln = len(s)\n\tans = []\n\tfor i in s:\n\t\tnum = int(i+(ln-1)*'0')\n\t\tif num!=0:\n\t\t\tans.append(num)\n\t\tln-=1\n\tprint(len(ans))\n\tfor i in ans:\n\t\tprint(i,end=\" \")\n\tprint()\n\treturn \nt = 1\nt = int(input())\nwhile t>0:\n\tt-=1\n\tsolve()", "\n\nfor _ in range(int(input())):\n\ts=input()\n\tprint(len(s)-s.count('0'))\n\n\tn=int(s)\n\tpw=1\n\twhile(n):\n\t\tif(n%10):\n\t\t\tprint(pw*(n%10),end=\" \")\n\t\tn//=10\n\t\tpw*=10\n\tprint()", "for _ in range(int(input())):\n s=input()\n n=len(s)-1\n k=0\n a=[]\n for x in s:\n if x!=\"0\":\n k+=1\n a.append(x+\"0\"*n)\n n-=1\n print(k)\n print(*a)\n", "for _ in range(int(input())):\n\tn = int(input())\n\tl = []\n\ti = 0\n\twhile n:\n\t\tif n % 10:\n\t\t\tl.append((n % 10) * 10 ** i)\n\t\ti += 1\n\t\tn //= 10\n\tprint(len(l))\n\tprint(*l)\n", "import math,sys\nfrom sys import stdin, stdout\nfrom collections import Counter, defaultdict, deque\ninput = stdin.readline\nI = lambda:int(input())\nli = lambda:list(map(int,input().split()))\n\ndef case():\n n=input().strip()\n ans=[]\n for i in range(len(n)):\n if(n[i]!=\"0\"):\n ans.append(n[i]+\"0\"*(len(n)-i-1))\n print(len(ans))\n print(*ans)\n\nfor _ in range(int(input())):\n case()", "for _ in range(int(input())):\n n = int(input())\n l = []\n for i in str(n):\n l.append(i)\n ans = []\n l = l[-1::-1]\n cnt = 0\n for i in l:\n if i!='0':\n ans.append(int(i)*pow(10,cnt))\n cnt+=1\n else:\n cnt+=1\n print(len(ans))\n print(*ans)\n # print(l) \n", "import sys\nfrom functools import lru_cache, cmp_to_key\nfrom heapq import merge, heapify, heappop, heappush, nlargest, nsmallest\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque, Counter as C\nfrom itertools import combinations as comb, permutations as perm\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nfrom time import perf_counter\nfrom fractions import Fraction\n# sys.setrecursionlimit(pow(10, 6))\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"output.txt\", \"w\")\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef data(): return sys.stdin.readline().strip()\ndef out(*var, end=\"\\n\"): sys.stdout.write(\" \".join(map(str, var))+end)\ndef l(): return list(sp())\ndef sl(): return list(ssp())\ndef sp(): return list(map(int, data().split()))\ndef ssp(): return list(map(str, data().split()))\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\n\n\nfor _ in range(int(data())):\n n = data()\n answer = []\n i = 0\n while i < len(n):\n if n[i] != '0':\n answer.append(int(n[i]) * pow(10, len(n)-i-1))\n i += 1\n out(len(answer))\n out(*answer)\n", "for nt in range(int(input())):\n\tn=int(input())\n\tif n>=1 and n<=9:\n\t\tprint (1)\n\t\tprint (n)\n\t\tcontinue\n\ts=str(n)\n\tcount=0\n\tans=[]\n\tfor i in range(len(s)):\n\t\tif s[i]!=\"0\":\n\t\t\tcount+=1\n\t\t\tans.append(s[i]+\"0\"*(len(s)-i-1))\n\tprint (count)\n\tprint (*ans)", "for t in range(int(input())):\n n = input()\n ans = [n[i] + \"0\" * (len(n) - i - 1) for i in range(len(n)) if n[i] != \"0\"]\n print(len(ans))\n print(\" \".join(ans))\n", "t = int(input())\nfor i in range(t):\n n = input()\n print(len(n) - n.count('0'))\n for j in range(len(n)):\n if n[j] != '0':\n print(n[j], '0' * (len(n) - j - 1),end=' ', sep='')\n print()", "t = int(input())\nfor y in range(t):\n\tn = input()\n\tans = []\n\tm = len(n)\n\tfor i in range(m):\n\t\tif n[i] != '0':\n\t\t\tans.append(int(n[i])*pow(10,m-i-1))\n\tprint(len(ans))\n\tprint(*ans)\n\n", "from sys import stdin, stdout \n#input = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n x = input()\n res = []\n for ind, i in enumerate(x):\n if i != '0':\n res.append(i + '0' * (len(x) - ind - 1))\n print(len(res))\n print(*res)\n", "t = int(input())\nfor tests in range(t):\n n = input()\n x = len(n)\n print(x - n.count('0'))\n for i in range(x):\n if n[i] != '0':\n print(n[i] + '0'* (x - i - 1), end =' ')\n print()\n", "def sol():\n x=int(input())\n res=[]\n pw=0\n while x>0:\n p=x%10\n if p>0:\n d=p*(10**pw)\n res.append(d)\n pw+=1\n x//=10\n\n print(len(res))\n print(*res)\n\nfor n in range(int(input())):\n sol()\n", "def read_int():\n return int(input())\n\n\ndef read_ints():\n return list(map(int, input().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n n = read_int()\n ans = []\n s = str(n)\n l = len(s)\n for i in range(l):\n if s[-i-1] != '0':\n ans.append(int(s[-i-1]) * (10 ** i))\n print(len(ans))\n print(' '.join(map(str, ans)))\n", "import math as mt \nimport sys,string\ninput=sys.stdin.readline\nimport random\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : list(map(int,input().split()))\nI=lambda :int(input())\nt=I()\nfor i in range(t):\n n=input().strip()\n k=len(n)-1\n l=[]\n for i in range(len(n)):\n if(n[i]!='0'):\n l.append(int(n[i])*pow(10,k))\n k-=1\n print(len(l))\n print(*l)\n", "import sys\nreadline = sys.stdin.readline\n\nt = int(input())\nfor _ in range(t):\n n = readline().rstrip()\n ans = []\n for i, c in zip(list(range(100)), reversed(n)):\n if c != '0':\n ans.append(c + '0'*i)\n print(len(ans))\n print(*ans)\n", "t = int(input())\nfor i in range(t):\n n = input()\n k = []\n for i in range(len(n)):\n if n[i] != \"0\":\n k.append(int(n[i])*10**(len(n)-i-1))\n print(len(k))\n print(*k)"] | {
"inputs": [
"5\n5009\n7\n9876\n10000\n10\n",
"7\n1\n1\n1\n1\n1\n1\n1\n",
"2\n9999\n52\n",
"2\n999\n52\n",
"2\n954\n18\n"
],
"outputs": [
"2\n9 5000 \n1\n7 \n4\n6 70 800 9000 \n1\n10000 \n1\n10 \n",
"1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n",
"4\n9 90 900 9000 \n2\n2 50 \n",
"3\n9 90 900 \n2\n2 50 \n",
"3\n4 50 900 \n2\n8 10 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 7,571 | |
b8168ed5122f526db9c3fc82dd9c662b | UNKNOWN | The only difference between easy and hard versions is constraints.
There are $n$ kids, each of them is reading a unique book. At the end of any day, the $i$-th kid will give his book to the $p_i$-th kid (in case of $i = p_i$ the kid will give his book to himself). It is guaranteed that all values of $p_i$ are distinct integers from $1$ to $n$ (i.e. $p$ is a permutation). The sequence $p$ doesn't change from day to day, it is fixed.
For example, if $n=6$ and $p=[4, 6, 1, 3, 5, 2]$ then at the end of the first day the book of the $1$-st kid will belong to the $4$-th kid, the $2$-nd kid will belong to the $6$-th kid and so on. At the end of the second day the book of the $1$-st kid will belong to the $3$-th kid, the $2$-nd kid will belong to the $2$-th kid and so on.
Your task is to determine the number of the day the book of the $i$-th child is returned back to him for the first time for every $i$ from $1$ to $n$.
Consider the following example: $p = [5, 1, 2, 4, 3]$. The book of the $1$-st kid will be passed to the following kids: after the $1$-st day it will belong to the $5$-th kid, after the $2$-nd day it will belong to the $3$-rd kid, after the $3$-rd day it will belong to the $2$-nd kid, after the $4$-th day it will belong to the $1$-st kid.
So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 200$) β the number of queries. Then $q$ queries follow.
The first line of the query contains one integer $n$ ($1 \le n \le 200$) β the number of kids in the query. The second line of the query contains $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$, all $p_i$ are distinct, i.e. $p$ is a permutation), where $p_i$ is the kid which will get the book of the $i$-th kid.
-----Output-----
For each query, print the answer on it: $n$ integers $a_1, a_2, \dots, a_n$, where $a_i$ is the number of the day the book of the $i$-th child is returned back to him for the first time in this query.
-----Example-----
Input
6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
Output
1 1 1 1 1
3 3 3
2 3 3 2 1 3
1
2 2 2 2
4 4 4 1 4 | ["for _ in range(int(input())):\n n = int(input())\n P = list(map(int, input().split()))\n ans = [0] * n\n for i in range(n):\n if ans[i] == 0:\n now = i\n cnt = 0\n cll = []\n while True:\n now = P[now] - 1\n cnt += 1\n cll.append(now)\n if now == i:\n break\n for u in cll:\n ans[u] = cnt\n print(' '.join(list(map(str, ans))))", "t = int(input())\nfor _ in range(t):\n n = int(input())\n p = list(map(int, input().split()))\n ans = [-1] * n\n for i in range(n):\n if ans[i] != -1:\n continue\n memo = {}\n tmp = i\n memo[tmp] = 1\n cnt = 1\n while True:\n tmp = p[tmp] - 1\n if tmp in memo:\n break\n else:\n memo[tmp] = 1\n cnt += 1\n for i in memo:\n ans[tmp] = cnt\n print(*ans)\n", "# !/usr/bin/env python3\n# encoding: UTF-8\n# Last Modified: 22/Oct/2019 08:13:15 PM\n\n\nimport sys\n\n\ndef main():\n for tc in range(int(input())):\n n = int(input())\n arr = get_array()\n ans = [1] * n\n for i in range(n):\n j = arr[i] - 1\n while j != i:\n ans[i] += 1\n j = arr[j] - 1\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()", "from math import *\nt = int(input())\nfor y in range(t):\n n = int(input())\n a = list(map(int,input().split()))\n for i in range(n):\n j = i\n ct = 0\n while(i != a[j]-1):\n j = a[j]-1\n ct += 1\n print(ct+1,end = \" \")\n print()", "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())\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n for i in range(n):\n a[i]-=1\n col = [0 for i in range(n)]\n c = 1\n for i in range(n):\n if not col[i]:\n s = i\n while col[s] == 0:\n col[s] = c\n s = a[s]\n c+=1\n d = defaultdict(int)\n for i in col:\n d[i]+=1\n ans = [0 for i in range(n)]\n for i in range(n):\n ans[i] = d[col[i]]\n print(*ans)", "q=int(input())\nfor _ in range(q):\n n=int(input())\n it=list(map(int,input().split()))\n cu=[i+1 for i in range(n)]\n ans=[10**9 for i in range(n)]\n j=1\n while 10**9 in ans:\n cc=cu[:]\n for i in range(n):\n cu[it[i]-1]=cc[i]\n for i in range(n):\n if cu[i]==i+1:\n ans[i]=min(ans[i],j)\n j+=1\n print(*ans)\n \n", "for _ in range(int(input())):\n n = int(input())\n p = [0] + list(map(int, input().split()))\n array = []\n for i in range(1, n + 1):\n c = 1\n k = p[i]\n while k != i:\n k = p[k]\n c += 1\n array.append(c)\n print (*array)", "tc = int(input())\n\nwhile tc > 0:\n\ttc -= 1\n\tn = int(input())\n\tp = [0] + list(map(int, input().split()))\n\n\tans = [0] * (n + 1)\n\tmk = [False] * (n + 1)\n\n\tfor i in range(1 , n + 1):\n\t\tif not mk[i]:\n\t\t\tsz = 1\n\t\t\tcurr = p[i]\n\t\t\tmk[i] = True\n\t\t\twhile curr != i:\n\t\t\t\tsz += 1\n\t\t\t\tmk[curr] = True\n\t\t\t\tcurr = p[curr]\n\n\t\t\tans[i] = sz\n\t\t\tcurr = p[i]\n\t\t\twhile curr != i:\n\t\t\t\tans[curr] = sz\n\t\t\t\tcurr = p[curr]\n\n\tprint(\" \".join([str(x) for x in ans[1:]]))\n\n\n", "t = int(input())\nfor _ in range(t):\n n = int(input())\n p = list(map(int, input().split()))\n ans = [-1] * n\n for i in range(n):\n if ans[i] != -1:\n continue\n memo = {}\n tmp = i\n memo[tmp] = 1\n cnt = 1\n while True:\n tmp = p[tmp] - 1\n if tmp in memo:\n break\n else:\n memo[tmp] = 1\n cnt += 1\n for j in memo:\n ans[j] = cnt\n print(*ans)\n", "t=int(input())\nwhile t:\n n=int(input())\n l=list(map(int,input().split()))\n for i in l:\n aa=i\n a=i\n d=0\n while 1:\n a=l[a-1]\n d+=1\n if(a==aa):\n break\n print(d,end=\" \")\n print()\n t-=1", "q = int(input())\nfor i in range(q):\n a = int(input())\n cycle = [1 for i in range(a)]\n\n tab = list(map(int, input().split()))\n\n for indice, j in enumerate(tab):\n var = indice +1\n\n while tab[var-1] != indice+1:\n var = tab[var-1]\n cycle[indice] += 1\n \n print(*cycle)", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n for i in range(n):\n a[i] -= 1\n for i in range(n):\n ans = 0\n x = a[i]\n while x != i:\n ans += 1\n x = a[x]\n print(ans + 1, end=\" \")\n print()\n", "import sys\ninput = sys.stdin.readline\n\nq=int(input())\n\ndef find(x):\n while Group[x] != x:\n x=Group[x]\n return x\n\ndef Union(x,y):\n if find(x) != find(y):\n Group[find(y)]=Group[find(x)]=min(find(y),find(x))\n\nfor testcases in range(q):\n n=int(input())\n P=list(map(int,input().split()))\n\n Group=[i for i in range(n)]\n\n for i in range(n):\n Union(i,P[i]-1)\n\n G=[find(i) for i in range(n)]\n\n count=[0]*n\n\n for g in G:\n count[g]+=1\n\n for i in range(n):\n print(count[G[i]],end=\" \")\n print()\n\n\n\n \n", "Q = int(input())\nfor q in range(Q):\n\tN = int(input())\n\tP = list(map(int, input().split()))\n\tout = []\n\ti = 1\n\tfor p in P:\n\t\to = 1\n\t\twhile p != i:\n\t\t\tp = P[p-1]\n\t\t\to += 1\n\t\tout.append(str(o))\n\t\ti += 1\n\tprint(\" \".join(out))", "q = int(input())\nfor i in range(q):\n n = int(input())\n a = [int(i) for i in input().split()]\n ans = [0] * n\n for i in range(n):\n now = a[a[i] - 1]\n count = 1\n while now != a[i]:\n now = a[now - 1]\n count += 1\n ans[i] = count\n print(*ans)", "def __starting_point():\n\n q = int(input())\n\n for t in range(q):\n n = int(input())\n l = [int(i) for i in input().split(\" \")]\n\n flag = True\n ans = []\n\n for i in range(1, len(l) + 1):\n j = l[i - 1]\n count = 1\n\n while j != i:\n j = l[j-1]\n count += 1\n ans.append(count)\n\n for i in ans:\n print(i, end=' ')\n print()\n\n__starting_point()", "T=int(input())\nwhile(T>0):\n n=int(input())\n p=[(int(i)-1) for i in input().split()]\n #print(p)\n ans=[]\n for i in range(0,n):\n curr=i\n count=1\n next=p[curr]\n while(next!=curr):\n next=p[next]\n count+=1\n ans.append(count)\n for i in range(0,len(ans)):\n print(ans[i],end=' ')\n print()\n T-=1", "N = []\nAA = []\nt = int(input())\nfor i in range(t):\n N.append(int(input()))\n a = list(map(int,input().split()))\n for j in range(len(a)):\n a[j] -= 1\n AA.append(a)\n\nfor i in range(t):\n n = N[i]\n A = AA[i]\n ans = [0] * n\n for j in range(n):\n c = 1\n b = A[j]\n while b != j:\n b = A[b]\n c += 1\n ans[j] = c\n print(\" \".join([str(i) for i in ans]))", "import sys\ndef I():\n return sys.stdin.readline().rstrip()\nq = int( I() )\nfor _ in range( q ):\n n = int( I() )\n c = [ -1 ] * n\n def getp( i ):\n s = []\n while c[ i ] >= 0:\n s.append( i )\n i = c[ i ]\n for j in s:\n c[ j ] = i\n return i\n p = list( map( int, I().split() ) )\n p = [ i - 1 for i in p ]\n for i, q in enumerate( p ):\n a, b = getp( i ), getp( q )\n if a != b:\n c[ a ] += c[ b ]\n c[ b ] = a\n for i in p:\n print( -c[ getp( i ) ], end = \" \" )\n print()\n", "q = int(input())\nfor i in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n b = [-1 for i in range(n)]\n c = [0 for i in range(n + 2)]\n used = [True for i in range(n)]\n for i in range(n):\n if used[i]:\n d = a[i] - 1\n cell = a[i] - 1\n b[cell] = d\n c[d] += 1\n used[cell] = False\n while cell != i:\n cell = a[cell] - 1\n c[d] += 1\n b[cell] = d\n used[cell] = False\n for i in range(n):\n print(c[b[i]], end=\" \")\n print()", "#n = int(input())\n#a = [int(x) for x in input().split()]\n\nq = int(input())\n\n\ndef solve():\n n = int(input())\n p = [int(x) for x in input().split()]\n days = [0] * n\n d = 0\n for i in range(n):\n d = 0\n j = p[i] - 1\n d += 1\n while(j != i):\n d += 1\n j = p[j] - 1\n days[i] = str(d)\n print(' '.join(days))\nfor _ in range(q):\n solve()", "import sys,math,string,bisect\ninput=sys.stdin.readline\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : list(map(int,input().split()))\nI=lambda :int(input())\nn=int(input())\nfor _ in range(n):\n k=I()\n g=[]\n l=[0]+L()\n for i in range(1,k+1):\n s=i\n c=1\n while(l[s]!=i):\n s=l[s]\n c+=1\n g.append(c)\n print(*g)\n \n", "import sys\ninput=sys.stdin.readline\nq=int(input())\nfor _ in range(q):\n n=int(input())\n a=list(map(int,input().split()))\n ans=[]\n for i in range(n):\n x=a[i]\n c=1\n while not (i+1)==x:\n x=a[x-1]\n c+=1\n ans.append(c)\n print(*ans)\n"] | {
"inputs": [
"6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3\n",
"1\n3\n1 2 3\n",
"20\n10\n3 8 1 4 9 6 10 2 7 5\n10\n10 4 8 6 5 3 1 2 9 7\n1\n1\n2\n2 1\n10\n2 5 3 6 9 7 4 10 8 1\n10\n1 7 4 6 9 10 8 2 3 5\n8\n3 8 1 7 6 4 2 5\n8\n7 4 5 2 8 1 6 3\n5\n1 2 4 3 5\n6\n4 2 5 6 3 1\n5\n5 3 2 4 1\n5\n4 3 5 1 2\n7\n6 5 1 7 4 2 3\n6\n6 2 4 1 5 3\n3\n3 1 2\n4\n1 3 4 2\n3\n3 1 2\n6\n4 2 1 5 3 6\n9\n4 5 7 8 1 6 2 3 9\n2\n2 1\n",
"20\n5\n3 4 5 1 2\n6\n3 6 4 5 1 2\n4\n4 2 1 3\n5\n2 5 4 3 1\n6\n5 3 1 6 2 4\n2\n1 2\n4\n4 2 1 3\n9\n1 8 2 4 6 9 5 3 7\n8\n8 5 6 4 3 1 7 2\n4\n3 1 4 2\n2\n1 2\n4\n1 2 3 4\n2\n2 1\n3\n1 3 2\n8\n5 6 3 8 4 1 7 2\n5\n2 4 1 5 3\n5\n5 2 1 4 3\n7\n6 2 5 1 4 7 3\n7\n2 4 6 5 1 7 3\n7\n3 6 2 4 1 7 5\n",
"20\n6\n4 5 6 3 2 1\n7\n1 4 3 6 5 2 7\n10\n4 6 8 2 5 7 3 1 9 10\n6\n4 5 2 3 1 6\n2\n1 2\n7\n4 2 3 7 1 6 5\n10\n3 6 2 8 4 1 7 9 10 5\n3\n1 3 2\n4\n4 3 1 2\n2\n2 1\n1\n1\n1\n1\n5\n1 5 2 3 4\n9\n5 2 8 7 1 6 3 9 4\n6\n2 5 4 6 3 1\n3\n1 2 3\n7\n7 5 2 1 3 4 6\n1\n1\n3\n2 3 1\n7\n3 4 5 2 6 7 1\n"
],
"outputs": [
"1 1 1 1 1 \n3 3 3 \n2 3 3 2 1 3 \n1 \n2 2 2 2 \n4 4 4 1 4 \n",
"1 1 1 \n",
"2 2 2 1 4 1 4 2 4 4 \n3 5 5 5 1 5 3 5 1 3 \n1 \n2 2 \n6 6 1 3 6 3 3 6 6 6 \n1 3 6 6 6 6 3 3 6 6 \n2 6 2 6 6 6 6 6 \n3 2 3 2 3 3 3 3 \n1 1 2 2 1 \n3 1 2 3 2 3 \n2 2 2 1 2 \n2 3 3 2 3 \n7 7 7 7 7 7 7 \n4 1 4 4 1 4 \n3 3 3 \n1 3 3 3 \n3 3 3 \n4 1 4 4 4 1 \n7 7 7 7 7 1 7 7 1 \n2 2 \n",
"5 5 5 5 5 \n4 2 4 4 4 2 \n3 1 3 3 \n3 3 2 2 3 \n4 4 4 2 4 2 \n1 1 \n3 1 3 3 \n1 3 3 1 4 4 4 3 4 \n6 6 6 1 6 6 1 6 \n4 4 4 4 \n1 1 \n1 1 1 1 \n2 2 \n1 2 2 \n6 6 1 6 6 6 1 6 \n5 5 5 5 5 \n3 1 3 1 3 \n6 1 6 6 6 6 6 \n4 4 3 4 4 3 3 \n6 6 6 1 6 6 6 \n",
"4 2 4 4 2 4 \n1 3 1 3 1 3 1 \n7 7 7 7 1 7 7 7 1 1 \n5 5 5 5 5 1 \n1 1 \n4 1 1 4 4 1 4 \n4 4 4 5 5 4 1 5 5 5 \n1 2 2 \n4 4 4 4 \n2 2 \n1 \n1 \n1 4 4 4 4 \n2 1 5 5 2 1 5 5 5 \n6 6 6 6 6 6 \n1 1 1 \n4 3 3 4 3 4 4 \n1 \n3 3 3 \n5 2 5 2 5 5 5 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 10,363 | |
356f9a1ff1fe7409d2ffd80c444abbe8 | UNKNOWN | You are both a shop keeper and a shop assistant at a small nearby shop. You have $n$ goods, the $i$-th good costs $a_i$ coins.
You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all $n$ goods you have.
However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all $n$ goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.
So you need to find the minimum possible equal price of all $n$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 100$) β the number of queries. Then $q$ queries follow.
The first line of the query contains one integer $n$ ($1 \le n \le 100)$ β the number of goods. The second line of the query contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^7$), where $a_i$ is the price of the $i$-th good.
-----Output-----
For each query, print the answer for it β the minimum possible equal price of all $n$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
-----Example-----
Input
3
5
1 2 3 4 5
3
1 2 2
4
1 1 1 1
Output
3
2
1 | ["for _ in range(int(input())):\n n = int(input())\n A = list(map(int, input().split()))\n s = sum(A)\n print((s + n - 1) // n)", "import math\nimport itertools\nimport collections\n\ndef getdict(n):\n d = {}\n if type(n) is list or type(n) is str:\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 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 wr(arr): return ''.join(map(str, arr))\ndef revn(n): return int(str(n)[::-1])\ndef prime(n):\n if n == 2:\n return True\n if n % 2 == 0 or n <= 1:\n return False\n sqr = int(math.sqrt(n)) + 1\n for d in range(3, sqr, 2):\n if n % d == 0:\n return False\n return True\n\nq = ii()\nfor i in range(q):\n n = ii()\n a = li()\n print(math.ceil(sum(a)/n))", "# Contest: Codeforces Round #590 (Div. 3) (https://codeforces.com/contest/1234)\n# Problem: A: Equalize Prices Again (https://codeforces.com/contest/1234/problem/A)\n\ndef rint():\n return int(input())\n\n\ndef rints():\n return list(map(int, input().split()))\n\n\nq = rint()\nfor _ in range(q):\n n = rint()\n a = rints()\n print((sum(a) + n - 1) // n)\n", "#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())\nfor tt in range(t):\n n=int(input())\n #n,k,s= map(int, sys.stdin.readline().split(' '))\n a=list(map(int,sys.stdin.readline().split(' ')))\n s=sum(a)\n v=(s//n)\n if(v*n<s):\n v+=1\n print(v)\n \n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()", "def ii(): return int(input())\ndef fi(): return float(input())\ndef si(): return input()\ndef mi(): return map(int,input().split())\ndef li(): return list(mi())\n\nimport math\n\nq=ii()\nfor i in range(q):\n n=ii()\n a=li()\n s=sum(a)\n ans=math.ceil(s/n)\n print(ans)", "import math\nq = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts = sum(map(int, input().split()))\n\tprint(int(math.ceil(s / n)))\n\t\n", "import math\n\nq = int(input())\n\nfor _ in range(q):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\n\ts = sum(a)\n\n\tr = s/len(a)\n\tr = math.ceil(r)\n\n\tprint(r)", "a = int(input())\nfor i in range(a):\n b = int(input())\n l = list(map(int, input().split()))\n print((sum(l)+b-1)//b)", "q = int(input())\nfor i in range(q):\n n = int(input())\n a = list(map(int, input().split()))\n print((sum(a) + n - 1) // n)\n", "import math\nq=int(input())\nfor i in range(q):\n n=int(input())\n a=[int(x) for x in input().split()]\n print(math.ceil(sum(a)/n))\n", "for _ in range(int(input())):\n n = int(input())\n li = list(map(int, input().split()))\n print((sum(li) + n - 1) // n)", "\"\"\"\nNTC here\n\"\"\"\nfrom sys import setcheckinterval, stdin, setrecursionlimit\nsetcheckinterval(1000)\nsetrecursionlimit(10**7)\n \n# print(\"Case #{}: {} {}\".format(i, n + m, n * m))\n \n \ndef iin(): return int(stdin.readline())\n \n \ndef lin(): return list(map(int, stdin.readline().split()))\n\n\nfor _ in range(iin()):\n n=iin()\n a=lin()\n sm=sum(a)\n print((sm+n-1)//n)", "#\n# Yet I'm feeling like\n# \tThere is no better place than right by your side\n# \t\tI had a little taste\n# \t\t\tAnd I'll only spoil the party anyway\n# \t\t\t\t'Cause all the girls are looking fine\n# \t\t\t\t\tBut you're the only one on my mind\n\nimport sys\n# import re\ninf = float(\"inf\")\n# sys.setrecursionlimit(1000000)\n\n# abc='abcdefghijklmnopqrstuvwxyz'\n# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}\nmod,MOD=1000000007,998244353\n# vow=['a','e','i','o','u']\n# dx,dy=[-1,1,0,0,-1,1,-1,1],[0,0,1,-1,1,1,-1,-1]\n\n# from functools import reduce\n# from collections import deque, Counter, OrderedDict,defaultdict\n# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace\nfrom math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan\n# from bisect import bisect_left,bisect_right,insort_left\n# import numpy as np\n# import queue\n# from copy import deepcopy\n# import random\n# import operator\n\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\ndef input(): return sys.stdin.readline().strip()\n\nT=int(input())\nwhile T:\n n=int(input())\n Arr=get_array()\n s=sum(Arr)\n ans = ceil(s/n)\n print(ans)\n T-=1", "# import sys\n# sys.stdin = open(\"in.txt\", \"r\")\n\nt = int(input())\n\nfor i in range(t):\n n = int(input())\n arr = [ int(x) for x in input().split() ]\n s = sum(arr)\n avg = s // n\n if avg * n < s: avg += 1\n print(avg)", "import sys\ninput = sys.stdin.readline\n\nq=int(input())\n\nfor testcases in range(q):\n n=int(input())\n A=list(map(int,input().split()))\n\n print(-(-sum(A)//n))\n", "for _ in range(int(input())):\n n = int(input())\n a = sum(list(map(int, input().split())))\n\n print((a+n-1)//n)\n", "import math\nn = int(input())\nfor i in range(n):\n k = int(input())\n a = [int(i) for i in input().split()]\n print(math.ceil(sum(a) / k))", "import math\nfor i in range(int(input())):\n n = int(input())\n t = list(map(int, input().split()))\n print(math.ceil(sum(t)/n))", "\nq = int(input())\nfor _ in range(q):\n\n n = int(input())\n a = [int(x) for x in input().split()]\n print((sum(a)+n-1)//n)\n\n", "def mp():\n return map(int, input().split())\n\nq = int(input())\nfor qq in range(q):\n n = int(input())\n a = list(mp())\n s = sum(a)\n print((s + n - 1) // n)", "q = int(input())\nfor i in range(q):\n n = int(input())\n prices_sum = sum(list(map(int, input().split())))\n print(prices_sum // n + bool(prices_sum % n))\n", "for c in range(int(input())) :\n n = int(input())\n a = list(map(int, input().split()))\n tot = sum(a)\n print( (tot + n - 1) // n )\n", "from math import ceil\n\nfor i in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n x = sum(ar)\n if x % len(ar) == 0:\n print(x // len(ar))\n else:\n print(ceil(x / len(ar)))\n", "import io, sys, atexit, os\nimport math as ma\nfrom decimal import Decimal as dec\nfrom itertools import permutations\nfrom itertools import combinations\n\n\ndef li ():\n\treturn list (map (int, sys.stdin.readline ().split ()))\n\n\ndef num ():\n\treturn map (int, sys.stdin.readline ().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\ndef lcm ( x, y ):\n\tgg = find_gcd (x, y)\n\treturn (x * y // gg)\n\n\n\n\n\n\nmm = 1000000007\n\ndef solve ():\n\tt = nu()\n\tfor tt in range (t):\n\t\tn=nu()\n\t\ta=li()\n\t\ts=sum(a)\n\t\tprint(int(ma.ceil(s/n)))\n\n\n\n\n\n\n\n\n\n\n\n\n\ndef __starting_point():\n\tsolve ()\n__starting_point()"] | {
"inputs": [
"3\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\n",
"1\n2\n777 1\n",
"1\n1\n2441139\n",
"3\n5\n1 2 3 4 5\n3\n1 2 3\n2\n777 778\n",
"1\n2\n777 778\n"
],
"outputs": [
"3\n2\n1\n",
"389\n",
"2441139\n",
"3\n2\n778\n",
"778\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,009 | |
a43eef7662b83a4a0f42a2ea8a506579 | UNKNOWN | In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$.
A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a > r_b)$ and programmers $a$ and $b$ are not in a quarrel.
You are given the skills of each programmers and a list of $k$ pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer $i$, find the number of programmers, for which the programmer $i$ can be a mentor.
-----Input-----
The first line contains two integers $n$ and $k$ $(2 \le n \le 2 \cdot 10^5$, $0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$ β total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers $r_1, r_2, \dots, r_n$ $(1 \le r_i \le 10^{9})$, where $r_i$ equals to the skill of the $i$-th programmer.
Each of the following $k$ lines contains two distinct integers $x$, $y$ $(1 \le x, y \le n$, $x \ne y)$ β pair of programmers in a quarrel. The pairs are unordered, it means that if $x$ is in a quarrel with $y$ then $y$ is in a quarrel with $x$. Guaranteed, that for each pair $(x, y)$ there are no other pairs $(x, y)$ and $(y, x)$ in the input.
-----Output-----
Print $n$ integers, the $i$-th number should be equal to the number of programmers, for which the $i$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
-----Examples-----
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
-----Note-----
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel. | ["def ke(i):\n return a[i]\nn,m=map(int,input().split())\na=list(map(int,input().split()))\nb=[]\nfor i in range(n):\n b.append(i)\nb.sort(key=ke)\nans=[0]*n\nk=0\nfor i in range(1,n):\n if a[b[i]]==a[b[i-1]]:\n k+=1\n ans[b[i]]=i-k\n else:\n k=0\n ans[b[i]]=i\nfor i in range(m):\n r1,r2=map(int,input().split())\n if (a[r1-1]>a[r2-1]):\n ans[r1-1]-=1\n elif a[r1-1]<a[r2-1]:\n ans[r2-1]-=1\nfor i in ans:\n print(i, end=' ')", "T = input().split(' ')\nn = int(T[0])\nk = int(T[1])\nS = input().split(' ')\nfor i in range(len(S)):\n S[i] = (int(S[i]), i)\nQ = S.copy()\nS.sort()\nN = [0] * len(S)\ntot = 0\nfor i in range(1, len(S)):\n if S[i][0] == S[i-1][0]:\n tot+=1\n else:\n tot=0\n N[S[i][1]] = i-tot\nB = [0] * len(S)\nfor i in range(k):\n W = input().split(' ')\n a = int(W[0])\n b = int(W[1])\n if Q[a-1][0] > Q[b-1][0]:\n B[a-1] += 1\n if Q[b-1][0] > Q[a-1][0]:\n B[b-1] += 1\nfor i in range(len(S)-1):\n print(N[i] - B[i], end=' ')\nprint(N[n-1] - B[n-1])\n", "n, k = list(map(int, input().split()))\nar = list(map(int, input().split()))\n\ncross = [0] * n\nres = [0] * n\n\nnar = list(sorted([[ar[x], x] for x in range(n)]))\n\ncur = ['1', 0]\nfor x in nar:\n if x[0] == cur[0]:\n cur[1] += 1\n cross[x[1]] += cur[1]\n else:\n cur[0] = x[0]\n cur[1] = 0\n\nfor x in range(k):\n a, b = [int(x) - 1 for x in input().split()]\n if ar[a] != ar[b]:\n cross[max(a, b, key=lambda x: ar[x])] += 1\n\nfor x in range(n):\n res[x] -= cross[x]\n res[nar[x][1]] += x\n\nprint(*res)\n", "from itertools import accumulate\n\ndef main():\n\tn, k = [int(_) for _ in input().split()]\n\tskills = [int(_) for _ in input().split()]\n\n\tb = [(r, i) for i, r in enumerate(skills)]\n\tb.sort()\n\n\tx = 0\n\tc = [0] * n\n\tcnt = 0\n\tfor r, i in b:\n\t\tif r > x:\n\t\t\tcnt_less = cnt\n\t\tc[i] = cnt_less\n\t\tcnt += 1\n\t\tx = r\n\n\t# print(c)\n\tfor _ in range(k):\n\t\tu, v = [int(_) for _ in input().split()]\n\t\tu -= 1\n\t\tv -= 1\n\t\tif skills[u] > skills[v]:\n\t\t\tc[u] -= 1\n\t\telif skills[v] > skills[u]:\n\t\t\tc[v] -= 1\n\n\tprint(' '.join(map(str, c)))\n\n\n\ndef __starting_point():\n\tmain()\n\n__starting_point()", "from bisect import bisect_left\n\nn, k = map(int, input().split())\na = [int(x) for x in input().split()]\nsa = sorted(a)\n\nans = [0] * n\nfor i in range(k):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n if a[x] > a[y]:\n ans[x] -= 1\n if a[y] > a[x]:\n ans[y] -= 1\n\nfor i in range(n):\n t = bisect_left(sa, a[i])\n ans[i] += t\n print(ans[i], end=' ')\n", "import bisect\nn,k=list(map(int,input().split()))\nr,o=list(map(int,input().split())),''\nd={}\nfor i in range(k):\n a,b=list(map(int,input().split()))\n if [b]!=d.setdefault(a,[b]):\n d[a]+=[b]\n if [a]!=d.setdefault(b,[a]):\n d[b]+=[a]\nrr=sorted(r)\nfor i in range(1,n+1):\n a=bisect.bisect_left(rr,r[i-1])\n if i in d:\n for j in d[i]:\n if r[j-1]<r[i-1]:\n a-=1\n o+=str(a)+' '\nprint(o)\n", "n, k = list(map(int, input().split()))\narr = list(map(int, input().split()))\nperson_to_skill = {}\nskill_to_numMentor = {}\nperson_to_numMentor = {}\nfor person in range(len(arr)):\n person_to_skill[person] = arr[person]\narr = sorted(arr)\ntemp = -1\nfor i in range(len(arr)):\n if arr[i] != temp:\n skill_to_numMentor[arr[i]] = i\n temp = arr[i]\nfor person in range(n):\n person_to_numMentor[person] = skill_to_numMentor[person_to_skill[person]]\nfor quarrel in range(k):\n p1, p2 = list(map(int, input().split()))\n if person_to_skill[p1 - 1] > person_to_skill[p2 - 1]:\n person_to_numMentor[p1 - 1] -= 1\n if person_to_skill[p2 - 1] > person_to_skill[p1 - 1]:\n person_to_numMentor[p2 - 1] -= 1\ns = \"\"\ns += str(person_to_numMentor[0])\nfor i in range(1, n):\n s += ' ' + str(person_to_numMentor[i])\nprint(s)", "[n, k] = [int(x) for x in input().split()]\nr = [int(x) for x in input().split()]\nprogs = [[i, x, 0, 0] for i, x in enumerate(r)]\nIND = 0\nRATE = 1\nREL = 2\nRES = 3\ni = 0\nwhile i < k:\n [a, b] = [int(x) for x in input().split()]\n a -= 1\n b -= 1\n if progs[a][RATE] > progs[b][RATE]:\n progs[a][REL] += 1\n if progs[a][RATE] < progs[b][RATE]:\n progs[b][REL] += 1\n i += 1\n\n\nprogs = sorted(progs, key=lambda p: p[RATE])\n\ni = 1\ncount = 0\nwhile i < n:\n cur = progs[i]\n prev = progs[i-1]\n if cur[RATE] > prev[RATE]:\n count = i\n cur[RES] = count - cur[REL]\n i += 1\n\nprogs = sorted(progs, key=lambda p: p[IND])\nfor p in progs:\n print(p[RES], end=' ')\n", "\n\ndef solve(n,m,a,adj):\n\ta = sorted(a)\n\n\tres = []\n\tfor i in range(n):\n\t\tres.append(0)\n\n\tequal = 0\n\tfor i in range(n):\n\t\tpos = a[i][1]\n\t\tif (i == 0):\n\t\t\tres[pos] = 0\n\t\t\tcontinue\n\n\t\tif (a[i][0] == a[i-1][0]):\n\t\t\tequal += 1\n\t\telse:\n\t\t\tequal = 0\n\n\t\tres[pos] = i - equal - len(adj[pos])\n\n\tfor i in res:\n\t\tprint(i, end = ' ')\n\t\t\n\n\n\n\n\nn, m = map(int, input().split())\n\ntmp = list(map(int, input().split()))\na = []\nadj = []\nfor i in range(n):\n\ta.append((tmp[i],i))\n\tadj.append([])\n\n\nfor i in range(m):\n\tx, y = map(int, input().split())\n\tx -= 1\n\ty -= 1\n\tif (a[x][0] < a[y][0]):\n\t\tadj[y].append(x)\n\telif (a[x][0] > a[y][0]):\n\t\tadj[x].append(y)\n\t\n\nsolve(n,m,a,adj)", "n, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nans = [0] * n\nfor i in range(k):\n\tx, y = [int(j) - 1 for j in input().split()]\n\tif a[x] < a[y]:\n\t\tans[y] -= 1\n\tif a[x] > a[y]:\n\t\tans[x] -= 1\nd = {}\ne = {}\nf = {}\nfor i in a:\n\td[i] = 0\n\tf[i] = True\n\te[i] = 0\nfor i in a:\n\td[i] += 1\n\te[i] += 1\n\nwk1 = [i for i in a]\nwk1.sort()\nfor i in range(n):\n\tif (f[wk1[i]]) and (wk1[i] != wk1[0]):\n\t\td[wk1[i]] += d[wk1[i - 1]]\n\t\tf[wk1[i]] = False\nfor i in range(n):\n\tans[i] += d[a[i]] - e[a[i]]\n\nfor i in range(n):\n\tif i != n - 1:\n\t\tprint(ans[i], end = \" \")\n\telse:\n\t\tprint(ans[i])\n", "R = lambda: map(int, input().split())\n\nn, k = R()\n\nr = list(R())\nh = sorted(r)\nd = {}\n\nd[h[0]] = 0 # d[i]: \u6bd4i\u5c0f\u7684\u6570\u5b57\u6570\u91cf\nfor i in range(1, n):\n if h[i-1] != h[i]:\n d[h[i]] = i\n\nres = [0]*n\nfor i in range(n): res[i] = d[r[i]]\n\nfor i in range(k):\n a, b = R()\n a -= 1; b -= 1\n if r[a] > r[b]: res[a] -= 1\n elif r[a] < r[b]: res[b] -= 1\n\nres = list(map(str, res))\nprint(' '.join(res))", "(n, k) = list(map(int, input().split()))\n\nd = {}\na = []\nfor x in input().split():\n x = int(x)\n if not x in d:\n d[x] = 0\n d[x] += 1\n a.append(x)\n \nlst = sorted(d)\nlst.reverse()\n\nd1 = {lst[0]: d[lst[0]]}\nfor x in range(1, len(lst)):\n d1[lst[x]] = d1[lst[x - 1]] + d[lst[x]]\n\narray = [0] * n\nfor x in range(n):\n array[x] = n - d1[a[x]]\n\nfor x in range(k):\n (l, r) = list(map(int, input().split()))\n if a[l - 1] > a[r - 1]:\n array[l - 1] -= 1\n elif a[l - 1] < a[r - 1]:\n array[r - 1] -= 1\n\nprint(*array)\n", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nrec = []\nrec1 = {}\nfor i in range(n):\n rec.append((i, a[i]))\n rec1[i + 1] = a[i]\n\n\nrec = sorted(rec, key=lambda s: s[1])\n\nnum = [0] * n\nj = 0\nfor i in range(n):\n num[rec[i][0]] = i\ni = 1\nwhile i < n:\n if rec[i - 1][1] == rec[i][1]:\n j = 1\n while i < n and rec[i - 1][1] == rec[i][1]:\n num[rec[i][0]] -= j\n j += 1\n i += 1\n i += 1\n\nfor i in range(k):\n x, y = map(int, input().split())\n if rec1[x] < rec1[y]:\n num[y - 1] -= 1\n elif rec1[y] < rec1[x]:\n num[x - 1] -= 1\n\nprint(\" \".join(map(str, num)))", "n,k = [int(s) for s in input().split()]\nr = [int(s) for s in input().split()]\nq = [0]*n\nfor i in range(k):\n x,y = [int(s)-1 for s in input().split()]\n if r[x] > r[y]:\n q[x] += 1\n if r[y] > r[x]:\n q[y] += 1\nr1 = []\nfor i in range(n):\n r1.append((r[i], i))\nr1.sort()\nlower = 0\nans = [0]*n\nfor i in range(n):\n if i > 0 and r1[i][0] > r1[i-1][0]:\n lower = i\n ans[r1[i][1]] = lower-q[r1[i][1]]\n\nprint(*ans, sep=\" \")", "from collections import Counter\ndef binary(x,ar):\n low=0\n high=len(ar)-1\n while low<=high:\n mid=(low+high)//2\n if ar[mid]==x:\n break\n elif ar[mid]<x:\n low=mid+1\n else:\n high=mid-1\n return mid\n\n\nn,q=list(map(int,input().split()))\nl=list(map(int,input().split()))\nfrq=dict(Counter(l))\nnew=sorted(set(l))\nlook=[frq[new[0]]]\nfor i in range(1,len(new)):\n look.append(look[i-1]+frq[new[i]])\nd=dict()\nfor i in range(q):\n li,r=list(map(int,input().split()))\n li-=1\n r-=1\n if li in d:\n d[li].append(r)\n else:\n d[li]=[r]\n \n if r in d:\n d[r].append(li)\n else:\n d[r]=[li]\nenum=[]\nfor i in range(n):\n x=binary(l[i],new)\n if x==0:\n sum1=0\n else:\n sum1=look[x-1]\n if i in d:\n \n for j in range(len(d[i])):\n if l[d[i][j]]<l[i]:\n sum1-=1\n enum.append(sum1)\nprint(*enum)\n \n \n \n \n\n", "n, k = map(int, input().split())\nm = list(map(int, input().split()))\nnew_m = [(m[i], i) for i in range(n)]\nnew_m.sort()\nans = [0 for i in range(n)]\nlast = -1\nfor i in range(1, len(new_m)):\n if new_m[i][0] == new_m[i - 1][0]:\n ans[new_m[i][1]] = ans[new_m[i - 1][1]]\n else:\n ans[new_m[i][1]] = i\nfor i in range(k):\n a, b = map(int, input().split())\n if m[a - 1] > m[b - 1]:\n ans[a - 1] -= 1\n elif m[a - 1] != m[b - 1]:\n ans[b - 1] -= 1\nprint(*ans)", "n, k = list(map(int, input().split()))\nskills = list((list(map(int, input().split()))))\nquarrels = [0] * n\n\nfor _ in range(k):\n x, y = list(map(int, input().split()))\n x -= 1\n y -= 1\n\n if skills[x] > skills[y]:\n quarrels[x] += 1\n elif skills[y] > skills[x]:\n quarrels[y] += 1\n\nresult = [0] * n\nnext_p = 1\n\nskills = sorted(enumerate(skills), key=lambda x: -x[1])\n\nfor i, skill in skills[:-1]:\n while next_p < n and skills[next_p][1] == skill:\n next_p += 1\n\n result[i] = n - next_p - quarrels[i]\n\nprint(' '.join(map(str, result)))\n", "from copy import copy\n\nn, k = map(int, input().split(' '))\nl = list(map(int, input().split(' ')))\nr = copy(l)\n\nidd = dict()\nfor i in range(n):\n try:\n idd[l[i]].add(i)\n except:\n idd[l[i]] = {i}\n\nnd = dict()\nl.sort()\n\nused = set()\n\nfor i in enumerate(l):\n if not i[1] in used:\n for x in idd[i[1]]:\n nd[x] = i[0]\n used.add(i[1])\n\nd = {i:0 for i in range(n)}\n\nfor i in range(k):\n a, b = map(lambda x: int(x) - 1, input().split(' '))\n if r[a] < r[b]:\n d[b] += 1\n elif r[b] < r[a]:\n d[a] += 1\n\nfor i in range(n):\n print(nd[i] - d[i], end=' ')", "from collections import Counter\ndef search(key,arr):\n low=0\n high=len(arr)-1\n while low<=high:\n mid=(low+high)//2\n if arr[mid]==key:\n break\n elif arr[mid]<key:\n low=mid+1\n else:\n high=mid-1\n return mid\n\nn,q=list(map(int,input().split()))\nl=list(map(int,input().split()))\nd=dict()\nsel=dict(Counter(l))\nno=sorted(set(l))\ntab=[sel[no[0]]]\nfor i in range(1,len(no)):\n tab.append(tab[i-1]+sel[no[i]])\nfor i in range(q):\n li,r=list(map(int,input().split()))\n li-=1\n r-=1\n if li in d:\n d[li].append(r)\n else:\n d[li]=[r]\n \n if r in d:\n d[r].append(li)\n else:\n d[r]=[li]\nfin=[]\nfor i in range(n):\n x=search(l[i],no)\n if x==0:\n sum1=0\n else:\n sum1=tab[x-1]\n if i in d:\n \n for j in range(len(d[i])):\n if l[d[i][j]]<l[i]:\n sum1-=1\n fin.append(sum1)\nprint(*fin)\n", "from collections import defaultdict\nn , k = input().split()\nn , k = [ int(n) , int(k) ]\nprog_power = defaultdict(set)\nprog = []\nfor ind,x in enumerate(input().split()) :\n prog_power[int(x)].add(ind+1)\n prog.append(int(x))\n\nm = defaultdict(set)\nfor i in range(k) :\n a1 , a2 = input().split()\n a1 , a2 = [int(a1) , int(a2) ]\n if prog[a1-1] > prog[a2-1] :\n m[a1].add(a2)\n elif prog[a1-1] < prog[a2-1] :\n m[a2].add(a1)\n\npower = {}\nsum = n\nfor i in sorted(prog_power.keys() , reverse = True) :\n sum -= len(prog_power[i])\n power[i] = sum\n \n\nfor ind,i in enumerate(prog) :\n mentor = power[i] - len(m[ind+1])\n print(mentor,end = ' ')\n\n\n\n\n\n\n\n\n\n\n\n\n", "params = [int(s) for s in input().split(\" \")]\nn = params[0]\nk = params[1]\nskills = [int(s) for s in input().split(\" \")]\nindexes_sorted= [b[0] for b in sorted(enumerate(skills),key=lambda i:i[1])]\nbad_relations={}\nfor i in range(k):\n items = [int(s) for s in input().split(\" \")]\n first = items[0] - 1\n second= items[1] - 1\n if skills[first] > skills[second]:\n bad_relations[first] = bad_relations.get(first, 0) + 1\n elif skills[second]> skills[first]:\n bad_relations[second] = bad_relations.get(second, 0) + 1\n\nnum_the_same=0\nresults = {}\nprev=None\nfor idx, index in enumerate(indexes_sorted):\n skill = skills[index]\n if skill==prev:\n num_the_same+=1\n else:\n num_the_same=0\n cnt = idx - num_the_same - bad_relations.get(index,0)\n if cnt < 0:\n cnt= 0\n results[index]= cnt\n prev= skill\nfinal=''\nfor i in range(n):\n final+=str((results[i])) + \" \"\n\nprint(final.strip())\n\n\n\n", "#!/usr/bin/env python3\nfrom sys import stdin, stdout\nfrom bisect import bisect_left\n\ndef rint():\n return map(int, stdin.readline().split())\n#lines = stdin.readlines()\n\nn, k = rint()\nr = list(rint())\nq = [0 for i in range(n)]\n\nfor i in range(k):\n x, y = rint()\n x -= 1\n y -= 1\n if r[x] > r[y]: \n q[x] +=1\n elif r[y] > r[x]:\n q[y] +=1\n\nans = [-1 for i in range(n)]\nr_sorted = r[:]\nr_sorted.sort()\n#print(\"r\", r)\n#print(\"r_sorted\", r_sorted)\n#print(\"q\", q)\nfor i in range(n):\n lower = bisect_left(r_sorted, r[i])\n ans[i] = max(0, lower - q[i])\nprint(*ans)", "from bisect import bisect_left\n\nn, k = map(int, input().split())\na = [int(x) for x in input().split()]\nsa = sorted(a)\n\nans = [0] * n\nfor i in range(k):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n if a[x] > a[y]:\n ans[x] -= 1\n if a[y] > a[x]:\n ans[y] -= 1\n\nfor i in range(n):\n t = bisect_left(sa, a[i])\n ans[i] += t\n print(ans[i], end=' ')"] | {
"inputs": [
"4 2\n10 4 10 15\n1 2\n4 3\n",
"10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n",
"2 0\n3 1\n",
"2 0\n1 1\n",
"10 35\n322022227 751269818 629795150 369443545 344607287 250044294 476897672 184054549 986884572 917181121\n6 3\n7 3\n1 9\n7 9\n10 7\n3 4\n8 6\n7 4\n6 10\n7 2\n3 5\n6 9\n3 10\n8 7\n6 5\n8 1\n8 5\n1 7\n8 10\n8 2\n1 5\n10 4\n6 7\n4 6\n2 6\n5 4\n9 10\n9 2\n4 8\n5 9\n4 1\n3 2\n2 1\n4 2\n9 8\n"
],
"outputs": [
"0 0 1 2 \n",
"5 4 0 5 3 3 9 0 2 5 \n",
"1 0 \n",
"0 0 \n",
"1 1 2 0 0 0 1 0 2 3 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 14,954 | |
359baa97aaf7631f03c0f0fa4061f9d6 | UNKNOWN | Authors have come up with the string $s$ consisting of $n$ lowercase Latin letters.
You are given two permutations of its indices (not necessary equal) $p$ and $q$ (both of length $n$). Recall that the permutation is the array of length $n$ which contains each integer from $1$ to $n$ exactly once.
For all $i$ from $1$ to $n-1$ the following properties hold: $s[p_i] \le s[p_{i + 1}]$ and $s[q_i] \le s[q_{i + 1}]$. It means that if you will write down all characters of $s$ in order of permutation indices, the resulting string will be sorted in the non-decreasing order.
Your task is to restore any such string $s$ of length $n$ consisting of at least $k$ distinct lowercase Latin letters which suits the given permutations.
If there are multiple answers, you can print any of them.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5, 1 \le k \le 26$) β the length of the string and the number of distinct characters required.
The second line of the input contains $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$, all $p_i$ are distinct integers from $1$ to $n$) β the permutation $p$.
The third line of the input contains $n$ integers $q_1, q_2, \dots, q_n$ ($1 \le q_i \le n$, all $q_i$ are distinct integers from $1$ to $n$) β the permutation $q$.
-----Output-----
If it is impossible to find the suitable string, print "NO" on the first line.
Otherwise print "YES" on the first line and string $s$ on the second line. It should consist of $n$ lowercase Latin letters, contain at least $k$ distinct characters and suit the given permutations.
If there are multiple answers, you can print any of them.
-----Example-----
Input
3 2
1 2 3
1 3 2
Output
YES
abb | ["n,k=map(int,input().split())\naa=list(map(int,input().split()))\nbb=list(map(int,input().split()))\nab=\"abcdefghijklmnopqrstuvwxyz\"\n#print(len(ab))\nss={}\nj=0\nit=[]\nfor i in aa:\n ss[i]=j\n j+=1\njj=0\nfor i in bb:\n ind=ss[i]\n j,ind=sorted([jj,ind])\n it.append([j,ind])\n # print(i,jj,ind)\n jj+=1\n \nit.sort()\ndo=1\nma=it[0][1]\nres=[]\nst=it[0][0]\n\nfor i in it[1:]:\n if i[0]<=ma:\n ma=max(ma,i[1])\n \n else:\n do+=1\n res.append([st,ma])\n st=i[0]\n ma=i[1]\n\n j+=1\nif res==[]:\n res=[[0,n-1]]\nelse:\n if res[-1][1]!=n-1:\n res.append([res[-1][1]+1,n-1])\nif len(res)<k:\n print(\"NO\")\nelse:\n print(\"YES\")\n if len(res)>k:\n # print(res[:k-1])\n # print(res)\n res=res[:k-1]+[[res[k-1][0],n-1]]\n kk=-1\n res.sort()\n ll=[0]*n\n for i in res:\n kk+=1\n for j in range(i[0],i[1]+1):\n ll[aa[j]-1]=ab[kk]\n for i in ll:\n print(i,end=\"\")\n print()\n \n\n \n", "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = list(map(int, input().split()))\nd = [0]*(n+5)\nfor q in range(n):\n d[s[q]] = q\nf, q2 = [], 0\nfor q in range(len(a)):\n if q-1 == q2:\n f.append(q)\n q2 = max(q2, d[a[q]])\nf.append(n)\nif len(f) < k:\n print('NO')\nelse:\n print('YES')\n g = [chr(ord('a')+q) for q in range(30)]\n ans = ['' for q in range(n)]\n q1 = 0\n for q in range(n):\n if f[q1] == q:\n q1 += 1\n q1 = min(q1, 25)\n ans[a[q]-1] = g[q1]\n print(''.join(ans))\n", "n, k = [int(i) for i in input().split()]\np = [int(i) for i in input().split()]\nq = [int(i) for i in input().split()]\noffs = ord(\"a\")\n\nans = [chr(offs+k-1)] * n\n# ans = \"\"\npmore = set()\nqmore = set()\n\nlet = 0\n# cnt = 0\nfor i in range(n):\n # cnt += 1\n pi = p[i]\n qi = q[i]\n if qi in pmore:\n pmore.remove(qi)\n else:\n qmore.add(qi)\n if pi in qmore:\n qmore.remove(pi)\n else:\n pmore.add(pi)\n\n ans[pi - 1] = chr(let+offs)\n if len(pmore) + len(qmore) == 0:\n \n let += 1\n if let == k:\n break\n\n\n\nif let == k:\n # if len(ans) < n:\n # ans += chr(offs+k-1) * (n- len(ans))\n print(\"YES\")\n print(\"\".join(ans))\nelse:\n print(\"NO\")", "from heapq import *\n\n\ndef solve(a, b):\n\n b_map = {i: idx for idx, i in enumerate(a)}\n\n intervals = []\n\n for idx, i in enumerate(b):\n f = b_map[i]\n intervals.append(sorted([f, idx]))\n\n intervals.sort(reverse=True)\n res = []\n endings = []\n for i in range(len(a)):\n while endings and endings[0] < i:\n heappop(endings)\n\n if not res:\n res.append(97)\n elif not endings:\n res.append(res[-1] + 1)\n else:\n res.append(res[-1])\n\n while intervals and intervals[-1][0] <= i:\n s, e = intervals.pop()\n heappush(endings, e)\n\n def build(k, r):\n res = [0] * len(k)\n\n for idx, i in enumerate(k):\n\n res[i - 1] = r[idx]\n\n return res\n # print(res)\n return build(a, res)\n\n\nn, k = [int(i) for i in input().split()]\n\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\nb = solve(a, b)\nstring = ''.join(chr(min(i, 97 + 25)) for i in b)\nif len(set(string)) < k: print(\"NO\")\nelse:\n print(\"YES\")\n print(string)", "n,k=[int(x) for x in input().split()]\na=[int(x) for x in input().split()]\nb=[int(x) for x in input().split()]\np=set()\nq=set()\nliterals=['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']\nit=0\ns=[0]*n\nfor i in range(n):\n p.add(a[i])\n q.add(b[i])\n s[a[i]-1]=literals[it]\n if a[i] in q:\n q.remove(a[i])\n p.remove(a[i])\n if b[i] in p:\n p.remove(b[i])\n q.remove(b[i])\n if not p and (not q):\n it=min(it+1,25)\n k-=1\nif k<=0:\n arr=''\n print('YES')\n for item in s:\n arr+=item\n print(arr)\nelse:\n print('NO')\n", "import sys\n\n\ndef main():\n n, m = [int(x) for x in sys.stdin.readline().strip().split()]\n p = [int(x) for x in sys.stdin.readline().strip().split()]\n q = [int(x) for x in sys.stdin.readline().strip().split()]\n\n sp = set()\n hashp = 0\n sq = set()\n hashq = 0\n\n res = ['z' for _ in range(n)]\n x = 0\n\n for c1, c2 in zip(p, q):\n sp.add(c1)\n hashp += c1 * c1\n sq.add(c2)\n hashq += c2 * c2\n\n if hashp == hashq and sp == sq:\n c = chr(ord('a') + x)\n x += 1\n for pos in sp:\n res[pos - 1] = c\n\n if x == m:\n print('YES')\n print(''.join(res))\n return\n\n sp.clear()\n hashp = 0\n sq.clear()\n hashq = 0\n\n\n print('NO')\n\n\nmain()\n", "from sys import stdin\nfrom sys import setrecursionlimit as SRL; SRL(10**7)\nrd = stdin.readline\nrrd = lambda: list(map(int, rd().strip().split()))\n\nlat = [chr(ord('a')+i) for i in range(26)]\n\n\nn,k = rrd()\n\np = list(rrd())\nq = list(rrd())\n\ncnt = [0]*200005\n\nct = 0\n\nans = ['a']*n\n\n\nnow = 0\nfor i in range(n):\n if q[i] == p[i]:\n if ct == 0 and i:\n now += 1\n now = min(now,25)\n ans[q[i]-1] = lat[now]\n\n else:\n if ct == 0 and i:\n now += 1\n now = min(now,25)\n\n cnt[q[i]]+=1\n cnt[p[i]]+=1\n\n if cnt[q[i]] == 2:\n ct -= 1\n else:\n ct += 1\n if cnt[p[i]] == 2:\n ct -= 1\n else:\n ct += 1\n\n ans[p[i]-1] = lat[now]\n ans[q[i]-1] = lat[now]\n\n\n\n\n\nif now+1 >= k:\n print(\"YES\")\n print(\"\".join(ans))\nelse:\n print(\"NO\")\n\n\n\n\n\n", "n, k = map(int,input().split())\nl1 = list(map(int,input().split()))\nl2 = list(map(int,input().split()))\nd = {}\nj = 1\nfor i in l1:\n d[i] = j\n j += 1\nl = [d[i] for i in l2]\n#l is the list that forces shit\nwei = [0] * (n+2)\nright = [0] * (n+2)\nfor i in range(n -1):\n #look at l[i], l[1+1]\n if l[i] < l[i+1]:\n continue\n wei[l[i+1]] += 1\n wei[l[i] + 1] -= 1\n right[l[i]] += 1\nodcinki = []\nl = 1\nr = 1\npref = [0] * (n + 2)\nfor i in range(1, n+2):\n pref[i] = pref[i-1] + wei[i]\nfor i in range(1, n + 2):\n if pref[i] == 0:\n odcinki.append([l,r])\n l = i + 1\n r = i + 1\n else:\n if pref[i] == right[i]:\n odcinki.append([l,r])\n l = i + 1\n r = i + 1\n \n else:\n r += 1\nif odcinki[0] == [1,1]:\n\todcinki = odcinki[1:]\nif odcinki[-1][0] == odcinki[-1][1] and odcinki[-1][0] > n:\n\todcinki = odcinki[:-1]\n \nlewe = [0] * (n+1)\nprawe = [0] * (n+1)\nfor i in odcinki:\n\tlewe[i[0]] = 1\n\tprawe[i[1]] = 1\nodp = [0] * (n+3)\ni = -1\nindx = 1\nreg = 0\nodp = [-1] * (n+3)\ncount = 0\nwhile indx < n + 1:\n\t#i stays the same iff [5,6,7,8,9] we are 6,7,8,9\n\tif prawe[indx-1] == 1:\n\t\treg = 0\n\tif lewe[indx] == 1:\n\t\treg = 1\n\t\tcount = 0\n\todp[indx] = i\n\t#kiedy i += 1\n\tif count == 0 or reg == 0:\n\t\ti += 1\n\tcount += 1\n\todp[indx] = i\n\tindx += 1\nodpp = [0] * (n + 3)\nfor i in range(n):\n odpp[l1[i]] = odp[i + 1]\nodpp = odpp[1:-2]\nif max(odpp) + 1 < k:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")\n\tfor i in range(n):\n\t\tprint(chr(97+min(25, odpp[i])), end = \"\")", "n, k = map(int, input().split())\np = list(map(int,input().split()))\nq = list(map(int, input().split()))\nsp = set()\nsq = set()\nchuj = 0\nodp = [chr(96 + 26) for i in range(n)]\nfor i in range(n):\n odp[p[i] - 1] = chr(97 + chuj)\n if p[i] - 1 in sq:\n sq.remove(p[i] - 1)\n else:\n sp.add(p[i] - 1)\n if q[i] - 1 in sp:\n sp.remove(q[i] - 1)\n else:\n sq.add(q[i] - 1)\n if len(sp) + len(sq) == 0:\n chuj += 1\n if chuj == 26:\n break\nif chuj < k:\n print(\"NO\")\nelse:\n print(\"YES\")\n print(\"\".join(odp))", "n, k = [int(i) for i in input().split()]\np = [int(i) for i in input().split()]\nq = [int(i) for i in input().split()]\noffs = ord(\"a\")\n \nans = [chr(offs+k-1)] * n\n# ans = \"\"\npmore = set()\nqmore = set()\n \nlet = 0\n# cnt = 0\nfor i in range(n):\n # cnt += 1\n pi = p[i]\n qi = q[i]\n if qi in pmore:\n pmore.remove(qi)\n else:\n qmore.add(qi)\n if pi in qmore:\n qmore.remove(pi)\n else:\n pmore.add(pi)\n \n ans[pi - 1] = chr(let+offs)\n if len(pmore) + len(qmore) == 0:\n \n let += 1\n if let == k:\n break\n \n \n \nif let == k:\n # if len(ans) < n:\n # ans += chr(offs+k-1) * (n- len(ans))\n print(\"YES\")\n print(\"\".join(ans))\nelse:\n print(\"NO\")", "n, k = list(map(int, input().split()))\ns = [0] * n\nfor i, v in enumerate(map(int, input().split())):\n s[v-1] = i\nt = [0] * n\nfor i, v in enumerate(map(int, input().split())):\n t[v-1] = i\np = [0] * n\nfor u, v in zip(s, t):\n if u == v: continue\n elif v < u: u, v = v, u\n p[u] += 1\n p[v] -= 1\nr = [0] * n\ncur = 0\nnxt = -1\nfor i, v in enumerate(p):\n if cur == 0 and nxt < 25: nxt += 1\n r[i] = nxt\n cur += v\n\nif nxt < k-1:\n print(\"NO\")\nelse:\n print(\"YES\")\n print(\"\".join([chr(ord('a')+r[x]) for x in s]))\n\n", "import math\nn = 3\nk = 2\n \np = [1,2,3]\nq = [1,3,2]\n \nn,k = [int(x) for x in input().split(' ')]\np = [int(x) -1 for x in input().split(' ')]\nq = [int(x) -1 for x in input().split(' ')]\n \n\ngroup_ids = []\n\n \np_ids = set()\nq_ids = set()\nfor i in range(n):\n if p[i] in q_ids:\n q_ids.remove(p[i])\n else:\n p_ids.add(p[i])\n\n if q[i] in p_ids:\n p_ids.remove(q[i])\n else:\n q_ids.add(q[i])\n\n if not bool(p_ids) and not bool(q_ids):\n group_ids.append(i)\n\nif len(group_ids) < k:\n print('NO')\n return\n \ndef get_letter(_id):\n alphabet = 'abcdefghijklmnopqrstuvwxyz'\n return alphabet[min(_id, len(alphabet)-1)]\n\n\nprint('YES')\nresult = [None] * n\nl = 0\nfor i in range(len(group_ids)):\n r = group_ids[i]\n letter = get_letter(i)\n for it in range(l, r+1):\n result[p[it]] = letter\n l = r+1\n\n\n \nprint(''.join(result))", "def main():\n n, m = list(map(int, input().split()))\n abc = list('zyxwvutsrqponmlkjihgfedcba'[26 - m:])\n res = [abc[0]] * (n + 1)\n res[0], pool, f = 'YES\\n', [False] * (n + 1), 0\n for p, q in zip(list(map(int, input().split())),\n list(map(int, input().split()))):\n if pool[p]:\n f -= 1\n else:\n pool[p] = True\n f += 1\n if pool[q]:\n f -= 1\n else:\n pool[q] = True\n f += 1\n res[p] = abc[-1]\n if not f:\n del abc[-1]\n if not abc:\n break\n print('NO' if abc else ''.join(res))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys\n\ninp = [int(x) for x in sys.stdin.read().split()]\n\nn = inp[0]\nk = inp[1]\nP = inp[2:n + 2]\nQ = inp[n + 2: n + n + 2]\n\nletters = 'abcdefghijklmnopqrstuvwxyz'\n\nindex = [0] * n\nfor i in range(n):\n P[i] -= 1\n Q[i] -= 1\n index[P[i]] = i\n\nintervals = []\nfor i in range(n - 1):\n if index[Q[i]] > index[Q[i + 1]]:\n intervals.append((index[Q[i + 1]], index[Q[i]]))\n\nintervals.sort()\ncolor = [0] * n\ncur_color = 0\ninterval_idx = 0\nlast = -1\nfor i in range(n):\n if last < i:\n cur_color += 1\n color[i] = cur_color\n while interval_idx < len(intervals) and intervals[interval_idx][0] == i:\n last = max(last, intervals[interval_idx][1])\n interval_idx += 1\n\nif cur_color < k:\n print('NO')\nelse:\n ans = ['a'] * n\n for i in range(n):\n ans[P[i]] = letters[min(25, color[i] - 1)]\n print('YES')\n print(''.join(ans))\n \n", "import sys\n\ninp = [int(x) for x in sys.stdin.read().split()]\n\nn = inp[0]\nk = inp[1]\nP = inp[2:n + 2]\nQ = inp[n + 2: n + n + 2]\n\nindex = [0] * n\nfor i in range(n):\n P[i] -= 1\n Q[i] -= 1\n index[P[i]] = i\n\nintervals = []\nfor i in range(n - 1):\n if index[Q[i]] > index[Q[i + 1]]:\n intervals.append((index[Q[i + 1]], index[Q[i]]))\n\nintervals.sort()\ncolor = [0] * n\ncur_color = 0\ninterval_idx = 0\nlast = -1\nfor i in range(n):\n if last < i:\n cur_color += 1\n color[i] = cur_color\n while interval_idx < len(intervals) and intervals[interval_idx][0] == i:\n last = max(last, intervals[interval_idx][1])\n interval_idx += 1\n\nif cur_color < k:\n print('NO')\nelse:\n ans = ['a'] * n\n for i in range(n):\n ans[P[i]] = chr(min(25, color[i] - 1) + ord('a'))\n print('YES')\n print(''.join(ans))\n \n", "# https://codeforces.com/contest/1213/problem/F\n\nn, k = map(int, input().split())\np = list(map(int, input().split()))\nq = list(map(int, input().split()))\n\ndef get(cur):\n if cur>=97+25:\n return chr(97+25)\n return chr(cur)\n\npos = [0] * (n+1)\nfor i, x in enumerate(q):\n pos[x] = i\n \nseg =[0]\ncnt = 0\nmax_=-1\n\nfor i, x in enumerate(p):\n max_ = max(max_, pos[x]) \n if i == max_:\n cnt+=1\n seg.append(i+1)\n \nif len(seg)-1<k:\n print('NO')\nelse:\n cur = 97 \n S = []\n for s, e in zip(seg[:-1], seg[1:]):\n for i in range(s, e):\n S.append(cur)\n cur+=1 \n \n print('YES')\n print(''.join([get(S[pos[x]]) for x in range(1, n+1)])) ", "import sys\ninput = sys.stdin.readline\n\nfrom operator import itemgetter\n\nN, K = map(int, input().split())\ninP = list(map(int, input().split()))\ninQ = list(map(int, input().split()))\n\n\nP = [None]*N\nfor i, p in enumerate(inP):\n P[p-1] = i+1\n\nQ = [None]*N\nfor i, q in enumerate(inQ):\n Q[q-1] = i+1\n\nNUM = []\nfor i, (p, q) in enumerate(zip(P, Q)):\n NUM.append((i, p, q))\n\ngraph = [-1]*(N+1)\nNUM.sort(key=itemgetter(2))\nfor i in range(N-1):\n pre = NUM[i][1]\n fow = NUM[i+1][1]\n graph[fow] = pre\n\nNUM.sort(key=itemgetter(1))\nColor = [-1]*(N+1)\ncolor = 0\nMAX = 1\nfor (ind, p, q) in NUM:\n if Color[p] == -1 and p > MAX:\n color += 1\n tmp = p\n while tmp != -1 and Color[tmp] == -1:\n MAX = max(MAX, tmp)\n Color[tmp] = color\n tmp = graph[tmp]\n\nif color >= K-1:\n print(\"YES\")\n ans = [None]*N\n for ind, p, q in NUM:\n c = Color[p]\n ans[ind] = chr(97+min(c, 25))\n print(\"\".join(ans))\nelse:\n print(\"NO\")"] | {
"inputs": [
"3 2\n1 2 3\n1 3 2\n",
"5 4\n1 3 2 4 5\n2 3 5 1 4\n",
"3 2\n3 1 2\n3 2 1\n",
"6 5\n5 6 1 2 3 4\n6 5 1 2 3 4\n",
"5 2\n5 2 4 3 1\n5 4 3 1 2\n"
],
"outputs": [
"YES\nabb\n",
"NO\n",
"YES\nbba\n",
"YES\nbcdeaa\n",
"YES\nbbbba\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 14,919 | |
5a6253e2de1a062c166ece859cf39ed1 | UNKNOWN | Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed $n$ cans in a row on a table. Cans are numbered from left to right from $1$ to $n$. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.
Vasya knows that the durability of the $i$-th can is $a_i$. It means that if Vasya has already knocked $x$ cans down and is now about to start shooting the $i$-th one, he will need $(a_i \cdot x + 1)$ shots to knock it down. You can assume that if Vasya starts shooting the $i$-th can, he will be shooting it until he knocks it down.
Your task is to choose such an order of shooting so that the number of shots required to knock each of the $n$ given cans down exactly once is minimum possible.
-----Input-----
The first line of the input contains one integer $n$ $(2 \le n \le 1\,000)$ β the number of cans.
The second line of the input contains the sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 1\,000)$, where $a_i$ is the durability of the $i$-th can.
-----Output-----
In the first line print the minimum number of shots required to knock each of the $n$ given cans down exactly once.
In the second line print the sequence consisting of $n$ distinct integers from $1$ to $n$ β the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.
-----Examples-----
Input
3
20 10 20
Output
43
1 3 2
Input
4
10 10 10 10
Output
64
2 1 4 3
Input
6
5 4 5 4 4 5
Output
69
6 1 3 5 2 4
Input
2
1 4
Output
3
2 1
-----Note-----
In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven't knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots $20 \cdot 1 + 1 = 21$ times. After that only second can remains. To knock it down Vasya shoots $10 \cdot 2 + 1 = 21$ times. So the total number of shots is $1 + 21 + 21 = 43$.
In the second example the order of shooting does not matter because all cans have the same durability. | ["n = int(input())\na = [int(x) for x in input().split()]\nb = [(a[i], i + 1) for i in range(n)]\nb.sort(reverse=True)\nans = 0\nfor i in range(n):\n ans += b[i][0] * i + 1\nprint(ans)\nfor i in b:\n print(i[1], end=' ')", "n = int(input())\nl = list(map(int, input().split()))\nfor i in range(n):\n l[i] = [l[i], i]\nres = 0\nl.sort()\nl = l[::-1]\nfor i2 in range(n):\n res += i2 * l[i2][0] + 1\nprint(res)\nfor i3 in range(n):\n print(l[i3][1] + 1, end=' ')", "'''input\n6\n5 4 5 4 4 5\n\n\n\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\nfrom heapq import heappush as hpush\nfrom heapq import heappop as hpop\nmod=10**9+7\n\ndef ri(flag=0):\n\tif flag==0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n\nn =ri(1)\na = ri()\n\nb = sorted(a,reverse=True)\nc = [i+1 for i in range(n)]\n\nc.sort(key = lambda x: a[x-1])\n\nc = c[::-1]\n\n\nans=0\nx=0\n\nfor i in range(n):\n\tans += (b[i]*(x)+1)\n\tx+=1\n\nprint(ans)\nprint(*c)", "import sys\ninput = lambda: sys.stdin.readline().strip()\n\nn = int(input())\nls = list(map(int, input().split()))\nls = [(i, ls[i-1]) for i in range(1, n+1)]\nls.sort(key=lambda x: x[1])\nls.reverse()\ncnt = 0\nfor i in range(n):\n cnt+=i*ls[i][1]+1\nprint(cnt)\nfor i in range(n):\n print(ls[i][0], end=' ')\nprint()\n", "from sys import stdin, stdout \n\n\n\nn = int(input())\n\nD = (list(map(int, input().split())))\n\nfor i in range(n):\n D[i] = [D[i], i]\nD.sort(reverse=True)\nans = 0\n\nfor i, d in enumerate(D):\n ans += d[0]*i + 1\n \nprint(ans)\n\nfor d in D:\n print(d[1] + 1, end= ' ')", "\nn = int(input())\nl = list(map(int,input().split()))\nans = []\nyo = 0\ncount = 0\nfor i in range(n):\n ans.append([l[i],i+1])\n\n\n\nfinal = []\nans.sort(reverse=True)\nfor a,b in ans:\n count+=yo*a + 1\n final.append(b)\n yo+=1\nprint(count)\nprint(*final)\n\n", "from bisect import *\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nfrom decimal import *\nfrom copy import *\nfrom heapq import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 10**6+1\nMOD = 10**9+7\nspf = [i for i in range(MAXN)]\ndef sieve():\n for i in range(2,MAXN,2):\n spf[i] = 2\n for i in range(3,int(MAXN**0.5)+1):\n if spf[i]==i:\n for j in range(i*i,MAXN,i):\n if spf[j]==j:\n spf[j]=i\n\ndef mhd(a,b):\n return abs(a[0]-b[0])+abs(b[1]-a[1])\n\ndef charIN(x= ' '):\n return(sys.stdin.readline().strip().split(x))\n\ndef arrIN(x = ' '):\n return list(map(int,sys.stdin.readline().strip().split(x)))\n\ndef eld(x,y):\n a = y[0]-x[0]\n b = x[1]-y[1]\n return (a*a+b*b)**0.5\n\ndef lgcd(a):\n g = a[0]\n for i in range(1,len(a)):\n g = math.gcd(g,a[i])\n return g\n\ndef ms(a):\n msf = -MAX\n meh = 0\n st = en = be = 0\n for i in range(len(a)):\n meh+=a[i]\n if msf<meh:\n msf = meh\n st = be\n en = i\n if meh<0:\n meh = 0\n be = i+1\n return msf,st,en\n\ndef ncr(n,r):\n num=den=1\n for i in range(r):\n num = (num*(n-i))%MOD\n den = (den*(i+1))%MOD\n\n return (num*(pow(den,MOD-2,MOD)))%MOD\n\n\n\ndef flush():\n return sys.stdout.flush()\n\n'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''\nn = int(input())\na = arrIN()\nx = [[i,a[i]] for i in range(n)]\nx.sort(key = lambda x:x[1],reverse=True)\nans = 0\ntemp = []\nfor i in range(n):\n ans+=x[i][1]*i+1\n temp.append(x[i][0]+1)\nprint(ans)\nprint(*temp)", "import sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nB=[[a,i] for i,a in enumerate(A)]\n\nB.sort(reverse=True)\n\nANS=0\nind=0\n\nfor b,i in B:\n ANS+=b*ind+1\n ind+=1\n\nprint(ANS)\nprint(*[B[i][1]+1 for i in range(n)])\n \n \n", "n = int(input())\nl = list( map( int, input().split() ) )\nl = [ (v, i) for i, v in enumerate( l ) ]\nl.sort()\nl.reverse()\ns, x = 0, 0\nfor v, i in l:\n s += v * x + 1\n x += 1\n\nprint( s )\nfor v, i in l:\n print( i + 1 )\n", "n = int(input())\ns = list(map(lambda x: (int(x[1]),x[0]),enumerate(input().split())))\ns.sort(reverse=True)\nans = 0\nfor i in range(n):\n ans+=(s[i][0]*i+1)\nprint(ans)\nprint(*map(lambda x: x[1]+1,s))", "n = int(input())\nli = list(map(int, input().split()))\n\nli = sorted(zip(li, list(range(len(li)))))[::-1]\nans = 0\n\nfor i in range(n):\n ans += li[i][0] * i + 1\nprint(ans)\nans_li = []\nfor i in range(n):\n ans_li.append(li[i][1] + 1)\nprint(*ans_li)\n\n", "#Starting 8 minutes late !\ndef fun(x):\n return x[0]\nn=int(input())\na=list(map(int,input().strip().split()))\nfor i in range(n):\n a[i]=[a[i],i+1]\na.sort(key=fun,reverse=True)\nop=0\nop2=\"\"\nfor i in range(n):\n op2+=str(a[i][1])+\" \"\n op+=a[i][0]*i+1\nprint(op)\nprint(op2)", "from operator import itemgetter\n\nN = int(input())\nA = list(map(int, input().split()))\n\nB = []\nfor i, a in enumerate(A):\n B.append((i, a))\n\nB.sort(reverse=True, key = itemgetter(1))\n\nscore = 0\nfor n, (i, b) in enumerate(B):\n score += b*n+1\n\nprint(score)\nfor i, _ in B:\n print(i+1, end=' ')\nprint()", "n = int(input())\na = list(map(int, input().split()))\nb = []\nfor i in range(n):\n b.append([a[i], i])\nb.sort(key=lambda x: x[0], reverse=True)\ncnt = 0\ns = 0\nres = []\nfor i in range(n):\n s += cnt * b[i][0] + 1\n cnt += 1\n res.append(str(b[i][1] + 1))\nprint(s)\nprint(' '.join(res))\n", "from collections import defaultdict\nn = int(input())\nrec = defaultdict(list)\norigi = list(map(int, input().split()))\nfor i in range(n):\n rec[origi[i]].append(i + 1)\na = sorted(origi, reverse=True)\nl = 0\nans = []\n# x = 0\nfor i in range(n):\n l += a[i] * i + 1\n # x += 1\n ans.append(rec[a[i]].pop())\nprint(l)\nfor i in ans:\n print(i, end=' ')\nprint('')", "import collections, heapq, bisect, math\n\ndef gcd(a, b):\n if b == 0: return a\n return gcd(b, a%b)\n\ndef solve(A):\n A = [(a,i) for i, a in enumerate(A)]\n A.sort(reverse=True)\n\n out = 0\n for i in range(len(A)):\n out += (i*A[i][0] + 1)\n \n print(out)\n print(' '.join(str(i+1) for _, i in A))\n\n\n\n\n\nq = 1#input()\ntests = []\nfor test in range(1):\n n = input()\n tests.append([int(p) for p in input().split(' ')])\nfor test in tests: solve(test)\n#print(solve(n,b))\n", "n = int(input())\nA = list(map(int, input().split()))\nfor i in range(n):\n A[i] = [-A[i], i]\nA.sort()\nans = 0\nfor i in range(n):\n ans += i * (-A[i][0]) + 1\nprint(ans)\nfor x in A:\n print(x[1] + 1, end=' ')", "#!/usr/bin/env python3\n\nn = int(input())\na = [int(i) for i in input().split()]\na = [(a[i], i) for i in range(len(a))]\na.sort(reverse=True)\n\ns = 0\norder = []\nfor i in range(len(a)):\n s += a[i][0] * i + 1\n order.append(a[i][1])\nprint(s)\nprint(' '.join([str(i + 1) for i in order]))\n", "n = int(input())\nl = list(map(int,input().split()))\nl1 = [i for i in range(1,n + 1)]\nfor i in range(n):\n min1 = i\n for j in range(i + 1,n):\n if l[j] > l[min1]:\n min1 = j\n l[i],l[min1] = l[min1],l[i]\n l1[i],l1[min1] = l1[min1],l1[i]\ncount = 0\nfor i in range(n):\n count += l[i] * i + 1\nprint(count)\nprint(*l1)\n", "n=int(input())\nli=list(map(int,input().split()))\nd={}\nb=[]\nfor i in range(1,n+1):\n k=li[i-1]\n try:\n d[k].append(i)\n except KeyError:\n d[k]=[i]\n b.append(k)\nb.sort(reverse=True)\nans1=[]\nans=0\nl=0\nfor i in b:\n for j in d[i]:\n ans1.append(j)\n ans+=l*i+1\n l+=1\nprint(ans)\nprint(*ans1)\n \n", "n = int(input())\na = [(int(el), i + 1) for i, el in enumerate(input().split())]\na = sorted(a, reverse=True)\nshots = 0\nfor i, (el, _) in enumerate(a):\n shots += i * el + 1\nprint(shots)\nprint(*(i for _, i in a))\n", "'''input\n6\n5 4 5 4 4 5\n'''\nfrom sys import stdin\n\n\ndef check_valid(string):\n\tstack = []\n\tfor i in string:\n\t\tif i in ['(', '[']:\n\t\t\tstack.append(i)\n\t\telif i == ')':\n\t\t\tif len(stack) > 0:\n\t\t\t\tif stack[-1] == '(':\n\t\t\t\t\tstack.pop()\n\t\t\t\t\tcontinue\n\t\t\treturn False\n\t\telif i == ']':\n\t\t\tif len(stack) > 0:\n\t\t\t\tif stack[-1] == '[':\n\t\t\t\t\tstack.pop()\n\t\t\t\t\tcontinue\n\t\t\treturn False\n\n\treturn len(stack) == 0\n\ndef merge(index):\n\taux = []\n\tif len(index) > 0:\n\t\taux = [index[0]]\n\t\tfor i in range(1, len(index)):\n\t\t\tif index[i][0] == aux[-1][1] + 1:\n\t\t\t\taux[-1][1] = index[i][1]\n\t\t\telse:\n\t\t\t\tif check_valid(string[aux[-1][1] + 1: index[i][0]]):\n\t\t\t\t\taux[-1][1] = index[i][1]\n\t\t\t\telse:\n\t\t\t\t\taux.append(index[i])\n\treturn aux\n\n\n# main starts\nn = int(stdin.readline().strip())\narr = []\narr = list(map(int, stdin.readline().split()))\nfor i in range(n):\n\tarr[i] = [i, arr[i]]\n\narr.sort(key = lambda x: x[1], reverse = True)\ncount = 0 \nans = []\ntotal = 0\nfor i in range(n):\n\tindex, a = arr[i]\n\tans.append(index + 1)\n\ttotal += count * a + 1\n\n\tcount += 1\n\nprint(total)\nprint(*ans)\n", "from collections import defaultdict as df\nn=int(input())\nd=df(list)\na=list(map(int,input().rstrip().split()))\nfor i in range(n):\n d[a[i]].append(i+1)\na.sort(reverse=True)\na=list(set(a))\na.sort(reverse=True)\nsum1=0\nans=[]\ncounter=0\nfor i in range(len(a)):\n for j in d[a[i]]:\n sum1+=(a[i]*counter) + 1\n counter+=1\n ans.append(j)\nprint(sum1)\nprint(*ans)\n \n \n"] | {
"inputs": [
"3\n20 10 20\n",
"4\n10 10 10 10\n",
"6\n5 4 5 4 4 5\n",
"2\n1 4\n",
"5\n13 16 20 18 11\n"
],
"outputs": [
"43\n1 3 2 \n",
"64\n2 1 4 3 \n",
"69\n6 1 3 5 2 4 \n",
"3\n2 1 \n",
"138\n3 4 2 1 5 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,802 | |
b2caa9f6f1aa8bfb58a2f7147b8735ad | UNKNOWN | Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:
- For any integer j (1 \leq j \leq i), P_i \leq P_j.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
- P_1, \ldots, P_N is a permutation of 1, \ldots, N.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N
P_1 ... P_N
-----Output-----
Print the number of integers i that satisfy the condition.
-----Sample Input-----
5
4 2 5 1 3
-----Sample Output-----
3
i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.
Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition. | ["n=int(input())\np=list(map(int,input().split()))\n\nc=1\n\nq=p[0]\n\nfor i in range(1,n):\n q=min(q,p[i])\n if p[i]<=q:\n c+=1\n\nprint(c)", "n = int(input())\np = list(map(int, input().split()))\n\nans = 0\nm = p[0]\n\nfor i in p:\n\tif m >= i:\n\t\tans += 1\n\t\tm = i\n\nprint(ans)", "N = int(input())\nP = [int(i) for i in input().split()]\n\np = N\nans = 0\nfor i in range(N):\n if p >= P[i]:\n ans += 1\n p = P[i]\n\nprint(ans)", "import sys\nimport math\nfrom collections import defaultdict, deque, Counter\nfrom copy import deepcopy\nfrom bisect import bisect, bisect_right, bisect_left\nfrom heapq import heapify, heappop, heappush\n \ninput = sys.stdin.readline\ndef RD(): return input().rstrip()\ndef F(): return float(input().rstrip())\ndef I(): return int(input().rstrip())\ndef MI(): return map(int, input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int, input().split()))\ndef TI(): return tuple(map(int, input().split()))\ndef LF(): return list(map(float,input().split()))\ndef Init(H, W, num): return [[num for i in range(W)] for j in range(H)]\n \n \ndef main():\n N = I()\n if N == 1:\n print(1)\n return\n\n L = LI()\n res = 1\n temp = L[0]\n for i in L[1:]:\n if temp >= i:\n res+=1\n temp = i\n \n print(res)\n \ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nP = [int(i) for i in input().split()]\nans = 0\na = N\nfor i in range(N):\n if(P[i] <= a):\n ans += 1\n a = min(a,P[i])\n continue\n a = min(a,P[i])\nprint(ans)", "def main():\n n = int(input())\n p = list(map(int,input().split()))\n minp = p[0]\n cnt = 0\n for i in range(n):\n if p[i]<=minp:cnt+=1\n minp = min(minp,p[i])\n print(cnt)\nmain()", "n = int(input())\nL = list(map(int,input().split()))\nmini = L[0]\nans = 0\n\nfor l in L:\n if mini >= l:\n ans += 1\n mini = l\nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\nc = 10 ** 20\ncon = 0\nfor i in range(N):\n if c > P[i]:\n con += 1\n c = P[i]\nprint(con)\n \n", "n = int(input())\na = list(map(int, input().split()))\n\ncnt = 0\nmina = a[0]\n\nfor i in a:\n if i <= mina:\n cnt += 1\n mina = i\n\nprint(cnt)", "N = int(input())\nP = list(map(int,input().split()))\nPm = P[0]\nans = 0\n\nfor i in range(N):\n if P[i] <= Pm:\n ans += 1\n Pm = P[i]\n \nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\n\nmini = 2*10**5\nans = 0\nfor i in P:\n if i <= mini:\n ans += 1\n mini = i\nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\n\nans = 0\nm = float(\"inf\")\nfor i in range(N):\n if P[i] <= m:\n ans += 1\n m = P[i]\nprint(ans)", "# author: Taichicchi\n# created: 10.10.2020 13:53:46\n\nimport sys\n\nN = int(input())\n\nP = list(map(int, input().split()))\n\nm = 100000000000000\ncnt = 0\n\nfor i in range(N):\n if P[i] <= m:\n cnt += 1\n m = min(m, P[i])\n\nprint(cnt)\n", "n = int(input())\np_l = list(map(int, input().split()))\nm_p_l = []\nmin_p = float('inf')\nfor i, p in enumerate(p_l):\n min_p = min(min_p, p)\n m_p_l.append(min_p)\nans = 0\nfor i, p in enumerate(p_l):\n if p == m_p_l[i]:\n ans += 1\nprint(ans)", "\nN = int(input())\nl = list(map(int, input().split()))\n\ncounter = 0\ncurmin = 1e9\nfor i in l:\n curmin = min(curmin, i)\n if i == curmin:\n counter += 1\nprint(counter)\n", "def resolve():\n n = int(input())\n p = tuple(map(int,input().split()))\n min_p = p[0]\n cnt = 1\n for i in range(1,n):\n if min_p > p[i]:\n min_p = p[i]\n cnt += 1\n print(cnt)\nresolve()", "N = int(input())\nP_ls = map(int, input().split(' '))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "n = int(input())\nalst = list(map(int, input().split()))\nmin_ = alst[0]\nans = 1\nfor a in alst[1:]:\n if a <= min_:\n ans += 1\n min_ = a\nprint(ans)", "N = int(input())\nP = tuple(map(int, input().split()))\n\ncount = 0\nmin_num = float('inf')\nfor i in P:\n if i < min_num:\n count += 1\n min_num = i\n\nprint(count)", "n = int(input())\npl = list(map(int, input().split()))\n\nmin_num = 1001001001\nans = 0\nfor p in pl:\n if p <= min_num:\n ans += 1\n min_num = p\n\nprint(ans)", "n = int(input())\npn = [int(num) for num in input().split()]\n \nmaxpj = n+1\nanswer = 0\nfor pi in pn:\n if pi < maxpj:\n answer += 1\n maxpj = pi\n\nprint(answer)", "N=int(input())\nA=list(map(int,input().split()))\ncore=1\nb=A[0]\nfor i in range(1,N):\n if b>A[i]:\n core+=1\n b=A[i]\n else:\n pass\nprint(core)", "n = int(input())\nP = list(map(int,input().split()))\nmi = P[0]\nans = 0\nfor i in range(n):\n if P[i] <= mi:\n ans += 1\n mi = P[i]\nprint(ans)", "import sys\nimport copy\nimport math\nimport itertools\nimport numpy as np\nN = int(input())\nP = [int(c) for c in input().split()]\n\nmin = P[0]\ncnt = 0\nfor i in range(N):\n if min >= P[i]:\n min = P[i]\n cnt += 1\nprint(cnt)", "n = int(input())\np = list(map(int,input().split()))\ncount = 0\na = p[0]\nfor x in range(len(p)):\n if p[x] <= a:\n count += 1\n a = p[x]\n \nprint(count)\n", "n = int(input())\nlst = list(map(int, input().split()))\n\nm = n+1\nans = 0\n\nfor i in lst:\n if i < m:\n ans += 1\n m = i\n\nprint(ans)", "N=int(input())\nP=list(map(int,input().split()))\na=P[0]\nn=1\nfor i in range(N-1):\n if a>P[i+1]:\n a=P[i+1]\n n+=1\nprint(n)", "import sys\nimport math\nfrom collections import defaultdict, deque, Counter\nfrom copy import deepcopy\nfrom bisect import bisect, bisect_right, bisect_left\nfrom heapq import heapify, heappop, heappush\n \ninput = sys.stdin.readline\ndef RD(): return input().rstrip()\ndef F(): return float(input().rstrip())\ndef I(): return int(input().rstrip())\ndef MI(): return map(int, input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int, input().split()))\ndef TI(): return tuple(map(int, input().split()))\ndef LF(): return list(map(float,input().split()))\ndef Init(H, W, num): return [[num for i in range(W)] for j in range(H)]\n \n \ndef main():\n N = I()\n if N == 1:\n print(1)\n return\n\n L = TI()\n res = 1\n temp = L[0]\n for i in L[1:]:\n if temp >= i:\n res+=1\n temp = i\n \n print(res)\n \ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nP = list(map(int,input().split()))\n\ncount = 1\nminP = P[0]\nfor i in range(1,N):\n if minP > P[i]:\n count += 1\n minP = min(minP,P[i])\nprint(count)", "n = int(input())\n\nlst = [ int(i) for i in input().split()]\nmn = lst[0]\ncount = 0\nfor d in lst:\n if mn >= d:\n count += 1\n mn = d\n \nprint(count)", "n = int(input())\np = list(map(int,input().split()))\nmin_p = n+1\nans = 0\nfor i in range(n):\n if p[i] < min_p:\n ans += 1\n min_p = p[i]\nprint(ans)", "n=int(input())\n\nplist=list(map(int,input().split()))\n\ntmpmin=2*(10**5)\ncount=0\nfor i in range(n):\n if tmpmin>=plist[i]:\n tmpmin=plist[i]\n count+=1\nprint(count)", "n=int(input())\np=list(map(int,input().split()))\nans,m=0,p[0]\nfor i in range(n):\n m=min(m,p[i])\n if m==p[i]: ans+=1\nprint(ans)", "n = int(input())\np = list(map(int,input().split()))\n\nmin_num = 10**6\ncnt = 0\nfor i in range(n):\n if p[i] < min_num:\n min_num = p[i]\n cnt += 1\nprint(cnt)", "n = int(input())\ns = list(map(int, input().split()))\n\nmin = s[0]\nans = 0\n\nfor i in range(n):\n if min >= s[i]:\n min = s[i]\n ans += 1\n\nprint(ans)\n", "n = int(input())\np = list(map(int, input().split()))\nans = 0\nmn = float('inf')\nfor i in range(n):\n mn = min(p[i], mn)\n if mn == p[i]:\n ans += 1\nprint(ans)", "n = int(input())\na = list(map(int,input().split()))\ncount = 0\nmina = n + 1\nfor i in a:\n if mina >= i:\n count += 1\n mina = i\n\nprint(count)", "N = int(input())\nS = list(map(int,input().split()))\n\ncnt = 1\nmin_n = S[0]\nfor n in S[1:]:\n #print(min_n,n)\n if n <= min_n:\n min_n = n\n cnt += 1\n \nprint(cnt)\n", "n = int(input())\np = list(map(int,input().split()))\n\nmini = float(\"inf\")\ncnt = 0\nfor i in range(n):\n if p[i] <= mini:\n cnt += 1\n mini = p[i]\nprint(cnt)", "N = int(input())\nP = list(map(int, input().split()))\n\nans = 0\ncheck = 10**9 + 7\n\nfor i in range(N):\n if check > P[i]:\n ans += 1\n check = P[i]\n\nprint(ans)", "n = int(input())\np = list(map(int,input().split()))\nmin = p[0]\nans = 0\nfor i in range(n):\n if min >= p[i]:\n ans += 1\n min = p[i]\nprint(ans)", "N=int(input())\nP=list(map(int,input().split()))\nans=0\nmini=10**6\nfor p in P:\n if p<=mini:\n mini=p\n ans+=1\nprint(ans)", "def main():\n\tn = int(input())\n\tp = [int(v) for v in input().split()]\n\tans = 1\n\tsofar = p[0]\n\tfor i in range(1, len(p)):\n\t\tsofar = min(p[i-1],sofar)\n\t\tif p[i] < sofar:\n\t\t\tans +=1\n\treturn ans\n\ndef __starting_point():\n print((main()))\n\n__starting_point()", "N = int(input())\nP = list(map(int, input().split()))\nans = 0\nnum = P[0]\n\nfor i in range(N):\n if num >= P[i]:\n ans += 1\n num = P[i]\n\nprint(ans)\n", "N = int(input())\nP = list(map(int, input().split()))\n\ndp = [0] * N\ndp[0] = P[0]\nans = 1\nfor i in range(1, N):\n if P[i] <= dp[i - 1]:\n dp[i] = P[i]\n ans += 1\n else:\n dp[i] = dp[i - 1]\n\nprint(ans)\nreturn", "n = int(input())\np = list(map(int, input().split()))\n\nmin = p[0]\ncount = 1\n\nfor i in range(1,n):\n if p[i] <= min:\n count += 1\n min = p[i]\n\nprint(count)", "n = int(input())\nP = list(map(int, input().split()))\nminSoFar = 2 * 10**5 + 1\nans = 0\nfor i in range(n):\n if P[i] < minSoFar:\n ans += 1\n minSoFar = min(minSoFar, P[i])\nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\n\ncnt = 0\n\nfor p in P:\n cnt += p <= N\n N = min(N, p)\n\nprint(cnt)", "#!/usr/bin/env python3\ndef main():\n _ = int(input())\n P = [int(x) for x in input().split()]\n\n res = P[0]\n ans = 0\n for p in P:\n if p <= res:\n ans += 1\n res = p\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N=int(input())\nP=list(map(int,input().split()))\nm=N\nans=0\nfor i in range(N):\n if m>=P[i]:\n ans+=1\n m=min(m,P[i])\nprint(ans)\n", "N = int(input())\np = [int(n) for n in input().split()]\n\ncount = 1\nval_min = p[0]\nfor i in range(1, N):\n if val_min >= p[i]:\n count += 1\n \n val_min = min(val_min, p[i])\n\nprint(count)", "import sys\n\nn = int(input())\np = list(map(int,input().split()))\nmin = sys.maxsize\ncnt = 0\n\nfor i in range(n):\n if min >= p[i]:\n min = p[i]\n cnt += 1\n\nprint(cnt)", "N = int(input())\np = list(map(int, input().split()))\n \n# \u6761\u4ef6\u306fN=O(10^5)\u3088\u308aO(N)\u3067\u89e3\u304f\n# \u4e8c\u91cd\u30eb\u30fc\u30d7\u3092\u3059\u308b\u3068\u3001O(N^2)\u3067\u9593\u306b\u5408\u308f\u306a\u3044\n# \u7d2f\u7a4d\u548c\u306e\u554f\u984c\uff08ABC-154-D\u3068\u304b\uff09\u3068\u540c\u3058\u767a\u60f3\u304c\u4f7f\u3048\u308b\uff01\n \n# \u5177\u4f53\u7684\u306bO(N)\u3067\u89e3\u304f\u305f\u3081\u306b\u3001\u6700\u521d\u306b\u5404i\u306b\u5bfe\u3057\u3066\u3001i\u756a\u76ee\u307e\u3067\u306e\u6700\u5c0f\u5024\u3092\u6c42\u3081\u3066\u304a\u304f\nm = [0]*(N)\nm[0] = p[0]\nfor i in range(1, N):\n m[i] = min(m[i-1], p[i])\n\n# \u5404i\u307e\u3067\u306e\u6700\u5c0f\u5024\u3068i\u756a\u76ee\u306e\u5024\u3092\u6bd4\u8f03\u3057\u3001\u6700\u5c0f\u5024\u306e\u65b9\u304c\u5927\u304d\u3051\u308c\u3070\u3088\u3044\nans = 1\nfor i in range(1, N):\n if m[i-1] >= p[i]: ans += 1\n\nprint(ans)", "N = int(input())\nP = list(map(int,input().split()))\n\nans = N\nmin_val = N\n\nfor i in range(N):\n target = P[i]\n\n if target < min_val:\n min_val = target\n\n if min_val < target:\n ans -= 1\n\nprint(ans)\n", "n = int(input())\np = [int(s) for s in input().split()]\n\nans = 1\nmin_val = p[0]\nfor i in range(1, n):\n if p[i] <= min_val:\n min_val = p[i]\n ans += 1\nprint(ans)", "n = int(input())\np = list(map(int,input().split()))\nans = 0\nfor i in range(n):\n if (i == 0):\n ans = ans + 1\n x = p[0]\n else:\n if (x < p[i]):\n pass\n else:\n ans = ans + 1\n x = p[i]\n\nprint(ans)\n", "n = int(input())\np = list(map(int, input().split()))\n\nans = 1\ncur_min = p[0]\n\nfor i in range(1, n):\n\tcur_min = min(p[i - 1], cur_min)\n\tif p[i] <= cur_min:\n\t\tans += 1\n\nprint(ans)", "n = int(input())\np = list(map(int,input().split()))\nans = 0\nm = 10**18\n\nfor i in p:\n if m > i:\n m = i\n ans += 1\nprint(ans)", "N = int(input())\nP_ls = map(int, input().split(' '))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "N = int(input())\nP_ls = list(map(int, input().split(' ')))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "n=int(input());a=[*map(int,input().split())];count,m=0,n+1\nfor i in a:\n if m>i: m=i;count+=1\nprint(count)", "N = int(input())\nP = list(map(int, input().split()))\n\ncnt = 0\nmini = float('inf')\n\nfor i in range(0, len(P)):\n if P[i] < mini:\n cnt += 1\n mini = P[i]\n\nprint(cnt)", "# C\nN = int(input())\nP = list(map(int,input().split()))\nmin_p = 10**10\nans = 0\nfor i in range(N):\n if min_p >= P[i]:\n ans += 1\n min_p = min(min_p,P[i])\nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\n\nS = sorted(P, reverse = True)\ncn = 0\nL = []\n\n\n\nfor i in range(N):\n if i == 0:\n cn = cn + 1\n L.append(P[i])\n\n else:\n if P[i] > L[0]:\n continue\n \n else:\n cn = cn + 1\n L.append(P[i])\n L.pop(0)\n\n\nprint(cn)", "N = int(input())\nP = list(map(int, input().split()))\na = 0\nfor p in P:\n if p <= N:\n a += 1\n N = p\nprint(a)", "N=int(input())\nlst = [int(n) for n in input().split()]\nm=999999\ncnt = 0\nfor l in range(N):\n m = min(m,lst[l])\n if m==lst[l]:\n cnt+=1\nprint(cnt)\n", "N = int(input())\nP_list = list(map(int, input().split()))\n\nnum_min = 2 * (10 ** 5)\nans = 0\n\nfor i in P_list:\n if num_min >= i:\n num_min = i\n ans += 1\n else:\n continue\n\nprint(ans)", "N = int(input())\nP_ls = list(map(int, input().split(' ')))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "N = int(input()) \ns = list(map(int,input().split()))\ntemp=1000000\ncount=0\nfor i in range(N):\n if temp>s[i]:\n count =count+1\n temp=s[i]\n\nprint(count)\n", "n=int(input())\np=list(map(int,input().split()))\nans=0\nm=2*10**5+1\nfor i in range(n):\n if m>p[i]:\n m=p[i]\n ans+=1\nprint(ans)", "N = int(input())\nP_ls = list(map(int, input().split(' ')))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "n=int(input())\na=list(map(int,input().split()))\nc=0\nj=float('inf')\nfor i in a:\n if i<j:\n c+=1\n j=i\nprint(c)", "import numpy as np\nN = int(input())\nP = [int(i) for i in input().split()]\nres = 0\nfor p, c_min in zip(P, np.minimum.accumulate(P)):\n if p <= c_min: res+=1\n \nprint(res)", "n = int(input())\np = list(map(int, input().split()))\nans = 1\np_min = p[0]\n\nfor i in range(1,n): \n if p_min >= p[i]:\n ans += 1\n p_min = min(p_min, p[i])\n\nprint(ans)", "n=int(input())\nl=list(map(int,input().split()))\na=n+1\nans=0\nfor i in range(n):\n if l[i]<=a:\n ans+=1\n a=l[i]\nprint(ans)", "N = int(input())\nP = list(map(int, input().split()))\nMin = P[0]\ncount = 0\nfor i in range(N):\n if Min >= P[i]:\n count += 1\n Min = P[i]\nprint(count)", "N = int(input())\nP = list(map(int, input().split()))\n\nans=1\n\np=P[0]\n\nfor i in range(N) :\n if p > P[i]:\n ans = ans + 1\n p = P[i]\n \n\nprint(ans)", "N = int(input())\nP = list(map(int,input().split()))\nm = P[0]\nk = 1\nfor j in range(N-1):\n i = j+1\n if m >= P[i]:\n k += 1\n m = min(m,P[i])\nprint(k) \n", "n=int(input())\np=list(map(int,input().split()))\n\nmin=p[0]\ncnt=0\nfor i in range(n):\n if min>=p[i]:\n cnt+=1\n min=p[i]\nprint(cnt)\n", "N = int(input())\nP = list(map(int,input().split()))\nT = [P[0]]+[10**10]*(N-1)\nans = 0\n\nfor i in range(N):\n T[i] = min(T[i-1],P[i])\n if P[i] <= T[i]:\n ans += 1\n\nprint(ans)", "n = int(input())\np = list(map(int, input().split()))\nmi = p[0]\nres = 0\nfor v in p:\n mi = min(v, mi)\n if mi == v:\n res += 1\nprint(res)", "from sys import setrecursionlimit, exit\nsetrecursionlimit(1000000000)\n\ndef main():\n n = int(input())\n p = list(map(int, input().split()))\n ans = 1\n minimum = p[0]\n for i in range(1, n):\n if minimum >= p[i]:\n ans += 1\n minimum = p[i]\n print(ans)\n\nmain()", "N=int(input())\nP=list(map(int, input().split()))\n\nans=0\ntempmin=P[0]\n\nfor i in range(N):\n\tif tempmin>=P[i]:\n\t\t#print(tempmin,P[i])\n\t\tans+=1\n\ttempmin=min(tempmin,P[i])\n\t\nprint(ans)", "n = int(input())\np = list(map(int, input().split()))\n\n\nlow = 3 * 10 ** 5\ncnt = 0\n\nfor x in p:\n if x < low:\n cnt += 1\n low = x\nprint(cnt)", "n = int(input())\np = list(map(int,input().split()))\nminp = p[0]\ncnt = 0\nfor i in range(n):\n if p[i]<=minp:cnt+=1\n minp = min(minp,p[i])\nprint(cnt)", "n = int(input())\nP = list(map(int, input().split()))\nans = 0\nm = 200002\nfor p in P:\n if p <= m:\n m = p\n ans += 1\nprint(ans)", "n = int(input())\nnum_list = list(map(int, input().split()))\n\ncnt = 0\nmin = num_list[0]\nfor i in range(n):\n if num_list[i] <= min:\n min = num_list[i]\n cnt += 1\n\nprint(cnt)", "N = int(input())\nP_ls = list(map(int, input().split(' ')))\nrst, min_val = 0, 10 ** 6\nfor i in P_ls:\n if min_val >= i:\n rst += 1\n min_val = i\nprint(rst)", "n = int(input())\np = list(map(int, input().split()))\nmini = p[0]\nans = 0\nfor i in p:\n if i <= mini:\n ans += 1\n mini = min(mini,i)\nprint(ans)", "n = int(input())\nx = list(map(int,input().split()))\ncount = 1\nm = x[0]\n\nfor i in range(1,n):\n if m >=x[i]:\n count+=1\n m = x[i]\n \nprint(count)", "# coding: utf-8\n\ndef main():\n N = int(input())\n tmp = 200001\n ans = 0\n A = list(map(int, input().split()))\n\n for a in A:\n if a < tmp:\n ans += 1\n tmp = a\n\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "N=int(input())\nP=list(map(int,input().split()))\n\ntmp=N\ncnt=0\nfor i in range(N):\n tmp=min(tmp,P[i])\n if tmp>=P[i]:\n cnt+=1\nprint(cnt)", "N = int(input())\nP_ls = map(int, input().split(' '))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "N = int(input())\nP_ls = map(int, input().split(' '))\nmin_val = 10 ** 6\nrst = 0\nfor i in P_ls:\n if i <= min_val:\n rst += 1\n min_val = i\nprint(rst)", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n numbers=[]\n n = int(input())\n numbers=list(map(int,input().split()))\n small=0\n dp=[]\n\n for idx,data in enumerate(numbers):\n if idx == 0:\n small=data\n dp.append(data)\n elif data < small:\n small=data\n dp.append(data)\n else:\n continue\n print(len(dp))\n\ndef __starting_point():\n main()\n__starting_point()", "def N():\n return int(input())\ndef L():\n return list(map(int,input().split()))\ndef NL(n):\n return [list(map(int,input().split())) for i in range(n)]\nmod = pow(10,9)+7\n\n#import numpy as np\nimport sys\nimport math\nimport collections\n\nn = N()\np = L()\nmi = sys.maxsize\ncnt = 0\nfor i in p:\n if i <= mi:\n cnt += 1\n mi = i\nprint(cnt)", "n=int(input())\na=list(map(int,input().split()))\nc=0\nj=float('inf')\nfor i in a:\n if i<j:\n c+=1\n j=min(j,i)\nprint(c)", "def main():\n\tn = int(input())\n\tp = [int(v) for v in input().split()]\n\tans = 1\n\tsofar = p[0]\n\tfor i in p:\n\t\tif i < sofar:\n\t\t\tans +=1\n\t\t\tsofar = i\n\treturn ans\n\ndef __starting_point():\n print((main()))\n\n__starting_point()", "N = int(input())\nP = list(map(int,input().split()))\nT = [P[0]]+[10**10]*(N-1)\nans = 0\n\nfor i in range(N):\n T[i] = min(T[i-1],P[i])\n\nfor i in range(N):\n if P[i] <= T[i]:\n ans += 1\n\nprint(ans)", "n = int(input())\nnum = list(map(int,input().split()))\ncount = 10**18\nans = 0\n\nfor i in num:\n if count > i:\n count = i\n ans += 1\n \nprint(ans) "] | {"inputs": ["5\n4 2 5 1 3\n", "4\n4 3 2 1\n", "6\n1 2 3 4 5 6\n", "8\n5 7 4 2 6 8 1 3\n", "1\n1\n"], "outputs": ["3\n", "4\n", "1\n", "4\n", "1\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 21,460 | |
0e45b94ca6e2f5b1159bcf4bab938546 | UNKNOWN | You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.
Here, an sequence b is a good sequence when the following condition holds true:
- For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be a good sequence.
-----Constraints-----
- 1 \leq N \leq 10^5
- a_i is an integer.
- 1 \leq a_i \leq 10^9
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
-----Output-----
Print the minimum number of elements that needs to be removed so that a will be a good sequence.
-----Sample Input-----
4
3 3 3 3
-----Sample Output-----
1
We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence. | ["import collections\n\nN=int(input())\nL=list(map(int,input().split()))\nL=sorted(L)\nC=collections.Counter(L)\nD=list(C.keys())\nE=list(C.values())\nK=len(C)\nans=0\nfor i in range(K):\n\tif D[i]==E[i]:\n\t\tans+=0\n\tif D[i]>E[i]:\n\t\tans+=E[i]\n\tif D[i]<E[i]:\n\t\tans+=(E[i]-D[i])\nprint(ans)\n", "n = int(input())\na = list(map(int,input().split()))\nans = 0\n\nfrom collections import defaultdict\ndd = defaultdict(int)\nfor key in a:\n dd[key] += 1\nfor key in dd.keys():\n #print(key,dd[key])\n if dd[key]>=key:\n ans += dd[key]-key\n else:\n ans += dd[key]\nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\ndict={}\nfor i in range(n):\n if a[i] not in dict:\n dict[a[i]]=1\n else:\n dict[a[i]]+=1\nans=0\nfor i in dict:\n if dict[i]<i:\n ans+=dict[i]\n elif dict[i]==i:\n continue\n else:\n ans+=dict[i]-i\nprint(ans)", "def main():\n n = int(input())\n inlis = list(map(int, input().split()))\n adic = dict()\n ans = 0\n\n for i in range(n):\n a = inlis[i]\n if a not in adic:\n adic[a] = 1\n else:\n adic[a] += 1\n if adic[a] > a:\n ans += 1\n \n for num in adic:\n if adic[num] < num:\n ans += adic[num]\n\n print(ans)\n \n\n \n\n\ndef __starting_point():\n main()\n__starting_point()", "n=int(input());a=list(map(int,input().split()));d={}\nfor i in a:\n if i not in d: d[i]=1\n else: d[i]+=1\nprint(sum([j if i>j else j-i for i,j in d.items()]))", "from collections import Counter\n\nN = int(input())\nA = Counter(list(map(int, input().split())))\n\nres = 0\nfor values, counts in list(A.items()):\n if(values > counts):\n res += counts\n elif(values < counts):\n res += counts - values\nprint(res)\n", "N=int(input())\n*A,=map(int,input().split())\nimport collections\n\nc = collections.Counter(A)\n\nans=0\nfor k,v in c.items():\n if k == v: continue\n if k < v: # k\u306b\u5bfe\u3057\u3066\u8981\u7d20\u6570\u304c\u591a\u3044\u306e\u3067\u53d6\u308a\u9664\u304f\n ans+=v-k\n if v < k: # k\u306b\u5bfe\u3057\u3066\u8981\u7d20\u6570\u304c\u5c11\u306a\u3044\u306e\u3067\u3001\u3059\u3079\u3066\u53d6\u308a\u9664\u304f\n ans+=v\nprint(ans)", "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\nfrom bisect import bisect, bisect_left, bisect_right\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN = INT()\nA = LIST()\n\nS = set(A)\nC = Counter(A)\ncnt = 0\nfor s in S:\n if C[s] != s:\n if C[s] > s:\n cnt += C[s] - s\n else:\n cnt += C[s]\nprint(cnt)", "input();a=list(map(int,input().split()));d={}\nfor i in a:\n if i not in d: d[i]=1\n else: d[i]+=1\nprint(sum([j if i>j else j-i for i,j in d.items()]))", "from collections import defaultdict\nN = int(input())\nA = list(map(int,input().split()))\nhashmap = defaultdict(int)\nfor a in A:\n hashmap[a]+=1\nans = 0\nfor k, v in hashmap.items():\n if k < v:\n ans+=v-k\n elif k > v:\n ans+=v\nprint(ans)", "from collections import Counter\n\nn = int(input())\na = list(map(int, input().split()))\n\ncount = 0\n\nfor i, j in Counter(a).items():\n if j-i < 0:\n count += j\n else:\n count += min(j-i, j)\n\nprint(count)", "n=int(input())\na=[int(i) for i in input().split()]\n\ndp=[0]*(n+2)\nfor i in a:\n if i>n:\n dp[-1]+=1\n else:\n dp[i]+=1\n\nans=dp[-1]\nfor i in range(1,n+1):\n if dp[i]>=i:\n ans+=dp[i]-i\n else:\n ans+=dp[i]\nprint(ans)\n", "import collections\nN=int(input())\na=list(map(int,input().split()))\nc=collections.Counter(a)\nans=0\nfor i,j in c.items():\n if i>j:\n ans+=j\n elif j>i:\n ans += j-i\nprint(ans)", "import sys\nfrom collections import Counter\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n n = ini()\n a = inl()\n c = Counter()\n for x in a:\n c[x] += 1\n ans = 0\n for k, v in c.items():\n if k <= v:\n ans += v - k\n else:\n ans += v\n\n return ans\n\n\nprint(solve())\n", "from collections import Counter\n\ndef mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n = int(input())\n a = Counter(Input())\n ans = 0\n for key, val in a.items():\n x = val - key\n if x < 0:\n ans += val\n elif x > 0:\n ans += x\n print(ans)\n\n\nmain()", "from collections import Counter\n\nN=input()\nlist1=list(map(int,input().split()))\ndict1=Counter(list1)\n\nkey1=list(dict1.keys())\nvalue1=list(dict1.values())\n\nans=0\nfor i in range(len(key1)):\n x=value1[i]\n y=key1[i]\n if x>=y:\n ans+=x-y\n else:\n ans+=x\n\nprint(ans)", "from collections import Counter\ninput();a=Counter(map(int,input().split()))\nprint(sum(j if i>j else j-i for i,j in a.items()))", "import sys\nfrom collections import Counter\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef main():\n n = int(input())\n a = Counter(list(map(int, input().split())))\n \n ans = 0;\n for k, v in a.items():\n if k < v:\n ans += v - k\n elif k > v:\n ans += v\n \n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "N=int(input())\na=list(map(int,input().strip().split()))\nd={}\n\nfor n in range(N):\n if d.get(a[n])==None:\n d[a[n]]=1\n else:\n d[a[n]]+=1\n\ncnt=0\nfor key in list(d.keys()):\n if key>d[key]:\n cnt+=d[key]\n else:\n cnt+=d[key]-key\n\nprint(cnt)\n", "from collections import Counter\nN = int(input())\nA = list(map(int, input().split()))\nA = Counter(A)\n\ncnt = 0\nfor i, j in list(A.items()):\n if i > j:\n cnt += j\n elif i < j:\n cnt += j-i\nprint(cnt)\n", "#!/usr/bin/env python\n\nn = int(input())\na = list(map(int, input().split()))\n\nd = {}\ncnt = 0 \nfor i in range(n):\n if a[i] not in d:\n d[a[i]] = 1 \n else: \n d[a[i]] += 1\n\nfor key in list(d.keys()):\n if d[key] != key:\n if d[key] < key:\n cnt += d[key]\n else:\n cnt += d[key]-key\n\nprint(cnt)\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# FileName: \tC\n# CreatedDate: 2020-10-09 21:07:08 +0900\n# LastModified: 2020-10-09 21:11:06 +0900\n#\n\n\nimport os\nimport sys\n# import numpy as np\n# import pandas as pd\nfrom collections import Counter\n\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n A_cnt = Counter(A)\n ans = 0\n for key, value in list(A_cnt.items()):\n if key == value:\n pass\n elif key > value:\n ans += value\n else:\n ans += value-key\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import collections as c\nN,*A = map(int,open(0).read().split())\nA = c.Counter(A)\nans=0\nfor a,n in A.items():\n if a<n:\n ans+=n-a\n elif a>n:\n ans+=n\nprint(ans)", "from collections import Counter\nn=int(input())\nL=Counter(list(map(int,input().split())))\nans=0\nfor i in L:\n if i!=L[i]:\n if L[i]-i>0:\n ans=ans+L[i]-i\n else:ans+=L[i]\nprint(ans)\n", "N = int(input())\nA = list(map(int, input().split()))\nd = dict()\nfor i in range(N):\n if d.get(A[i]) is None:\n d[A[i]] = 1\n else:\n d[A[i]] += 1\nans = 0\nfor key, value in list(d.items()):\n if key <= value:\n ans += value - key\n else:\n ans += value\nprint(ans)\n\n\n", "from collections import Counter\nn = int(input())\nc = Counter(map(int, input().split()))\nans = 0\nfor i in c:\n if c[i]>i:\n ans += c[i]-i\n elif c[i]<i:\n ans += c[i]\nprint(ans)", "import collections\nn = int(input())\na = list(map(int,input().split()))\n\na_cnt = collections.Counter(a)\n#print(a_cnt)\ncnt = 0\nfor item in a_cnt.items():\n if item[0]<item[1]:\n cnt += item[1]-item[0]\n elif item[0]>item[1]:\n cnt += item[1]\nprint(cnt)", "import sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan2, degrees\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy, copy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\n\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(): return list(map(int, input().split()))\n\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef main():\n N = INT()\n li = LIST()\n A = defaultdict(int)\n for i in li:\n A[i] += 1\n cnt = 0\n for i in list(A.keys()):\n if i < A[i]:\n cnt += A[i]-i\n elif i > A[i]:\n cnt += A[i]\n\n print(cnt)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nA = list(map(int,input().split()))\nans = 0\ndict = {}\nfor i in range(N):\n if A[i] in dict:\n dict[A[i]] += 1\n else:\n dict[A[i]] = 1\n#print(dict)\nfor x in dict:\n if x > dict[x]:\n ans += dict[x]\n else:\n ans += dict[x]-x\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\ns = set(a)\n\nd = {}\nfor i in s:\n d[i] = 0\nfor i in a:\n d[i] += 1\n\nans = 0\nfor i in d:\n c = d[i]\n if c < i:\n ans += c\n elif c >= i:\n ans += c - i\nprint(ans)", "import collections as c\n\nn = int(input())\ns = list(map(int,input().split()))\ns = c.Counter(s)\nans = 0\nfor i in s.items():\n a = i[0]\n b = i[1]\n if b<a:\n ans += b\n else:\n ans += b-a\nprint(ans)", "import collections\nn = int(input())\na = list(map(int, input().split()))\nc = collections.Counter(a)\nans = 0\nfor k in c.keys():\n if k > c[k]:\n ans += c[k]\n elif k < c[k]:\n ans += c[k] - k\nprint(ans)", "import sys\nimport math\nfrom collections import Counter\n\n\ninint = lambda: int(sys.stdin.readline())\ninintm = lambda: map(int, sys.stdin.readline().split())\ninintl = lambda: list(inintm())\ninstrm = lambda: map(str, sys.stdin.readline().split())\ninstrl = lambda: list(instrm())\n\nn = inint()\nA = inintl()\n\nC = Counter(A)\nans = 0\n\nfor c in C:\n if c > C[c]:\n ans += C[c]\n elif c < C[c]:\n ans += C[c] - c\n\nprint(ans)", "from collections import Counter\n \nN = input()\nA = list(map(int, input().split()))\n \ncounter = Counter(A)\n \ncnt = 0\nfor k, v in counter.items():\n if v < k:\n cnt += v\n elif v > k:\n cnt += v - k\n \n \nprint(cnt)", "N=int(input())\n\na=list(map(int,input().split()))\n\na.sort()\nc=1\nans=0\nfor i in range(N-1):\n if a[i]==a[i+1]:\n c+=1\n if c>a[i]:\n ans+=1\n else:\n if c<a[i]:\n ans+=c\n c=1\n else:\n c=1\nif c<a[N-1]:\n ans+=c\n\nprint(ans)\n", "#\n# abc082 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\nfrom collections import Counter\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"4\n3 3 3 3\"\"\"\n output = \"\"\"1\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"5\n2 4 1 4 2\"\"\"\n output = \"\"\"2\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"6\n1 2 2 3 3 3\"\"\"\n output = \"\"\"0\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"1\n1000000000\"\"\"\n output = \"\"\"1\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_5(self):\n input = \"\"\"8\n2 7 1 8 2 8 1 8\"\"\"\n output = \"\"\"5\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N = int(input())\n A = tuple(map(int, input().split()))\n C = Counter(A)\n\n ans = 0\n for k, v in list(C.items()):\n if v > k:\n ans += v - k\n elif v < k:\n ans += v\n\n print(ans)\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "N = int(input())\nA = list(map(int,input().split()))\nans = 0\nA.sort()\n\ncount = 0\nm = 0\n\nfor i in range(N):\n if count == 0:\n m = A[i]\n count += 1\n elif A[i] == m:\n count += 1\n else:\n if m > count:\n ans += count\n else:\n ans += count-m\n count = 1\n m = A[i]\n\nif m > count:\n ans += count\nelse:\n ans += count-m\n\nprint(ans)", "from collections import Counter\ninput();a=Counter(map(int,input().split()))\nprint(sum([j if i>j else j-i for i,j in a.items()]))", "from collections import Counter\nn = int(input())\na = Counter(list(map(int, input().split())))\ncnt = 0\nfor x,y in a.items():\n if x==y: continue\n if x>y: cnt += y\n else: cnt += y-x\nprint(cnt)", "import collections\nn=int(input())\na=list(map(int,input().split()))\nl=list(set(a))\nm=collections.Counter(a)\nans=0\nfor i in range(len(l)):\n if m[l[i]]<l[i]:\n ans+=m[l[i]]\n else:\n ans+=m[l[i]]-l[i]\nprint(ans)", "n = int(input())\na = list(map(int,input().split()))\nd = dict()\nfor i in a:\n if i not in d:\n d[i] = 1\n\n else:\n d[i] += 1\ncount = 0\nfor key, value in list(d.items()):\n if int(key) > value:\n count += int(value)\n elif int(key) < value:\n count += value - int(key)\n\nprint(count)\n", "N = int(input())\na = list(map(int,input().split()))\nimport collections\nA = collections.Counter(a)\nans = 0\nfor i,j in A.items():\n if j > i:\n ans += j-i\n elif i > j:\n ans += j\nprint(ans)", "import sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import accumulate, permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left\nfrom fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\nINPUT = lambda: sys.stdin.readline().rstrip()\nINT = lambda: int(INPUT())\nMAP = lambda: list(map(int, INPUT().split()))\nS_MAP = lambda: list(map(str, INPUT().split()))\nLIST = lambda: list(map(int, INPUT().split()))\nS_LIST = lambda: list(map(str, INPUT().split()))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN = INT()\nA = LIST()\n\nA_c = Counter(A)\n\nans = 0\nfor k, v in zip(list(A_c.keys()), list(A_c.values())):\n if k < v:\n ans += v - k\n elif k > v:\n ans += v\nprint(ans)\n", "n = int(input())\nalist = list(map(int,input().split()))\nfrom collections import Counter\nadic = Counter(alist)\ncount = 0\nfor k,v in adic.items():\n if int(k) <= v:\n count+=(v-int(k))\n else:\n count+=v\nprint(count)", "def count(list):\n dict = {}\n for i in range(len(list)):\n dict[list[i]] = dict.get(list[i], 0) + 1\n return dict\n\nn = int(input())\na = list(map(int,input().split()))\ndic = count(a)\nans = 0\n\nfor i, x in dic.items():\n differ = x - i\n if differ>0:\n ans += differ\n elif differ<0:\n ans += x\n\nprint(ans)", "N = int(input())\na = [int(s) for s in input().split()]\np = {}\n\nfor b in a:\n if b in p:\n p[b] += 1\n else:\n p[b] = 1\n\nans = 0\nfor k in p:\n if k > p[k]:\n ans += p[k]\n elif k < p[k]:\n ans += (p[k] - k)\n\nprint(ans)", "import collections as c\ninput();print(sum(j if i>j else j-i for i,j in c.Counter(map(int,input().split())).items()))", "from collections import Counter\nans = 0\n_ = input()\na = list(map(int, input().split()))\nfor k,v in Counter(a).items():\n if k > v:\n ans += v\n elif k < v:\n ans += v-k\nprint(ans)", "N=int(input())\na=list(map(int,input().split()))\n\na=sorted(a)\nl=a[0]\ncnt=0\n\nb=[]\nfor i in range(N):\n if a[i]==l:\n cnt+=1\n else:\n b.append([l,cnt])\n l=a[i]\n cnt=1\nif cnt>0:\n b.append([l,cnt])\n\nans=0\nfor i in range(len(b)):\n if b[i][0]>b[i][1]:\n ans+=b[i][1]\n else:\n ans+=b[i][1]-b[i][0]\n\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\nimport collections\na = collections.Counter(a)\nans = 0\nfor i,j in list(a.items()):\n if i>j:\n ans += j\n else:\n ans += abs(i-j)\nprint(ans)\n", "from collections import Counter\n\nN, *A = list(map(int, open(0).read().split()))\ncnt = Counter(A)\nans = 0\nfor k, v in list(cnt.items()):\n if k > v:\n ans += v\n else:\n ans += v - k\nprint(ans)\n", "from collections import Counter\n\nN = int(input())\nD = list(map(int,input().split()))\n\nCD = Counter(D)\nCD=list(CD.items())\ncount=0\nfor i in range(len(CD)):\n if CD[i][0]<CD[i][1]:\n count=count+CD[i][1]-CD[i][0]\n elif CD[i][0]>CD[i][1]:\n count=count+CD[i][1]\nprint(count)", "n = int(input())\n#a, b = map(int,input().split())\nal = list(map(int, input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\nans = 0\ndic = {}\nfor a in al:\n dic[a] = dic.get(a, 0)+1\n\nfor k, v in dic.items():\n if k == v:\n pass\n elif k < v:\n ans += v-k\n else:\n ans += v\nprint(ans)", "from collections import Counter\n\nn = int(input())\nA = list(map(int, input().split()))\n\ncnt_A = Counter(A)\n\nans = 0\nfor k, v in cnt_A.items():\n if v - k >= 0:\n ans += v - k\n else:\n ans += v\nprint(ans)", "import math\nfrom collections import Counter\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn = ii()\na = li()\n\ncnt = Counter(a)\nans = 0\nfor i,j in cnt.items():\n if i > j:\n ans += j\n else:\n ans += j - i\nprint(ans)", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, a: \"List[int]\"):\n from collections import Counter\n ans = 0\n for k, v in list(Counter(a).items()):\n ans += v - k if v >= k else v\n return ans\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n a = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"\n print((solve(N, a)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef __starting_point():\n #test()\n main()\n\n__starting_point()", "n = int(input())\na = list(map(int, input().split()))\ncnt = dict()\n\nfor ai in a:\n if ai not in list(cnt.keys()):\n cnt[ai] = 1\n else:\n cnt[ai] += 1\n\nans = 0\nfor k in list(cnt.keys()):\n if cnt[k] > k:\n ans += cnt[k] - k\n elif cnt[k] < k:\n ans += cnt[k]\nprint(ans)\n", "import collections\n\nn = int(input())\na = list(map(int,input().split()))\nc = collections.Counter(a)\n\ncnt = 0\nfor k,v in list(c.items()):\n cnt += min(v-k,v) if v-k >=0 else v\nprint(cnt)\n", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\n#\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7cfb\n# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);\n# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nn = I()\nCount = Counter(readInts())\nans = 0\nfor k,v in list(Count.items()):\n if k < v:\n ans += v - k\n if v < k:\n ans += v\nprint(ans)\n", "from collections import Counter\nn = int(input())\naa = Counter(map(int, input().split()))\nans = 0\nfor k, v in aa.items():\n if k < v:\n ans += v - k\n elif k > v:\n ans += v\nprint(ans)", "from collections import Counter\n\n_ = input()\na = [int(i) for i in input().split()]\n\nans = 0\nfor k, v in Counter(a).items():\n if k < v:\n ans += v - k\n elif v < k:\n ans += v\nelse:\n print(ans)", "import collections\nn = int(input())\naa = list(map(int, input().split()))\ncc = collections.Counter(aa)\ncnt = 0\nfor c in list(cc.items()):\n if c[0] > c[1]:\n cnt += c[1]\n elif c[0] == c[1]:\n continue\n elif c[0] < c[1]:\n cnt += c[1]-c[0]\nprint(cnt)\n", "from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\n\ncount = Counter(a)\nans = 0\nfor k,v in count.items():\n if k < v: ans += v-k\n elif v < k: ans += v\nprint(ans)", "N=int(input())\na=list(map(int,input().split()))\na.append(10**10)\na.sort()\nn=0\nc=0\nans=0\nfor i in range(N+1):\n if n!=a[i]:\n if n<c:ans+=c-n\n elif c<n:ans+=c\n n=a[i]\n c=1\n else:c+=1\nprint(ans)", "import collections\nN = int(input())\nlsA = list(map(int,input().split()))\ncounterA = collections.Counter(lsA)\nans = 0\nfor i in counterA.keys():\n if i == counterA[i]:\n continue\n if i < counterA[i]:\n ans += counterA[i]-i\n elif i > counterA[i]:\n ans += counterA[i]\n\nprint(ans)", "n = int(input())\nA = list(map(int, input().split()))\n\nd = {}\nfor a in A:\n d[a] = d.get(a, 0) + 1\n\nans = 0\nfor a in d:\n if d[a]>a:\n ans += d[a]-a\n elif d[a]<a:\n ans += d[a]\nprint(ans)", "import collections\n\nN = int(input())\na = list(map(int,input().split()))\nans = 0\n\naa = collections.Counter(a).most_common()\n#print(aa)\n\nfor i,j in aa:\n if i > j:\n ans += j\n if i < j:\n ans += j-i\n \nprint(ans)", "from collections import Counter\nN = int(input())\nC = Counter(map(int, input().split()))\nans = 0\nfor i in C:\n if C[i]>i:\n ans += C[i]-i\n elif C[i]<i:\n ans += C[i]\nprint(ans)", "from collections import Counter\n\nn = int(input())\nal = list(map(int, input().split()))\nc = Counter(al)\n\nans = 0\nfor k, v in list(c.items()):\n if k == v:\n continue\n elif k > v:\n ans += v\n else:\n ans += v-k\n\nprint(ans)\n", "#!/usr/bin/env python3\n\n#import\n#import math\n#import numpy as np\nN = int(input())\n#= input()\n#= map(int, input().split())\nA = list(map(int, input().split()))\n#= [input(), input()]\n#= [list(map(int, input().split())) for _ in range(N)]\n#= [int(input()) for _ in range(N)]\n#= {i:[] for i in range(N)}\n\ndic = {}\n\nfor a in A:\n if a in dic:\n dic[a] += 1\n else:\n dic[a] = 1\n\nans = 0\n\nfor key in dic:\n if dic[key] != key:\n if dic[key] > key:\n ans += dic[key] - key\n else:\n ans += dic[key]\n\nprint(ans)", "N = int(input())\na = list(map(int, input().split()))\n\na_dic = {}\n\nfor i in range(N):\n if a[i] not in a_dic.keys():\n a_dic[a[i]] = 1\n else:\n a_dic[a[i]] += 1\n \nans = 0\n\nfor i in a_dic.keys():\n if a_dic[i] >= i:\n ans += a_dic[i] - i\n elif a_dic[i] < i:\n ans += a_dic[i]\n \nprint(ans)", "N=int(input())\nlst=list(map(int,input().split()))\nlst.sort()\nfreq={}\nfor i in lst:\n if i in freq:\n freq[i]+=1\n else:\n freq[i]=1\nans=0\nfor key,value in freq.items():\n if key>value:\n ans+=value\n elif key<value:\n ans+=abs(key-value)\nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\nhindo=dict()\nfor i in a:\n if i in hindo:\n hindo[i]+=1\n else:\n hindo[i]=1\nans=0\nfor num,cnt in hindo.items():\n if num==cnt:\n continue\n else:\n if num>cnt:\n ans+=cnt\n else:\n ans+=cnt-num\nprint(ans)", "import collections\nn = int(input())\na = list(map(int, input().split()))\nc = collections.Counter(a)\nans = 0\nfor e in c:\n if e < c[e]:\n ans += c[e] - e\n elif e > c[e]:\n ans += c[e]\nprint(ans)", "from collections import Counter\nans = 0\n_ = input()\na = Counter(map(int, input().split()))\nfor k,v in a.items():\n if k > v:\n ans += v\n elif k < v:\n ans += v-k\nprint(ans)", "import collections\n\nn = int(input())\na = list(map(int, input().split()))\n\nc = collections.Counter(a)\nans = 0\n\nfor k, v in list(c.items()):\n if k > v:\n ans += v\n if k < v:\n ans += v - k\n \nprint(ans)\n", "N=int(input())\na=list(map(int,input().split()))\na.sort()\na.append(0)\ni=0\nans=0\nwhile i<N:\n x=a[i]\n count=0\n while a[i]==x:\n i+=1\n count+=1\n if count<x:\n ans+=count\n else:\n ans+=count-x\nprint(ans)\n", "from collections import Counter\n\ninput()\na = Counter(map(int, input().split()))\nprint(sum(v - k if k <= v else v for k, v in a.items()))", "n = int(input())\ndic = {}\n\nA = list(map(int, input().split()))\n\nfor a in A:\n if a in dic:\n dic[a] += 1\n else:\n dic[a] = 1\n\nans = 0\n\nfor key in dic:\n if dic[key] != key:\n if dic[key] > key:\n ans += dic[key] - key\n else:\n ans += dic[key]\n\nprint(ans)", "from collections import Counter\nn = int(input())\nA = Counter(list(map(int, input().split())))\nans = 0\nfor k, v in list(A.items()):\n if k > v:\n ans += v\n elif k < v:\n ans += v - k\n\nprint(ans)\n", "from collections import Counter\n\nn = int(input())\nd = Counter(list(map(int, input().split())))\n\nans = 0\nfor k, v in d.items():\n if k > v:\n ans += v\n elif k < v:\n ans += v-k\nprint(ans)", "from collections import Counter\n\nN = input()\nA = list(map(int, input().split()))\n\ncounter = Counter(A)\n\ncnt = 0\nfor k, v in list(counter.items()):\n if v < k:\n cnt += v\n elif v > k:\n cnt += v - k\n\n\nprint(cnt)\n", "import collections\n\nn = int(input())\na = list(map(int, input().split()))\n\nc = collections.Counter(a)\n\nans = 0\n\nfor i in c.keys():\n if(c[i] >= i):\n ans += c[i] - i\n else:\n ans += c[i]\nprint(ans)", "N = input()\nA = sorted([int(x) for x in input().split()])\nimport bisect as bs\nans = 0\nf = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x)\nfor a in set(A):\n cnt = f(A,a)\n if cnt < a:\n ans += cnt\n else:\n ans += cnt-a\nprint(ans)", "from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\nb = Counter(a)\nans = 0\nfor i in set(a):\n if b[i] < i:\n ans += b[i]\n else:\n ans += b[i]-i\nprint(ans)", "import collections\nn = int(input())\nA = list(map(int,input().split()))\nC = collections.Counter(A)\nans = 0\n\nfor k,v in C.items():\n if k == v: continue\n elif k < v: ans += (v - k)\n else: ans += v\n\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\n\nvalues = {}\ncnt = n\n\nfor i in range(n):\n if a[i] in values:\n values[a[i]] += 1\n else:\n values[a[i]] = 1\n\n if values[a[i]] == a[i]:\n cnt -= a[i]\n\nprint(cnt)", "\nfrom collections import defaultdict\n\nN = int(input())\nA = list(map(int, input().split()))\n\nD = defaultdict(int)\nfor a in A:\n D[a] += 1\n\nans = 0\nfor a, x in D.items():\n if x >= a:\n ans += x-a\n else:\n ans += x\n\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\nnum_map = dict()\nfor i in range(n):\n if a[i] not in num_map:\n num_map[a[i]] = 1\n else:\n num_map[a[i]] += 1\n\nres = 0\nfor key, value in list(num_map.items()):\n if key <= value:\n res += value - key\n else:\n res += value\n\nprint(res)\n", "def main():\n n = int(input())\n a_lst = list(map(int, input().split()))\n a_lst.sort()\n a_set_lst = list(set(a_lst))\n a_set_lst.sort()\n\n count_lst = []\n count = 1\n if n == 1:\n count_lst.append(count)\n else:\n for i in range(n - 1):\n a1 = a_lst[i]\n a2 = a_lst[i + 1]\n\n if a1 == a2:\n count += 1\n if i == n - 2:\n count_lst.append(count)\n else:\n count_lst.append(count)\n count = 1\n if a_lst[-1] != a_lst[-2]:\n count_lst.append(count)\n\n minimum = 0\n for i in range(len(a_set_lst)):\n number = a_set_lst[i]\n count = count_lst[i]\n\n if count < number:\n minimum += count\n else:\n minimum += count - number\n\n print(minimum)\n\n\ndef __starting_point():\n main()\n__starting_point()", "from collections import Counter\nN = int(input())\na = list(map(int, input().split()))\na_counter = Counter(a)\n\nans = 0\n\nif N == 1 and a[0] != 1:\n print(1)\n return\nelif N == 1 and a[0] == 1:\n print(0)\n return\n\n\nfor i in (a_counter.items()):\n key = (i[0])\n value = (i[1])\n\n if key == value:\n pass\n \n elif key < value:\n ans = ans + (value - key)\n else:\n ans = ans + (value) \n\nprint(ans)", "from collections import Counter\nn = int(input())\na = Counter(list(map(int, input().split())))\n\nans = 0\nfor x,y in a.items():\n if x<y: ans += y-x\n elif y<x: ans += y\nprint(ans)", "from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\na = Counter(a).most_common()\nnum = 0\nfor i,j in a:\n if i < j:\n num += (j-i)\n elif j < i:\n num += j\nprint(num)", "#!/usr/bin/env python3\nfrom collections import Counter\nimport sys\nsys.setrecursionlimit(10**6)\n\n\nn = int(input())\na = list(map(int, input().split()))\n\nc = Counter(a)\n\nans = 0\nfor i in sorted(c.keys()):\n if c[i] < i:\n ans += c[i]\n elif c[i] == i:\n continue\n elif c[i] > i:\n ans += c[i]-i\nprint(ans)\n", "from collections import Counter\n\nn = int(input())\na = list(map(int, input().split()))\n\nca = Counter(a)\nans = 0\nfor k in list(ca.keys()):\n if ca[k] > k:\n ans += ca[k] - k\n elif ca[k] < k:\n ans += ca[k]\n\nprint(ans)\n", "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom functools import reduce\nfrom bisect import bisect_left, insort_left\nfrom heapq import heapify, heappush, heappop\n\nINPUT = lambda: sys.stdin.readline().rstrip()\nINT = lambda: int(INPUT())\nMAP = lambda: list(map(int, INPUT().split()))\nS_MAP = lambda: list(map(str, INPUT().split()))\nLIST = lambda: list(map(int, INPUT().split()))\nS_LIST = lambda: list(map(str, INPUT().split()))\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef main():\n N = INT()\n A = LIST()\n\n c = Counter(A)\n ans = 0\n for k, v in list(c.items()):\n if k < v:\n ans += v - k\n elif k > v:\n ans += v\n\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Sep 23 15:39:14 2020\n\n@author: liang\n\"\"\"\n\nN = int(input())\nA = [int(x) for x in input().split()]\nd = [0]*N\nans = 0\nfor a in A:\n if a > N :\n ans += 1\n else:\n d[a-1] += 1\n\nfor i in range(N):\n if d[i] > 0:\n if d[i] > i+1:\n ans += d[i] - (i+1)\n if d[i] < i+1:\n ans += d[i]\n#print(d)\nprint(ans)", "from collections import Counter\ninput();print(sum(j if i>j else j-i for i,j in Counter(map(int,input().split())).items()))", "from collections import Counter\nfrom itertools import starmap\ndef main():\n N = input()\n A = list(map(int, input().split()))\n count = Counter(A)\n remove = lambda x,y: y-x if y >= x else y\n ans = sum(starmap(remove, count.items()))\n print(ans)\n\nmain()", "n = int(input())\na = [int(x) for x in input().split()]\na.sort()\nflag = [False] * n\nres = 0\n\nfor i in range(n):\n if flag[i]:\n continue\n \n c = 0\n j = i\n \n while a[i] == a[j]:\n c += 1\n flag[j] = True\n j += 1\n if j == n:\n break\n \n if c == a[i] or c == 0:\n continue\n elif c < a[i]:\n res += c\n else:\n res += c - a[i]\n \nprint(res)"] | {"inputs": ["4\n3 3 3 3\n", "5\n2 4 1 4 2\n", "6\n1 2 2 3 3 3\n", "1\n1000000000\n", "8\n2 7 1 8 2 8 1 8\n"], "outputs": ["1\n", "2\n", "0\n", "1\n", "5\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 34,591 | |
9e7116f615a4ab39e7e22817fd127354 | UNKNOWN | We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable Snuke assigned 0.
-----Constraints-----
- The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.
-----Input-----
Input is given from Standard Input in the following format:
x_1 x_2 x_3 x_4 x_5
-----Output-----
If the variable Snuke assigned 0 was x_i, print the integer i.
-----Sample Input-----
0 2 3 4 5
-----Sample Output-----
1
In this case, Snuke assigned 0 to x_1, so we should print 1. | ["a=list(map(int,input().split()))\nfor i in range(len(a)):\n if a[i]==0:\n print(i+1)", "x_1, x_2, x_3, x_4, x_5 = list(map(int, input().split()))\nls = [x_1, x_2, x_3, x_4, x_5]\nnum = ls.index(0)\nprint((num + 1))\n", "x = list(map(int,input().split()))\n\nprint((x.index(0)+1))\n", "x = list(map(int, input().split()))\n\nprint(x.index(0) + 1)", "sum = 0\nfor i in map(int,input().split()):\n sum += i\nprint(15-sum)", "print(15-sum(map(int,input().split())))", "x=[int(x) for x in input().split()]\nprint(x.index(0)+1)", "x = input().split()\nx = [ int(i) for i in x ]\n\nfor i in range(len(x)):\n if x[i] ==0:\n print((i+1))\n", "print(input().replace(' ','').find('0')+1)", "x1,x2,x3,x4,x5 = map(int,input().split())\n\nif x1 == 0 : print(1)\nif x2 == 0 : print(2)\nif x3 == 0 : print(3)\nif x4 == 0 : print(4)\nif x5 == 0 : print(5)", "x = list(map(int,input().split()))\n\nfor i in range(5):\n if x[i] == 0:\n print((i+1))\n", "a, b, c, d, e= map(int, input().split())\n\nif a == 0:\n print(1)\nelif b == 0:\n print(2)\nelif c == 0:\n print(3)\nelif d == 0:\n print(4)\nelse:\n print(5)", "a, b, c, d, e = list(map(int,input().split()))\n\nif a == 0:\n print((1))\nelif b == 0:\n print((2))\nelif c == 0:\n print((3))\nelif d == 0:\n print((4))\nelse:\n print((5))\n", "x=input().split()\n\nfor i in range(0,5):\n if x[i]==\"0\":\n print(i+1)", "print(list(map(int,input().split())).index(0) + 1)", "x = input().split() #['0', '2', '3', '4', '5']\nx = [ int(i) for i in x]\n\nfor i in range(len(x)):\n if x[i] == 0:\n print(i+1)", "x = list(map(int, input().split()))\n\nfor i in range(len(x)):\n if x[i] == 0:\n print(i+1)\n break\n else:\n continue", "print(input().find('0')//2+1)", "import sys\nfrom collections import deque, defaultdict, Counter\nfrom itertools import accumulate, product, permutations, combinations\nfrom operator import itemgetter\nfrom bisect import bisect_left, bisect_right\nfrom heapq import heappop, heappush\nfrom math import ceil, floor, sqrt, gcd, inf\nfrom copy import deepcopy\nimport numpy as np\nimport scipy as sp\n\nINF = inf\nMOD = 1000000007\n\nX = [int(i) for i in input().split()]\n\ntmp = 0\nres = 0\nres = 15 - sum(X)\n\nprint(res)\n", "x1, x2, x3, x4, x5 = map(int, input().split())\nif x1 == 0:\n print(1)\n return\nif x2 == 0:\n print(2)\n return\nif x3 == 0:\n print(3)\n return\nif x4 == 0:\n print(4)\n return\nif x5 == 0:\n print(5)\n return", "ls = list(map(int, input().split()))\nfor i in range(5):\n if ls[i] == 0:\n print(i+1)\n break", "x = list(map(int, input().split()))\nfor i in range(5):\n if x[i] == 0:\n print((i+1))\n", "x1, x2, x3, x4, x5 = map(int, input().split())\nl = [x1, x2, x3, x4, x5]\nprint(l.index(0) + 1)", "Xs = list(input().split())\nprint(int(Xs.index('0')) + 1)", "print(input().index('0')//2+1)", "y = [int(i) for i in input().split()]\n\nif(y[0]==0): print(1);\nelif(y[1]==0): print(2);\nelif(y[2]==0): print(3);\nelif(y[3]==0): print(4);\nelif(y[4]==0): print(5);", "X = list(map(int,input().split()))\n\nprint((X.index(0) + 1))\n", "x = [int(i) for i in input().split()]\nfor i in range(5):\n if(x[i] == 0):\n print(i+1)", "import numpy as np\n\nx = np.array(list(map(int, input().split())))\ny = np.arange(1,6)\nprint(-sum(x-y))", "xxx = list(map(int, input().split()))\nans = 0\nfor i in range(5):\n if xxx[i] == 0:\n ans = i + 1\nprint(ans)", "value_list = list(map(int, input().split()))\nprint(value_list.index(0) + 1)", "\nl = list(map(int,input().split()))\n\nprint(l.index(0)+1)", "x = list(map(int,input().split()))\n\nfor i in range(len(x)):\n if x[i]==0:\n print(i+1)", "y = [int(i) for i in input().split()]\nfor i in range(5):\n if(y[i]==0): print((i+1));\n", "x = input().split() # ['0', '2', '3', '4', '5']\nx = [ int(i) for i in x ]\n\nfor i in range(len(x)):\n if x[i] == 0:\n print(i+1)", "x=input()\nx=list(map(int,x.split()))\nfor i in range(len(x)):\n if x[i]==0:\n print(i+1)", "a,b,c,d,e = map(str,input().split())\ns = [a,b,c,d,e]\nnum = s.index('0')\nprint(num+1)", "print(input().split().index('0')+1)", "print(input().split().index(\"0\") + 1)", "num = map(int,input().split())\ns=sum(num)\nprint(15-s)", "x = list(map(int, input().split()))\ni = 0\nfor value in x :\n i = i + 1\n if value == 0 :\n print(i)\n break", "a, b, c, d, e = list(map(int, input().split()))\nif a == 0:\n print((1))\nif b == 0:\n print((2))\nif c == 0:\n print((3))\nif d == 0:\n print((4))\nif e == 0:\n print((5))\n", "l = list(map(int,input().split()))\nfor i in range(0,5) :\n if l[i] == 0 :\n print(i+1)", "xl = list(map(int,input().split()))\nprint(xl.index(0)+1)", "x = [int(x) for x in input().split()]\n\nfor i in range(5):\n if x[i] == 0:\n print(i+1)", "X = list(map(int, input().split()))\n\nprint (X.index(0) + 1)", "X=list(map(int,input().split()))\nsum=0\nfor i in X:\n sum+=i\nprint(15-sum)", "X = list(map(int,input().split()))\n\nprint(X.index(0)+1)", "x = list((int(i) for i in input().split()))\nfor i in range(5):\n if x[i] == 0:\n print(i+1)\n break", "x_list=list(map(int,input().split()))\nfor i in range(len(x_list)):\n if (i+1) != x_list[i]:\n print((i+1))\n", "x=input().split()\nx=[ int(i) for i in x]\n\nfor i in range (len(x)):\n if x[i]==0:\n print((i+1))\n", "x=list(map(int,input().split()))\nfor i in range(5):\n if x[i]==0:\n print(i+1)", "x = list(map(int, input().split()))\na = 300\nfor i in range(len(x)):\n if x[i] == 0:\n a = i + 1\nprint(a)\n", "x =list(map(int, input().split()))\n\nfor i in range(len(x)):\n if x[i] == 0:\n print(i+1)", "li = input().split()\nprint ((li.index(\"0\")) + 1)", "S = list(map(int, input().split()))\n\nprint(S.index(0)+1)", "x = list(map(int, input().split()))\n\nfor i in range(len(x)):\n if int(x[i]) == 0:\n print(i+1)", "l = list(map(int,input().split()))\nfor i in range(5):\n if(l[i]==0):\n print(i+1)", "a=list(map(int,input().split()))\nt=0\ns=0\nfor i in range(len(a)):\n t=t+1\n if a[i]!=i+1:\n s=t\nprint(s)", "x=list(map(int ,input().split()))\nfor i in range(5):\n if i+1!=x[i]:\n print(i+1)", "x=list(map(int,input().split()))\nfor i in range(5):\n if x[i]==0:\n print(i+1)", "a = input().split()\nprint(a.index('0')+1)", "print(input().split().index('0')+1)", "variables = [int(i) for i in input().split()]\nfor i in range(5) :\n if variables[i]==0 :\n print(i+1)", "l = list(map(int, input().split()))\nfor i in range(5):\n if l[i] == 0:\n ans = i + 1\n print(ans)\n", "l = list(map(int, input().split()))\nfor i in range(5):\n if l[i] == 0:\n print((i + 1))\n", "x = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(5):\n if x[i] == 0:\n ans = i + 1\n\nprint(ans)\n", "#!/usr/bin/env python3\n\nimport sys\n\ninput = iter(sys.stdin.read().splitlines()).__next__\n\nsys.setrecursionlimit(10000)\n\nA = list(map(int, input().split()))\n\nfor i in range(len(A)):\n if A[i] == 0:\n print((i+1))\n\n", "x = list(map(int, input().split()))\nif x[0] == 0:\n print('1')\nelif x[1] == 0:\n print('2')\nelif x[2] == 0:\n print('3')\nelif x[3] == 0:\n print('4')\nelse:\n print('5')", "a,b,c,d,e = map(int,input().split())\n\nif a*1 == 0:\n print(1)\nelif b*1 == 0:\n print(2)\nelif c*1 == 0:\n print(3)\nelif d*1 == 0:\n print(4)\nelif e*1 == 0:\n print(5)", "x = list(map(int, input().split()))\nfor i in range(len(x)):\n if x[i] == 0:\n print(i+1)", "x = input()\nfor i in range(1,6):\n if str(i) not in x:\n print(i)\n break", "N = list(map(int,input().split()))\nprint(N.index(0)+1)", "a, b, c, d, e = list(map(int, input().split()))\nif a == 0:\n print((1))\nelif b == 0:\n print((2))\nelif c == 0:\n print((3))\nelif d == 0:\n print((4))\nelse:\n print((5))\n", "a = [int(x) for x in input().split()]\nprint(a.index(0) + 1)", "x=list(map(int,input().split()))\nfor i in range(5):\n if x[i]!=i+1:\n print(i+1)", "x = list(map(int, input().split()))\n\nfor i in range(5):\n if x[i] == 0:\n print((i + 1))\n break\n", "data = [int(x) for x in input().split(\" \")]\n\nfor i in range(len(data)):\n if data[i] == 0: print((i+1))\n", "x=list(map(int,input().split()))\nprint(x.index(0)+1)", "x1, x2, x3, x4, x5 = map(int,input().split())\nif x1 == 0:\n print(1)\nelif x2 == 0:\n print(2)\nelif x3 == 0:\n print(3)\nelif x4 == 0:\n print(4)\nelse:\n print(5)", "x=list(map(int ,input().split()))\ncount=0\nfor i in range(0,5):\n\tif(x[i]==0):\n\t\tcount+=1\n\t\tnumber=i+1\n\telse:\n\t\tcount+=0\n\t\t\nprint(number)\n", "X = input().split()\nprint((X.index(\"0\") + 1))\n", "# #\n # author : samars_diary #\n # 18-09-2020 \u2502 18:46:42 #\n# #\n\nimport sys, os.path\n\n#if(os.path.exists('input.txt')):\n #sys.stdin = open('input.txt',\"r\")\n #sys.stdout = open('output.txt',\"w\")\n\nsys.setrecursionlimit(10 ** 5)\n\ndef mod(): return 10**9+7\ndef i(): return sys.stdin.readline().strip()\ndef ii(): return int(sys.stdin.readline())\ndef li(): return list(sys.stdin.readline().strip())\ndef mii(): return map(int, sys.stdin.readline().split())\ndef lii(): return list(map(int, sys.stdin.readline().strip().split()))\n\n#print=sys.stdout.write\n\ndef solve():\n a=lii()\n print(1+a.index(0))\n\nfor _ in range(1):\n solve()", "xs = list(map(int, input().split()))\nprint(xs.index(0) + 1)", "x1,x2,x3,x4,x5 = map(int,input().split())\n\nif x1==0:\n print('1')\nelif x2==0:\n print('2')\nelif x3==0:\n print('3')\nelif x4==0:\n print('4')\nelif x5==0:\n print('5')", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect\n#from operator import itemgetter\n#from heapq import heappush, heappop\n#import numpy as np\n#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson\n#from scipy.sparse import csr_matrix\n#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\nimport sys\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nnf = lambda: float(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nnb = lambda: list(map(float, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nx = na()\nprint(x.index(0) + 1)", "a = list(map(int,input().split()))\nprint(15-sum(a))", "Xs = [int(x) for x in input().split()]\n\nprint(Xs.index(0) + 1)", "x=list(map(int,input().split()))\ny=x.index(0)\nprint(y+1)", "print(list(input().split()).index(\"0\") + 1) ", "x=list(input().split())\nfor i in range(len(x)):\n if(x[i]==\"0\"):\n print(i+1)", "print(input().split().index('0')+1)", "x1,x2,x3,x4,x5=list(map(int,input().split()))\n\nif x1 == 0:\n print(1)\nelif x2 == 0:\n print(2)\nelif x3 == 0:\n print(3)\nelif x4 == 0:\n print(4)\nelse:\n print(5)", "c = list(map(int,input().split()))\n\nfor i in range(0,5):\n if c[i] != i+1:\n print((i+1))\n else:\n pass\n", "def main():\n nums = list(map(int,input().split()))\n for i,n in enumerate(nums):\n if n == 0:\n return i + 1\n\ndef __starting_point():\n print(main())\n__starting_point()", "X = list(map(int, input().split()))\n\nprint((X.index(0) + 1))\n"] | {"inputs": ["0 2 3 4 5\n", "1 2 0 4 5\n", "1 0 3 4 5\n", "1 2 3 0 5\n", "1 2 3 4 0\n"], "outputs": ["1\n", "3\n", "2\n", "4\n", "5\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,553 | |
c917e686827a6c93dbbeb6ce75fde190 | UNKNOWN | There is a bar of chocolate with a height of H blocks and a width of W blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.
Find the minimum possible value of S_{max} - S_{min}.
-----Constraints-----
- 2 β€ H, W β€ 10^5
-----Input-----
Input is given from Standard Input in the following format:
H W
-----Output-----
Print the minimum possible value of S_{max} - S_{min}.
-----Sample Input-----
3 5
-----Sample Output-----
0
In the division below, S_{max} - S_{min} = 5 - 5 = 0. | ["H, W = map(int, input().split())\nans = float('inf')\nfor h in range(1,H):\n S = [h * W]\n w = W // 2\n S += [(H-h) * w]\n S += [(H-h) * (W-w)]\n ans = min(ans,max(S)-min(S))\n\nfor h in range(1,H):\n S = [h * W]\n hb = (H-h) // 2\n S += [hb * W]\n S += [(H-h-hb) * W]\n ans = min(ans,max(S)-min(S))\n\nfor w in range(1,W):\n S = [H * w]\n h = H // 2\n S += [h * (W-w)]\n S += [(H-h) * (W-w)]\n ans = min(ans,max(S)-min(S))\n\nfor w in range(1,W):\n S = [w * H]\n wb = (W-w) // 2\n S += [wb * H]\n S += [(W-w-wb) * H]\n ans = min(ans,max(S)-min(S))\n\nprint(ans)", "H, W = list(map(int, input().split()))\n\nif (H%3==0) or (W%3==0):\n print((0))\nelse:\n ans = H * W\n H, W = min(H, W), max(H, W)\n for wi in range(1, W//2 + 1):\n S1 = H * wi\n if (H%2==0) or ((W-wi)%2==0):\n S2 = H * (W-wi) // 2\n S3 = S2\n else:\n S2 = min(H, W-wi) * (max(H, W-wi)//2)\n S3 = S2 + min(H, W-wi)\n ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))\n for hi in range(1, H//2 + 1):\n S1 = W * hi\n if (W%2==0) or ((H-hi)%2==0):\n S2 = W * (H-hi) // 2\n S3 = S2\n else:\n S2 = min(W, H-hi) * (max(W, H-hi)//2)\n S3 = S2 + min(W, H-hi)\n ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))\n \n print(ans)\n \n", "def aaa(a, b):\n return abs((a // 3 * b) - ((a // 3 + 1) * b))\n\n\ndef bbb(a, b):\n ret = 1000 * 100\n for x in range(1, a):\n xx = a - x\n i = x * b\n j = xx * (b // 2)\n k = xx * (b // 2 + (b % 2))\n tmp = max(abs(i - j), abs(j - k), abs(k - i))\n ret = min(ret, tmp)\n return ret\n\n\nH, W = list(map(int, input().split()))\n\nif H % 3 == 0 or W % 3 == 0:\n print((0))\nelse:\n a = aaa(H, W)\n b = aaa(W, H)\n c = bbb(H, W)\n d = bbb(W, H)\n print((min(a, b, c, d)))\n", "H,W = map(int,input().split())\nans = [H//2+W//3+1,H//3+W//2+1,H,W]\n\nif(H%3==0 or W%3==0):\n ans+=[0]\nif(H%2==0):\n ans+=[H//2]\nif(W%2==0):\n ans+=[W//2]\n\nprint(min(ans))", "h,w = map(int,input().split())\n\ntmps = 0\nans = 10**18\nfor i in range(1,h):\n\tk = (h-i)//2\n\tt = [i*w, k*w, (h-i-k)*w]\n\ttmp = max(t)-min(t)\n\tans = min(tmp, ans)\n\tk = w//2\n\tt = [i*w, (h-i)*k, (h-i)*(w-k)]\n\ttmp = max(t)-min(t)\n\tans = min(tmp, ans)\nfor i in range(1,w):\n\tk = (w-i)//2\n\tt = [i*h, k*h, (w-i-k)*h]\n\ttmp = max(t)-min(t)\n\tans = min(tmp, ans)\n\tk = h//2\n\tt = [i*h, (w-i)*k, (w-i)*(h-k)]\n\ttmp = max(t)-min(t)\n\tans = min(tmp, ans)\nprint(ans)", "h,w = map(int,input().split())\nans = 10**10\n\ndef menseki(h,w):\n nonlocal ans\n for i in range(1,h):\n # \u7e261\u6a2a2\n haba = w//2\n ans = min(ans,max(i*w,haba*(h-i),(w-haba)*(h-i))-min(i*w,haba*(h-i),(w-haba)*(h-i)))\n # \u7e263\u5206\u5272\n if i == h-1:\n continue\n tate = (h-i)//2\n ans = min(ans,max(w*i,tate*w,(h-i-tate)*w)-min(w*i,tate*w,(h-i-tate)*w))\n\nmenseki(h,w)\nmenseki(w,h)\n\nprint(ans)", "from math import ceil, floor\n\n\ndef main():\n h, w = list(map(int, input().split()))\n d = h * w\n d = min((ceil(h / 3) - floor(h / 3)) * w, d)\n d = min((ceil(w / 3) - floor(w / 3)) * h, d)\n dd = h * w\n for i in range(h):\n u = i * w\n d1 = (h - i) * ceil(w / 2)\n d2 = (h - i) * floor(w / 2)\n di = max(abs(u - d1), abs(u - d2))\n if di > dd:\n break\n dd = di\n d = min(dd, d)\n dd = h * w\n for i in range(w):\n u = i * h\n d1 = (w - i) * ceil(h / 2)\n d2 = (w - i) * floor(h / 2)\n di = max(abs(u - d1), abs(u - d2))\n if di > dd:\n break\n dd = di\n d = min(dd, d)\n print(d)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "h,w=list(map(int,input().split()))\n\ninf=float('inf')\n\nans=inf\n\nfor i in range(1,h):\n a=i*w\n rest=h*w-a\n b=(w//2)*(h-i)\n c=rest-b\n max_s=max(a,b,c)\n min_s=min(a,b,c)\n ans=min(ans,max_s-min_s)\n \nfor j in range(1,w):\n A=j*h\n Rest=h*w-A\n B=(h//2)*(w-j)\n C=Rest-B\n Max_s=max(A,B,C)\n Min_s=min(A,B,C)\n ans=min(ans,Max_s-Min_s)\n \nif w>=3:\n if w%3==0:\n ans=0\n else:\n ans=min(ans,h)\n \nif h>=3:\n if h%3==0:\n ans=0\n else:\n ans=min(ans,w)\n \nprint(ans)\n \n\n", "def resolve():\n H, W = list(map(int, input().split()))\n \n def _solve(H, W):\n mean_w = W // 2\n ans = float(\"inf\")\n for h in range(1, H):\n s1 = h * W\n mean_h = (H-h) // 2\n for i in range(0, 2):\n if i == 0:\n s2 = (H-h)*mean_w\n s3 = (H-h)*(W-mean_w)\n if i == 1:\n s2 = mean_h*W\n s3 = (H-h-mean_h)*W\n ans = min(ans, max(s1, s2, s3)-min(s1, s2, s3))\n return ans\n\n print(min(_solve(H, W), _solve(W, H)))\n\nif '__main__' == __name__:\n resolve()", "h, w = map(int, input().split())\nif h % 3 == 0 or w % 3 == 0:\n print(0)\nelse:\n if h > w:\n h, w = w, h\n ans = h\n for w1 in range(w//3-2, w//3+3):\n s1 = w1 * h\n w2 = w-w1\n for h1 in range(h//2 + 1):\n s2 = w2 * h1\n s3 = w2 * (h-h1)\n ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))\n h, w = w, h\n for w1 in range(w//3-2, w//3+3):\n s1 = w1 * h\n w2 = w-w1\n for h1 in range(h//2 + 1):\n s2 = w2 * h1\n s3 = w2 * (h-h1)\n ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))\n print(ans)", "H, W = map(int, input().split())\n\ndef abc(x,y,z): #x,y:\u9ad8\u3055\u307e\u305f\u306f\u5e45\u3001z:\uff59\u306e\u5e45\u3092\u3082\u3064\u30d4\u30fc\u30b9\u306e\u9ad8\u3055\n a = z * y\n if (x-z)&1 and y&1:\n b = max(x-z, y)//2 * min(x-z,y)\n c = x*y - a - b\n else:\n b = c = (x-z)*y//2\n return a, b, c\n\ndef diffS(a,b,c): #a,b,c:abc()\u306e\u623b\u308a\u5024\n return max(a, b, c) - min(a, b, c)\n\ndef solve(x, y): #x,y:\u9ad8\u3055\u307e\u305f\u306f\u5e45\n z = x // 3\n return min(diffS(*abc(x,y,z)), diffS(*abc(x,y,z+1)))\n\n\nif H % 3 == 0 or W % 3 == 0:\n ans = 0\nelse:\n ans = min(solve(H,W), solve(W,H))\nprint(ans)", "# solution\n# online help taken\n\nh,w=map(int,input().split())\nans=h*w\n\nif h%3==0 or w%3==0:\n ans=0\nelse:\n ans=min(h,w)\n \na=round(h/3)*w\nb=(h-round(h/3))*(w//2)\nc=h*w-a-b\nd=max(a,b,c)-min(a,b,c)\nans=min(ans,d)\na=round(w/3)*h\nb=(w-round(w/3))*(h//2)\nc=h*w-a-b\nd=max(a,b,c)-min(a,b,c)\nans=min(ans,d)\nprint(ans)", "h,w = map(int,input().split())\ns = [h*w] * 4\n\nif h == w == 2:\n print(1)\n return\nif h % 3 == 0 or w % 3 == 0:\n print(0)\n return\n\nif w > 2:\n s[0] = h\nif h > 2:\n s[1] = w\nif h % 2 == 0:\n s[2] = h // 2\nelse:\n tmp = h*w\n for i in range(w//3, w//3+2):\n s1 = i * h\n s2 = (w-i) * (h//2)\n s3 = (w-i) * (h//2 + 1)\n tmp = min(tmp, max(s1, s2, s3) - min(s1, s2, s3))\n s[2] = tmp\nif w % 2 == 0:\n s[3] = w // 2\nelse:\n tmp = h*w\n for i in range(h//3, h//3 + 2):\n s1 = i * w\n s2 = (h-i) * (w//2)\n s3 = (h-i) * (w//2 + 1)\n tmp = min(tmp, max(s1, s2, s3) - min(s1, s2, s3))\n s[3] = tmp\n\nprint(min(s))", "import sys\nH, W = map(int,input().split())\nif H % 3 == 0 or W % 3 == 0:\n print(0)\n return\ndef solve(p, q):\n r = int(p / 2)\n s = int(q / 3)\n a, b, c = p*s, r*(q-s), (p-r)*(q-s)\n ans = max(a, b, c) - min(a, b, c)\n a, b, c = p*(s+1), r*(q-s-1), (p-r)*(q-s-1)\n ans = min(ans, max(a, b, c) - min(a, b, c))\n return ans\nans = min(W, H, solve(H, W), solve(W, H))\nprint(ans)", "ma = lambda :map(int,input().split())\nlma = lambda :list(map(int,input().split()))\ntma = lambda :tuple(map(int,input().split()))\nni = lambda:int(input())\nyn = lambda fl:print(\"Yes\") if fl else print(\"No\")\nimport collections\nimport math\nimport itertools\nimport heapq as hq\n\nH,W=ma()\ndef f(H,W):\n ret=10**10+5\n for h in range(1,H):\n s1 = h*W\n s2,s3 = (H-h)//2*W,(H-h+1)//2*W\n ret=min(ret,max(s1,s2,s3) -min(s1,s2,s3) )\n s2,s3 = W//2*(H-h),(W+1)//2*(H-h)\n ret=min(ret,max(s1,s2,s3) -min(s1,s2,s3) )\n return ret\nprint(min(f(H,W),f(W,H)))\n", "H, W = map(int, input().split())\nif (H%3) * (W%3) == 0:\n print(0)\n return\n\nans = H * W\nw1 = W // 2\nw2 = W - w1\nS1 = (H - 1) * w1; T1 = W * ((H-1)//2)\nS2 = (H - 1) * w2; T2 = W * (H-1) - T1\nS3 = W\nh = H - 1\nfor i in range(H-1):\n diff1 = max(S1, S2, S3) - min(S1, S2, S3)\n diff2 = max(T1, T2, S3) - min(T1, T2, S3)\n ans = min(ans, diff1, diff2)\n S1 -= w1; S2 -= w2; S3 += W\n h -= 1\n T1 = W * (h//2)\n T2 = W*h - T1\n\nh1 = H // 2\nh2 = H - h1\nS1 = (W - 1) * h1; T1 = H * ((W-1)//2)\nS2 = (W - 1) * h2; T2 = H * (W-1) - T1\nS3 = H\nw = W - 1\nfor i in range(W-1):\n diff1 = max(S1, S2, S3) - min(S1, S2, S3)\n diff2 = max(T1, T2, S3) - min(T1, T2, S3)\n ans = min(ans, diff1, diff2)\n S1 -= h1; S2 -= h2; S3 += H\n w -= 1\n T1 = H * (w//2)\n T2 = H*w - T1\n\nprint(ans)", "H,W = map(int,input().split())\n\nans = 1e19\n##\u7e26\u65b9\u5411\u306e\u63a2\u7d22\nfor i in range(1,H):\n tate = W*i##\u4e0a\u304b\u3089\u6a2a\u306b\u5207\u308b\n ##\u6a2a\u306b\u5207\u308b\n if i < H-1:\n mini = W*((H-i)//2)##\u5206\u5272\u3057\u305f\u3084\u3064\n ##print(tate,mini,H*W-mini-tate)\n ans = min(ans,max(tate,mini,H*W-mini-tate)-min(tate,mini,H*W-mini-tate))\n\n ##\u7e26\u306b\u5207\u308b\n mini = (H-i)*(W//2)\n ##print(tate,mini,H*W-mini-tate)\n ans = min(ans,max(tate,mini,H*W-tate-mini)-min(tate,mini,H*W-tate-mini))\n\n##\u6a2a\u65b9\u5411\u306e\u63a2\u7d22\nfor i in range(1,W):\n yoko = H*i\n if i < W-1:\n mini = H*((W-i)//2)\n ##print(yoko,mini,H*W-mini-yoko)\n ans = min(ans,max(yoko,mini,H*W-mini-yoko)-min(yoko,mini,H*W-yoko-mini))\n mini = (W-i)*(H//2)\n ##print(yoko,mini,H*W-yoko-mini)\n ans = min(ans,max(yoko,mini,H*W-yoko-mini)-min(yoko,mini,H*W-yoko-mini))\n\nprint(ans)", "h,w=map(int,input().split())\nmini=h*w\nfor i in range(1,h):\n if mini > max(w*(h-i),(w//2+w%2)*i) - min(w*(h-i),(w//2)*i):\n mini = max(w*(h-i),(w//2+w%2)*i) - min(w*(h-i),(w//2)*i)\n\nfor i in range(1,w):\n if mini > max(h*(w-i),(h//2+h%2)*i) - min(h*(w-i),(h//2)*i):\n mini = max(h*(w-i),(h//2+h%2)*i) - min(h*(w-i),(h//2)*i)\n\nif h%3 == 0 or w%3 == 0:\n mini=0\nelse:\n if mini > h:\n mini = h\n elif mini > w:\n mini = w\n else:\n pass\nprint(mini)", "h, w = list(map(int, input().split()))\nif not h%3 or not w%3:\n print((0))\nelse:\n ans = min([h, w])\n for i in range(h):\n sub = max([abs(w*i-w//2*(h-i)), abs(w*i-(w-w//2)*(h-i))])\n if ans > sub:\n ans = sub\n for i in range(w):\n sub = max([abs(h*i-h//2*(w-i)), abs(h*i-(h-h//2)*(w-i))])\n if ans > sub:\n ans = sub\n print(ans)\n", "H, W = map(int, input().split())\nif (H%3) * (W%3) == 0:\n print(0)\n return\n\nans = min(H, W)\nw1 = W // 2\nw2 = W - w1\nS1 = (H - 1) * w1\nS2 = (H - 1) * w2\nS3 = W\nfor i in range(H-1):\n diff = max(S1, S2, S3) - min(S1, S2, S3)\n ans = min(ans, diff)\n S1 -= w1; S2 -= w2; S3 += W\n\nh1 = H // 2\nh2 = H - h1\nS1 = (W - 1) * h1\nS2 = (W - 1) * h2\nS3 = H\nfor i in range(W-1):\n diff = max(S1, S2, S3) - min(S1, S2, S3)\n ans = min(ans, diff)\n S1 -= h1; S2 -= h2; S3 += H\n\nprint(ans)", "h,w = map(int, input().split())\nans = 1000000000\nif max(h,w) >= 3:\n if h >= w :\n ans = w*min(1,(h%3))\n else:\n ans = h*min(1,(w%3))\nif h%3 == 0:\n ans = 0\nif w%3 == 0:\n ans = 0\nfor i in range(1,h):\n ans_ = max(i*w,(h-i)*(w+(w%2))//2) - min(i*w,(h-i)*(w-(w%2))//2)\n ans = min(ans,ans_)\nfor i in range(1,w):\n ans_ = max(i*h,(w-i)*(h+(h%2))//2) - min(i*h,(w-i)*(h-(h%2))//2)\n ans = min(ans,ans_)\nprint(ans)", "h, w = map(int, input().split())\nINF = 100000000\n\n#\u7e26\u306b3\u3064\u5206\u3051\u308b\u5834\u5408\nif w % 3 == 0:\n s_tate = 0\nelse:\n s_tate = (int(w/3)+1) * h - int(w/3) * h\n\n#\u6a2a\u306b3\u3064\u306b\u5206\u3051\u308b\u5834\u5408\nif h % 3 == 0:\n s_yoko = 0\nelse:\n s_yoko = (int(h/3)+1) * w - int(h/3) * w\n\n#\u4e0a\u5074\u306b\u7e26\u306b2\u3064\u3001\u4e0b\u65b9\u306b1\u3064\u3067\u308f\u3051\u308b\u5834\u5408\ncase3 = INF\nif w%2 == 0:\n for i in range(1,h):\n buf = abs((int(w/2) * i) - (w * (h-i)))\n case3 = min(buf, case3)\nelse:\n for i in range(1,h):\n buf1 = int(w/2) * i\n buf2 = (int(w/2)+1) * i\n buf3 = w * (h - i)\n buf = [buf1, buf2, buf3]\n buf = sorted(buf)\n sa = buf[2] - buf[0]\n case3 = min(sa, case3)\n\n#\u5de6\u5074\u306b\uff11\u3064\u3001\u53f3\u5074\u306b\u6a2a\u306b\uff12\u3064\u3067\u308f\u3051\u308b\u5834\u5408\ncase4 =INF\nif h%2 == 0:\n for i in range(1,w):\n buf = abs((int(h/2) * i) - (h * (w-i)))\n case4 = min(buf, case4)\nelse:\n for i in range(1,w):\n buf1 = int(h/2) * i\n buf2 = (int(h/2)+1) * i\n buf3 = h * (w - i)\n buf = [buf1, buf2, buf3]\n buf = sorted(buf)\n sa = buf[2] - buf[0]\n case4 = min(sa, case4)\nans1 = min(s_tate, s_yoko)\nans2 = min(case3, case4)\n\nans = min(ans1, ans2)\n\n#print(s_tate, s_yoko, case3, case4)\n\nprint(ans)", "def pattern1(A, B):\n s1 = (A // 3) * B\n s2 = ((A - (A // 3)) // 2) * B\n s3 = A * B - s1 - s2\n return max([abs(s1 - s2), abs(s2 - s3), abs(s3 - s1)])\n\n\ndef pattern2(A, B):\n a1 = A // 2\n a2 = A - a1\n b1 = (2 * B + 1) // 3\n b2 = B - b1\n s1, s2, s3 = a1 * b1, a2 * b1, A * b2\n return max([abs(s1 - s2), abs(s2 - s3), abs(s3 - s1)])\n\n\ndef main():\n H, W = list(map(int, input().split(' ')))\n ans = min([\n pattern1(H, W),\n pattern1(W, H),\n pattern2(H, W),\n pattern2(W, H)\n ])\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "H, W = map(int, input().split())\n\nans = 10**12\n\n# 1\u679a\u76ee\u3092(1,2,...,H-1)*W\u3068\u3059\u308b\nfor h in range(1, H):\n s1 = W * h\n # \u6b8b\u308a\u306f(H-h)*W\n\n # \u6b8b\u308a\u3092\u6a2a\u306b\u5272\u308b\u5834\u5408\n h2 = (H - h) // 2\n h3 = (H - h) - h2\n s2 = W * h2\n s3 = W * h3\n max_s = max(s1, s2, s3)\n min_s = min(s1, s2, s3)\n ans = min(ans, max_s - min_s)\n\n # \u6b8b\u308a\u3092\u7e26\u306b\u5272\u308b\u5834\u5408\n w2 = W // 2\n w3 = W - w2\n s2 = (H - h) * w2\n s3 = (H - h) * w3\n max_s = max(s1, s2, s3)\n min_s = min(s1, s2, s3)\n ans = min(ans, max_s - min_s)\n\n# 1\u679a\u76ee\u3092H*(1,2,...,W-1)\u3068\u3059\u308b\nfor w in range(1, W):\n s1 = w * H\n # \u6b8b\u308a\u306fH*(W-w)\n\n # \u6b8b\u308a\u3092\u6a2a\u306b\u5272\u308b\u5834\u5408\n h2 = H // 2\n h3 = H - h2\n s2 = (W - w) * h2\n s3 = (W - w) * h3\n max_s = max(s1, s2, s3)\n min_s = min(s1, s2, s3)\n ans = min(ans, max_s - min_s)\n\n # \u6b8b\u308a\u3092\u7e26\u306b\u5272\u308b\u5834\u5408\n w2 = (W - w) // 2\n w3 = (W - w) - w2\n s2 = H * w2\n s3 = H * w3\n max_s = max(s1, s2, s3)\n min_s = min(s1, s2, s3)\n ans = min(ans, max_s - min_s)\n\nprint(ans)", "H,W = map(int,input().split())\nans = [H//2+W//3+1,H//3+W//2+1,H,W]\n\nif(H%3==0 or W%3==0):\n ans+=[0]\nif(H%2==0):\n ans+=[H//2]\nif(W%2==0):\n ans+=[W//2]\n\nprint(min(ans))", "h,w=map(int,input().split())\npattern=[h//2+w//3+1,h//3+w//2+1,h,w]\nif h%3==0 or w%3==0:\n pattern+=[0]\nif h%2==0:\n pattern+=[h//2]\nif w%2==0:\n pattern+=[w//2]\nprint(min(pattern))", "h, w = list(map(int, input().split()))\n\nif h % 3 == 0 or w % 3 == 0:\n print((0))\n return\nans = 10 ** 10\nif h >= 3:\n ans = min(h, ans)\n\nif w >= 3:\n\n ans = min(ans, w)\n # print(kouho)\n\nfor i in range(1, h):\n num1 = w * (i)\n num2 = (h - i) * (w // 2)\n num3 = (h - i) * (w - w // 2)\n kouho = [num1, num2, num3]\n kouho.sort()\n ans = min(ans, kouho[-1] - kouho[0])\nfor i in range(1, w):\n num1 = h * (i)\n num2 = (w - i) * (h // 2)\n num3 = (w - i) * (h - h // 2)\n kouho = [num1, num2, num3]\n kouho.sort()\n ans = min(ans, kouho[-1] - kouho[0])\nprint(ans)\n", "h,w=map(int,input().split());print(min(min(min(max((i*w,(h-i)//2*w,(h-i-(h-i)//2)*w))-min((i*w,(h-i)//2*w,(h-i-(h-i)//2)*w)),max((i*w,w//2*(h-i),(h-i)*(w-w//2)))-min((i*w,w//2*(h-i),(h-i)*(w-w//2))))for i in range(h)),min(min(max((h*i,(w-i)//2*h,h*(w-i-(w-i)//2)))-min((h*i,(w-i)//2*h,h*(w-i-(w-i)//2))),max((h*i,h//2*(w-i),(h-h//2)*(w-i)))-min((h*i,h//2*(w-i),(h-h//2)*(w-i))))for i in range(w))))", "h,w=map(int,input().split())\nh_half=h//2\nw_half=w//2\ns_hw=h*w\nmin_x=s_hw\n\n# H*n \u306e\u7bc4\u56f2\u3092\u63a2\u67fb\nfor n in reversed(range(1,w_half+2)):\n a=h*n\n b=h_half*(w-n)\n c=s_hw-(a+b)\n s1=max(a,b,c)-min(a,b,c)\n d=(w-n)//2*h\n e=s_hw-(a+d)\n s2=max(a,d,e)-min(a,d,e)\n min_x=min(min_x,s1,s2)\n\n# n*W \u306e\u7bc4\u56f2\u3092\u63a2\u67fb\nfor n in reversed(range(1,h_half+2)):\n a=w*n\n b=w_half*(h-n)\n c=s_hw-(a+b)\n s1=max(a,b,c)-min(a,b,c)\n d=(h-n)//2*w\n e=s_hw-(a+d)\n s2=max(a,d,e)-min(a,d,e)\n min_x=min(min_x,s1,s2)\n\nprint(min_x)", "def cut(ch, cw):\n total = ch*cw\n if not ch % 2 or not cw % 2:\n x = ch*cw // 2\n return x, x\n else:\n x = max(ch*(cw//2), cw*(ch//2))\n return x, total - x\n\n\nh, w = map(int,input().split())\n\nans = h*w\n\nfor i in range(2):\n yh = h // 3 + i\n s = [yh*w]\n ch = h - yh\n s += cut(ch, w)\n ans = min(ans, max(s) - min(s))\n\nfor i in range(2):\n yw = w // 3 + i\n s = [h*yw]\n cw = w - yw\n s += cut(h, cw)\n ans = min(ans, max(s) - min(s))\n\nprint(ans)", "#!/usr/bin/env python3\nclass V:\n def __init__(self, f, v = None):\n self.f = f\n self.v = v\n \n def __str__(self):\n return str(self.v)\n \n def __call__(self, n):\n if n is None:\n return self.v\n\n if self.v is None:\n self.v = n\n return self.v\n self.v = self.f(self.v, n) \n\nh, w = map(int, input().split())\n\ndef minmax(*args):\n return max(args) - min(args)\n\ndef sep(m, n):\n a = b = c = 0\n nn = n // 2\n ans = V(min, float(\"inf\"))\n\n for i in range(1, m):\n a = i * n\n mm = (m - i) // 2\n \n # \u6a2a\n b, c = (m - i) * nn, (m - i) * (n - nn)\n ans(minmax(a, b, c))\n\n # \u7e26\n b, c = mm * n, (m - i - mm) * n\n ans(minmax(a, b, c))\n \n return ans.v\n\nprint(min(sep(h, w), sep(w, h)))", "def answer(H,W,ans_kari):\n\n for x in range(1,W):\n y1 = H // 2\n Sa1 = H * x\n Sb1 = (W - x) * y1\n Sc1 = (W - x) * (H - y1)\n M = max(Sa1,Sb1,Sc1)\n m = min(Sa1,Sb1,Sc1)\n\n y2 = (W - x) // 2\n Sa2 = H * x\n Sb2 = H * y2\n Sc2 = H * (W - x - y2)\n M2 = max(Sa2,Sb2,Sc2)\n m2 = min(Sa2,Sb2,Sc2)\n\n if ans_kari > min(M-m,M2-m2):\n ans_kari = min(M-m,M2-m2)\n\n return ans_kari\n\ndef __starting_point():\n H,W = [int(i) for i in input().split()]\n ans = H * W\n ans = answer(H,W,ans)\n \n H,W = W,H\n\n if answer(H,W,ans) < ans:\n ans = answer(H,W,ans)\n\n print(ans)\n\n__starting_point()", "H, W = map(int, input().split())\nans = float('inf')\nfor h in range(1,H):\n Sa = h * W\n w = W // 2\n Sb = (H-h) * w\n Sc = (H-h) * (W-w)\n ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))\n\nfor h in range(1,H):\n Sa = h * W\n hb = (H-h) // 2\n Sb = hb * W\n Sc = (H-h-hb) * W\n ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))\n\nfor w in range(1,W):\n Sa = H * w\n h = H // 2\n Sb = h * (W-w)\n Sc = (H-h) * (W-w)\n ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))\n\nfor w in range(1,W):\n Sa = w * H\n wb = (W-w) // 2\n Sb = wb * H\n Sc = (W-w-wb) * H\n ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))\n\nprint(ans)", "import math\n\ndef main():\n\tH, W = [int(a) for a in input().split(\" \")]\n\n\tcand = []\n\t# case 1. w 3 split, h 3 split\n\tif W % 3 == 0 or H % 3 == 0:\n\t\tprint((0))\n\t\treturn 0\n\t# W % 3 !== 0 and H % 3 !== 0\n\tcand.append(H)\n\tcand.append(W)\n\t# case 2. w split -> h split\n\tcand += split_3(H, W)\n\tcand += split_3(W, H)\n\n\tprint((min(cand)))\n\treturn 0\n\ndef split_3(a, b):\n\ta_f = math.floor(a/3)\n\ta_c = math.ceil(a/3)\n\tb_f = math.floor(b/2)\n\tb_c = math.ceil(b/2)\n\n\ta1 = [b * a_f, (a - a_f) * b_f, a * b - (a - a_f) * b_f - b * a_f]\n\ta2 = [b * a_c, (a - a_c) * b_f, a * b - (a - a_c) * b_f - b * a_c]\n\ta3 = [b * a_f, (a - a_f) * b_c, a * b - (a - a_f) * b_c - b * a_f]\n\ta4 = [b * a_c, (a - a_c) * b_c, a * b - (a - a_c) * b_c - b * a_c]\n\n\treturn [max(a1) - min(a1), max(a2) - min(a2), max(a3) - min(a3), max(a4) - min(a4)]\n\nmain()\n", "H, W = map(int, input().split())\n\ndef case1(h, w):\n MIN = float('inf')\n for i in range(1, h):\n sa = i * w\n sb = (h - i) * (w//2)\n sc = (h - i) * (w - w//2)\n if max([sa,sb,sc]) - min([sa,sb,sc]) < MIN:\n MIN = max([sa,sb,sc]) - min([sa,sb,sc]) \n return MIN\n\ndef case2(h, w):\n MIN = float('inf')\n for i in range(1, h):\n sa = i * w\n sb = (h - i)//2 * w\n sc = (h - i -(h - i)//2) * w\n if max([sa,sb,sc]) - min([sa,sb,sc]) < MIN:\n MIN = max([sa,sb,sc]) - min([sa,sb,sc]) \n return MIN\nprint(min([case1(H,W) , case1(W,H), case2(H,W), case2(W,H)]))", "import sys\nreadline = sys.stdin.readline\nfrom math import floor, ceil\nfrom decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\ndef round(f, r=0):\n return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)\n\ndef main():\n H, W = map(int, readline().rstrip().split())\n ans = H * W\n if H >= 3:\n y1 = int(round(H/3))\n y2 = (H-y1) // 2\n y3 = H - y1 - y2\n ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))\n if W >= 3:\n x1 = int(round(W/3))\n x2 = (W-x1) // 2\n x3 = W - x1 - x2\n ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))\n \n # \u7e26\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u6a2a\u306b\u30b9\u30e9\u30a4\u30b9\n x1_cand = [floor(W/3), ceil(W/3)]\n # x1_cand = [i for i in range(1, W)]\n y1 = H\n for x1 in x1_cand:\n x2 = W - x1\n x3 = x2\n y2 = H // 2\n y3 = H - y2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n # \u6a2a\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u7e26\u306b\u30b9\u30e9\u30a4\u30b9\n y1_cand = [floor(H/3), ceil(H/3)]\n # y1_cand = [i for i in range(1, H)]\n x1 = W\n for y1 in y1_cand:\n y2 = H - y1\n y3 = y2\n x2 = W // 2\n x3 = W - x2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "h,w = map(int,input().split())\nif (h%3 == 0) or (w%3 == 0):\n print(0)\nelse:\n ans = h*w\n for i in range(1,max(h,w)//2 + 1):\n a = min(h,w)*i\n b = (max(h,w)-i)*(min(h,w)//2)\n if min(h,w)%2 != 0:\n c = (max(h,w)-i)*(min(h,w)//2 + 1)\n else:\n c = b\n kari = max(a,b,c)-min(a,b,c)\n if ans > kari:\n ans = kari\n ans3 = h*w\n for i in range(1,min(h,w)//2 + 1):\n a = max(h,w)*i\n b = (min(h,w)-i)*(max(h,w)//2)\n if max(h,w)%2 != 0:\n c = (min(h,w)-i)*(max(h,w)//2 + 1)\n else:\n c = b\n kari = max(a,b,c)-min(a,b,c)\n if ans3 > kari:\n ans3 = kari\n ans2 = ((max(h,w)//3 + 1)*min(h,w))-((max(h,w)//3)*min(h,w))\n print(min(ans,ans2,ans3))", "h, w = map(int, input().split())\nif h % 3 == 0 or w % 3 == 0:\n print(0)\nelse:\n ans = min(w, h)\n for w1 in range(w//3, w//3+3):\n s1 = w1 * h\n w2 = w-w1\n for h1 in range(h//2, h//2+2):\n s2 = w2 * h1\n s3 = w2 * (h-h1)\n ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))\n h, w = w, h\n for w1 in range(w//3, w//3+3):\n s1 = w1 * h\n w2 = w-w1\n for h1 in range(h//2, h//2+2):\n s2 = w2 * h1\n s3 = w2 * (h-h1)\n ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))\n print(ans)", "h,w = map(int, input().split())\nif (h%3==0 or w%3==0):\n print(0)\n return\nans = float(\"inf\")\nif (w%2==0):\n ans = min(ans, (h-h//3)*(w//2) - h//3*w)\n ans = min(ans, abs((h-h//3-1)*(w//2) - (h//3+1)*w))\nelse:\n if (h%3==1):\n ans = min(ans, max(abs((h-h//3)*(w//2) - h//3*w),abs((h-h//3)*(w//2+1) - h//3*w), abs(h-h//3)))\n else:\n ans = min(ans, max(abs((h-h//3-1)*(w//2) - (h//3+1)*w),abs((h-h//3-1)*(w//2+1) - (h//3+1)*w), abs(h-h//3-1)))\nans = min(ans,w)\n \na = w\nw = h\nh = a\n#print(h,w)\nif (w%2==0):\n ans = min(ans, (h-h//3)*(w//2) - h//3*w)\n ans = min(ans, abs((h-h//3-1)*(w//2) - (h//3+1)*w))\nelse:\n if (h%3==1):\n ans = min(ans, max(abs((h-h//3)*(w//2) - h//3*w),abs((h-h//3)*(w//2+1) - h//3*w), abs(h-h//3)))\n else:\n ans = min(ans, max(abs((h-h//3-1)*(w//2) - (h//3+1)*w),abs((h-h//3-1)*(w//2+1) - (h//3+1)*w), abs(h-h//3-1)))\nans = min(ans,w)\n \nprint(ans)", "H, W = map(int, input().split())\n\nans = float(\"inf\")\nfor h, w in zip([H, W], [W, H]):\n # ah \u306e\u5168\u63a2\u7d22\n for ah in range(1, h):\n # \u6b8b\u308a\u3092\u7e26\u5272\u308a\n Sa = ah * w\n bw = (w - 1) // 2 + 1\n Sb = (h - ah) * bw\n Sc = (h - ah) * (w - bw)\n ans = min(ans, (max(Sa, Sb, Sc)-min(Sa, Sb, Sc)))\n\n # \u6b8b\u308a\u3092\u6a2a\u5272\u308a\n if (h - ah) > 1:\n bh = ((h - ah) - 1) // 2 + 1\n Sb = bh * w\n Sc = (h - ah - bh) * w\n ans = min(ans, (max(Sa, Sb, Sc)-min(Sa, Sb, Sc)))\n \nprint(ans)", "def main():\n h, w = list(map(int, input().split()))\n d = h * w\n for i in range(1, h):\n sh = (h - i) // 2\n s = (i * w, sh * w, (h - i - sh) * w)\n d = min(max(s) - min(s), d)\n sv = w // 2\n s = (i * w, (h - i) * sv, (h - i) * (w - sv))\n d = min(max(s) - min(s), d)\n for i in range(1, w):\n sv = (w - i) // 2\n s = (h * i, h * sv, h * (w - i - sv))\n d = min(max(s) - min(s), d)\n sh = h // 2\n s = (h * i, sh * (w - i), (h - sh) * (w - i))\n d = min(max(s) - min(s), d)\n print(d)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "h,w=map(int,input().split())\nans=min(h,w)\nif h%3==0 or w%3==0:\n print(0)\n return\nfor hi in range(1,h):\n mi=min(w*hi,w//2*(h-hi),(w-w//2)*(h-hi))\n ma=max(w*hi,w//2*(h-hi),(w-w//2)*(h-hi))\n ans=min(ans,ma-mi)\nfor wi in range(1,w):\n mi=min(h*wi,h//2*(w-wi),(h-h//2)*(w-wi))\n ma=max(h*wi,h//2*(w-wi),(h-h//2)*(w-wi))\n ans=min(ans,ma-mi)\nprint(ans)", "H, W = list(map(int, input().split()))\n\nans = float('inf')\n\n# first cut vertical\nfor x in range(1, W):\n S1 = x * H\n # cut vertical\n w2 = (W - x) // 2\n w3 = W - x - w2\n S2 = w2 * H\n S3 = w3 * H\n S_max = max(S1, S3)\n S_min = min(S1, S2)\n ans = min(ans, S_max - S_min)\n # cut horizontal\n h2 = H // 2\n h3 = H - h2\n S2 = (W - x) * h2\n S3 = (W - x) * h3\n S_max = max(S1, S3)\n S_min = min(S1, S2)\n ans = min(ans, S_max - S_min)\n# first cut horizontal\nfor y in range(1, H):\n S1 = W * y\n # cut vertical\n w2 = W // 2\n w3 = W - w2\n S2 = w2 * (H - y)\n S3 = w3 * (H - y)\n S_max = max(S1, S3)\n S_min = min(S1, S2)\n ans = min(ans, S_max - S_min)\n # cut horizontal\n h2 = (H - y) // 2\n h3 = H - y - h2\n S2 = W * h2\n S3 = W * h3\n S_max = max(S1, S3)\n S_min = min(S1, S2)\n ans = min(ans, S_max - S_min)\n\nprint(int(ans))", "def min_value(w, h):\n\tans = float('inf')\n\tfor i in range(1, h):\n\t\ta = w*i\n\t\tv_t = (h-i)//2 * w\n\t\tv_b = (h-i)*w - v_t\n\t\tv_re = max(a, v_t, v_b) - min(a, v_t, v_b)\n\t\th_l = (h-i)*(w//2)\n\t\th_r = (h-i)*w-h_l\n\t\th_re = max(a, h_l, h_r) - min(a, h_l, h_r)\n\t\tans = min(ans, v_re, h_re)\n\treturn ans\n\ndef resolve():\n\th, w = map(int, input().split())\n\ta = min_value(w, h)\n\tb = min_value(h, w)\n\tprint(min(a, b))\nresolve()", "h, w = list(map(int, input().split()))\n\ndef defs(h, w):\n ans = 10 ** 12\n for i in range(1, h):\n sa = i * w\n h2 = h - i\n\n for j in range(2):\n if j == 0:\n sb = h2 * (w // 2)\n sc = h2 * (w - (w // 2))\n else:\n sb = (h2 // 2) * w\n sc = (h - i - (h2 // 2)) * w\n\n s_max = max(sa, sb, sc)\n s_min = min(sa, sb, sc)\n\n ans = min(ans, s_max - s_min)\n return ans\n\nprint((min(defs(h, w), defs(w, h))))\n", "h,w=map(int,input().split())\nif h==2 and w==2:\n print(1)\n return\nans=10**10\nif h>=3:\n if h%3==0:\n a=0\n else:\n a=w\n if a<ans:\n ans=a\nif w>=3:\n if w%3==0:\n a=0\n else:\n a=h\n if a<ans:\n ans=a\nif h>1:\n b=h//3\n x1=w*b\n x2=(h-b)*(w//2)\n x3=h*w-x1-x2\n a=max(x1,x2,x3)-min(x1,x2,x3)\n if a<ans:\n ans=a\n x1=w*(b+1)\n x2=(h-b-1)*(w//2)\n x3=h*w-x1-x2\n a=max(x1,x2,x3)-min(x1,x2,x3)\n if a<ans:\n ans=a\n b=w//3\n x1=h*b\n x2=(w-b)*(h//2)\n x3=h*w-x1-x2\n a=max(x1,x2,x3)-min(x1,x2,x3)\n if a<ans:\n ans=a\n x1=h*(b+1)\n x2=(w-b-1)*(h//2)\n x3=h*w-x1-x2\n a=max(x1,x2,x3)-min(x1,x2,x3)\n if a<ans:\n ans=a\nprint(ans)", "import sys\nh, w = list(map(int, input().split()))\nif h%3==0 or w%3==0:\n print((0))\n return\nans=h*w #inf\nfor i in range(1, h):\n s1=i*w\n s2=(h-i)*(w//2)\n s3=h*w-s1-s2\n now=max(s1, s2, s3)-min(s1, s2, s3)\n #print(i, now)\n ans=min(ans, now)\nfor j in range(1, w):\n s1=h*j\n s2=(w-j)*(h//2)\n s3=h*w-s1-s2\n now=max(s1, s2, s3)-min(s1, s2, s3)\n ans=min(ans, now)\nif w>3:\n ans=min(ans, h)\nif h>3:\n ans=min(ans, w)\nprint(ans)\n", "#\n# Written by NoKnowledgeGG @YlePhan\n# ('\u03c9')\n#\n#import math\n#mod = 10**9+7\n#import itertools\n#import fractions\n#import numpy as np\n#mod = 10**4 + 7\n\"\"\"def kiri(n,m):\n r_ = n / m\n if (r_ - (n // m)) > 0:\n return (n//m) + 1\n else:\n return (n//m)\"\"\"\n\n\"\"\" n! mod m \u968e\u4e57\nmod = 1e9 + 7\nN = 10000000\nfac = [0] * N\ndef ini():\n fac[0] = 1 % mod\n for i in range(1,N):\n fac[i] = fac[i-1] * i % mod\"\"\"\n\n\"\"\"mod = 1e9+7\nN = 10000000\npw = [0] * N\ndef ini(c):\n pw[0] = 1 % mod\n for i in range(1,N):\n pw[i] = pw[i-1] * c % mod\"\"\"\n\n\"\"\"\ndef YEILD():\n yield 'one'\n yield 'two'\n yield 'three'\ngenerator = YEILD()\nprint(next(generator))\nprint(next(generator))\nprint(next(generator))\n\"\"\"\n\"\"\"def gcd_(a,b):\n if b == 0:#\u7d50\u5c40\u306fc,0\u306e\u6700\u5927\u516c\u7d04\u6570\u306fc\u306a\u306e\u306b\n return a\n return gcd_(a,a % b) # a = p * b + q\"\"\"\n\"\"\"def extgcd(a,b,x,y):\n d = a\n if b!=0:\n d = extgcd(b,a%b,y,x)\n y -= (a//b) * x\n print(x,y)\n else:\n x = 1\n y = 0\n return d\"\"\"\n\n\ndef readInts():\n return list(map(int,input().split()))\nmod = 10**9 + 7\ndef main():\n H,W = readInts()\n LIST = [H//2 + W//3 + 1, W//3 + H//2 + 1, H, W]\n if H%3 == 0 or W % 3 == 0:\n LIST += [0]\n if H % 2 == 0:\n LIST += [H//2]\n if W % 2 == 0:\n LIST += [W//2]\n print(min(LIST))\n \ndef __starting_point():\n main()\n__starting_point()", "h,w=list(map(int,input().split()))\nif h%3==0 or w%3==0:\n print((0))\nelse:\n num1=max((h//3)*w,(h-(h//3))*(w//2),(h-(h//3))*(w-(w//2)))-min((h//3)*w,(h-(h//3))*(w//2),(h-(h//3))*(w-(w//2)))\n num2=max((w//3)*h,(w-(w//3))*(h//2),(w-(w//3))*(h-(h//2)))-min((w//3)*h,(w-(w//3))*(h//2),(w-(w//3))*(h-(h//2)))\n num3=max((h//3+1)*w,(h-(h//3+1))*(w//2),(h-(h//3+1))*(w-(w//2)))-min((h//3+1)*w,(h-(h//3+1))*(w//2),(h-(h//3+1))*(w-(w//2)))\n num4=max((w//3+1)*h,(w-(w//3+1))*(h//2),(w-(w//3+1))*(h-(h//2)))-min((w//3+1)*h,(w-(w//3+1))*(h//2),(w-(w//3+1))*(h-(h//2)))\n print((min(num1,num2,num3,num4,h,w)))\n", "H, W = map(int, input().split())\nS = H * W\nans = S\n\nfor h in range(1,H):\n s1 = h * W\n s2 = W // 2 * (H-h)\n s3 = S-s1-s2\n ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\n s2 = (H-h) // 2 * W\n s3 = S-s1-s2\n ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\nfor w in range(1,W):\n s1 = H * w\n s2 = H // 2 * (W-w)\n s3 = S-s1-s2\n ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\n s2 = (W-w) // 2 * H\n s3 = S-s1-s2\n ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\nprint(ans)", "h,w=list(map(int,input().split()))\na1=min(h*(w%3!=0),w*(h%3!=0))\na2=10**6\na3=10**6\nfor i in range(1,h):\n mx=max(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))\n mn=min(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))\n a2=min(a2,mx-mn)\nfor i in range(1,w):\n mx=max(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))\n mn=min(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))\n a3=min(a3,mx-mn)\nprint((min(a1,a2,a3)))\n", "def answer(H,W,ans):\n\n for x in range(1,W):\n y1 = H // 2\n Sa1 = H * x\n Sb1 = (W - x) * y1\n Sc1 = (W - x) * (H - y1)\n M = max(Sa1,Sb1,Sc1)\n m = min(Sa1,Sb1,Sc1)\n\n y2 = (W - x) // 2\n Sa2 = H * x\n Sb2 = H * y2\n Sc2 = H * (W - x - y2)\n M2 = max(Sa2,Sb2,Sc2)\n m2 = min(Sa2,Sb2,Sc2)\n\n if ans > min(M-m,M2-m2):\n ans = min(M-m,M2-m2)\n\n return ans\n\ndef __starting_point():\n H,W = [int(i) for i in input().split()]\n ans = H * W\n ans = answer(H,W,ans)\n\n H,W = W,H\n\n if answer(H,W,ans) < ans:\n ans = answer(H,W,ans)\n\n print(ans)\n\n__starting_point()", "h, w = map(int, input().split())\n\np1 = [(h//3) * w, (h//3) * w, (h-2*(h//3))*w]\np2 = [(w//3) * h, (w//3) * h, (w-2*(w//3))*h]\np3 = [(h//3) * w, (h - h//3)* (w//2), h*w - (h//3) * w - (h - h//3)* (w//2)]\np4 = [(w//3) * h, (w - w//3)* (h//2), h*w - (w//3) * h - (w - w//3)* (h//2)]\n\np5 = [(h//3 + 1) * w, (h//3 + 1) * w, (h-2*(h//3 + 1))*w]\np6 = [(w//3 + 1) * h, (w//3 + 1) * h, (w-2*(w//3 + 1))*h]\np7 = [(h//3 + 1) * w, (h - h//3 - 1)* (w//2), h*w - (h//3 + 1) * w - (h - h//3 - 1)* (w//2)]\np8 = [(w//3 + 1) * h, (w - w//3 - 1)* (h//2), h*w - (w//3 + 1) * h - (w - w//3 - 1)* (h//2)]\n\nprint(min(max(p1)-min(p1), max(p2)-min(p2), max(p3)-min(p3), max(p4)-min(p4), max(p5)-min(p5), max(p6)-min(p6), max(p7)-min(p7), max(p8)-min(p8)))", "#!/usr/bin/env python3\n\n\ndef main():\n H, W = list(map(int, input().split()))\n if H % 3 == 0 or W % 3 == 0:\n print((0))\n else:\n ans = min(W,H)\n\n # H\u30921:2\u3067\u5206\u5272\n for i in range(3):\n d = (H // 3)- 1 + i\n if d > 0:\n choco = [d * W, (H-d) * (W//2), (H-d) * (W - W//2)]\n ans = min(ans, max(choco) - min(choco))\n \n # W\u30921:2\u3067\u5206\u5272\n for i in range(3):\n d = (W // 3)- 1 + i\n if d > 0:\n choco = [d * H, (W-d) * (H//2), (W-d) * (H - H//2)]\n ans = min(ans, max(choco) - min(choco))\n \n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "def divide_into_three(X, Y):\n minimum = float(\"inf\")\n for x in range(1, X):\n b1 = x * Y\n if not all(((X - x) & 1, Y & 1)):\n b2 = b3 = ((X - x) * Y) >> 1\n else:\n s, l = sorted((X - x, Y))\n b2 = s * (l >> 1)\n b3 = s * l - b2\n diff = max((b1, b2, b3)) - min((b1, b2, b3))\n minimum = min(minimum, diff)\n return minimum\n\nH, W = map(int, input().split())\nprint(min(divide_into_three(H, W), divide_into_three(W, H)))", "import sys\nreadline = sys.stdin.readline\nfrom math import floor, ceil\nfrom decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\n\ndef round(f, r=0):\n return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)\n\ndef main():\n H, W = map(int, readline().rstrip().split())\n ans = H * W\n if H >= 3:\n y1 = int(round(H/3))\n y2 = (H-y1) // 2\n y3 = H - y1 - y2\n ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))\n if W >= 3:\n x1 = int(round(W/3))\n x2 = (W-x1) // 2\n x3 = W - x1 - x2\n ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))\n \n # \u7e26\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u6a2a\u306b\u30b9\u30e9\u30a4\u30b9\n x1_cand = [int(round(W/3))]\n y1 = H\n for x1 in x1_cand:\n x2 = W - x1\n x3 = x2\n y2 = H // 2\n y3 = H - y2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n # \u6a2a\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u7e26\u306b\u30b9\u30e9\u30a4\u30b9\n y1_cand = [int(round(H/3))]\n x1 = W\n for y1 in y1_cand:\n y2 = H - y1\n y3 = y2\n x2 = W // 2\n x3 = W - x2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "h,w=map(int,input().split())\nmin_ = h*w\nif h % 3 == 0:\n min_ = 0\nelse:\n min_ = min(min_, w)\nif w % 3 == 0:\n min_ = 0\nelse:\n min_ = min(min_, h)\nfor i in range(1, w):\n p1 = h//2*i\n p2 = (h-h//2)*i\n p3 = h*(w-i)\n min_ = min(min_, max(p1,p2,p3)-min(p1,p2,p3))\nfor i in range(1, h):\n p1 = w//2*i\n p2 = (w-w//2)*i\n p3 = w*(h-i)\n min_ = min(min_, max(p1,p2,p3)-min(p1,p2,p3))\nprint(min_)", "# \u7d20\u76f4\u306b\u5168\u63a2\u7d22\u3057\u305f\u307b\u3046\u304c\u697d\nH,W = (int(T) for T in input().split())\nminSH = H*W\nminSW = H*W\nfor TH in range(1,H):\n BlockA = TH*W\n\n if TH<=(H-2):\n BlockB1 = ((H-TH)//2)*W\n BlockC1 = H*W-(BlockA+BlockB1)\n BigSCa1 = max(BlockA,BlockB1,BlockC1)\n SmlSCa1 = min(BlockA,BlockB1,BlockC1)\n DifSCa1 = BigSCa1-SmlSCa1\n else:\n DifSCa1 = H*W\n\n if W>=2:\n BlockB2 = (H-TH)*(W//2)\n BlockC2 = H*W-(BlockA+BlockB2)\n BigSCa2 = max(BlockA,BlockB2,BlockC2)\n SmlSCa2 = min(BlockA,BlockB2,BlockC2)\n DifSCa2 = BigSCa2-SmlSCa2\n else:\n DifSCa2 = H*W\n\n if min(DifSCa1,DifSCa2)<minSH:\n minSH = min(DifSCa1,DifSCa2)\n\nfor TW in range(1,W):\n BlockA = H*TW\n\n if TW<=(W-2):\n BlockB1 = H*((W-TW)//2)\n BlockC1 = H*W-(BlockA+BlockB1)\n BigSCa1 = max(BlockA,BlockB1,BlockC1)\n SmlSCa1 = min(BlockA,BlockB1,BlockC1)\n DifSCa1 = BigSCa1-SmlSCa1\n else:\n DifSCa1 = H*W\n\n if H>=2:\n BlockB2 = (H//2)*(W-TW)\n BlockC2 = H*W-(BlockA+BlockB2)\n BigSCa2 = max(BlockA,BlockB2,BlockC2)\n SmlSCa2 = min(BlockA,BlockB2,BlockC2)\n DifSCa2 = BigSCa2-SmlSCa2\n else:\n DifSCa2 = H*W\n\n if min(DifSCa1,DifSCa2)<minSW:\n minSW = min(DifSCa1,DifSCa2)\n\nprint(min(minSH,minSW))", "h, w = list(map(int, input().split()))\n\nans = 10 ** 10\nfor i in range(h):\n x = (i + 1) * w\n mid = (h - i - 1) // 2\n y = mid * w\n z = (h - i - 1 - mid) * w\n ans = min(ans, max(x, y, z) - min(x, y, z))\n\n mid = w // 2\n y = (h - i - 1) * mid\n z = (h - i - 1) * (w - mid)\n ans = min(ans, max(x, y, z) - min(x, y, z))\n\nfor j in range(w):\n x = (j + 1) * h\n mid = (w - j - 1) // 2\n y = mid * h\n z = (w - j - 1 - mid) * h\n ans = min(ans, max(x, y, z) - min(x, y, z))\n\n mid = h // 2\n y = (w - j - 1) * mid\n z = (w - j - 1) * (h - mid)\n ans = min(ans, max(x, y, z) - min(x, y, z))\n\nprint(ans)\n", "def abc062_c():\n h, w = map(int, input().split())\n # 2 <= h, w \u306e\u305f\u30811\u306e\u5834\u5408\u306f\u8003\u3048\u306a\u3044\n # \u3069\u3061\u3089\u304b\u304c3\u306e\u500d\u6570\u306a\u3089\u3074\u3063\u305f\u308a3\u5206\u5272\u3067\u304d\u308b (\u5e73\u884c2\u7dda)\n if h % 3 == 0 or w % 3 == 0:\n print(0)\n return\n # \u5e73\u884c2\u7dda\u3067\u5272\u308b\u3068\u304d\u306e\u5dee\u5206\u6700\u5c0f\u306f\u3001\u77ed\u8fba1\u672c\u5206\n ans = min(h, w)\n # \u305d\u308c\u4ee5\u5916\u306f\u4f8b2\u4f8b3\u306e\u5272\u308a\u65b9 (\u76f4\u4ea42\u7dda)\n for x, y in [(w, h), (h, w)]:\n for i in range(1, x):\n sa = i * y\n sb = (x - i) * (y // 2)\n sc = (x - i) * (y - y // 2)\n diff = max(sa, sb, sc) - min(sa, sb, sc)\n ans = min(diff, ans)\n print(ans)\n\nabc062_c()", "H,W=list(map(int,input().split()))\n\nif H%3==0 or W%3==0:\n print((0))\n return\n\nA=0\nB=0\nans=H*W\n\nif H%2==0:\n A=H//2\n B=H//2\nelse:\n A=H//2+1\n B=H-A\nfor i in range(1,W):\n S1=A*i\n S2=B*i\n S3=(W-i)*H\n SMaxMin=max(S1,S2,S3)-min(S1,S2,S3)\n ans=min(ans,SMaxMin)\nif W%2==0:\n A=W//2\n B=W//2\nelse:\n A=W//2+1\n B=W-A;\nfor i in range(1,H):\n S1=A*i\n S2=B*i\n S3=(H-i)*W\n SMaxMin=max(S1,S2,S3)-min(S1,S2,S3)\n ans=min(ans,SMaxMin)\nif H>=3:\n ans=min(ans,W)\nif W>=3:\n ans=min(ans,H)\nprint(ans)\n", "H,W = [int(i) for i in input().split()]\nans = H * W\n\nfor x in range(1,W):\n y1 = H // 2\n Sa1 = H * x\n Sb1 = (W - x) * y1\n Sc1 = (W - x) * (H - y1)\n M = max(Sa1,Sb1,Sc1)\n m = min(Sa1,Sb1,Sc1)\n\n y2 = (W - x) // 2\n Sa2 = H * x\n Sb2 = H * y2\n Sc2 = H * (W - x - y2)\n M2 = max(Sa2,Sb2,Sc2)\n m2 = min(Sa2,Sb2,Sc2)\n\n if ans > min(M-m,M2-m2):\n ans = min(M-m,M2-m2)\n\nH,W = W,H\nfor x in range(1,W):\n y = H // 2\n Sa1 = H * x\n Sb1 = (W - x) * y\n Sc1 = (W - x) * (H - y)\n M = max(Sa1,Sb1,Sc1)\n m = min(Sa1,Sb1,Sc1)\n\n y2 = (W - x) // 2\n Sa2 = H * x\n Sb2 = H * y2\n Sc2 = H * (W - x - y2)\n M2 = max(Sa2,Sb2,Sc2)\n m2 = min(Sa2,Sb2,Sc2)\n\n if ans > min(M-m,M2-m2):\n ans = min(M-m,M2-m2)\n\nprint(ans)\n", "h,w=map(int,input().split())\nif h%3==0 or w%3==0:\n print(0)\nelse:\n temp=[w,h]\n if h%2==0 and w%2==0:\n temp.append(abs(int(w//3+1)*h-int(w-w//3-1)*int(h//2)))\n temp.append(abs(int(w//3)*h-int(w-w//3)*int(h//2))) \n temp.append(abs(int(h//3+1)*w-int(h-h//3-1)*int(w//2)))\n temp.append(abs(int(h//3)*w-int(h-h//3)*int(w//2))) \n elif h%2==0:\n temp.append(max(int(h//3*w),int(h-h//3)*int(w//2),int(h-h//3)*int(w//2+1))-min(int(h//3*w),int(h-h//3)*int(w//2),int(h-h//3)*int(w//2+1)))\n temp.append(max(int(h//3+1)*w,int(h-h//3-1)*int(w//2),int(h-h//3-1)*int(w//2+1))-min(int(h//3+1)*w,int(h-h//3-1)*int(w//2),int(h-h//3-1)*int(w//2+1)))\n temp.append(abs(int(w//3+1)*h-int(w-w//3-1)*int(h//2)))\n temp.append(abs(int(w//3)*h-int(w-w//3)*int(h//2))) \n elif w%2==0:\n temp.append(max(int(w//3*h),int(w-w//3)*int(h//2),int(w-w//3)*int(h//2+1))-min(int(w//3*h),int(w-w//3)*int(h//2),int(w-w//3)*int(h//2+1)))\n temp.append(max(int(w//3+1)*h,int(w-w//3-1)*int(h//2),int(w-w//3-1)*int(h//2+1))-min(int(w//3+1)*h,int(w-w//3-1)*int(h//2),int(w-w//3-1)*int(h//2+1)))\n temp.append(abs(int(h//3+1)*w-int(h-h//3-1)*int(w//2)))\n temp.append(abs(int(h//3)*w-int(h-h//3)*int(w//2))) \n else:\n temp.append(max(int(h//3*w),int(h-h//3)*int(w//2),int(h-h//3)*int(w//2+1))-min(int(h//3*w),int(h-h//3)*int(w//2),int(h-h//3)*int(w//2+1)))\n temp.append(max(int(h//3+1)*w,int(h-h//3-1)*int(w//2),int(h-h//3-1)*int(w//2+1))-min(int(h//3+1)*w,int(h-h//3-1)*int(w//2),int(h-h//3-1)*int(w//2+1)))\n temp.append(max(int(w//3*h),int(w-w//3)*int(h//2),int(w-w//3)*int(h//2+1))-min(int(w//3*h),int(w-w//3)*int(h//2),int(w-w//3)*int(h//2+1)))\n temp.append(max(int(w//3+1)*h,int(w-w//3-1)*int(h//2),int(w-w//3-1)*int(h//2+1))-min(int(w//3+1)*h,int(w-w//3-1)*int(h//2),int(w-w//3-1)*int(h//2+1)))\n print(min(temp))", "h, w = list(map(int, input().split()))\nans = 10**9\nif h % 3 == 0 or w % 3 == 0:\n ans = 0\nelse:\n for width in range(1, w):\n left = width * h\n if h % 2 == 0:\n right_up = (w-width)*(h//2)\n right_down = right_up\n else:\n right_up = (w-width)*(h//2+1)\n right_down = (w-width)*(h//2)\n ans = min(ans, max(left, right_up, right_down) - min(left, right_up, right_down))\n for height in range(1, h):\n up = w * height\n if w % 2 == 0:\n down_left = (w//2)*(h-height)\n down_right = down_left\n else:\n down_left = (w//2)*(h-height)\n down_right = (w//2+1)*(h-height)\n ans = min(ans, max(up, down_left, down_right) - min(up, down_left, down_right))\n ans = min(ans, min(h, w))\nprint(ans)\n", "h,w = map(int,input().split())\n\nif h % 3 == 0 or w % 3 == 0:\n print(0)\nelse:\n best = (h*w)/3\n # w\u304b\u3089\u5272\u308b\u65b9\u6cd5\n col_num = int(round(best/h))\n remain_w = w - col_num\n h1 = h // 2\n h2 = h - h1\n w1 = remain_w // 2\n w2 = remain_w - w1\n min_area1 = min(remain_w*h1, remain_w*h2, col_num*h) # \u5782\u76f4\n max_area1 = max(remain_w*h1, remain_w*h2, col_num*h)\n min_area2 = min(w2*h, w1*h, col_num*h) # \u5e73\u884c\n max_area2 = max(w2*h, w1*h, col_num*h)\n num_w1 = max_area1 - min_area1\n num_w2 = max_area2 - min_area2\n # h\u304b\u3089\u5272\u308b\u65b9\u6cd5\n row_num = int(round(best/w))\n remain_h = h - row_num\n w1 = w // 2\n w2 = w - w1\n h1 = remain_h // 2\n h2 = remain_h - h1\n min_area1 = min(remain_h*w1, remain_h*w2, row_num*w) # \u5782\u76f4\n max_area1 = max(remain_h*w1, remain_h*w2, row_num*w)\n min_area2 = min(h2*w, h1*w, row_num*w) # \u5e73\u884c \n max_area2 = max(h2*w, h1*w, row_num*w)\n num_h1 = max_area1 - min_area1\n num_h2 = max_area2 - min_area2\n print(min(num_h1,num_w1,num_h2,num_w2))", "import collections \nh,w = map(int,input().split())\n\ndef hkara(h,w):\n hans = 10**9\n for i in range(1,h):\n #yoko\n fst = w*i\n snd = w//2*(h-i)\n trd = (w-w//2)*(h-i)\n mx = max(max(fst,snd),trd)\n mn = min(min(fst,snd),trd)\n hans = min(mx-mn,hans)\n #tate\n tfst = w*i\n tsnd = (h-i)//2*w\n ttrd = (h-(h-i)//2-i)*w\n tmx = max(max(tfst,tsnd),ttrd)\n tmn = min(min(tfst,tsnd),ttrd)\n hans = min(tmx-tmn,hans)\n return hans\n\ndef wkara(h,w):\n wans = 10**9\n for i in range(1,w):\n fst = h*i\n snd = h//2*(w-i)\n trd = (h-h//2)*(w-i)\n mx = max(max(fst,snd),trd)\n mn = min(min(fst,snd),trd)\n wans = min(mx-mn,wans)\n #tate\n tfst = h*i\n tsnd = (w-i)//2*h\n ttrd = (w-(w-i)//2-i)*h\n tmx = max(max(tfst,tsnd),ttrd)\n tmn = min(min(tfst,tsnd),ttrd)\n wans = min(tmx-tmn,wans)\n return wans\n\nprint(min(hkara(h,w),wkara(h,w)))", "h,w=list(map(int,input().split()))\n\ndef sds(h,w):\n sdmin=h*w\n for hi in range(1,h):\n s1=hi*w\n s2=(h-hi)*(w//2)\n s3=(h-hi)*(w-w//2)\n sd=max(s1,s2,s3)-min(s1,s2,s3)\n sdmin=min(sdmin,sd)\n \n h2=(h-hi)//2\n s2=h2*w\n s3=(h-hi-h2)*w\n sd=max(s1,s2,s3)-min(s1,s2,s3)\n sdmin=min(sdmin,sd)\n\n return sdmin\n\nprint((min(sds(h,w),sds(w,h))))\n", "from math import ceil\n\n\ndef main():\n H, W = list(map(int, input().split()))\n if H*W % 3 == 0:\n print((0))\n return\n ans1 = float('inf')\n ans2 = float('inf')\n ans3 = min(H, W)\n # h == T\u306e\u4e0a\n for h in range(1, H + 1):\n if W % 2 == 0:\n ans1 = min(ans1, abs(h*(W//2) - W*(H - h)))\n else:\n ans1 = min(\n ans1,\n max([\n abs((h*(W//2) - W*(H - h))),\n abs(h*((W + 1)//2) - W*(H - h)),\n h\n ]))\n for w in range(1, W + 1):\n if H % 2 == 0:\n ans2 = min(ans2, abs(w*(H//2) - H*(W - w)))\n else:\n ans2 = min(\n ans2, max([abs((w*(H//2) - H*(W - w))), abs(w*((H + 1)//2) - H*(W - w)), w]))\n print((min([ans1, ans2, ans3])))\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "def main():\n H, W = (int(_) for _ in input().split())\n INF = 10 ** 11\n\n def calc(h, w):\n # \u7e26\u306b\u5272\u308b\n w1 = w // 2\n w2 = w - w1\n ret = INF\n for hh in range(1, h):\n ret = min(ret, max(w * hh, (h-hh)*w1, (h-hh)*w2) - min(w * hh, (h-hh)*w1, (h-hh)*w2))\n #\u6a2a\u306b\u5272\u308b\n for hh in range(1, h):\n h1 = (h-hh)//2\n h2 = h - hh - h1\n ret = min(ret, max(w*hh, w*h1, w*h2) - min(w*hh, w*h1, w*h2))\n return ret\n m1 = calc(H, W)\n m2 = calc(W, H)\n print((min(m1, m2)))\n return\ndef __starting_point():\n main()\n\n__starting_point()", "H, W = map(int, input().split())\n\nh = min(H, W)\nw = max(H, W)\ns = h*w\n\nres = 10**10\n\nfor i in range(1, w):\n a = h*i\n b = (w-i)//2*h\n c = s-a-b\n res = min(max(a, b, c)-min(a, b, c), res)\n\n b = (w-i)*(h//2)\n c = s-a-b\n res = min(max(a, b, c)-min(a, b, c), res)\n\n\nfor i in range(1, h):\n a = w*i\n \n b = (h-i)//2*w\n c = s-a-b\n res = min(max(a, b, c)-min(a, b, c), res)\n\n b = (h-i)*(w//2)\n c = s-a-b\n res = min(max(a, b, c)-min(a, b, c), res)\n\nprint(res)", "H,W=map(int,input().split())\n\nif H%3==0 or W%3==0:\n print(0)\nelif H==2 or W==2:\n ans0=min(H,W)\n \n H,W=min(H,W),max(H,W)\n w1=W//3\n w2=W-w1\n s1=2*w1\n s2=w2\n ans1=s2-s1\n \n w1=W//3+1\n w2=W-w1\n s1=2*w1\n s2=w2\n ans2=s1-s2\n print(min(ans0,ans1,ans2))\nelse:\n ans0=min(H,W)\n \n h1=H//2\n h2=H-h1\n \n w1=W//3\n w2=W-w1\n s1=w1*H\n s2=w2*h1\n s3=w2*h2\n ans1=max(s1,s2,s3)-min(s1,s2,s3)\n \n w1=W//3+1\n w2=W-w1\n s1=w1*H\n s2=w2*h1\n s3=w2*h2\n ans2=max(s1,s2,s3)-min(s1,s2,s3)\n \n H,W=W,H\n h1=H//2\n h2=H-h1\n \n w1=W//3\n w2=W-w1\n s1=w1*H\n s2=w2*h1\n s3=w2*h2\n ans3=max(s1,s2,s3)-min(s1,s2,s3)\n \n w1=W//3+1\n w2=W-w1\n s1=w1*H\n s2=w2*h1\n s3=w2*h2\n ans4=max(s1,s2,s3)-min(s1,s2,s3)\n print(min(ans0,ans1,ans2,ans3,ans4))", "h,w=map(int,input().split())\nstand=h*w/3\nprevh,prevw=1,1\nmini=10**18\nfor i in range(2,h+1):\n if abs(stand-i*w)<abs(stand-prevh*w):\n prevh=i\nif h-prevh>=2:\n mini=min(mini,max((h-prevh)//2*w,prevh*w,-(-(h-prevh)//2)*w)-min((h-prevh)//2*w,prevh*w,-(-(h-prevh)//2)*w))\nmini=min(mini,max(w//2*(h-prevh),prevh*w,-(-w//2)*(h-prevh))-min(w//2*(h-prevh),prevh*w,-(-w//2)*(h-prevh)))\n#print(mini)\nfor i in range(2,w+1):\n if abs(stand-i*h)<abs(stand-prevw*h):\n prevw=i\nif w-prevw>=2:\n mini=min(mini,max((w-prevw)//2*h,prevw*h,-(-(w-prevw)//2)*h)-min((w-prevw)//2*h,prevw*h,-(-(w-prevw)//2)*h))\nmini=min(mini,max(h//2*(w-prevw),prevw*h,-(-h//2)*(w-prevw))-min(h//2*(w-prevw),prevw*h,-(-h//2)*(w-prevw)))\nprint(mini)", "import sys\n\n\ndef main():\n h, w = map(int, input().split())\n if h % 3 == 0 or w % 3 == 0:\n print(0)\n return\n\n pattern = [h, w]\n for x in range(1, w//2 + 2):\n first = x * h\n h1 = h // 2\n h2 = h - h1\n second = (w-x) * h1\n thrid = (w-x) * h2\n result = max(first, second, thrid) - min(first, second, thrid)\n pattern.append(result)\n\n for y in range(1, h//2 + 2):\n first = y * w\n w1 = w // 2\n w2 = w - w1\n second = (h-y) * w1\n thrid = (h-y) * w2\n result = max(first, second, thrid) - min(first, second, thrid)\n pattern.append(result)\n\n print(min(pattern))\n\n\ndef __starting_point():\n main()\n__starting_point()", "def f(x,y,z):\n return max(x,y,z)-min(x,y,z)\n\nh, w = list(map(int, input().split()))\nl = []\nans1, ans2 = h*w, h*w\nfor i in range(1,h//2+1):\n s1 = i*w\n s2 = w*((h-i)//2)\n s3 = h*w-s1-s2\n s4 = (h-i)*(w//2)\n s5 = h*w-s1-s4\n ans1 = min(ans1, f(s1,s2,s3),f(s1,s4,s5))\n\nfor i in range(1,w//2+1):\n s1 = i*h\n s2 = h*((w-i)//2)\n s3 = h*w-s1-s2\n s4 = (w-i)*(h//2)\n s5 = h*w-s1-s4\n ans2 = min(ans2, f(s1,s2,s3),f(s1,s4,s5))\nprint((min(ans1,ans2)))\n", "import sys\ninput = sys.stdin.readline\n\nH,W = list(map(int,input().split()))\nS = H*W\ns1 = 0\nans = 10**10\nfor i in range(1,H):\n s1 += W\n s2 = (H-i)*(W//2)\n s3 = S - s1 -s2\n ans = min(ans,(max(s1,s2,s3)-min(s1,s2,s3)))\n\n s2 = ((H-i)//2)*W\n s3 = S - s1 -s2\n ans = min(ans,(max(s1,s2,s3)-min(s1,s2,s3)))\n\ns1 = 0\nfor i in range(1,W):\n s1 += H\n s2 = (W-i)*(H//2)\n s3 = S - s1 -s2\n ans = min(ans,(max(s1,s2,s3)-min(s1,s2,s3)))\n\n s2 = ((W-i)//2)*H\n s3 = S - s1 -s2\n ans = min(ans,(max(s1,s2,s3)-min(s1,s2,s3)))\n\nprint(ans)\n", "H, W = list(map(int, input().split(' ')))\n\nans = []\n\nfor h in range(1, H):\n r1 = h * W\n\n h = H - h\n\n r2a = h // 2 * W\n r3a = -1 * (-h // 2) * W\n r2b = W // 2 * h\n r3b = -1 * (-W // 2) * h\n\n ans.append(max(r1, r2a, r3a) - min(r1, r2a, r3a))\n ans.append(max(r1, r2b, r3b) - min(r1, r2b, r3b))\n\nfor w in range(1, W):\n r1 = H * w\n\n w = W - w\n\n r2a = H // 2 * w\n r3a = -1 * (-H // 2) * w\n r2b = w // 2 * H\n r3b = -1 * (-w // 2) * H\n\n ans.append(max(r1, r2a, r3a) - min(r1, r2a, r3a))\n ans.append(max(r1, r2b, r3b) - min(r1, r2b, r3b))\n\nprint((min(ans)))\n", "# coding: utf-8\n# hello world\u3068\u8868\u793a\u3059\u308b\nimport sys\nimport numpy\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**7)\nfrom collections import Counter, deque\nfrom collections import defaultdict\nfrom itertools import combinations, permutations, accumulate, groupby, product\nfrom bisect import bisect_left,bisect_right\nfrom heapq import heapify, heappop, heappush\nfrom math import floor, ceil,pi,factorial\nfrom operator import itemgetter\nfrom copy import deepcopy\ndef I(): return int(input())\ndef MI(): return map(int, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI2(): return [int(input()) for i in range(n)]\ndef MXI(): return [[LI()]for i in range(n)]\ndef SI(): return input().rstrip()\ndef printns(x): print('\\n'.join(x))\ndef printni(x): print('\\n'.join(list(map(str,x))))\ninf = 10**17\nmod = 10**9 + 7\n\nh,w=MI()\nif w%3==0:\n s1=0\nelse:\n s1=h\nif h%3==0:\n s2=0\nelse:\n s2=w\nfw=floor(w/3)\nfh=floor(h/2)\ncw=ceil(w/3)\nSMAX1=(w-fw)*(h-fh)\nSMIN1=min(fw*h,(w-fw)*fh)\nSMAX2=max(cw*h,(w-cw)*(h-fh))\nSMIN2=(w-cw)*fh\n#print(SMAX1,SMIN1,SMAX2,SMIN2)\ns3=min(SMAX1-SMIN1,SMAX2-SMIN2)\nh,w=w,h\nfw=floor(w/3)\nfh=floor(h/2)\ncw=ceil(w/3)\nSMAX1=(w-fw)*(h-fh)\nSMIN1=min(fw*h,(w-fw)*fh)\nSMAX2=max(cw*h,(w-cw)*(h-fh))\nSMIN2=(w-cw)*fh\ns4=min(SMAX1-SMIN1,SMAX2-SMIN2)\n#print(s1,s2,s3,s4)\nans=min(s1,s2,s3,s4)\nprint(ans)", "import sys\nreadline = sys.stdin.readline\nfrom decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\n\ndef round(f, r=0):\n return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)\n\ndef main():\n H, W = map(int, readline().rstrip().split())\n ans = H * W\n if H >= 3:\n y1 = int(round(H/3))\n y2 = (H-y1) // 2\n y3 = H - y1 - y2\n ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))\n if W >= 3:\n x1 = int(round(W/3))\n x2 = (W-x1) // 2\n x3 = W - x1 - x2\n ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))\n \n # \u7e26\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u6a2a\u306b\u30b9\u30e9\u30a4\u30b9\n x1 = int(round(W/3))\n y1 = H\n x2 = W - x1\n x3 = x2\n y2 = H // 2\n y3 = H - y2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n # \u6a2a\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u7e26\u306b\u30b9\u30e9\u30a4\u30b9\n y1 = int(round(H/3))\n x1 = W\n y2 = H - y1\n y3 = y2\n x2 = W // 2\n x3 = W - x2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "h, w = list(map(int, input().split()))\n\n\ndef calc(a, b):\n ret = a * b\n for i in range(1, a):\n area1 = b // 2 * i\n area2 = -(-b // 2) * i\n area3 = a * b - (area1 + area2)\n #print(area1, area2, area3)\n ret = min(ret, max(area1, area2, area3) - min(area1, area2, area3))\n return ret\n\nif h % 3 == 0 or w % 3 == 0:\n print((0))\nelse:\n ans = h * w\n for i in range(1, max(h, w) - 1):\n area1 = min(h, w) * i\n area2 = min(h, w) * ((max(h, w) - i) // 2)\n area3 = min(h, w) * (-(-(max(h, w) - i) // 2))\n #print(area1, area2, area3)\n ans = min(ans, max(area1, area2, area3) - min(area1, area2, area3))\n print((min(calc(h, w), calc(w, h), ans)))\n", "import sys\n\ndef solve(h, w):\n res = [((h + 2) // 3 - h // 3) * w]\n for d in [h // 3, (h + 2) // 3]:\n cand = sorted([d * w, (h - d) * (w // 2), (h - d) * ((w + 1) // 2)])\n res.append(cand[-1] - cand[0])\n return min(res)\n\nh, w = map(int, sys.stdin.readline().split())\n\ndef main():\n print(min(solve(h, w), solve(w, h)))\n\ndef __starting_point():\n main()\n__starting_point()", "h, w = map(int, input().split())\n\nans = 10**9\nfor i in range(1,h):\n x = h-i\n s0 = i*w\n s1 = x*(w//2)\n s2 = x*(w-w//2)\n s = max(s0,s1,s2)-min(s0,s1,s2)\n ans = min(ans,s)\n s3 = w*(x//2)\n s4 = w*(x-x//2)\n s = max(s0,s3,s4)-min(s0,s3,s4)\n ans = min(ans,s)\n\nfor i in range(1,w):\n x = w-i\n s0 = i*h\n s1 = x*(h//2)\n s2 = x*(h-h//2)\n s = max(s0,s1,s2)-min(s0,s1,s2)\n ans = min(ans,s)\n s3 = h*(x//2)\n s4 = h*(x-x//2)\n s = max(s0,s3,s4)-min(s0,s3,s4)\n ans = min(ans, s)\nprint(ans)", "h, w = map(int, input().split())\nif not h%3 or not w%3:\n print(0)\nelse:\n ans = min([h, w])\n for i in range(h):\n sub = max([abs(w*i-w//2*(h-i)), abs(w*i-(w-w//2)*(h-i))])\n if ans > sub:\n ans = sub\n for i in range(w):\n sub = max([abs(h*i-h//2*(w-i)), abs(h*i-(h-h//2)*(w-i))])\n if ans > sub:\n ans = sub\n print(ans)", "h,w=list(map(int,input().split()))\nans=[]\nimport sys\ndef s(a,b):\n for i in range(a):\n s=a*b\n x=i*b\n y=((a-i)//2)*b\n z=s-x-y\n\n d=(a-i)*(b//2)\n e=s-x-d\n ma=max(x,y,z)\n mi=min(x,y,z)\n mc=max(x,e,d)\n mn=min(x,e,d)\n res=min((ma-mi),(mc-mn))\n ans.append(res)\n return min(ans)\n \nf=s(h,w)\ng=s(w,h)\nprint((min(f,g)))\n \n# print(ans)\n# print(min(ans))\n \n", "h,w = list(map(int, input().split()))\nans = 10**10\nif h%3 == 0 or w%3 == 0:\n print(0)\n return\n \nfor H in range(1, h + 1):\n a = H * w\n b = (h - H) * (w // 2)\n c = (h - H) * (w - w // 2)\n ans = min(ans, max(a,b,c) - min(a,b,c))\n\nfor W in range(1, w + 1):\n a = W * h\n b = (w - W) * (h // 2)\n c = (w - W) * (h - h // 2)\n ans = min(ans, max(a,b,c) - min(a,b,c))\n\nif h > 3:\n ans = min(ans, w*((h+2)//3) - w*(h//3))\n\nif w > 3:\n ans = min(ans, h*((w+2)//3) - h*(w//3))\n \nprint(ans)", "import sys\n\nsys.setrecursionlimit(10 ** 7)\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef resolve():\n H, W = list(map(int, input().split()))\n\n if H % 3 == 0 or W % 3 == 0:\n print((0))\n return\n\n res = f_inf\n for h in range(H):\n A = h * W\n\n B = W * ((H - h) // 2)\n C = W * ((H - h) - (H - h) // 2)\n ma = max(A, B, C)\n mi = min(A, B, C)\n res = min(res, ma - mi)\n\n B = (H - h) * (W // 2)\n C = (H - h) * (W - W // 2)\n ma = max(A, B, C)\n mi = min(A, B, C)\n res = min(res, ma - mi)\n\n for w in range(W):\n A = w * H\n\n B = H * ((W - w) // 2)\n C = H * ((W - w) - (W - w) // 2)\n ma = max(A, B, C)\n mi = min(A, B, C)\n res = min(res, ma - mi)\n\n B = (W - w) * (H // 2)\n C = (W - w) * (H - H // 2)\n ma = max(A, B, C)\n mi = min(A, B, C)\n res = min(res, ma - mi)\n\n print(res)\n\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "h,w = map(int, input().split())\nans = 10**9\nfor p,o in zip([h,w],[w,h]):\n for i in range(1, p//2 + 1):\n sa = i * o\n hi = (p-i)//2\n sb = o * hi\n sc = o * (p - i - hi)\n t = max(sa,sb,sc) - min(sa,sb,sc)\n ans = min(ans, t)\n \n wi = o//2\n sb = (p - i) * wi\n sc = (p - i) * (o - wi)\n t = max(sa,sb,sc) - min(sa,sb,sc)\n ans = min(ans, t)\nprint(ans)", "H, W = map(int, input().split())\nM = 10 ** 10\n\nif H == 2 and W == 2:\n M = 1\n\nif H > 2:\n HH = H // 3\n S1 = HH * W\n HH = H - H // 3\n HHH = HH // 2\n S2 = HHH * W\n HHH = HH - HH // 2\n S3 = HHH * W\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\n HH = H // 3\n S1 = HH * W\n WW = W // 2\n S2 = (H - HH) * WW\n WW = W - W // 2\n S3 = (H - HH) * WW\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\n HH = H // 3 + 1\n S1 = HH * W\n WW = W // 2\n S2 = (H - HH) * WW\n WW = W - W // 2\n S3 = (H - HH) * WW\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\nif W > 2:\n WW = W // 3\n S1 = WW * H\n WW = W - W // 3\n WWW = WW // 2\n S2 = WWW * H\n WWW = WW - WW // 2\n S3 = WWW * H\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\n WW = W // 3\n S1 = WW * H\n HH = H // 2\n S2 = (W - WW) * HH\n HH = H - H // 2\n S3 = (W - WW) * HH\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\n WW = W // 3 + 1\n S1 = WW * H\n HH = H // 2\n S2 = (W - WW) * HH\n HH = H - H // 2\n S3 = (W - WW) * HH\n m = max(S1, S2, S3) - min(S1, S2, S3)\n M = min(M, m)\n\nprint(M)", "h,w = map(int,input().split())\nans = h*w\nfor i in range(1,h):\n A = w*i\n if w%2 == 0 or (h-i)%2 == 0:\n B = ((h-i)*w)//2\n C = ((h-i)*w)//2\n else:\n if h-i <= w:\n B = (h-i)*((w//2)+1)\n C = (h-i)*(w//2)\n else:\n B = ((h-i)//2 + 1) * w\n C = ((h-i)//2) * w\n ans = min(ans,max(A,max(B,C)) - min(A,min(B,C)))\n\nfor i in range(1,w):\n A = h*i\n if (w-i)%2 == 0 or h%2 == 0:\n B = ((w-i)*h)//2\n C = ((w-i)*h)//2\n else:\n if w-i <= h:\n B = (w-i)*((h//2)+1)\n C = (w-i)*(h//2)\n else:\n B = ((w-i)//2 + 1) * h\n C = ((w-i)//2) * h\n ans = min(ans,max(A,max(B,C)) - min(A,min(B,C)))\nprint(ans)", "def main():\n h, w = list(map(int, input().split()))\n if h % 3 == 0 or w % 3 == 0:\n print((0))\n return\n\n ans = h * w\n for _ in range(2):\n i = h // 3\n j = w // 2\n\n x = [(i - 1, h - i + 1), (i, h - i), (i + 1, h - i - 1)]\n y = [(j - 1, w - j + 1), (j, w - j), (j + 1, w - j - 1)]\n for (u, v) in x:\n # case1\n a, b = v // 2, v - v // 2\n s = [w * u, w * a, w * b]\n d = max(s) - min(s)\n ans = min(ans, d)\n for (s, t) in y:\n # case2\n s = [u * w, v * s, v * t]\n d = max(s) - min(s)\n ans = min(ans, d)\n\n w, h = h, w\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "H,W = map(int, input().split())\n\ndif = 10**10\n\nif H%3==0 or W%3==0:\n\tprint(0)\n\treturn\n\nfor i in range(H):\n\ta = i*W\n\th = (H-i)//2\n\tabc = [a, h*W, (H-i-h)*W]\n\tif not(0 in abc):\n\t\tdif = min(dif, max(abc)-min(abc))\n\t\n\th = H-i\n\tw = W//2\n\tabc = [a, h*w, h*(W-w)]\n\tif not(0 in abc):\n\t\tdif = min(dif, max(abc)-min(abc))\n\nfor i in range(W):\n\ta = H*i\n\tw = (W-i)//2\n\tabc = [a, H*w, H*(W-i-w)]\n\tif not(0 in abc):\n\t\tdif = min(dif, max(abc)-min(abc))\n\t\n\tw = W-i\n\th = H//2\n\tabc = [a, h*w, (H-h)*w]\n\tif not(0 in abc):\n\t\tdif = min(dif, max(abc)-min(abc))\n\nprint(dif)", "from sys import stdin\ndef main():\n #\u5165\u529b\n readline=stdin.readline\n h,w=map(int,readline().split())\n\n if h*w%3==0:\n ans=0\n else:\n ans=float(\"inf\")\n #\u7e26\u65b9\u5411\u306b\u5168\u63a2\u7d22\n s1=w//2*h\n s2=h*w-s1\n for i in range(1,h):\n s3=i*w\n s1-=w//2\n s2-=w-w//2\n ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\n for i in range(1,h-1):\n s3=i*w\n s1=(h-i)//2*w\n s2=h*w-s3-s1\n ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\n #\u6a2a\u65b9\u5411\u306b\u5168\u63a2\u7d22\n s1=h//2*w\n s2=h*w-s1\n for j in range(1,w):\n s3=j*h\n s1-=h//2\n s2-=h-h//2\n ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n \n for j in range(1,w-1):\n s3=j*h\n s1=(w-j)//2*h\n s2=h*w-s3-s1\n ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "import sys\nreadline = sys.stdin.readline\nfrom math import floor, ceil\n\ndef main():\n H, W = map(int, readline().rstrip().split())\n ans = H * W\n if H >= 3:\n ans = min(ans, abs(W*(H//3) - W*(H-H//3*2)))\n if W >= 3:\n ans = min(ans, abs(H*(W//3) - H*(W-W//3*2)))\n \n # \u7e26\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u6a2a\u306b\u30b9\u30e9\u30a4\u30b9\n # x1_cand = [floor(W/3), ceil(W/3)]\n x1_cand = [i for i in range(1, W)]\n y1 = H\n for x1 in x1_cand:\n x2 = W - x1\n x3 = x2\n y2 = H // 2\n y3 = H - y2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n x2 = (W-x1) // 2\n x3 = (W-x1-x2)\n ans = min(ans, max((x1*H), (x2*H), (x3*H)) - min((x1*H), (x2*H), (x3*H)))\n\n # \u6a2a\u306b\u30b9\u30e9\u30a4\u30b9 + \u6b8b\u308a\u306b\u7e26\u306b\u30b9\u30e9\u30a4\u30b9\n # y1_cand = [floor(H/3), ceil(H/3)]\n y1_cand = [i for i in range(1, H)]\n x1 = W\n for y1 in y1_cand:\n y2 = H - y1\n y3 = y2\n x2 = W // 2\n x3 = W - x2\n ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))\n\n y2 = (H-y1) // 2\n y3 = (H-y1-y2)\n ans = min(ans, max((W*y1), (W*y2), (W*y3)) - min((W*y1), (W*y2), (W*y3)))\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "h , w = list(map(int, input().split()))\nmi=h*w\ns=h*w\nfor i in range(h):\n s1=w*i\n if w%2==0 or (h-i)%2==0:\n s2=(s-s1)//2\n s3=s2\n elif h-i<w:\n s2=(h-i)*(w-1)//2\n s3=(h-i)*(w+1)//2\n else:\n s2=(h-i-1)//2*w\n s3=(h-i+1)//2*w\n d=abs(min(s1,s2,s3)-max(s1,s2,s3))\n if d<mi:\n mi=d\nfor i in range(w):\n s1=h*i\n if (w-i)%2==0 or h%2==0:\n s2=(s-s1)//2\n s3=s2\n elif w-i<h:\n s2=(w-i)*(h-1)//2\n s3=(w-i)*(h+1)//2\n else:\n s2=(w-i-1)//2*h\n s3=(w-i+1)//2*h\n d=abs(min(s1,s2,s3)-max(s1,s2,s3))\n if d<mi:\n mi=d\nprint(mi)\n", "h, w = list(map(int, input().split()))\ntanpen = min(h, w)\nchohen = max(h, w)\n\nif h%3 == 0 or w%3 == 0:\n print((0))\nelse:\n def findmin(h, w):\n ans = h*w\n for i in range(1, h):\n remi = h - i\n s1 = i*w\n s2 = (w//2) * remi\n s3 = (w - w//2) * remi\n ans = min(ans, max(s1, s2, s3) - min(s1, s2))\n\n s2 = w * (remi//2)\n s3 = w * (remi - remi//2)\n ans = min(ans, max(s1, s2, s3) - min(s1, s2))\n return ans\n print((min(findmin(h, w), findmin(w, h))))\n", "# coding: utf-8\nimport re\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nimport collections\nfrom fractions import Fraction\nimport itertools\nfrom copy import deepcopy\nimport random\nimport time\nimport os\nimport queue\nimport sys\nimport datetime\nfrom functools import lru_cache\n#@lru_cache(maxsize=None)\nreadline=sys.stdin.readline\nsys.setrecursionlimit(2000000)\n#import numpy as np\nalphabet=\"abcdefghijklmnopqrstuvwxyz\"\nmod=int(10**9+7)\ninf=int(10**20)\ndef yn(b):\n if b:\n print(\"yes\")\n else:\n print(\"no\")\ndef Yn(b):\n if b:\n print(\"Yes\")\n else:\n print(\"No\")\ndef YN(b):\n if b:\n print(\"YES\")\n else:\n print(\"NO\")\nclass union_find():\n def __init__(self,n):\n self.n=n\n self.P=[a for a in range(n)]\n self.rank=[0]*n\n \n def find(self,x):\n if(x!=self.P[x]):self.P[x]=self.find(self.P[x])\n return self.P[x]\n \n def same(self,x,y):\n return self.find(x)==self.find(y)\n \n def link(self,x,y):\n if self.rank[x]<self.rank[y]:\n self.P[x]=y\n elif self.rank[y]<self.rank[x]:\n self.P[y]=x\n else:\n self.P[x]=y\n self.rank[y]+=1\n \n def unite(self,x,y):\n self.link(self.find(x),self.find(y))\n \n def size(self):\n S=set()\n for a in range(self.n):\n S.add(self.find(a))\n return len(S)\ndef ispow(a,b):#a\u306fb\u306e\u7d2f\u4e57\u6570\u304b\n now=b\n while now<a:\n now*=b\n if now==a:return True\n else:return False\ndef getbin(num,size):\n A=[0]*size\n for a in range(size):\n if (num>>(size-a-1))&1==1:\n A[a]=1\n else:\n A[a]=0\n return A\ndef getfacs(n,mod_=0):\n A=[1]*(n+1)\n for a in range(2,len(A)):\n A[a]=A[a-1]*a\n if(mod_>0):A[a]%=mod_\n return A\ndef comb(n,r,mod,fac):\n if(n-r<0):return 0\n return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod\ndef nextcomb(num,size):\n x=num&(-num)\n y=num+x\n z=num&(~y)\n z//=x\n z=z>>1\n num=(y|z)\n if(num>=(1<<size)):return False\n else:return num\ndef getprimes(n,type=\"int\"):\n if n==0:\n if type==\"int\":return []\n else:return [False]\n A=[True]*(n+1)\n A[0]=False\n A[1]=False\n for a in range(2,n+1):\n if A[a]:\n for b in range(a*2,n+1,a):\n A[b]=False\n if(type==\"bool\"):return A\n B=[]\n for a in range(n+1):\n if(A[a]):B.append(a)\n return B\ndef isprime(num):\n if(num<=1):return False\n i=2\n while i*i<=num:\n if(num%i==0):return False\n i+=1\n return True\ndef ifelse(a,b,c):\n if a:return b\n else:return c\ndef join(A,c=\"\"):\n n=len(A)\n A=list(map(str,A))\n s=\"\"\n for a in range(n):\n s+=A[a]\n if(a<n-1):s+=c\n return s\ndef factorize(n,type_=\"dict\"):\n b = 2\n list_ = []\n while b * b <= n:\n while n % b == 0:\n n //= b\n list_.append(b)\n b+=1\n if n > 1:list_.append(n)\n if type_==\"dict\":\n dic={}\n for a in list_:\n if a in dic:\n dic[a]+=1\n else:\n dic[a]=1\n return dic\n elif type_==\"list\":\n return list_\n else:\n return None\ndef pm(x):\n return x//abs(x)\ndef inputintlist():\n return list(map(int,input().split()))\n######################################################################################################\n\nH,W=inputintlist()\nans=inf\nfor a in range(1,H):\n A=a*W\n #\u4e26\u884c\u306b\u5206\u5272\n B=((H-a)//2)*W\n C=H*W-A-B\n ans=min(ans,max([A,B,C])-min([A,B,C]))\n \n #\u5782\u76f4\u306b\u5206\u5272\n B=(W//2)*(H-a)\n C=H*W-A-B\n ans=min(ans,max([A,B,C])-min([A,B,C]))\n \nH,W=W,H\nfor a in range(1,H):\n A=a*W\n #\u4e26\u884c\u306b\u5206\u5272\n B=((H-a)//2)*W\n C=H*W-A-B\n ans=min(ans,max([A,B,C])-min([A,B,C]))\n \n #\u5782\u76f4\u306b\u5206\u5272\n B=(W//2)*(H-a)\n C=H*W-A-B\n ans=min(ans,max([A,B,C])-min([A,B,C]))\n \n\nprint(ans)\n\n\n\n\n\n\n\n\n\n\n", "h,w=map(int,input().split())\na1=min(h*(w%3!=0),w*(h%3!=0))\na2=10**6\na3=10**6\nfor i in range(1,h):\n mx=max(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))\n mn=min(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))\n a2=min(a2,mx-mn)\nfor i in range(1,w):\n mx=max(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))\n mn=min(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))\n a3=min(a3,mx-mn)\nprint(min(a1,a2,a3))"] | {"inputs": ["3 5\n", "4 5\n", "5 5\n", "100000 2\n", "100000 100000\n"], "outputs": ["0\n", "2\n", "4\n", "1\n", "50000\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 72,678 | |
192098171d46438154a5f756df46ae2a | UNKNOWN | We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
- For each 1 β€ i β€ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.
Determine whether Snuke can achieve his objective.
-----Constraints-----
- 2 β€ N β€ 10^5
- a_i is an integer.
- 1 β€ a_i β€ 10^9
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
-----Output-----
If Snuke can achieve his objective, print Yes; otherwise, print No.
-----Sample Input-----
3
1 10 100
-----Sample Output-----
Yes
One solution is (1, 100, 10). | ["#!/usr/bin/env python\n\nn = int(input())\na = list(map(int, input().split()))\n\nn2 = 0 \nn4 = 0 \nfor i in range(n):\n if a[i]%4 == 0:\n n4 += 1\n elif a[i]%2 == 0:\n n2 += 1\n\nok = True\nif n2 == 0:\n if n4 >= n//2:\n ok = True\n else:\n ok = False\nelse:\n n1 = n-n2-n4\n n1 += 1\n nn = n1+n4\n if n4 >= nn//2:\n ok = True\n else:\n ok = False\n\nif ok: \n print('Yes')\nelse:\n print('No')", "N = int(input())\nA = list(map(int, input().split()))\n\nfour = 0\nodd = 0\nfor a in A:\n if a % 2 == 1:\n odd += 1\n if a % 4 == 0:\n four += 1\nif N % 2 == 1:\n if odd - four <= 1:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n if odd - four <= 0:\n print(\"Yes\")\n else:\n print(\"No\")", "n = int(input())\na, b = 0, 0\nfor i in map(int, input().split()):\n if i % 4 == 0:\n a += 1\n elif i % 2 == 0:\n b += 1\nc = n - a - b\nif b == 0:\n if a + 1 < c:\n print(\"No\")\n else:\n print(\"Yes\")\nelse:\n if a < c:\n print(\"No\")\n else:\n print(\"Yes\")", "n=int(input())\na=list(map(int,input().split()))\ns=0\nt=0\nu=0\nfor i in range(n):\n if a[i]%4==0:\n s=s+1\n elif a[i]%2==0:\n t=t+1\n else:\n u=u+1\nif t>=1:\n if s>=u:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n if s-u>=-1:\n print(\"Yes\")\n else:\n print(\"No\")\n \n", "n = int(input())\na = list(map(int, input().split()))\n\nfour = 0\ntwo = 0\nother = 0\nfor i in a:\n if i % 4 == 0:\n four += 1\n elif i % 2 == 0:\n two += 1\n else:\n other += 1\n\nans = 'No'\nother += two % 2\nif four + 1 >= other:\n ans = 'Yes'\n\nprint(ans)", "def main():\n n = int(input())\n As = list(map(int, input().split()))\n fours = 0\n evens = 0\n odds = 0\n for A in As:\n if A % 4 == 0:\n fours += 1\n elif A % 2 == 0:\n evens += 1\n else:\n odds += 1\n\n if fours+(evens)//2 >= n//2:\n ans = 'Yes'\n else:\n ans = 'No'\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nd4 = 0\nd2 = 0\nfor i in list(map(int,input().split())):\n if i % 4 == 0:\n d4 += 1\n elif i % 2 == 0:\n d2 += 1\n else:\n None\nif N <= d4*2 + 1:\n print(\"Yes\")\nelif N - d4 * 2 <= d2 :\n print(\"Yes\")\nelse:\n print(\"No\")", "N = int(input())\na = list(map(int, input().split()))\n\nnum2 = 0\nnum4 = 0\nodd = 0\nfor i in a:\n if i % 4 == 0:\n num4 += 1\n continue\n elif i % 2 == 0:\n num2 += 1\n continue\n else:\n odd += 1\n continue\nif odd<=num4 or (N%2==1 and num4==N//2):\n print('Yes')\nelse:\n print('No')\n", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom fractions import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\n#import bisect\n#\n# d = m - k[i] - k[j]\n# if kk[bisect.bisect_right(kk,d) - 1] == d:\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\ndef readInts():\n return list(map(int,input().split()))\ndef I():\n return int(input())\nn = I()\nA = readInts()\nfour = 0\ntwo = 0\nfor i in range(n):\n if A[i]%4 == 0:\n four += 1\n elif A[i]%2 == 0:\n two += 1\nprint(('Yes' if four + two//2 >= n//2 else 'No'))\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# FileName: \tC\n# CreatedDate: 2020-09-04 15:44:42 +0900\n# LastModified: 2020-09-13 16:06:20 +0900\n#\n\n\nimport os\nimport sys\n# import numpy as np\n# import pandas as pd\n\n\ndef main():\n n = int(input())\n A = list(map(int, input().split()))\n A_4 = [x for x in A if x % 4 == 0]\n A_2 = [x for x in A if x % 4 != 0 and x % 2 == 0]\n A_0 = [x for x in A if x % 2 != 0]\n if len(A_2) == 0 and len(A_0) <= len(A_4) + 1:\n print(\"Yes\")\n elif len(A_0) <= len(A_4):\n print(\"Yes\")\n else:\n print(\"No\")\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nA = [int(a) for a in input().split(\" \")]\n\nm_2_but_4 = 0\nm_4 = 0\nm_none = 0\nfor i in range(len(A)):\n if A[i] % 4 == 0:\n m_4 += 1\n elif A[i] % 2 == 0:\n m_2_but_4 += 1\n else:\n m_none += 1\n\nif m_2_but_4:\n print(\"Yes\") if m_4 >= m_none else print(\"No\")\nelse:\n print(\"Yes\") if m_4 + 1 >= m_none else print(\"No\")", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N, *A = list(map(int, read().split()))\n \n m = sum(1 for a in A if a % 2 == 1)\n n2 = sum(1 for a in A if a % 2 == 0 and a % 4 != 0)\n n4 = sum(1 for a in A if a % 4 == 0)\n \n if m <= n4:\n print('Yes')\n elif m == n4 + 1:\n if n2 == 0:\n print('Yes')\n else:\n print('No')\n else:\n print('No')\n \n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N=int(input())\nls=[int(s) for s in input().split()]\na0=0\na2=0\nfor n in ls:\n if n%2==1:\n a0+=1\n elif n%4==0:\n a2+=1\nif a2>a0-1:\n print('Yes')\nelif a2==a0-1:\n if a0+a2<N:\n print('No')\n else:\n print('Yes')\nelse:\n print('No')", "_=int(input())\na=list(map(int,input().split()))\n\nx,y,z=0,0,0\nfor i in a:\n if i%4 == 0:\n z+=1\n elif i%2 == 0:\n y+=1\n else:\n x+=1\nif y:\n if x <= z:\n print('Yes')\n else:\n print('No')\nelse:\n if x <= z+1:\n print('Yes')\n else:\n print('No')", "N=int(input())\na=list(map(int,input().split()))\nl=[0]*N\nfor i in range(N):\n if a[i]%4:\n if a[i]%2:l[i]=1\n else:l[i]=2\n else:l[i]=4\nprint('Yes'if l.count(1)+(1 if l.count(2)else 0)<=1+l.count(4)else'No')", "n = int(input())\na = [int(x) for x in input().split()]\nres = \"No\"\n\ndef check(p):\n if p % 4 == 0:\n return 2\n elif p % 2 == 0:\n return 1\n else:\n return 0\n \nc0 = 0\nc2 = 0\nc4 = 0\nfor i in range(n):\n a[i] = check(a[i])\n if a[i] == 2:\n c4 += 1\n elif a[i] == 1:\n c2 += 1\n else:\n c0 += 1\n \nif c0 == c4 + 1 and c2 == 0:\n res = \"Yes\"\nelif c0 <= c4:\n res = \"Yes\"\n\nprint(res)", "##\nN = int(input())\nN_List = list(map(int,input().split()))\nFour_List = [i for i in N_List if i % 4 == 0]\nTwo_List = [i for i in N_List if i % 2 == 0]\nif len(Two_List)-len(Four_List) > 0:\n N = N - (len(Two_List) - len(Four_List)) + 1\n\nif N // 2 <= len(Four_List):\n print(\"Yes\")\nelse:\n print(\"No\")", "def even(x):\n flag1 = False\n if x % 2 == 0:\n flag1 = True\n return flag1\n\n\ndef multiple_of_4(x):\n flag2 = False\n if x % 2 == 0:\n x //= 2\n if x % 2 == 0:\n flag2 = True\n return flag2\n\n\ndef main():\n n = int(input())\n a_lst = list(map(int, input().split()))\n flag = False\n\n multiple_of_4_count = 0\n for i in range(n):\n if multiple_of_4(a_lst[i]):\n multiple_of_4_count += 1\n\n if multiple_of_4_count >= n // 2:\n flag = True\n else:\n even_count = 0\n for i in range(n):\n if even(a_lst[i]):\n even_count += 1\n tmp = n - 2 * multiple_of_4_count\n even_count -= multiple_of_4_count\n\n if even_count >= tmp:\n flag = True\n\n if flag:\n print('Yes')\n else:\n print('No')\n\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nA = list(map(int,input().split()))\nx = 0\ny = 0\n\nfor a in A:\n if a%4==0:\n x+=1\n elif a%2==0:\n y+=1\n\nif N//2<=x+y//2:\n print(\"Yes\")\nelse:\n print(\"No\")", "from collections import deque\n\nn = int(input())\nA = list(map(int, input().split()))\n\ncnt_2 = 0\ncnt_4 = 0\nfor i in range(n):\n a = A[i]\n if a%4==0:\n cnt_4+=1\n elif a%2==0:\n cnt_2+=1\ncnt_else = n-cnt_2-cnt_4\ncnt_else += cnt_2%2\n\nif cnt_else-1 <= cnt_4:\n print(\"Yes\")\nelse:\n print(\"No\")", "n=int(input())\na=[int(i) for i in input().split()]\n\nA_num=0\nB_num=0\nC_num=0\n\nfor i in a:\n if i%4==0:\n C_num+=1\n elif i%2==0:\n B_num+=1\n else:\n A_num+=1\n\ndef ans():\n if A_num==1:\n if C_num>=1:\n return True\n return False\n else:\n if n==2*A_num-1:\n if C_num==A_num-1:\n return True\n return False\n\n elif n<2*A_num-1:\n return False\n else:\n if C_num>=A_num:\n return True\n return False\nif ans():\n print(\"Yes\")\nelse:\n print(\"No\")\n", "n=int(input())\na=list(map(int, input().split()))\nx = 0\ny = 0\nfor i in a:\n if i %2 != 0:\n x+=1\n elif i%4 == 0:\n y+=1\nif y >=x:\n print('Yes')\n return\nelse:\n if x+y == len(a) and y == x-1:\n print('Yes')\n else:\n print('No')", "N = int(input())\na = list(map(int,input().split()))\n\ncnt2 = 0\ncnt4 = 0\ncntodd = 0\nfor i in a:\n if i % 4 == 0:\n cnt4 += 1\n elif i % 2 == 0:\n cnt2 += 1\n else:\n cntodd += 1\n\nif cnt2 == 0 and cnt4 + 1 >= cntodd:\n ans = 'Yes'\nelif cnt4 >= cntodd:\n ans = 'Yes'\nelse:\n ans = 'No'\nprint(ans) ", "\nN = int(input())\na = list(map(int,input().split()))\nsa=[]\nc = [0]*4\nans = 'No'\n\n#4\u3067\u5272\u3063\u305f\u4f59\u308a\u4e00\u89a7\u8868\u4f5c\u6210\nfor i in a:\n sa.append(i%4)\n \nfor i in sa:\n c[i]+=1\n \n#2\u306e\u500d\u6570\u304c\u306a\u3044\u6642\u3001\u5947\u6570\u306e\u6570\u306e\u548c\u304c4\u306e\u500d\u6570\u306e\u500b\u6570+1\u4ee5\u4e0b\u306a\u3089OK \nif c[2]==0:\n if c[1]+c[3]<=c[0]+1:\n ans = 'Yes'\n#2\u306e\u500d\u6570\u304c\u3042\u308b\u6642\u3001\u307e\u3068\u3081\u3066\u7aef\u306b\u5bc4\u305b\u3066\u3001\u5947\u6570\u500b\u3067\u3082\u5076\u6570\u500b\u3067\u3082\u5947\u65701\u500b\u5206\u306e\u6271\u3044\u306b\u306a\u308b\n#\u3088\u3063\u3066\u5947\u6570\u306e\u6570\u306e\u548c\u304c4\u306e\u500d\u6570\u306e\u500b\u6570\u4ee5\u4e0b\u3067\u3042\u308c\u3070OK\nelse:\n if c[1]+c[3]<=c[0]:\n ans = 'Yes'\n\n#print(c)\nprint(ans)", "N = int(input())\na = list(map(int, input().split()))\ncount = 0\nhcount = 0\nfor x in a:\n if x % 4 == 0:\n count += 1\n elif x % 2 == 0:\n hcount += 1\n\nif (count + (hcount // 2)) >= (N // 2):\n print('Yes')\nelse:\n print('No')\n", "from collections import Counter\nn=int(input())\na=list(map(int,input().split()))\namod4=list([x%4 for x in a])\nd=Counter(amod4)\nif n-d[0]-d[2]<d[0]+1:\n print('Yes')\nelif d[2]==0 and n==2*d[0]+1:\n print('Yes')\nelse:\n print('No')\n", "#import\n#import math\n#import numpy as np\nN = int(input())\n#= input()\n#= map(int, input().split())\na = list(map(int, input().split()))\n#= [input(), input()]\n#= [list(map(int, input().split())) for _ in range(N)]\n#= {i:[] for i in range(N)}\n\nalen = N\ntwo = 0\nfour = 0\n\nfor aa in a:\n if aa % 4 == 0:\n four += 1\n elif aa % 2 == 0:\n two += 1\n\nother = alen - two - four\n\nres = False\n\nif other > four + 1:\n pass\nelif other == four + 1:\n if two == 0:\n res = True\nelse:\n res = True\n\nif res:\n print(\"Yes\")\nelse:\n print(\"No\")", "_ = input()\na = [int(x) for x in input().split()]\n\nodd = []\nm4 = []\nm2 = 0\nfor i in a:\n if i % 2 != 0:\n odd.append(i)\n elif i % 4 == 0:\n m4.append(i)\n else:\n m2 = 1\nelse:\n lodd = len(odd)\n if lodd == 0 or lodd + m2 - 1 <= len(m4):\n print(\"Yes\")\n else:\n print(\"No\")", "n=int(input())\na=list(map(int,input().split()))\none=0\nfour=0\ntwo=0\nfor i in range(n):\n cnt=0\n num=a[i]\n while num%2==0:\n cnt+=1\n num//=2\n if cnt==0:\n pin=1\n elif cnt==1:\n pin=2\n else:\n pin=4\n if pin==1:\n one+=1\n elif pin==4:\n four+=1\n else:\n two+=1\nif two>0:\n one+=1\nif one<=four+1:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "n = int(input())\na = list(map(int,input().split()))\nt = [0 for _ in range(3)]\n\nfor i in range(n):\n\tif a[i] % 2 == 0:\n\t\tif a[i] % 4 == 0:\n\t\t\tt[2] += 1\n\t\telse:\n\t\t\tt[1] += 1\n\telse:\n\t\tt[0] += 1\n\nif t[0] + (t[1]%2) <= t[2] + 1:\n\tprint(\"Yes\")\nelse:\n\tprint(\"No\")", "n = int(input())\na = list(map(int, input().split()))\nfour = 0\ntwo = 0\nfor i in range(n):\n if a[i] % 4 == 0:\n four += 1\n elif a[i] % 2 == 0:\n two += 1\n\nif 2 * four + 1 >= n:\n print(\"Yes\")\nelif 2 * four + two >= n:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "import math\nN = int(input())\nA = list(map(int, input().split()))\ncount = []\nfor i in A:\n if i%4 == 0:\n count.append(\"4\")\n elif i%2 == 0:\n count.append(\"2\")\n else:\n count.append(\"1\")\nB1 = count.count(\"4\")\nB2 = count.count(\"1\")\nif count.count(\"2\") == 0:\n print(\"Yes\" if B1+1 >= B2 else \"No\")\nelse:\n print(\"Yes\" if B1 >= B2 else \"No\")", "_ = input()\na = [int(x) for x in input().split()]\n\nodd = []\nm4 = []\nm2 = 0\nfor i in a:\n if i % 2 != 0:\n odd.append(i)\n elif i % 4 == 0:\n m4.append(i)\n else:\n m2 = 1\nelse:\n if len(odd) + m2 - 1 <= len(m4):\n print(\"Yes\")\n else:\n print(\"No\")", "n = int(input())\na_lst = list(map(int, input().split()))\n\ncnt = 0\nfor a in a_lst:\n if a % 4 == 0:\n cnt += 2\n elif a % 2 == 0:\n cnt += 1\n else:\n pass\n\nif cnt // 2 >= n // 2:\n print('Yes')\nelse:\n print('No')", "N=int(input())\na=list(map(int,input().split()))\nfor i in range(N):\n if a[i]%4==0:\n a[i]=2\n elif a[i]%2==0:\n a[i]=1\n else:\n a[i]=0\nzero=a.count(0)\none=a.count(1)\ntwo=a.count(2)\n\nif zero>two+1:\n print(\"No\")\nelif zero==two+1:\n if zero+two==N:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n print(\"Yes\")\n", "from collections import defaultdict\n\nd = defaultdict(int)\nd=[0]*3\nn = int(input())\n\nfor i in list(map(int, input().split())):\n if i % 4 == 0:\n d[2] += 1\n elif i % 2 == 0:\n d[1] += 1\n else:\n d[0] += 1\nt = d[2] - d[1]\nif (d[0] <= d[2]) or ((d[0] == d[2] + 1) and (d[1] == 0)):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "#\n# abc069 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"3\n1 10 100\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"4\n1 2 3 4\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"3\n1 4 1\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"2\n1 1\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_5(self):\n input = \"\"\"6\n2 7 1 8 2 8\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N = int(input())\n A = list(map(int, input().split()))\n\n Q = 0\n E = 0\n O = 0\n for a in A:\n if a % 4 == 0:\n Q += 1\n elif a % 2 == 0:\n E += 1\n else:\n O += 1\n\n if N-2*Q <= 0 or (N-2*Q) == 1 or N-2*Q == E:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "n = int(input())\nA=list(map(int, input().split()))\n\nans=\"No\"\nc1=c2=c4=0\nfor a in A:\n if a%4==0:\n c4+=1\n elif a%2==0:\n c2+=1\n else:\n c1+=1\n\nif c4==0 and c1>0 :\n ans=\"No\"\nelif c1<=c4+(c2==0) :\n ans=\"Yes\"\nelse:\n ans=\"No\"\n\nprint( ans )\n\n", "N=int(input())\na=list(map(int,input().split()))\n\nn4,n2=0,0\nfor i in range(N):\n if a[i] % 4 == 0:n4 += 1\n elif a[i] % 2 == 0:n2 += 1\n \nif n4 >= N//2:print('Yes')\nelif n4*2 + n2 >= N:print('Yes')\nelse:print('No')", "n=int(input())\na=list(map(int,input().split()))\n\nx2=0\nx4=0\nx1=0\nfor x in a:\n if x%2==0:\n x2+=1\n if x%4==0:\n x4+=1\n if x%2==1:\n x1+=1\n \nif x4+x1==n:\n if x4>=x1-1:\n print('Yes')\n else:\n print('No')\n \nelse:\n if x4>=x1:\n print('Yes')\n else:\n \n print('No')\n", "input();a=list(map(int,input().split()))\nb1,b2,b4=0,0,0\nfor i in a:\n if i%2!=0: b1+=1\n elif i%4==0: b4+=1\n else: b2+=1\nprint('Yes' if b1<=b4 else 'No' if b2 else 'Yes' if b1<=b4+1 else 'No')", "n = int(input())\nan = [int(num) for num in input().split()]\n\none,two,four = 0, 0, 0\nfor a in an:\n if a%4 == 0:\n four += 1\n elif a%2 == 0:\n two += 1\n else :\n one += 1\n \nif two == 0 and four >= one - 1 :\n print(\"Yes\")\nelif four >= one :\n print(\"Yes\")\nelse :\n print(\"No\")", "N = int(input())\na = list(map(int,input().split()))\nf = []\nt = []\no = []\nans = 'No'\n\nfor i in a:\n if i%4==0:\n f.append(i)\n elif i%2==0:\n t.append(i)\n else:\n o.append(i)\n\nif len(t)==0:\n if len(o)<=len(f)+1:\n ans = 'Yes'\nelse:\n if len(o)<=len(f):\n ans = 'Yes'\nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\nx=0\ny=0\nfor i in range(n):\n if a[i]%2!=0:\n x+=1\n elif a[i]%4==0:\n y+=1\n\nif x<=y:\n print(\"Yes\")\nelse:\n if x+y==n and x==y+1:\n print(\"Yes\")\n else:\n print(\"No\")", "input();a,b,c,d,r=list(map(int,input().split())),0,0,0,'NYoe s'\nfor i in a:\n if i%2!=0: b+=1\n elif i%4==0: c+=1\n else: d+=1\nprint([r[b<=c::2],r[b<=c+1::2]][d==0])", "n = int(input())\na = list(map(int, input().split()))\nfour = 0\ntwo = 0\nfor i in range(n):\n if a[i] % 4 == 0:\n four += 1\n elif a[i] % 2 == 0:\n two += 1\n\nif four >= n // 2 or n - 2 * four <= two:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "input();a=list(map(int,input().split()))\nb1,b2,b4=0,0,0\nfor i in a:\n if i%2!=0: b1+=1\n elif i%4==0: b4+=1\n elif i%2==0: b2+=1\nprint('Yes' if b1<=b4 else 'No' if b2 else 'Yes' if b1<=b4+1 else 'No')", "from collections import Counter\n\nn = int(input())\nA = list(map(int, input().split()))\nA = [min(x & -x, 4) for x in A]\n\nCA = Counter(A)\nnum0 = CA[1]\nnum1 = CA[2]\nnum2 = CA[4]\nif num1:\n num1 = 1\nif num2 - (num1 + num0) >= -1:\n print(\"Yes\")\n\nelse:\n print(\"No\")\n", "n = int(input())\nal = list(map(int, input().split()))\n\ncount2 = 0\ncount4 = 0\n\nfor a in al:\n if a % 4 == 0:\n count4 += 1\n elif a%2==0:\n count2+=1\n\nv=count2//2\n\nn-=v*2\nif count4 >= n//2:\n ans='Yes'\nelse:\n ans='No'\n\nprint(ans)", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n n = ini()\n a = inl()\n\n c4, c2 = 0, 0\n for x in a:\n if x % 4 == 0:\n c4 += 1\n elif x % 2 == 0:\n c2 += 1\n c1 = n - c2 - c4\n\n if c4 == 0:\n return c1 == 0 and c2 >= 2\n return c4 >= c1 or (c4 + 1 == c1 and c2 == 0)\n\n\nprint(\"Yes\" if solve() else \"No\")\n", "n = int(input())\na_ls = list(map(int, input().split()))\nn_4k = 0\nn_2k = 0\nn_odd = 0\nfor i in range(n):\n if a_ls[i] % 4 ==0:\n n_4k += 1\n elif a_ls[i] % 2 ==0:\n n_2k += 1\n else:\n n_odd += 1\nres = 'No'\nif n_odd == 0:\n res = 'Yes'\nelse:\n if n_2k > 0:\n if n_odd <= n_4k:\n res = 'Yes'\n else:\n if n_odd <= n_4k+1:\n res = 'Yes'\nprint(res)", "n=int(input()) \nc=list(map(int, input().split()))\na = 0\na2 = 0\na4 = 0\n\nfor i in c:\n if i%2 != 0:\n a += 1\n if i%2 == 0 and i%4 != 0:\n a2 += 1\n if i%4 == 0:\n a4 += 1\nif a == 0 :\n print('Yes')\nif a > 0 and a2 == 0:\n if a <= a4 +1 :\n print('Yes')\n else:\n print('No')\nif a > 0 and a2 > 0:\n if a <= a4 :\n print('Yes')\n else:\n print('No')", "n = int(input())\na = list(map(int, input().split()))\nc_ki = 0\nc_4 = 0\nc_2 = 0\nfor i in range(n):\n if a[i] % 2 == 1:\n c_ki += 1\n elif a[i] % 4 == 0:\n c_4 += 1\n else:\n c_2 += 1\nif c_ki <= c_4:\n print(\"Yes\")\nelif c_ki-1 == c_4 and c_2 == 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "N = int(input())\na = [int(x) for x in input().split()]\ncnt4 = 0\ncnt2 = 0\nfor x in a:\n if x % 4 == 0:\n cnt4 += 1\n continue\n if x % 2 == 0:\n cnt2 += 1\ncnt2 = cnt2//2*2\nif N-cnt2 > 2*cnt4+1:\n print('No')\nelse:\n print('Yes')", "n=int(input())\na=list(map(int,input().split()))\nb,c,d=0,0,0\nfor i in a:\n if i%4==0:\n b+=1\n elif i%2==0:\n c+=1\n else:\n d+=1\nif c==0 and b>=d-1:\n print(\"Yes\")\nelif b>=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "n = int(input())\nA = list(map(int, input().split()))\n\nmulti_4 = 0\nmulti_2 = 0\nodd = 0\nfor a in A:\n if a % 4 == 0:\n multi_4 += 1\n elif a % 2 == 0:\n multi_2 += 1\n else:\n odd += 1\n\nif multi_2 > 0:\n if odd > multi_4:\n print('No')\n else:\n print('Yes')\nelse:\n if odd > multi_4 + 1:\n print('No')\n else:\n print('Yes')\n", "N = int(input())\nA = list(map(int,input().split()))\n\ntwo = 0\nfour = 0\nodd = 0\n\nfor a in A:\n if a % 4 == 0:\n four += 1\n elif a % 2 == 0:\n two += 1\n\nN -= max(0, two - 1)\n\nprint(\"Yes\" if four >= N // 2 else \"No\")", "import sys\n\nn=int(input())\na=[int(x) for x in input().rstrip().split()]\n\neven=0\nodd=0\nnum4=0\nfor i in a:\n if i%4==0:\n num4+=1\n continue\n\n elif i%2==0:\n even+=1\n else:\n odd+=1\n\n\nif odd<=num4:\n print(\"Yes\")\nelif odd-1==num4 and even==0:\n print(\"Yes\")\nelif odd==0 and 2<=even:\n print(\"Yes\")\nelse:\n print(\"No\")", "n = int(input())\na = list(map(int,input().split()))\n\ncodd = 0\ncfour = 0\n\nfor i in range(n):\n\tif a[i]%2 != 0:\n\t\tcodd += 1\n\tif a[i]%4 == 0:\n\t\tcfour += 1\nceven = n - cfour - codd\n\nif cfour >= codd:\n\tprint('Yes')\nelif ceven == 0 and cfour + 1 == codd:\n\tprint('Yes')\nelse:\n\tprint('No')", "import numpy as np\n \nN=int(input())\nA=np.array(list(map(int,input().split())))\n \nodd=np.count_nonzero(A%2!=0)\nfour=np.count_nonzero(A%4==0)\nans='No'\n\nif odd==1 and four>=1:\n ans='Yes'\nelif odd==2 and four>=2:\n ans='Yes'\nelse:\n if odd+four==N and odd-1<=four:\n ans='Yes'\n elif odd<=four:\n ans='Yes'\nprint(ans)", "with open(0) as f:\n N, *a = list(map(int, f.read().split()))\ni, j, k = 0, 0, 0\nfor x in a:\n if x%4 == 0:\n i += 1\n elif x%2 == 0:\n j += 1\n else:\n k += 1\n \nif j > 0:\n k += 1\nprint(('Yes' if k <= i+1 else 'No'))\n", "import math\nn = int(input())\na = list(map(int, input().split()))\nc2 = 0\nc4 = 0\nfor i in a:\n if i%4==0:\n c4+=1\n elif i%2==0:\n c2+=1\n\nif c2 == len(a):\n print('Yes')\nelif c2 >= 2:\n if c4 >= (math.ceil((len(a)-c2)/2)):\n print('Yes')\n else:\n print('No')\nelif c4 >=(len(a)//2):\n print('Yes')\nelse:\n print('No')", "n=int(input())\nl=list(map(int,input().split()))\nx,y,z=0,0,0\nfor a in l:\n if a%4==0:\n z+=1\n elif a%2==0:\n y+=1\n else:\n x+=1\nif y>0:\n x+=1\nprint(('Yes'if x<=z+1 else'No'))\n", "n = int(input())\na = list(map(int, input().split()))\n\nx = 0\ny = 0\nz = 0\nfor i in a:\n if i%4 == 0: x += 1\n elif i%2 == 0: y += 1\n else: z += 1\n\nif y%2+z-1 <= x: print(\"Yes\")\nelse: print(\"No\")", "n=int(input())\na=list(map(int,input().split()))\nc2=0\nc4=0\nfor aa in a:\n if aa%2 == 0:\n if aa%4 == 0:\n c4+=1\n else:\n c2+=1\nc0=n-(c2+c4)\ncc=c4-c0\nif c2>=1 and c2 != n:\n cc-=1\nprint((\"Yes\" if cc >= -1 else \"No\"))\n", "n = int(input())\na = list(map(int, input().split()))\na4 = []\na2 = []\na1 = []\nfor i in range(n):\n if a[i] % 4 == 0:\n a4.append(a[i])\n elif a[i] % 2 == 0:\n a2.append(a[i])\n else:\n a1.append(a[i])\nif len(a4) >= n//2:\n print(\"Yes\")\nelif len(a4) + len(a2)//2 >= n//2:\n print(\"Yes\")\nelse:\n print(\"No\")", "def main():\n n = int(input())\n a = [int(an) for an in input().split()]\n exist2 = False\n not4 = 0\n count4 = 0\n for an in a:\n if an % 2 == 0:\n if an % 4 == 0:\n count4 += 1\n else:\n if not exist2:\n exist2 = True\n not4 += 1\n else:\n not4 += 1\n print(('Yes' if count4 >= not4 - 1 else 'No'))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nA = list(map(int, input().split()))\nmod0 = 0\nmod2 = 0\nmod13 = 0\n\nfor a in A:\n mod = a % 4\n if mod == 0:\n mod0 += 1\n elif mod == 2:\n mod2 += 1\n else:\n mod13 += 1\n \nif mod2 > 0:\n if mod13 <= mod0:\n print('Yes')\n else:\n print('No')\nelse:\n if mod13-1 <= mod0:\n print('Yes')\n else:\n print('No')", "N=int(input())\na=list(map(int,input().strip().split()))\n\neven=0\nodd=0\nfour=0\nfor n in range(N):\n if a[n]%4==0:\n four+=1\n elif a[n]%2==0:\n even+=1\n else:\n odd+=1\n\nif odd==0:\n print(\"Yes\")\nelse:\n if even==0:\n if four>=odd-1:\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n if four>=odd:\n print(\"Yes\")\n else:\n print(\"No\")", "n = int(input())\na_list = list(map(int, input().split()))\n\nx = y = z = 0\nfor a in a_list:\n if a % 4 == 0:\n x += 1\n elif a % 2 == 0:\n y += 1\n else:\n z += 1\nif (y == 0 and x >= z - 1) or (y > 0 and x >= z):\n print(\"Yes\")\nelse:\n print(\"No\")", "input();a,b,c,d,r=list(map(int,input().split())),0,0,0,'NYoe s'\nfor i in a:\n if i%2!=0: b+=1\n elif i%4==0: c+=1\n else: d+=1\nprint([r[b<=c::2],r[b<=c+1::2]][not d])", "input();a,b1,b2,b4,r=list(map(int,input().split())),0,0,0,'NYoe s'\nfor i in a:\n if i%2!=0: b1+=1\n elif i%4==0: b4+=1\n else: b2+=1\nprint([r[b1<=b4::2],r[b1<=b4+1::2]][not b2])", "n = int(input())\n\narr = list(map(int, input().split()))\n\nodd_num = len([e for e in arr if e % 2 != 0])\nfour_num = len([e for e in arr if e % 4 == 0])\neven_num = n - odd_num - four_num\n\nif even_num:\n print(\"Yes\" if four_num >= odd_num else \"No\")\nelse:\n print(\"Yes\" if four_num >= odd_num - 1 else \"No\")", "n = int(input())\na = list(map(int, input().split()))\n\nx,y,z = 0,0,0\nfor i in a:\n if i%4 == 0: x += 1\n elif i%2 == 0: y += 1\n else: z += 1\n \nif x >= z-1+y%2: print(\"Yes\")\nelse: print(\"No\")", "n = int(input())\nA = list(map(int, input().split()))\nd, q, x = 0, 0, 0\nfor a in A:\n if a % 4 == 0:\n q += 1\n elif a % 2 == 0:\n d += 1\n else:\n x += 1\nx += d % 2\nd -= d % 2\nif q+1 >= x:\n print('Yes')\nelse:\n print('No')\n# print(d,q,x)\n", "n=int(input())\n\nL=list(map(int,input().split()))\na=0\nb=0\n\nfor i in range(n):\n\tif L[i]%4==0:\n\t\tb+=1\n\tif L[i]%2==1:\n\t\ta+=1\n\nif a+b==n and a-b==1:\n\tprint('Yes')\n\treturn\nif b>=a:\n\tprint('Yes')\nelse:\n\tprint('No')", "N=int(input())\n*A,=map(int,input().split())\n\ni1=len([i for i in A if i%2!=0])\ni4=len([i for i in A if i%4==0])\ni2=min(1,N-i1-i4)\n\n# print(i1,i2,i4)\nprint('Yes' if (i1+i2-1)<=i4 else 'No')", "N = int(input())\nA = list(map(int, input().split()))\ncnt_odd = 0\ncnt_4 = 0\nfor a in A:\n if a % 2 != 0:\n cnt_odd += 1\n elif a % 4 == 0:\n cnt_4 += 1\nif cnt_odd + cnt_4 == N and cnt_odd -1 == cnt_4:\n print('Yes')\nelse:\n print(('Yes' if cnt_4 >= cnt_odd else 'No'))\n", "_ = input()\na = [int(x) for x in input().split()]\n\nodd, m4, m2 = 0, 0, 0\nfor i in a:\n if i % 2 != 0:\n odd += 1\n elif i % 4 == 0:\n m4 += 1\n else:\n m2 = 1\nelse:\n if odd + m2 - 1 <= m4:\n print(\"Yes\")\n else:\n print(\"No\")", "N = int(input())\na = list(map(int,input().split()))\nc2 = 0\nc4 = 0\nfor i in range(N):\n if a[i]%4 == 0:\n c4 += 1\n elif a[i]%2 == 0:\n c2 += 1\nf = c4 * 2 + 1\nif f >= N or f + c2 - 1 >= N:\n print(\"Yes\")\nelse:\n print(\"No\")", "n = int(input())\na = list(map(int, input().split()))\n\ncnt4 = 0\ncnt2 = 0\nfor i in a:\n if i % 4 == 0:\n cnt4 += 1\n elif i % 2 == 0:\n cnt2 += 1\n\nif cnt4 >= n//2:\n print('Yes')\nelif 2 * cnt4 >= n - cnt2:\n print('Yes')\nelse:\n print('No')", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 02:20:18 2020\n\n@author: liang\n\"\"\"\n\nN = int(input())\nA = [int(x) for x in input().split()]\n\nc0 = 0\nc4 = 0\nfor a in A:\n if a%2 == 1:\n c0 += 1\n elif a%4 == 0:\n c4 += 1\n\nif c0 <= c4:\n print(\"Yes\")\nelse:\n if c0 + c4 == N and c0 == c4 + 1:\n print(\"Yes\")\n else:\n print(\"No\")", "n = int(input())\nli = list(map(int,input().split()))\nlis = []\nx = 0\ny = 0\nz = 0\nfor i in range(n):\n if li[i] % 4 == 0:\n x += 1\n elif li[i] % 2 == 0:\n y = 1\n else:\n z += 1\nif y == 0:\n if x + 1 >= z:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n if x >= z:\n print(\"Yes\")\n else:\n print(\"No\")", "N = int(input())\nA = list(map(int, input().split()))\n\nother, two, four = (0, 0, 0)\nfor a in A:\n if a%4 == 0:\n four += 1\n elif a%2 == 0:\n two += 1\n else:\n other += 1\n \nans = \"No\"\nif other <= four:\n ans = \"Yes\"\nelif other-four == 1 and two == 0:\n ans = \"Yes\"\n \nprint(ans)\n", "input();a=list(map(int,input().split()))\nb1,b2,b4=[],[],[];ans=''\nfor i in a:\n if i%2!=0:\n b1.append(i)\n elif i%4==0:\n b4.append(i)\n elif i%2==0:\n b2.append(i)\nif b2:\n if len(b1)<=len(b4):\n ans='Yes'\n else:\n ans='No'\nelse:\n if len(b1)<=len(b4)+1:\n ans='Yes'\n else:\n ans='No'\nprint(ans)", "import collections\n_ = input()\nA = collections.Counter(int(T) for T in input().split()).most_common()\nNum4 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4==0)\nNum2 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4!=0 and A[T][0]%2==0)\nOdd = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%2!=0)\nif Num2>0: Capacity = Num4\nelse: Capacity = Num4+1\nif Capacity>=Odd: print('Yes')\nelse: print('No')", "N = int(input())\nlsa = list(map(int,input().split()))\nans = 'Yes'\ni4 = 0\ni2 = 0\ni1 = 0\nfor i in range(N):\n if lsa[i] % 4 == 0:\n i4 += 1\n elif lsa[i] % 2 == 0:\n i2 += 1\n else:\n i1 += 1\nif i4+1 < i1:\n ans = 'No'\nelif i2%2 == 1 and i4+1 == i1:\n ans = 'No'\nprint(ans)", "input();a,b1,b2,b4=list(map(int,input().split())),0,0,0\nfor i in a:\n if i%2!=0: b1+=1\n elif i%4==0: b4+=1\n else: b2+=1\nprint(['NYoe s'[b1<=b4::2],'NYoe s'[b1<=b4+1::2]][not b2])", "input();a,b1,b2,b4=list(map(int,input().split())),0,0,0\nfor i in a:\n if i%2!=0: b1+=1\n elif i%4==0: b4+=1\n else: b2+=1\nprint('Yes'if b1<=b4 else'No'if b2 else'Yes'if b1<=b4+1 else'No')", "n = int(input())\na_list = [int(x) for x in input().split()]\nx = y = z = 0\nfor a in a_list:\n if a % 4 == 0:\n x += 1\n elif a % 2 == 0:\n y += 1\n else:\n z += 1\nprint(\"Yes\" if (y == 0 and x >= z - 1) or (y > 0 and x >= z) else \"No\")", "import sys\ninput = sys.stdin.readline\n\nN = int(input())\na = list(map(int,input().split()))\n\nn_c4 = 0\nn_c2 = 0\nn_c0 = 0\n\nfor ai in a:\n if ai%4 ==0:\n n_c4 += 1\n elif ai%2 ==0:\n n_c2 += 1\n else:\n n_c0 += 1\nif n_c4>=n_c0 or (n_c4 == n_c0-1 and n_c4+n_c0 == N) :\n print('Yes')\nelse:\n print('No')\n", "N = int(input())\na = [int(i) for i in input().split()]\n\nki = 0\ngu_2 = 0\ngu_4 = 0\n\nfor i in a:\n if i % 4 == 0:\n gu_4 += 1\n elif i % 2 == 0:\n gu_2 += 1\n else:\n ki += 1\n\nif ki <= gu_4:\n print('Yes')\nelse:\n if gu_4 + 1 == ki and gu_4 + ki == N:\n print('Yes')\n else:\n print('No')", "n = int(input())\na = list(map(int,input().split()))\nli = [0,0,0]\nfor i in range(n):\n if a[i]%4==0:\n li[2] +=1\n continue\n elif a[i]%2==0:\n li[1] +=1\n else:\n li[0] +=1\n#print(li)\n\nif li[0]==0:\n print(\"Yes\")\nelif li[0]==1:\n if li[2]>=1:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n k = li[0]\n if n>=2*k:\n if li[2]>=k:\n print(\"Yes\")\n else:\n print(\"No\")\n elif n==2*k-1:\n if li[2]>=k-1:\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n print(\"No\")\n \n", "# 2 2 4 1 4 1\n# 1 4 1 2 2\nn = int(input())\na = list(map(int,input().split()))\ni2 = 0\ni4 = 0\nfor i in range(n):\n if a[i]%4==0:\n i4 += 1\n if a[i]%2==0:\n i2 += 1\n\nif n//2 <= i4:\n print('Yes')\nelse:\n tmp = n//2\n if n%2==0:\n if (tmp - i4) * 2 <= (i2 - i4):\n print('Yes')\n else:\n print('No')\n else:\n if (tmp - i4) * 2 + 1 <= (i2 - i4):\n print('Yes')\n else:\n print('No')\n", "N = int(input())\nA = list(map(int, input().split()))\ncnt = [0]*3\n\nfor x in A:\n x %= 4\n if x == 0:\n cnt[2] += 1\n elif x == 2:\n cnt[1] += 1\n else:\n cnt[0] += 1\n\nif cnt[0] <= cnt[2] or ( cnt[1] == 0 and cnt[0] == cnt[2] + 1):\n print(\"Yes\")\nelse:\n print(\"No\")", "n = int(input())\na = list(map(int, input().split()))\n\nnum4 = 0\nnum2 = 0\nfor i in range(n):\n if a[i]%4 == 0:\n num4 += 1\n elif a[i]%2 == 0:\n num2 += 1\n\n#print(num4, num2)\n\n\n\nif n-num4*2 <= 1:\n print(\"Yes\")\nelif n-num4*2 <= num2:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "n = int(input())\na = list(map(int, input().split()))\nbai4 = []\nbai2 = []\nbai_ = []\nfor ai in a:\n if ai % 4 == 0:\n bai4.append(ai)\n elif ai % 2 == 0:\n bai2.append(ai)\n else:\n bai_.append(ai)\n\nlen_bai_ = len(bai_)\nlen_bai2 = len(bai2)\nlen_bai4 = len(bai4)\n\n\nif len_bai_ > len_bai4:\n if len_bai_ == len_bai4 + 1 and n == len_bai_ + len_bai4:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n print(\"Yes\")", "N = int(input())\nA = list(map(int,input().split()))\nX = [0,0,0]\n\nfor i in range(len(A)):\n if A[i]%4 == 0:\n X[2] += 1\n elif A[i]%2 == 0:\n X[1] += 1\n else:\n X[0] += 1\n\nif 2*X[2] + 1 >= N:\n print(\"Yes\")\nelif 2*X[2] + X[1]>= N:\n print(\"Yes\")\nelse:\n print(\"No\")"] | {"inputs": ["3\n1 10 100\n", "4\n1 2 3 4\n", "3\n1 4 1\n", "2\n1 1\n", "6\n2 7 1 8 2 8\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "Yes\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 36,083 | |
e875d316a1a4854eb0171b12f991e4d2 | UNKNOWN | You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.
-----Notes-----
For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:
- N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.
- There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.
For example, xy < xya and atcoder < atlas.
-----Constraints-----
- The lengths of s and t are between 1 and 100 (inclusive).
- s and t consists of lowercase English letters.
-----Input-----
Input is given from Standard Input in the following format:
s
t
-----Output-----
If it is possible to satisfy s' < t', print Yes; if it is not, print No.
-----Sample Input-----
yx
axy
-----Sample Output-----
Yes
We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa. | ["import sys\n\ninput = sys.stdin.readline\ns = list(input().strip())\nt = list(input().strip())\nif sorted(s) < sorted(t, reverse=True):\n print(\"Yes\")\nelse:\n print(\"No\")", "s=list(input())\nt=list(input())\ns.sort()\nt.sort(reverse=True)\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")\n \n", "s = sorted(input())\nt = sorted(input(), reverse=True)\ns = \"\".join(s)\nt = \"\".join(t)\n#print(s, t)\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = sorted(list(input()))\nt = sorted(list(input()), reverse=True)\n\nif s < t:\n print('Yes')\nelse:\n print('No')\n", "from collections import defaultdict\n\ns = input()\nt = input()\n\nAL = \"abcdefghijklmnopqrstuvwxyz\"\nS = defaultdict(int)\nT = defaultdict(int)\n\nfor al in s:\n S[al] += 1\n\nfor al in t:\n T[al] += 1\n\nans_s = \"\"\nfor al in AL:\n ans_s += al*S[al]\n\nans_t = \"\"\nfor al in reversed(list(AL)):\n ans_t += al*T[al]\n\nif ans_s < ans_t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\nprint('Yes' if s < t else 'No')", "s = list(input())\nt = list(input())\n\ns.sort()\nt.sort(reverse = True)\n\ns1 = ''.join(s)\nt1 = ''.join(t)\n\nif s < t :\n print(\"Yes\")\nelse :\n print(\"No\")\n", "s = \"\".join(sorted(input()))\nt = \"\".join(sorted(input(), reverse=True))\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = input()\nt = input()\n\ns = \"\".join(sorted(s))\nt = \"\".join(sorted(t)[::-1])\n\nprint(( \"Yes\" if s<t else \"No\"))\n", "s=sorted(input())\nt=sorted(input(),reverse=True)\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = sorted(list(input()))\nt = reversed(sorted(list(input())))\nif \",\".join(s) < \",\".join(t):\n print(\"Yes\")\nelse:\n print(\"No\")", "s = list(input())\nt = list(input())\n\ns = sorted(s)\nt = sorted(t, reverse=True)\n\n#print(s,t)\nflag = [0,0]\n\nif len(s) < len(t):\n for i in range(len(s)):\n if s[i]<t[i]:\n print('Yes')\n break\n elif s[i] > t[i]:\n print('No')\n break\n elif i == len(s)-1:\n print('Yes')\nelif len(s) > len(t):\n for i in range(len(t)):\n if s[i]<t[i]:\n print('Yes')\n break\n elif s[i] > t[i]:\n print('No')\n break\n elif i == len(t)-1:\n print('No')\nelif len(s) == len(t):\n for i in range(len(s)):\n if s[i]<t[i]:\n print('Yes')\n break\n elif s[i] > t[i]:\n print('No')\n break\n elif i == len(s)-1:\n print('No')\n", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\ns = \"\".join(s)\nt = \"\".join(t)\nprint(\"Yes\" if s < t else \"No\")", "s = sorted(input())\nt = sorted(input())[::-1]\nprint((\"Yes\" if s<t else \"No\"))\n", "s = sorted(input())\nt = sorted(input(),reverse = True)\nflag1 = True\nflag2 = False\nif len(s) < len(t):\n for i in range(len(s)):\n if s[i] != t[i]:\n flag1 = False\n break\nelse:\n flag1 = False\nfor i in range(min(len(s), len(t))):\n if s[i] < t[i]:\n flag2 = True\n break\n elif s[i] > t[i]:\n break\nif flag1 or flag2:\n print('Yes')\nelse:\n print('No')\n", "s = list(map(str, input().rstrip()))\nt = list(map(str, input().rstrip()))\n\ns.sort()\nt.sort(reverse=True)\n\ns = \"\".join(s)\nt = \"\".join(t)\n\nprint(\"Yes\" if s < t else \"No\")", "s = sorted(input())\nt = sorted(input(), reverse=True)\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")", "def main():\n s = input()\n t = input()\n s_list = []\n t_list = []\n for i in range(len(s)):\n s_list.append(s[i])\n for i in range(len(t)):\n t_list.append(t[i])\n s_list.sort()\n t_list.sort(reverse = True)\n #print(s_list,t_list)\n #if 'a'<'b':\n #print ('Yes')\n s_l = len(s_list)\n t_l = len(t_list)\n if s_l >= t_l:\n ans = 'No'\n else:\n ans = 'Yes'\n\n for i in range(min(s_l,t_l)):\n if s_list[i] == t_list[i]:\n continue\n elif s_list[i] > t_list[i]:\n return ('No')\n else:\n return('Yes')\n\n return ans\n\nprint((main()))\n", "s,t = [input() for i in range(2)]\n\ns_2 = sorted(s)\nt_2 = sorted(t,reverse=True)\n\nif s_2 < t_2:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = list(input())\nt = list(input())\ns = sorted(s)\nt = sorted(t,reverse = True)\nif \"\".join(s) < \"\".join(t):\n print(\"Yes\")\nelse:\n print(\"No\")", "s=input()\nt=input()\ndata=['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']\nS=[0]*len(s)\nT=[0]*len(t)\nfor i in range(len(s)):\n S[i]=data.index(s[i])\nfor i in range(len(t)):\n T[i]=data.index(t[i])\nS.sort()\nT.sort(reverse=True)\nif S<T:\n print('Yes')\nelse:\n print('No')", "S = input()\nT = input()\n\nif sorted(S) < sorted(T,reverse=True) :\n print(\"Yes\")\nelse :\n print(\"No\")", "s = sorted(input())\nt = sorted(input())[::-1]\nif s < t:\n print('Yes')\nelse:\n print('No')\n", "s = ''.join(sorted(list(input())))\nt = ''.join(sorted(list(input()))[::-1])\nprint('Yes' if s < t else 'No')", "s = \"\".join(sorted(str(input())))\nt = \"\".join(sorted(str(input()), reverse=True))\nif s < t:\n print('Yes')\nelse:\n print('No')", "#28 B - Two Anagrams AC\ns = list(input())\nt = list(input())\n\ns = sorted(s,reverse = False)\nt = sorted(t,reverse = True)\n\ns = ''.join(s)\nt = ''.join(t)\nif s < t:\n print('Yes')\nelse:\n print('No')", "s,t=sorted(list(input())),sorted(list(input()),reverse=True)\nprint(\"Yes\" if s<t else \"No\")", "s = input()\nt = input()\n\ns = sorted(s)\nt = sorted(t)[::-1]\n\nanswer = \"Yes\"\nfor i in range(len(s)):\n if i == len(t):\n answer = \"No\"\n break\n s_c = s[i]\n t_c = t[i]\n if s_c < t_c:\n break\n elif s_c == t_c:\n continue\n else:\n answer = \"No\"\n break\n\nif s == t:\n answer = \"No\"\n\nprint(answer)", "#!/usr/bin/env python3\nimport sys\nsys.setrecursionlimit(10**6)\n\ns = list(str(input()))\nt = list(str(input()))\n\ns.sort()\nt.sort(reverse=True)\n\ns = \"\".join(s)\nt = \"\".join(t)\n\nans = sorted([s, t])\n# print(ans)\n\nif ans[0] == t:\n print(\"No\")\nelse:\n print(\"Yes\")\n", "s = str(input())\nt = str(input())\n\n# \u6587\u5b57\u5217s\u3092\u30bd\u30fc\u30c8\uff08sorted\u3092\u3059\u308b\u3068\u914d\u5217\u578b\u306b\u306a\u308b\u306e\u3067join\u3057\u3066\u4e0a\u3052\u308b\u5fc5\u8981\u3042\u308a\uff09\nsort_s_list = sorted(s)\nsort_s = \"\".join(sort_s_list)\n\n# \u6587\u5b57\u5217t\u3092\u9006\u30bd\u30fc\u30c8\nt_list = list(t)\nt_list.sort(reverse = True)\nreverse_sort_t = \"\".join(t_list)\n\nif sort_s < reverse_sort_t:\n print(\"Yes\")\nelse:\n print(\"No\")", "#28 B - Two Anagrams\ns = list(input())\nt = list(input())\n\ns = sorted(s,reverse = False)\nt = sorted(t,reverse = True)\n\nresult = 'No'\nrang = min(len(s),len(t))\nfor i in range(rang):\n if ord(s[i]) < ord(t[i]):\n result = 'Yes'\n break\nelse:\n # \u6587\u5b57\u304c\u4e00\u7dd2\u3067 t \u306e\u65b9\u304c\u6587\u5b57\u6570\u304c\u591a\u3044\u3068\u304d\n if (s[:rang] == t[:rang]) and len(s) < len(t):\n result = 'Yes'\nprint(result)", "s = sorted(str(input()))\nt = sorted(str(input()), reverse = True)\nprint(\"Yes\" if s < t else \"No\")", "#n = int(input())\n#a, b = map(int,input().split())\n#l = list(map(int,input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\ns = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\nif s < t:\n print('Yes')\nelse:\n print('No')\n", "s = list(str(input()))\nt = list(str(input()))\n\nasc_s = sorted(s)\ndesc_t = sorted(t, reverse=True)\n\nprint(\"Yes\" if ''.join(asc_s) < ''.join(desc_t) else \"No\")", "s=\"\".join(sorted(str(input())))\nt=\"\".join(sorted(str(input()),reverse=True))\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s=list(input())\nt=list(input())\ns.sort()\nt.sort(reverse=True)\nif s<t:print('Yes')\nelse:print('No')", "a, b = [sorted(input()) for i in range(2)]\nprint(\"Yes\" if a < b[::-1] else \"No\")", "s = input()\nt = input()\n\nss = sorted(s)\ntt = sorted(t, reverse=True)\n\n\ndef checker(s, t):\n for sz in ss:\n for tz in tt:\n if sz > tz:\n return 'No'\n elif sz == tz:\n continue\n else:\n return 'Yes'\n if len(ss) < len(tt):\n return 'Yes'\n return 'No'\n\n\nprint((checker(ss, tt)))\n", "s = input()\nt = input()\n\ns_list = list(s)\nt_list = list(t)\n\ns_sorted = sorted(s_list)\nt_sorted = sorted(t_list, reverse=True)\n\ns_joined = ''.join(s_sorted) \nt_joined = ''.join(t_sorted) \n\nif s_joined < t_joined:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = ''.join(sorted(input()))\nt = ''.join(reversed(sorted(input())))\n\nif s < t:\n print('Yes')\nelse:\n print('No')\n", "S = sorted(input())\nT = sorted(input(), reverse=True)\n\nif S < T:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "#!/usr/bin/env python3\nimport sys\nsys.setrecursionlimit(10**6)\n\ns = list(str(input()))\nt = list(str(input()))\n\ns.sort()\nt.sort(reverse=True)\n\ns = \"\".join(s)\nt = \"\".join(t)\n\nans = sorted([s, t])\n# print(ans)\n\nif ans[0] == t:\n print(\"No\")\nelse:\n print(\"Yes\")\n", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\ns = ''.join(s)\nt = ''.join(t)\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = str(input())\nt = str(input())\na = ''.join(sorted(s))\nb = ''.join(sorted(t, reverse=True))\nif a < b:\n print('Yes')\nelse:\n print('No')", "s = input()\nt = input()\n\nS = \"\".join(sorted(list(s)))\nT = \"\".join(sorted(list(t), reverse=True))\n\nif S < T:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = sorted(input())\nT = sorted(input())[::-1]\nprint(\"Yes\" if S<T else \"No\")", "S = sorted(input())\nT = sorted(input(), reverse=True)\n\nif S >= T:\n print(\"No\")\nelse:\n print(\"Yes\")", "s=list(input())\nt=list(input())\ns.sort()\nt.sort(reverse=True)\ns=\"\".join(s)\nt=\"\".join(t)\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = list(input())\nt = list(input())\n\nss = sorted(s)\ntt = sorted(t, reverse=True)\n\nsa = ''.join(ss)\nta = ''.join(tt)\n\nif sa < ta:\n print('Yes')\nelse:\n print('No')", "list_s = sorted(list(input()))\nlist_t = sorted(list(input()), reverse=True)\nif \"\".join(list_s) < \"\".join(list_t): print(\"Yes\")\nelse: print(\"No\")", "s = list(input())\nt = list(input())\n\ns.sort(reverse=False)\nt.sort(reverse=True)\n\nif \"\".join(s) < \"\".join(t):\n print(\"Yes\")\nelse:\n print(\"No\")", "s, t = [input() for i in range(2)]\nns = ''.join(sorted(s))\nnt = ''.join(sorted(t, reverse=True))\nprint('Yes') if ns < nt else print('No')\n", "s=sorted(list(input()))\nt=sorted(list(input()),reverse=True)\nfor i in range(min(len(s),len(t))):\n if ord(s[i])<ord(t[i]):\n print(\"Yes\")\n return\n elif ord(s[i])>ord(t[i]):\n print(\"No\")\n return\nif len(s)>=len(t):\n print(\"No\")\nelse:\n print(\"Yes\")", "s = sorted(input())\nt = sorted(input(),reverse=True)\nif(s < t): print(\"Yes\")\nelse: print(\"No\")", "s = input()\nt = input()\nS = sorted(s)\nT = sorted(t,reverse=True)\n#print(S,T)\nans = \"W\"\nfor i in range(min(len(s),len(t))):\n if S[i] > T[i]:\n ans = \"No\"\n break\n elif ans == \"W\" and S[i] == T[i]:\n ans = \"W\"\n elif ans == \"W\" and S[i] < T[i]:\n ans = \"Yes\"\n break\nif ans == \"W\":\n if len(s) < len(t):\n ans = \"Yes\"\n else:\n ans = \"No\"\nprint(ans)", "ss, ts = sorted(list(input())), list(reversed(sorted(list(input()))))\nresult = False\nmin_size = min(len(ss), len(ts))\n\nif ss[:min_size] == ts[:min_size] and len(ss) < len(ts):\n result = True\nelse:\n for index in range(min(len(ss), len(ts))):\n if ss[index] < ts[index]:\n result = True\n break\n\nif result:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = sorted(list(input()))\nt = sorted(list(input()),reverse=True)\nif s<t:\n print('Yes')\nelse:\n print('No')", "s=input()\nt=input()\n\ns_d = ''.join(sorted(s))\nt_d = ''.join(sorted(t,reverse=True))\n\narr = [t_d,s_d]\narr=sorted(arr)\n\nif s==t:\n print('No')\n return\n\nif arr[0]==s_d:\n print('Yes')\nelse:\n print('No')", "s = str(input())\nt = str(input())\n\nnum2alpha = lambda c: chr(c+96)\n#print(num2alpha(3)) #==> c\nalpha2num = lambda c: ord(c) - ord('a') + 1\n#alpha2num('y') #==> 25 \n\nS = [0] * 26\nT = [0] * 26\nfor i in range(len(s)):\n S[alpha2num(s[i]) - 1] += 1\nfor i in range(len(t)):\n T[alpha2num(t[i]) - 1] += 1\n#print(S, T) \n \nss = 0\nwhile S[ss] == 0:\n ss += 1\ntt = 25\nwhile T[tt] == 0:\n tt -= 1\n \nif tt < ss:\n print(\"No\")\nelif tt > ss:\n print(\"Yes\")\nelse:\n if (T[tt] == sum(T)) and (S[ss] == sum(S)):\n if sum(T) > sum(S):\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n print(\"No\")\n \n \n \n\n \n", "s = sorted(input())\nt = sorted(input(),reverse = True)\nif s < t:\n print('Yes')\nelse:\n print('No')", "# -*- coding: utf-8 -*-\n\ns = list(input())\nt = list(input())\n\nN = len(s)\nM = len(t)\n\ns_d = sorted(s)\nt_d = sorted(t, reverse=True)\n\nans ='No'\nif N < M:\n new_t = \"\".join(t_d[:N])\n new_s = \"\".join(s_d)\n if new_t == new_s:\n ans ='Yes'\n\nif ans == 'No':\n pos = 0\n for i in range(min(N, M)):\n if s_d[i]!=t_d[i]:\n pos = i\n break\n if s_d[pos] < t_d[pos]:\n ans ='Yes'\n\nprint(ans)", "s = input()\nt = input()\n\nsorted_s = sorted(s)\nsorted_t = sorted(t, reverse=True)\n\n#print(sorted_s)\n#print(sorted_t)\n\nif sorted_s < sorted_t:\n print(\"Yes\")\nelse:\n print(\"No\")\n\n", "S = list(input())\nT = list(input())\n\nS.sort()\nT.sort(reverse=True)\n\nalpha = list('abcdefghijklmnopqrstuvwxyz')\n\ncheck = False\ncnt = 0\nfor s, t in zip(S,T):\n res = alpha.index(s) - alpha.index(t)\n if res < 0:\n check = True\n break\n elif res == 0:\n cnt += 1\n\nif cnt == len(S):\n if len(S) < len(T):\n check = True\n\nprint(\"Yes\" if check else \"No\")", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse = True)\nif s < t:\n print('Yes')\nelse:\n print('No')", "s = input()\nt = input()\n\ns = list(s)\nt = list(t)\ns.sort()\nt.sort(reverse=True)\n\ns = \"\".join(s)\nt = \"\".join(t)\n\nprint(\"Yes\") if s < t else print(\"No\")", "s = list(input())\nt = list(input())\n\ns.sort()\nt.sort(reverse=True)\n\ns = ''.join(s)\nt = ''.join(t)\n\nif s < t:\n print('Yes')\nelse:\n print('No')\n", "S = input()\nT = input()\nS_len = len(S)\nT_len = len(T)\nS_sorted = sorted(S)\nT_sorted = sorted(T, reverse=True)\nans = True\nfor i in range(min(S_len, T_len)):\n s = ord(S_sorted[i])\n t = ord(T_sorted[i])\n if s < t:\n print('Yes')\n return\n if s == t:\n continue\n else:\n print('No')\n return\nif S_len >= T_len:\n print('No')\nelse:\n print('Yes')\n", "s = input()\nt = input()\ns = sorted(s)\nt = sorted(t, reverse=True)\ns_t = [s, t]\ns_t.sort()\nif s_t[0] == s and s_t[1] != s:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = list(input())\nt = list(input())\ns.sort()\nt.sort(reverse=True)\n\nl = [''.join(s),''.join(t)]\n\nif l == sorted(l) and l[0]!=l[1]:\n print('Yes')\nelse:\n print('No')", "s = input()\ns_asc = ''.join(sorted(s))\nt = input()\nt_desc = ''.join(sorted(t, reverse=True))\nif s_asc < t_desc:\n\tprint('Yes')\nelse:\n\tprint('No')", "s = input()\nt = input()\n\nif \"\".join(sorted(s)) < \"\".join(list(reversed(sorted(t)))):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = input()\nt = input()\n\nif \"\".join(sorted(s)) < \"\".join(sorted(t, reverse=True)):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a = list(input())\nb = list(input())\na.sort()\nb.sort()\nb.reverse()\na=''.join(a)\nb=''.join(b)\nif a < b:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = sorted(x for x in input())\nt = sorted([x for x in input()], reverse=True)\nprint('Yes' if s < t else 'No')", "def main():\n import sys\n pin=sys.stdin.readline\n pout=sys.stdout.write\n perr=sys.stderr.write\n S=input()\n T=input()\n if S==T:\n print(\"No\")\n return\n if S in T:\n print(\"Yes\")\n return\n s=list(S)\n t=list(T)\n \n s.sort()\n t.sort(reverse=True)\n if s==t:\n print(\"No\")\n return\n \n# if(len(s)<len(t)):\n# print(\"Yes\")\n# return\n for i in range(min(len(s),len(t))):\n if ord(s[i])>ord(t[i]):\n print(\"No\")\n return\n elif ord(s[i])<ord(t[i]):\n print(\"Yes\")\n return\n print(\"No\")\n return\nmain()", "s=sorted(input())\nt=sorted(input())[::-1]\nprint(\"Yes\" if s<t else \"No\")", "#!/usr/bin/env python3\n\n\ndef main():\n s = sorted(input())\n t = sorted(input(), reverse=True)\n if s < t:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\nmain()\n", "#!/usr/bin/env python3\nimport sys\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef main():\n s = input()\n t = input()\n\n listS = []\n for i in range(len(s)):\n listS.append(s[i])\n\n listT = []\n for i in range(len(t)):\n listT.append(t[i])\n\n listS = sorted(listS)\n listT = sorted(listT, reverse=True)\n\n sortedS = ''\n for i in range(len(listS)):\n sortedS += listS[i]\n sortedT = ''\n for i in range(len(listT)):\n sortedT += listT[i]\n\n if sortedS < sortedT:\n print('Yes')\n else:\n print('No')\n\ndef __starting_point():\n main()\n\n__starting_point()", "s,t=sorted(list(input())),sorted(list(input()),reverse=True)\nprint(\"Yes\" if s<t else \"No\")", "#ABC082\ns = sorted(input())\nt = sorted(input())[::-1]\nprint(\"Yes\" if s<t else \"No\")", "s = input().rstrip()\nt = input().rstrip()\n\ns = tuple(sorted(s))\nt = tuple(sorted(t, reverse=True))\nif s < t:\n print('Yes')\nelse:\n print('No')", "s = sorted(input())\nt = sorted(input(),reverse = True)\nif s < t:\n print('Yes')\nelse:\n print('No')", "s = sorted(input())\nt = sorted(input())[::-1]\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\nt = input()\nif ''.join(sorted(s)) < ''.join(sorted(t, reverse=True)):\n print('Yes')\nelse :\n print('No')", "s = list(input())\nt = list(input())\n\ns.sort()\nt.sort(reverse = True)\n\nif s < t:\n print('Yes')\nelse:\n print('No')", "s = sorted(input())\nt = sorted(input(), reverse=True)\nprint('Yes' if s < t else 'No')", "def answer(s: str, t: str) -> str:\n return 'Yes' if sorted(s) < sorted(t, reverse=True) else 'No'\n\ndef main():\n s = input()\n t = input()\n print(answer(s,t))\n\ndef __starting_point():\n main()\n__starting_point()", "s = input()\nt = input()\nimport sys\nif s==t:\n print(\"No\")\n return\nss = sorted(list(s))\ntt = sorted(list(t))[::-1]\nif sorted([ss,tt])[0] == ss:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = list(input())\nt = list(input())\n\ns.sort()\nt.sort(reverse = True)\n\nfor i in range(min(len(s), len(t))):\n if s[i] < t[i]:\n print('Yes')\n break\n elif s[i] > t[i]:\n print('No')\n break\n else:\n continue\nelse:\n if len(t) > len(s):\n print('Yes')\n else:\n print('No')", "s=list(input())\nt=list(input())\n\ns.sort()\nt.sort(reverse=True)\n\nfor i in range(min(len(s),len(t))):\n if(s[i]<t[i]):\n print(\"Yes\")\n return\n if(s[i]>t[i]):\n print(\"No\")\n return\n\nif(len(s)<len(t)):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s=input()\nt=input()\ns=sorted(s)\nt=sorted(t,reverse=True)\n\nprint('Yes' if s<t else 'No')", "s = input()\nt = input()\n \nsp = sorted(s)\ntp = sorted(t, reverse=True)\n#print(sp, tp)\nprint(('Yes' if sp < tp else 'No'))\n", "s, t = sorted(input()), sorted(input())[::-1]\n\nif \"\".join(s) < \"\".join(t):\n print(\"Yes\")\nelse:\n print(\"No\")", "S = sorted(input())\nT = sorted(input())[::-1]\nprint('Yes' if S < T else 'No')", "s = input()\nt = input()\nord_s = []\nord_t = []\n\nfor i in range(len(s)):\n ord_s.append(ord(s[i]))\nelse:\n ord_s.sort()\n \nfor i in range(len(t)):\n ord_t.append(ord(t[i]))\nelse:\n ord_t.sort(reverse = True)\n\nfor i in range(min(len(s), len(t))):\n if ord_s[i] < ord_t[i]:\n print('Yes')\n break\n elif ord_s[i] == ord_t[i]:\n pass\n else:\n print('No')\n break\nelse:\n if len(s) < len(t):\n print('Yes')\n else:\n print('No')", "s,t=[input() for i in range(2)]\nprint('Yes' if sorted(s)<sorted(t,reverse=True) else 'No')", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n s = ins()\n t = ins()\n s = sorted(s)\n t = sorted(t, reverse=True)\n return s < t\n\n\nprint(\"Yes\" if solve() else \"No\")\n", "s = input()\nt = input()\nif s < t:\n print(\"Yes\")\n return\ns = list(s)\nt = list(t)\ns = sorted(s)\nt = sorted(t)\nt = t[::-1]\ns = ''.join(s)\nt = ''.join(t)\nif s < t:\n print(\"Yes\")\nelse:\n print(\"No\")"] | {"inputs": ["yx\naxy\n", "ratcode\natlas\n", "cd\nabc\n", "w\nww\n", "zzz\nzzz\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 21,683 | |
1af7f1dca0c1eb961224f75ee5c054f5 | UNKNOWN | We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.
If the objective is achievable, print YES. Otherwise, print NO.
-----Constraints-----
- 1 β€ A β€ 100
- 1 β€ B β€ 100
- 0 β€ C < B
-----Input-----
Input is given from Standard Input in the following format:
A B C
-----Output-----
Print YES or NO.
-----Sample Input-----
7 5 1
-----Sample Output-----
YES
For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5. | ["a,b,c = map(int,input().split())\n\nmod = a % b\nans = 'NO'\nfor i in range(1,b): \n if (i*mod) % b == c:\n ans = 'YES'\n break\n \nprint(ans) ", "def answer(a: int, b: int, c: int) -> str:\n for i in range(1, b + 1):\n if a * i % b == c:\n return 'YES'\n return 'NO'\n\n\ndef main():\n a, b, c = map(int, input().split())\n print(answer(a, b, c))\n\n\ndef __starting_point():\n main()\n__starting_point()", "A,B,C=map(int,input().split())\nmod=set()\ntmp=0\nD=A\nwhile tmp not in mod:\n mod.add(tmp)\n tmp=D%B\n if tmp==C:\n print('YES')\n return\n D+=A\nprint('NO')", "A,B,C = map(int,input().split())\n\nif len([A for A in range(A,10000,A) if A%B==C]):\n print('YES')\nelse:\n print('NO')", "a, b, c = map(int, input().split())\ns = \"NO\"\nfor i in [a * j for j in range(1, b)]:\n if i % b == c:\n s = \"YES\"\n break\n\nprint(s)", "A, B, C = map(int, input().split())\n\namari = []\n\nfor i in range(1, B+1):\n amari.append(A*i%B)\n\nprint('YES' if C in amari else 'NO')", "a, b, c = map(int, input().split())\nres = \"NO\"\nfor i in range(1, b+1): #b\u3067\u5272\u308b=\u4f59\u308a\u304cb\u500b\u306e\u7a2e\u985e\u51fa\u308b\n if (a*i)%b == c:\n res = \"YES\"\n break\nprint(res)", "import sys\nA, B, C = list(map(int, input().split()))\n\nfor i in range(100):\n if C == (A*i%B):\n print(\"YES\")\n return\nprint(\"NO\")\n", "a,b,c=map(int,input().split())\nfor i in range(a,b*a+1,a):\n if i%b==c: print('YES');break\nelse:\n print('NO')", "a, b, c = map(int, input().split())\nfor i in range(1, b+1): #b\u3067\u5272\u308b=\u4f59\u308a\u304cb\u500b\u306e\u7a2e\u985e\u51fa\u308b\n if (a*i)%b == c:\n print(\"YES\")\n return\nprint(\"NO\")", "import sys\nimport copy\nimport math\nimport itertools\nimport numpy as np\n\nA,B,C = [int(c) for c in input().split()]\na = []\ncnt=0\nwhile True:\n cnt+=A\n a.append(cnt%B)\n if C == cnt%B:\n print(\"YES\")\n return\n elif a.count(cnt%B) >1:\n print(\"NO\")\n return", "A,B,C=list(map(int,input().split()))\ns=0\nfor i in range(1,B+1):\n x=A*i%B\n if x==C:\n s=s+1\n else:\n s=s\nif s!=0:\n print('YES')\nelse:\n print('NO')\n\n\n", "import math\nA,B,C = map(int, input().split())\n\nfor i in range(1, B+1):\n if A*i%B == C:\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "a, b, c = list(map(int, input().split()))\ncount = 0\n#a\u306b\uff11\uff5eb\u306e\u6570\u3092\u304b\u3051\u305f\u30ea\u30b9\u30c8\nfor i in range(b + 1):\n if ((i * a) % b) == c:\n print(\"YES\")\n count += 1\n break\n else:\n pass\n\nif count == 0:\n print(\"NO\")\nelse:\n pass\n", "a, b, c = map(int, input().split())\nn = a\nans = 'NO'\nfor i in range(1, b + 1):\n if n % b == c:\n ans = 'YES'\n break\n else:\n n += a\nprint(ans)", "a,b,c = map(int,input().split())\ni = 0\nflag = True\nwhile flag:\n num = b * i\n if (num + c) % a == 0:\n print(\"YES\")\n flag = False\n elif i >= 10**5:\n print(\"NO\")\n break\n else:\n i += 1", "a,b,c=map(int,input().split())\nd=a%b\nfor i in range(b):\n if (d*i)%b==c:\n print('YES')\n return\nprint('NO')", "A, B, C = map(int,input().split())\n\nans = \"NO\"\n\nfor i in range(1,B+1):\n if A*i%B == C:\n ans = \"YES\"\n\nprint(ans)", "import sys\na,b,c=map(int,input().split())\ni=1\nl=[]\nwhile True:\n aa=a*i%b\n if aa in l:\n break\n l.append(aa)\n i+=1\n if aa!=0 and c%aa==0:\n print('YES')\n return\nprint('NO')", "a,b,c = map(int, input().split())\n\nganma = a%b\nif ganma == 0:\n if ganma == c:\n print(\"YES\")\n else:\n print(\"NO\")\n\nelse:\n mod_list = []\n for i in range(b):\n mod = (i*ganma)%b\n mod_list.append(mod)\n\n zero_one_list = []\n for i in range(b):\n if mod_list[i] == c:\n zero_one_list.append(1)\n else:\n zero_one_list.append(0)\n \n sum_list = sum(zero_one_list)\n\n if sum_list >= 1:\n print(\"YES\")\n else:\n print(\"NO\")", "a, b, c = list(map(int, input().split()))\nfor i in range(1, b + 1):\n if a * i % b == c:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n", "a, b, c = map(int, input().split())\nhist = []\n\nans = 'NO'\nfor i in range(1, b+1):\n mod = (a*i) % b\n if mod == c:\n ans = 'YES'\n break\n elif mod in hist:\n break\n hist.append(mod)\n \nprint(ans)", "import sys\nimport math\nimport itertools\nimport collections\nimport heapq\nimport re\nimport numpy as np\nfrom functools import reduce\n\nrr = lambda: sys.stdin.readline().rstrip()\nrs = lambda: sys.stdin.readline().split()\nri = lambda: int(sys.stdin.readline())\nrm = lambda: list(map(int, sys.stdin.readline().split()))\nrl = lambda: list(map(int, sys.stdin.readline().split()))\ninf = float('inf')\nmod = 10**9 + 7\n\na, b, c = rm()\nlen_ = 1\ns = set()\ns.add(a)\ni = a\nwhile len_ == len(s):\n i += a\n i %= b\n len_ += 1\n s.add(i)\nfor i in list(s):\n if i == c:\n print('YES')\n return\nelse:\n print('NO')\n\n\n\n\n\n\n\n\n\n\n\n", "a, b, c = list(map(int, input().split()))\nfor i in range(1, 2*b+1):\n if i*a%b == c:\n print('YES')\n return\nprint('NO')\n", "a,b,c = map(int, input().split())\n\nresult = \"NO\"\nfor i in range(1, b):\n if a*i%b == c:\n result = \"YES\"\n break\n\nprint(result)", "a, b, c = list(map(int, input().split()))\nans = []\nfor i in range(1, b + 1):\n ans.append((a * i) % b)\nprint((\"YES\" if c in ans else \"NO\"))\n", "import copy\na, b, c = map(int,input().split())\n\nx = copy.deepcopy(a)\nvisited = [False] * (b+1)\nflg = True\nwhile True:\n x %= b\n if x == c:\n break\n elif visited[x]:\n flg = False\n break\n else:\n visited[x] = True\n x += a\nprint('YES') if flg else print('NO')", "import math\na,b,c = map(int, input().split())\nx = math.gcd(a , b)\nif c % x == 0:\n print(\"YES\")\nelse:\n print(\"NO\")", "#ABC060 B:Choose Integers\n\na,b,c = map(int, input().split())\nans = 'NO'\n\nfor i in range(b):\n num = i * a\n mod = num % b\n if mod == c:\n ans = 'YES'\n break\nprint(ans)", "A, B, C = map(int, input().split())\n\nans = \"NO\"\nfor i in range(1, 1000):\n a = A*i\n if a % B == C:\n ans = \"YES\"\n break\n \nprint(ans)", "# -*- coding: utf-8 -*-\n\nA,B,C = map(int, input().split())\n\nans = \"NO\"\nfor i in range(B+1):\n res = A * i % B\n if res == C:\n ans = \"YES\"\n break\n\nprint(ans)", "a, b, c = map(int, input().split())\nd = []\nfor i in range(1, b + 1):\n d.append((a * i) % b)\nif c in d:\n print('YES')\nelse:\n print('NO')", "A,B,C = map(int,input().split())\nfor i in range(B):\n if (i+1)*A%B== C:\n print('YES')\n return\nprint('NO')", "def __starting_point():\n a, b, c = map(int, input().split())\n\n for i in range(1000000):\n m = a * i % b\n if m == c:\n print('YES')\n return\n print('NO')\n__starting_point()", "a, b, c = map(int, input().split())\nfor i in range(1,b+1):\n k = (a*i)%b\n if k == c:\n print(\"YES\")\n return\nprint(\"NO\")", "import re\nimport copy\n\ndef accept_input():\n a,b,c = list(map(int,input().split()))\n return a,b,c\n\na,b,c = accept_input()\naamari = a%b\namaridict = {}\ncuramari = a%b\nfor i in range(b):\n curamari = (curamari+aamari)%b\n amaridict[curamari] = 1\nif c in amaridict:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a, b, c = map(int, input().split())\ncount = 1\nwhile a*count % b != 0:\n count += 1\nfor i in range(count):\n if a*i%b == c:\n print(\"YES\")\n return\nprint(\"NO\")", "# -*- coding: utf-8 -*-\nimport numpy as np\nimport sys\nfrom collections import deque\nfrom collections import defaultdict\nimport heapq\nimport collections\nimport itertools\nimport bisect\nfrom scipy.special import comb\nimport copy\nsys.setrecursionlimit(10**6)\n\n\ndef zz():\n return list(map(int, sys.stdin.readline().split()))\n\n\ndef z():\n return int(sys.stdin.readline())\n\n\ndef S():\n return sys.stdin.readline()[:-1]\n\n\ndef C(line):\n return [sys.stdin.readline() for _ in range(line)]\n\n\nA, B, C = zz()\nfor i in range(1, B + 1):\n if ((A * i) % B == C):\n print('YES')\n return\nprint('NO')\n", "a, b, c = map(int,input().split())\nA = []\nfor i in range(1,b+1):\n mod = a*i % b\n if mod in A:break\n A.append(mod)\n\nA.sort()\nif len(A) >= 2:\n i = A[1]\nelse:\n i = 0\n\nif i == 0 and c == 0:\n print('YES')\n return\nelif i == 0 and c != 0:\n print('NO')\n return\n\nif c % i == 0:\n print('YES')\nelse:\n print('NO')", "A, B, C = map(int, input().split())\n\nfor i in range(100):\n if ((C+B*i)/A).is_integer():\n print('YES')\n return\nprint('NO')", "import math\n\nA,B,C=list(map(int,input().split()))\nx=math.gcd(A,B)\n\nif C%x==0:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a,b,c=map(int,input().split())\nprint(\"YES\" if any((a*i)%b==c for i in range(1,b+1)) else \"NO\")", "A, B, C = list(map(int, input().split()))\nclear = 0\n\nfor i in range(1, B):\n if (A * i) % B == C:\n clear = 1\n break\n\nif clear == 0:\n print('NO')\nelse:\n print('YES')\n\n\n", "a,b,c = map(int, input().split())\nfor i in range(1,b):\n if (a*i+c)%b == 0:\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "a, b, c = list(map(int, input().split()))\n\naa = a\ns = a % b\ndata = []\n\nwhile True:\n aa += a\n data.append(aa % b)\n if aa % b == s:\n break\n \ndata.sort()\n\nif a % b == 0:\n print(\"NO\")\nelif c % data[1] != 0:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "a,b,c= map(int,input().split())\nfor i in range(1,b+1):\n if i*a % b == c:\n print('YES')\n return\nprint('NO')", "from math import gcd\nnumbers = list(map(lambda x: int(x), input().split()))\na, b, c = numbers[0], numbers[1], numbers[2]\nprint('YES') if not c % gcd(a, b) else print('NO')\n", "a, b, c =map(int, input().split())\n\nans = \"NO\"\n\nfor i in range(1, b+1):\n if a*i % b == c:\n ans = \"YES\"\n break\n\nprint(ans)", "a,b,c = map(int, input().split())\n\nflag = True\n\nfor i in range(b):\n if (a*(i+1))%b == c:\n print(\"YES\")\n flag = False\n break\n \nif flag:\n print(\"NO\")", "A, B, C = list(map(int, input().split()))\n#kA%B\u306e\u6570\u5217\u306b\u306a\u308b\n#A\u3092B\u3067\u5272\u3063\u305f\u3042\u307e\u308a\u306fB-1\u4ee5\u4e0b\u306b\u306a\u308b\n#(k+B)A%B = (kA+BA)%B = kA%B + BA%B = kA%B\nfor i in range(1, B+1):\n if A*i%B == C:\n print('YES')\n return\nprint('NO')\n", "A, B, C = map(int, open(0).readline().split())\nimport math\nprint('YES' if C % math.gcd(B,A%B) == 0 else 'NO')", "a, b, c =map(int, input().split())\n\nans = \"NO\"\n\nfor i in range(1, b+1):\n if a*i % b == c:\n ans = \"YES\"\n break\n\nprint(ans)", "a,b,c = map(int,input().split())\nfor i in range(1,b+1):\n if a*i%b == c:\n print(\"YES\")\n return\n elif i == b:\n print(\"NO\")", "A,B,C= map(int,input().split())\nA %= B\nfor i in range(1,B+1):\n if A*i%B ==C:\n print('YES')\n return\nprint('NO')", "from fractions import gcd\nA, B, C = map(int, input().split())\nif C % gcd(A, B) == 0:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "\nA,B,C = map(int,input().split())\ndp = [0]*1000\n\nans = 'NO'\ncur_A = A\nwhile 1:\n if cur_A % B == C:\n ans = 'YES'\n break\n elif dp[cur_A%B] == 1:\n ans = 'NO'\n break\n dp[cur_A % B] = 1\n cur_A += A\nprint(ans)", "a, b, c = map(int, input().split())\nans = 'NO'\nfor num in range(1, b + 1):\n if (num * a) % b == c:\n ans = 'YES'\n break\n else:\n pass\nprint(ans)", "a,b,c = [int(x) for x in input().split()]\n\ndef gcd(x,y):\n while y != 0:\n x, y = y, x % y\n return x\n\nif c % gcd(a,b) == 0:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c = map(int,input().split())\nans = 'NO'\nfor i in range(1,b+1):\n if (a*i)%b == c:\n ans = 'YES'\nprint(ans)", "a, b, c = map(int, input().split())\n\nfor i in range(1, b+1):\n if a*i % b == c:\n print('YES')\n return\n\nprint('NO')", "A, B , C = map(int, input().split())\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a%b\n\treturn a\n\nif A==1:\n\tprint(\"YES\")\nelif C%gcd(A,B)==0:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "A, B, C = map(int,input().split())\ndef answer():\n for i in range(1, B+1):\n if A * i % B == C:\n return (\"YES\")\n return (\"NO\")\n\nprint(answer())", "a, b, c = map(int, input().split())\nfor i in range(1, b + 1):\n if a * i % b == c:\n print(\"YES\")\n return\n \nprint(\"NO\")", "a, b, c = list(map(int, input().split()))\nfor i in range(a, (a * b) + 1, a):\n if i % b == c:\n print(\"YES\")\n return\nprint(\"NO\")\n", "from sys import stdin, stdout # only need for big input\n\ndef solve():\n a, b, c = list(map(int, input().split())) \n possible = False\n for k in range(b):\n if ( a * k - c ) % b == 0:\n possible = True\n break\n if possible :\n print(\"YES\")\n else:\n print(\"NO\")\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n__starting_point()", "a, b, c = map(int, input().split())\ncnt = 0\nfor i in range(1, 10**5):\n if (a*i)%b == c:\n print(\"YES\")\n break\n else:\n cnt += 1\n if cnt == 10**5 - 1:\n print(\"NO\")\n break", "def zz():\n return list(map(int,input().split()))\n\na,b,c = zz()\nans = 0\nfor i in range(1,b+1):\n if (a*i)%b == c:\n ans = 1\n break\n\nif ans == 0:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "a, b, c = map(int, input().split())\njudge=False\nfor i in range(b):\n if a*i%b==c:\n judge = True\n break\n\nif judge:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c=map(int,input().split())\nans=\"NO\"\nfor i in range(1,b+1):\n if a*i%b==c:\n ans=\"YES\"\n break\n\nprint(ans)", "a,b,c=map(int, input().split())\nres=\"NO\"\nfor i in range(b):\n if (a*i)%b==c:\n res=\"YES\"\n break \nprint(res)", "ans = 'NO'\na, b, c = map(int, input().split())\nmemo = []\nfor i in range(1, 10**9):\n tmp = (a * i)%b\n if tmp == c:\n ans = 'YES'\n break\n if tmp in memo:\n break\n else:\n memo.append(tmp)\nprint(ans)", "a,b,c = map(int,input().split())\nbool = False\nfor i in range(1,101):\n if a * i % b == c:\n bool = True\nif bool:\n print('YES')\nelse:\n print('NO')", "a,b,c=map(int,input().split())\nfor i in range(100):\n if (b*i+c)%a==0:\n print('YES')\n return\nprint('NO')", "A,B,C = list(map(int,input().split()))\nR = C % B\n\nfound = False\nfor n in range(1,101):\n if n*A % B == R:\n found = True\n break\n \nif found:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "# -*- coding: utf-8 -*-\n\nA,B,C = map(int, input().split())\n\nmod = []\nfor i in range(max(B,C)):\n res = A * i % B\n if res == C:\n ans = \"YES\"\n break\n if res in mod:\n ans = \"NO\"\n break\n mod.append(res)\n\nprint(ans)", "a, b, c = map(int, input().split())\n\nn = a\ncnt = 1\nwhile cnt <= b:\n if n % b == c:\n print('YES')\n return\n cnt += 1\n n += a\nprint('NO')", "a,b,c = map(int, input().split())\nres = 0\nfor i in range(1,101):\n if (a*i) % b == c:\n res += 1\n \nprint(\"YES\") if res > 0 else print(\"NO\")", "a,b,c = map(int,input().split())\nans = False\nfor i in range(b):\n if a*i%b == c :\n ans = True\n\nprint(\"YES\" if ans else \"NO\")", "A, B, C = map(int, input().split())\nwhile B != 0:\n A, B = B, A % B\nprint('YES' if C % A == 0 else 'NO')", "a,b,c=list(map(int,input().split()))\n\nans=\"NO\"\nfor i in range(0,b+1):\n for j in range(0,a+1):\n if a*i == b*j+c:\n ans=\"YES\"\n break\n \nprint(ans)\n", "lst = input().split()\n\nA = int(lst[0])\nB = int(lst[1])\nC = int(lst[2])\n\nL = []\n\nfor i in range(1, B+1):\n L.append((A * i) % B)\n\nif C in L:\n print('YES')\nelse:\n print('NO')", "a, b, c = map(int,input().split())\nans = 'NO'\n\nfor i in range(1,b+1):\n mod = a*i % b\n if mod == 0:continue\n elif c % mod == 0:\n ans = 'YES'\n break\n\nprint(ans)", "a,b,c = map(int,input().split())\nmodb = [0]*100\nfor i in range(1,100000):\n n = a*i\n m = n%b\n # print(n,m)\n if(modb[m] != 0):\n break\n modb[m] = 1\n\nprint(\"YES\" if(modb[c] == 1) else \"NO\")", "#9 B - Choose Integers AC(hint)\nA,B,C = map(int,input().split())\n\nresult = 'NO'\n\nnum = 0\n#(k+B)A%B = (kA + AB)%B = kB\nfor i in range(1,B+1):\n num = (A*i)%B\n if num == C:\n result = 'YES'\n break\nprint(result) ", "a, b, c = map(int, input().split())\n\nfor i in range(b):\n if (a * i) % b == c:\n print('YES')\n break\n elif (a * i) % b == 0 and i > 0:\n print('NO')\n break", "import sys, math\nfrom itertools import combinations as c, product as p\nfrom collections import deque\nsys.setrecursionlimit(10**9)\nINF = float('inf')\nMOD = 10**9 + 7\n#MOD = 998244353\n\n\ndef si(): return input()\ndef ii(): return int(input())\ndef fi(): return float(input())\ndef lstr(): return input().split()\ndef lint(): return list(map(int, input().split()))\ndef lintdec(): return list(map(lambda x:int(x) - 1, input().split()))\ndef lnstr(n): return [input() for _ in range(n)]\ndef lnint(n): return [int(input()) for _ in range(n)]\ndef lint_list(n): return [lint() for _ in range(n)]\n\n\n\n############################################################\nA, B, C = lint()\n\nq = 0\nwhile q <= 100:\n if (q * B + C) % A == 0:\n print('YES')\n break\n q += 1\nelse:\n print('NO')", "a, b, c = map(int, input().split())\n\nans='NO'\nfor i in range(1,b+1):\n if a*i % b ==c:\n ans='YES'\nprint(ans)", "a, b, c = map(int, input().split())\nprint(\"YES\" if any((a*i)%b==c for i in range(1, b+1)) else \"NO\")", "a,b,c= map(int,input().split())\nfor i in range(b):\n if (a*i-c)%b ==0:\n print(\"YES\")\n return\nprint(\"NO\")", "a, b, c=map(int, input().split())\nd=a%b\ns=set()\nwhile d not in s:\n s.add(d)\n d=(d+a)%b\nif c in s:\n print('YES')\nelse:\n print('NO')", "A, B, C = list(map(int, input().split()))\ncalc = 0\n\nfor i in range(1000):\n calc += A\n rem = calc % B\n if rem == C:\n print('YES')\n return\n\nprint('NO')\n", "a,b,c = map(int,input().split())\n\nfor i in range(1,b):\n if a*i%b == c:\n print('YES')\n break\nelse:\n print('NO')", "A, B, C=map(int, input().split(\" \"))\ncandidate=[(A*i)%B for i in range(1, B-1)]\n\nif C in candidate:\n print('YES')\nelse:\n print('NO')", "A, B, C=map(int, input().split(\" \"))\nmod=[]\npivot=1\nstep=1\n\nwhile True:\n pivot = (step*A)%B\n if (step*A)%B==C:\n print('YES')\n #print('debug', step)\n break\n elif pivot in mod:\n print('NO')\n break\n else:\n mod.append(pivot)\n step=step+1", "A, B, C = map(int, input().split())\n\nfor i in range(1, B+1):\n if i*A % B == C:\n print(\"YES\")\n return\nprint(\"NO\")", "A,B,C = map(int,input().split())\n\ncheck = False\nfor i in range(1, B+1):\n if (A * i) % B == C:\n check = True\n \nprint(\"YES\" if check else \"NO\")", "a,b,c=input().split()\na=int(a)\nb=int(b)\nc=int(c)\nd=0\nfor i in range(1000):\n if a*i%b==c:\n d=d+1\nif d==0:\n print(\"NO\")\nelse:\n print(\"YES\")", "# ?\n# \u3069\u3046\u3084\u3063\u3066\u5168\u63a2\u7d22\u3059\u308b\u306e\u304b\u308f\u304b\u3089\u3093\na, b, c = map(int, input().split())\nfor i in range(1, 1000):\n if (a * i) % b == c:\n print(\"YES\")\n return\nprint(\"NO\")"] | {"inputs": ["7 5 1\n", "2 2 1\n", "1 100 97\n", "40 98 58\n", "77 42 36\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 20,050 | |
7f7a34e6bf07141dc5e14c94d4520e2a | UNKNOWN | There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)
What is the area of this yard excluding the roads? Find it.
-----Note-----
It can be proved that the positions of the roads do not affect the area.
-----Constraints-----
- A is an integer between 2 and 100 (inclusive).
- B is an integer between 2 and 100 (inclusive).
-----Input-----
Input is given from Standard Input in the following format:
A B
-----Output-----
Print the area of this yard excluding the roads (in square yards).
-----Sample Input-----
2 2
-----Sample Output-----
1
In this case, the area is 1 square yard. | ["a,b=map(int, input().split()) \nprint(a*b-a-b+1)", "n,m = map(int, input().split())\nprint((n-1)*(m-1))", "a,b = list(map(int,input().split()))\nprint(((a-1) * (b-1)))\n", "A, B = list(map(int, input().split()))\nprint(((A-1)*(B-1)))\n", "a,b=map(int, input().split())\n\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint((a * b) - (a + b - 1))", "A,B = map(int,input().split())\nprint((A-1)*(B-1))", "A, B = map(int, input().split())\nprint((A - 1) * (B - 1))", "a,b = list(map(int,input().split()))\nprint(((a-1)*(b-1)))\n\n", "A,B = map(int,input().split())\nprint(A*B-(A+B-1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint((a-1)*(b-1))", "A, B = map(int, input().split())\nans = (A * B) - (A + B - 1)\n\nprint(ans)", "a, b = map(int, input().split())\nprint((a - 1) * (b - 1))", "A,B=list(map(int,input().split()))\n\nprint((A*B-A-B+1))\n", "A,B = map(int, input().split())\n\nprint(A*B-A-B+1)", "a, b = list(map(int, input().split()))\nprint(((a - 1) * (b - 1)))\n", "A,B = list(map(int, input().split()))\n\nans = int(A*B-A-B+1)\nprint(ans)\n", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "A,B= (int(x) for x in input().split())\nmenseki=A*B\nnyan=menseki-A-B+1\nprint(nyan)", "A,B = (int(x) for x in input().split())\nprint((A-1)*(B-1))", "import sys\nimport math\n\n#https://atcoder.jp/contests/agc008/submissions/15248942\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninm = lambda: map(int, sys.stdin.readline().split())\ninl = lambda: list(inm())\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\nA,B = inm()\n\nprint(A*B-A-B+1)\n", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "n,i=map(int,input().split())\nprint((n-1)*(i-1))", "A,B=map(int,input().split())\nprint((A-1)*(B-1))", "a,b = map(int, input().split())\nprint((a-1)*(b-1))", "a,b = map(int,input().split())\nprint(a*b-a-b+1)", "a, b = list(map(int, input().split()))\nprint((a-1)*(b-1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint((a-1)* (b-1))", "a,b=map(int,input().split(\" \"))\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\n\nprint((a-1) * (b-1))", "a,b = map(int,input().split())\n\nprint((a-1)*(b-1))", "A,B = map(int,input().split())\nprint(A*B-A-B+1)", "a,b = map(int, input().split())\nprint(a*b-a-b+1)", "a, b = map(int, input().split())\nprint(a * b - a - b + 1)", "A,B = map(int,input().split())\nans = A * B - (B + A - 1)\nprint(ans)", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "A, B = map(int, input().split())\n\nprint((A-1)*(B-1))", "a, b = list(map(int, input().split()))\nprint((a*b - a - b + 1))\n", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "import sys\ninput = sys.stdin.readline\nins = lambda: input().rstrip()\nini = lambda: int(input().rstrip())\ninm = lambda: map(int, input().split())\ninl = lambda: list(map(int, input().split()))\n\na, b = inm()\nprint(a*b - 1*a - 1*b + 1)", "a,b=input().split()\na=int(a)\nb=int(b)\nprint(int((a-1)*(b-1)))", "a, b = map(int, input().split())\nprint((a - 1) * (b - 1))", "A, B = map(int, input().split())\n\nprint((A-1) * (B-1))", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "a,b=map(int, input().split())\nprint((a-1)*(b-1))", "a,b= map(int,input().split())\nprint((a-1)*(b-1))", "\na,b=map(int,input().split())\nprint((a-1)*(b-1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "A,B=list(map(int,input().split()))\nprint((A*B-(A+B-1)))\n\n", "w,h = map(int, input().split(\" \"))\nprint((w-1)*(h-1))", "a,b,=map(int,input().split())\nprint((a-1)*(b-1))", "a,b=map(int, input().split())\nprint(a*b-a-b+1)", "a,b = [int(x) for x in input().split()]\nprint((a-1)*(b-1))", "A, B = list(map(int, input().split()))\nprint(((A-1)*(B-1)))\n", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "a,b = map(int, input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint(a*b-(a+b-1))", "A,B=list(map(int,input().split()))\nprint(((A-1)*(B-1)))\n", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint((a-1)*(b-1))", "A,B=map(int,input().split())\nprint((A-1)*(B-1))", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n A, B = list(map(int, readline().split()))\n\n print(((A - 1) * (B - 1)))\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "len_a, len_b = list(map(int, input().split()))\n\ntotal_area = len_a * len_b\nroad = len_a + len_b - 1\nprint((total_area - road))\n", "A, B = map(int, input().split())\nprint((A*B) - (A + B - 1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint(a*b - (a+b-1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "#!/usr/bin/env python3\n\ndef main():\n a, b = list(map(int, input().split()))\n print(((a - 1) * (b - 1)))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "A, B, = map(int, input().split())\nprint((A-1)*(B-1))", "a, b = map(int, input().split())\nprint((a-1)*(b-1))", "A, B = map(int, input().split())\nprint(A*B-A-B+1)", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "a, b = map(int, input().split())\nprint((a - 1) * (b - 1))", "A, B = map(int, input().split())\n\nC = A - 1\nD = B - 1\nE = C * D\n\nprint(E)", "a, b = map(int, input().split())\nans = (a-1) * (b-1)\nprint(ans)", "def mapt(fn, *args):\n return list(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n a, b = Input()\n print((a-1) * (b-1))\n\n\nmain()", "# ABC106\n# A Garden\nA, B = list(map(int, input().split()))\nans = (A * B) - (A + B - 1)\nprint(ans)\n", "A,B = map(int, input().split())\nprint(A*B-(A+B-1))", "a,b = map(int,input().split())\nprint((a-1)*(b-1))", "H, W = map(int, input().split())\n\nprint((H-1)*(W-1))", "a,b = map(int, input ().split ())\nprint ((a-1)*(b-1))", "a,b = map(int,input().split())\nprint(a*b-a-b+1)", "a, b = map(int, input().split())\n\nprint((a - 1) * (b - 1))", "a,b=map(int,input().split())\nprint((a-1)*(b-1))", "a,b=map(int,input().split())\nprint(a*b-b-a+1)", "a,b = map(int,input().split())\nprint(str(a*b-a-b+1))", "A, B = map(int, input().split())\nprint((A-1) * (B - 1))", "a, b = map(int, input().split())\nres = (a - 1) * (b - 1)\nprint(res)", "a, b = map(int, input().split())\nprint((a-1)*(b-1))", "a,b=map(int,input().split())\nans=(a-1)*(b-1)\nprint(ans)", "a, b = map(int, input().split())\nprint(a * b - a - b + 1)", "x, y = map(int, input().split())\nprint(x*y - x - y + 1)", "a,b=map(int,input().split())\nprint(int((a-1)*(b-1)))", "a, b = map(int, input().split())\nprint((a*b) - (a + b - 1))", "a, b = map(int, input().split())\n\nprint((a - 1) * (b - 1))", "# coding = SJIS\n\na, b = map(int, input().split())\n\nprint((a - 1) * (b - 1))", "a,b,=map(int,input().split())\na-=1;b-=1\nprint(a*b)"] | {"inputs": ["2 2\n", "5 7\n", "91 61\n", "100 100\n", "22 15\n"], "outputs": ["1\n", "24\n", "5400\n", "9801\n", "294\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 7,139 | |
5c41a1224ed997a3cc77086370c9a5a1 | UNKNOWN | We have a long seat of width X centimeters.
There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.
At most how many people can sit on the seat?
-----Constraints-----
- All input values are integers.
- 1 \leq X, Y, Z \leq 10^5
- Y+2Z \leq X
-----Input-----
Input is given from Standard Input in the following format:
X Y Z
-----Output-----
Print the answer.
-----Sample Input-----
13 3 1
-----Sample Output-----
3
There is just enough room for three, as shown below:
Figure | ["#!/usr/bin/env python3\nimport sys\nsys.setrecursionlimit(10**6)\n\nx, y, z = list(map(int, input().split()))\n\nprint(((x-z)//(y+z)))\n", "x, y, z = list(map(int, input().split()))\n\nx -= z\ny += z\nprint((x // y))\n", "x, y, z = map(int, input().split())\nfor i in range(100000):\n if (i+1)*z + i*y > x:\n print(i-1)\n break", "x,y,z=map(int,input().split())\nprint((x-z)//(y+z))", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "X, Y, Z = map(int, input().split())\n\nX -= Z\nprint(X//(Y+Z))", "x,y,z = map(int,input().split())\nans = 0\ni = 1\nwhile 1:\n haba = (i*y)+((i+1)*z)\n if haba>x : break\n else : ans = i\n i+=1\n \nprint(ans)", "x, y, z = map(int,input().split())\n\nresult = 0\nwhile y*result + z*(result+1) <= x:\n result += 1\n\nprint(result-1)", "a,b,c = map(int,input().split())\n#lis = list(map(int,input().split()))\nprint((a-c)//(b+c))", "x,y,z = map(int,input().split())\nx = x-z\nprint(x//(y+z))", "X, Y, Z = list(map(int, input().split()))\nprint(((X-Z)//(Y+Z)))\n", "x,y,z=list(map(int,input().split()))\nans=(x-z)//(y+z)\nprint(ans)\n", "x,y,z=map(int, input().split())\nprint(int((x-z)/(y+z)))", "x, y, z = list(map(int, input().split()))\n\ni = 1\nwhile True:\n if (y + z) * i + z > x:\n print((i-1))\n break\n i += 1\n", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "x,y,z = list(map(int, input().split()))\nb = x-z\nc = y+z\n\nprint(b//c)", "X, Y, Z = map(int, input().split())\nprint((X-Z)//(Y+Z))", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "x,y,z = map(int, input().split())\nprint((x-z)//(y+z))", "x, y, z = [int(i) for i in input().split()]\nans = x // (y + z)\nif x - (ans * (y + z)) < z:\n ans -= 1\nprint(ans)\n", "x, y, z = list(map(int, input().split()))\nx -= z\ny += z\nprint((x//y))\n", "X,Y,Z = map(int,input().split())\nl = X-Z\nprint(l//(Y+Z))", "x, y, z = map(int,input().split())\n\ncnt = 1\nx -= y + 2*z\n\nwhile x >= y + z:\n cnt += 1\n x -= y + z\nprint(cnt)", "x, y, z = map(int, input().split())\nsum = y + z + z\nif x < sum:\n print(0)\nelse:\n ans = 1\n while sum <= x:\n sum += y + z\n ans += 1\n\n\n print(ans - 1)", "x,y,z = map(int,input().split())\nyz = y + z\nx -= z\nprint(x // yz)", "x,y,z=map(int,input().split())\nprint((x-z)//(y+z))", "def main():\n X, Y, Z = list(map(int, input().split()))\n rest = X - Z\n c = 0\n while rest > 0:\n rest = rest - Y - Z\n if rest < 0:\n print(c)\n return\n elif rest == 0:\n print((c+1))\n return\n else:\n c += 1\nmain()\n", "x, y, z = list(map(int, input().split()))\nprint(((x - z) // (y + z)))\n", "x,y,z = map(int,input().split())\ntmp = (x-z)//(y+z)\namari = (x-z)%(y+z)\n#print(tmp,amari)\nprint(tmp)", "x, y, z = map(int, input().split())\n\none_length = y + z\nprint(int((x-z) / one_length))", "x,y,z=map(int,input().split())\nprint((x-z)//(y+z))", "x, y, z = map(int, input().split())\nprint((x-z)//(y+z))", "X, Y, Z = list(map(int, input().split()))\nif X - Y - 2 * Z < 0:\n print((0))\n return\nX = X - Y - 2 * Z\nans = 1\nfor i in range(10 ** 5):\n if X - Y - Z >= 0:\n X = X - Y - Z\n ans += 1\n continue\n else:\n break\nprint(ans)\n", "x, y, z = [int(i) for i in input().split()]\nprint((x - z) // (y + z))", "X, Y, Z = list(map(int, input().split()))\nans = (X - Z) // (Y + Z)\nprint(ans)\n", "# coding = SJIS\n\nx, y, z = map(int,input().split())\n\na = x - z\nprint(a // (y + z))", "X, Y, Z = map(int, input().split())\nprint((X-Z)//(Y+Z))", "x,y,z=map(int, input().split())\nx-=z\nprint(x//(y+z))", "x,y,z = map(int,input().split())\nx -= y+2*z\nans = 1\nwhile x-(y+z) >= 0:\n ans += 1\n x -= y+z\nprint(ans)", "#78B\nx,y,z=map(int,input().split())\nprint((x-z)//(z+y))", "X, Y, Z = map(int,input().split())\n\nX = X - Z\n\nprint(X//(Y + Z))", "\nx,y,z=map(int,input().split())\nx -= z\nprint(x//(y+z))", "a,b,c=map(int,input().split());print((a-c)//(b+c))", "x,y,z = map(int,input().split())\nx-= z\nprint(x//(y+z))", "x,y,z=map(int,input().split())\nn=[i for i in range(z,x-z,y+z)]\nif n[-1]+y+z<=x:\n print(len(n))\nelse:\n print(len(n)-1)", "x,y,z=map(int, input().split())\nprint((x-z)//(y+z))", "X,Y,Z = map (int, input ().split ())\nX = X-Z\nA = (X/(Y+Z))//1\nprint (round (A))", "x,y,z = map(int,input().split())\nprint((x - z) //(y + z))", "x,y,z = map(int, input().split())\nprint((x-z)//(y+z))", "x,y,z=map(int,input().split())\n\nprint((x-z)//(y+z))", "a = list(map(int,input().split()))\n# b = list(map(int,input().split()))\n\nx = 0\ncount=0\n\nwhile a[0]-a[2]>= x:\n x += a[1]\n x += a[2]\n count+=1\n\nprint((count-1))\n\n", "x, y, z = map(int, input().split())\nprint((x - z) // (y + z))", "x=list(map(int,input().split()))\nprint((x[0]-x[2])//(x[1]+x[2]))", "x, y, z = map(int, input().split())\n\nprint(int((x - z) / (y + z)))", "def answer(x: int, y: int, z: int) -> int:\n return len(range(y + z * 2, x + 1, y + z))\n\n\ndef main():\n x, y, z = map(int, input().split())\n print(answer(x, y, z))\n\n\ndef __starting_point():\n main()\n__starting_point()", "x,y,z=map(int,input().split());print((x-z)//(y+z))", "x, y, z = map(int, input().split())\nx -= z\nprint(x//(y+z))", "X, Y, Z = [int(i) for i in input().split()]\n\nn = X // (Y+Z)\nm = X % (Y+Z)\n\nif m >= Z:\n print(n)\nelse:\n print((n - 1))\n", "x,y,z=map(int,(input().split()))\nans=1\nx-=(y+2*z)\nprint(ans+x//(y+z))", "X, Y, Z = map(int, input().split())\nX -= Z\nprint(X//(Y+Z))", "x, y, z = map(int, input().split())\n\ncnt = 0\nlength = x - (2*z)\n\ncnt += length//(y+z)\nlength = length%(y+z)\nif y <= length:\n cnt += 1\n\nprint(cnt)", "x, y, z = map(int, input().split())\nans = (x-z)//(y+z)\nprint(ans)", "def main():\n x, y, z = list(map(int, input().split()))\n x -= y + z * 2\n ans = 0\n if x < 0:\n return ans\n while x >= 0:\n ans += 1\n x -= y + z\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a,b,c=map(int,input().split())\nprint((a-c)//(b+c))", "import math\nX, Y, Z = list(map(int, input().split()))\n\nX -= Z\n\nprint((math.floor(X/(Y+Z))))\n", "x, y, z = map(int, input().split())\n\nnum = x//(y+z)\nif x >= num*y + (num*z + z):\n print(num)\nelse:\n print(num-1)", "x,y,z=map(int, input().split()) \nprint((x-z)//(y+z))", "X,Y,Z=list(map(int,input().split()))\nprint(((X-Z)//(Y+Z)))\n", "import sys\nimport math\nimport itertools\nimport collections\nimport heapq\nimport re\nimport numpy as np\nfrom functools import reduce\n\nrr = lambda: sys.stdin.readline().rstrip()\nrs = lambda: sys.stdin.readline().split()\nri = lambda: int(sys.stdin.readline())\nrm = lambda: list(map(int, sys.stdin.readline().split()))\nrl = lambda: list(map(int, sys.stdin.readline().split()))\ninf = float('inf')\nmod = 10**9 + 7\n\na, b, c = rm()\nprint(((a-c) // (b+c)))\n\n\n\n\n\n\n\n", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n x, y, z = Input()\n\n people = x // y\n spaces = (people + 1) * z\n while True:\n if people * y + spaces <= x:\n print(people)\n return\n people -= 1\n spaces = (people + 1) * z\n\n\nmain()", "x, y, z = map(int, input().split())\nprint((x - z) // ( y + z))", "X,Y,Z=map(int,input().split())\nprint((X-Z)//(Y+Z))", "x,y,z=list(map(int,input().split()))\n\nans = 0\n\nfor i in range(x):\n \n if y*i+z*(i+1) <= x:\n ans=max(ans, i)\nprint(ans)\n", "X, Y, Z = list(map(int, input().split()))\nans = 0\nfor i in range(1, 10 ** 5):\n if X - Y * i - Z * (i + 1) >= 0:\n ans = i\n continue\n else:\n break\nprint(ans)\n", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "x, y, z = list(map(int, input().split()))\n\nx -= z\n\nprint(( x // (y+z) ))\n", "x, y, z = list(map(int, input().split()))\nres = (x - z) // (y + z)\nprint(res)\n", "import sys\n\nsys.setrecursionlimit(10**7)\ndef I(): return int(sys.stdin.readline().rstrip())\ndef MI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #\u7a7a\u767d\u3042\u308a\ndef LI2(): return list(map(int,sys.stdin.readline().rstrip())) #\u7a7a\u767d\u306a\u3057\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split()) #\u7a7a\u767d\u3042\u308a\ndef LS2(): return list(sys.stdin.readline().rstrip()) #\u7a7a\u767d\u306a\u3057\n\n\nX,Y,Z = MI()\nX -= Z\nprint((X//(Y+Z)))\n", "x,y,z = list(map(int, input().split()))\nprint((x - z) // (y + z))", "lst = input().split()\nx = int(lst[0])\ny = int(lst[1])\nz = int(lst[2])\n\nx -= z\n\nprint(x // (y + z))", "a,b,c = map(int,input().split())\nfor i in range(a):\n if b * (i + 1) + c * (i + 2) > a:\n print(i)\n return", "def main():\n x, y, z = list(map(int, input().split()))\n x -= y + z * 2\n ans = 0\n if x < 0:\n print(ans)\n while x >= 0:\n ans += 1\n x -= y + z\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "x, y, z = (int(i) for i in input().split())\nans = 0\nwhile True:\n x -= (y + z)\n if x - z >= 0: ans += 1\n else: break\nprint(ans)", "x, y, z = map(int, input().split())\n\nprint((x - z) // (y + z))", "x, y, z = map(int, input().split())\nw = x - z\nprint(w // (y + z))", "x,y,z = map(int,input().split())\nfor ans in range(1,100000):\n if ans*y+(ans+1)*z <= x < (ans+1)*y+(ans+2)*z:\n print(ans)\n return", "x, y, z = map(int, input().split())\nans = (x - z) // (y + z)\nprint(ans)", "x,y,z = map(int,input().split())\nprint((x-z)//(y+z))", "x, y, z = map(int, input().split())\nx -= z\ncount = 0\nwhile x >= y + z:\n x -= y + z\n count += 1\nprint(count)", "a,b,c=input().split()\na=int(a)\nb=int(b)\nc=int(c)\nprint((a-c)//(b+c))", "X, Y, Z = (int(x) for x in input().split())\n\nans = (X-Z)//(Y+Z)\nprint(ans)", "import math\nx, y, z = map(int, input().split())\nprint(int(math.floor((x - z) / (y + z))))", "x,y,z = map(int, input().split())\nprint((x-z)//(y+z))", "X,Y,Z=map(int,input().split())\nL=X-Z\nans=0\nfor i in range(1000000):\n if L >= (Z+Y)*i:\n ans=i\n else:\n break\nprint(ans)", "X,Y,Z = map(int,input().split())\nprint((X - Z) // (Y + Z))", "def answer(x: int, y: int, z: int) -> int:\n return (x - z) // (y + z)\n\n\ndef main():\n x, y, z = map(int, input().split())\n print(answer(x, y, z))\n\n\ndef __starting_point():\n main()\n__starting_point()", "x, y ,z = map(int, input().split())\nprint((x - z) // (y + z))", "x,y,z=map(int,input().split())\nn=0\nwhile True:\n if n*y+(n+1)*z>x:\n print(n-1)\n return\n n+=1", "X, Y, Z = map(int, input().split())\nN = ((X - Z ) // (Y + Z))\nprint(N)"] | {"inputs": ["13 3 1\n", "12 3 1\n", "100000 1 1\n", "64146 123 456\n", "64145 123 456\n"], "outputs": ["3\n", "2\n", "49999\n", "110\n", "109\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 10,976 | |
ef973cb2377edbe7d9f9e81e81767ef8 | UNKNOWN | On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
-----Constraints-----
- All input values are integers.
- 1 \leq N \leq 100
- 0 \leq a_i, b_i, c_i, d_i < 2N
- a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.
- b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N
-----Output-----
Print the maximum number of friendly pairs.
-----Sample Input-----
3
2 0
3 1
1 3
4 2
0 4
5 5
-----Sample Output-----
2
For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5). | ["N = int(input())\nab = [list(map(int, input().split())) for _ in range(N)]\ncd = [list(map(int, input().split())) for _ in range(N)]\nab.sort()\ncd.sort()\n\ng = [[] for _ in range(N)]\n\nfor i, pab in enumerate(ab):\n for j, pcd in enumerate(cd):\n if pab[0] < pcd[0] and pab[1] < pcd[1]:\n g[j].append([pab[1],i])\n \nans = 0\ns = set()\n\nfor gg in g:\n gg.sort(reverse=True)\n for ggg in gg:\n if ggg[1] in s:continue\n else:\n ans += 1\n s.add(ggg[1])\n break\nprint(ans)\n", "N = int(input())\nR = [list(map(int,input().split())) for n in range(N)]\nB = [list(map(int,input().split())) for n in range(N)]\nR.sort(key=lambda x:-x[1])\nB.sort()\nans=0\n\nfor c,d in B:\n for a,b in R:\n if a<c and b<d:\n ans+=1\n R.remove([a,b])\n break\n\nprint(ans)", "import sys\nimport heapq, math\nfrom itertools import zip_longest, permutations, combinations, combinations_with_replacement\nfrom itertools import accumulate, dropwhile, takewhile, groupby\nfrom functools import lru_cache\nfrom copy import deepcopy\n\nsys.setrecursionlimit(10000000)\n\nN = int(input())\nAB = []\nCD = []\n\nfor i in range(N):\n A, B = map(int, input().split())\n AB.append((A, B))\n\nfor i in range(N):\n C, D = map(int, input().split())\n CD.append((C, D))\n\nAB.sort()\nCD.sort()\n\nused = [False] * N\ncnt = 0\n\nfor i in range(N):\n m = -1\n for j in range(N):\n if not used[j] and CD[i][0] > AB[j][0] and CD[i][1] > AB[j][1]:\n if m < 0 or AB[m][1] < AB[j][1]:\n m = j\n\n if m >= 0:\n used[m] = True\n cnt += 1\n\nprint(cnt)", "import sys\ninput = sys.stdin.readline\n\nfrom scipy.sparse import csr_matrix\nfrom scipy.sparse.csgraph import maximum_bipartite_matching\nimport numpy as np\n\nN = int(input())\n\nX = []\nY = []\nfor i in range(N):\n X.append([int(i) for i in input().split()])\n\nfor i in range(N):\n Y.append([int(i) for i in input().split()])\n\ndata = []\nfor i in range(len(X)):\n for j in range(N):\n if X[i][0] < Y[j][0] and X[i][1] < Y[j][1]:\n data.append([i,j,1])\n\n\nif not data:\n print(0)\n return\n\nedge = np.array(data, dtype = np.int64).T\n# graph = csr_matrix((edge[2], (edge[:2] - 1)), (V, V))\ngraph = csr_matrix((edge[2], (edge[:2])), (len(X), len(Y))) # \u756a\u53f7\u306e\u30c7\u30af\u30ea\u30e1\u30f3\u30c8\u304c\u4e0d\u8981\u306a\u5834\u5408\n\nmatching = maximum_bipartite_matching(graph, perm_type=\"column\")\n\nprint(sum(d!=-1 for d in matching))", "N=int(input())\nred=[]\nblue=[]\nfor _ in range(N):\n a,b = map(int,input().split())\n red.append((a+1,b+1))\nfor _ in range(N):\n c,d = map(int,input().split())\n blue.append((c+1,d+1))\n\nblue.sort(key=lambda x:x[0])\nfor b in blue:\n c = None\n bx, by = b\n for r in red:\n rx, ry = r\n if rx < bx and ry < by:\n if c is None or c[1] < ry:\n c = r\n if c:\n red.remove(c)\n\nprint(N-len(red))", "# coding: utf-8\nimport sys\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\n\"\"\"\nN\u304c\u5c0f\u3055\u3044\u306e\u3067\u3001Y\u5ea7\u6a19\u3067cand\u306b\u5165\u308c\u3066\u304a\u304f\n\"\"\"\nN = ir()\nAB = [lr() for _ in range(N)]\nCD = [lr() for _ in range(N)]\ncand = [0] * (2*N)\nABCD = [(a, b, 0) for a, b in AB] + [(c, d, 1) for c, d in CD]\nABCD.sort()\nanswer = 0\nfor X, Y, Z in ABCD:\n if Z == 0:\n cand[Y] += 1\n else:\n for y in range(Y-1, -1, -1):\n if cand[y] > 0:\n answer += 1\n cand[y] -= 1\n break\n\nprint(answer)\n", "N = int(input())\nab = [list(map(int, input().split())) for _ in range(N)]\ncd = [list(map(int, input().split())) for _ in range(N)]\nab.sort(reverse=True)\ncd.sort()\np = 0\nfor c in cd:\n ac = [-1, -1]\n for a in ab:\n if c[0] > a[0] and c[1] > a[1] and ac[1] < a[1]:\n ac = a\n if ac != [-1, -1]:\n p += 1\n ab.remove(ac)\n\nprint(p)\n", "n = int(input())\nAB = list(list(map(int,input().split())) for _ in range(n))\nCD = list(list(map(int,input().split())) for _ in range(n))\n\nCD.sort() # sort x in ascending order\nAB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order\n\ndim_b = [[] for _ in range(n)]\nfor b in range(n):\n for r in range(n):\n if AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:\n dim_b[b] += [r]\n\nvis_r = [False]*(n)\nfor b in range(n): # ascending order of x\n for r in dim_b[b]: # descending order of y\n if not vis_r[r]: vis_r[r] = True; break\n\nprint((sum(vis_r)))\n", "#!/usr/bin/env python3\n\nimport networkx as nx\n\n\nn = int(input())\nab = [list(map(int, input().split())) for i in range(n)]\ncd = [list(map(int, input().split())) for i in range(n)]\n\n\nmatch_list = [[] for i in range(n)]\nfor i in range(n):\n for j in range(n):\n a, b = ab[i]\n c, d = cd[j]\n\n if a < c and b < d:\n match_list[i].append(j)\n# print(match_list)\n\n\ngroup1 = list(range(n))\ngroup2 = list(range(n, 2*n))\n\ng = nx.Graph()\ng.add_nodes_from(group1, bipartite=1)\ng.add_nodes_from(group2, bipartite=0)\n\nfor i, list_ in enumerate(match_list):\n for j in list_:\n g.add_edge(i, j+n, weight=1)\n\n# A, B = bipartite.sets(g)\n# print(A, B)\n# pos = dict()\n# pos.update((n, (1, i)) for i, n in enumerate(A))\n# pos.update((n, (2, i)) for i, n in enumerate(B))\n# nx.draw_networkx(g, pos)\n# nx.draw_networkx_edges(g, pos)\n# plt.axis(\"off\")\n# plt.show()\n\n\nd = nx.max_weight_matching(g)\n\nprint((len(d)))\n", "n=int(input())\nab=[list(map(int,input().split())) for _ in range(n)]\ncd=[list(map(int,input().split())) for _ in range(n)]\nab.sort(key=lambda x:x[0])\ncd.sort(key=lambda x:x[0])\nans=0\ni=0\nred_x=[]\nimport bisect\nfor c,d in cd:\n while i<n and ab[i][0]<c:\n bisect.insort_right(red_x,ab[i][1])\n i+=1\n if red_x and red_x[0]<d:\n idx=bisect.bisect_right(red_x,d)-1\n ans+=1\n red_x.pop(idx)\nprint(ans)", "from collections import defaultdict\nfrom itertools import product\n\nN = int(input())\n\nred_points = [tuple(map(int, input().split(' '))) for _ in range(N)]\nblue_points = [tuple(map(int, input().split(' '))) for _ in range(N)]\n\nedges = defaultdict(set)\n\nfor i, j in product(list(range(N)), repeat=2):\n a, b = red_points[i]\n c, d = blue_points[j]\n\n if a < c and b < d:\n edges[i].add(j + N)\n edges[j + N].add(i)\n\npairs = [-1] * (2 * N)\nans = 0\n\n\ndef dfs(v, seen):\n seen[v] = True\n for u in edges[v]:\n w = pairs[u]\n if w < 0 or (not seen[w] and dfs(w, seen)):\n pairs[v] = u\n pairs[u] = v\n return True\n return False\n\n\nfor v in range(2 * N):\n if pairs[v] < 0:\n seen = [False] * (2 * N)\n if dfs(v, seen):\n ans += 1\n\nprint(ans)\n", "N = int(input())\nRed = [[int(T) for T in input().split()] for TN in range(0,N)]\nRed.sort(key=lambda X:X[1],reverse=True)\nBlue = [[int(T) for T in input().split()] for TN in range(0,N)]\nBlue.sort(key=lambda X:X[0])\nCount = 0\n\nfor TB in range(0,N):\n DelInd = -1\n for TR in range(0,len(Red)):\n if Blue[TB][0]>Red[TR][0] and Blue[TB][1]>Red[TR][1]:\n DelInd = TR\n break\n if DelInd!=-1:\n del Red[DelInd]\n Count += 1\nprint(Count)", "N = int(input())#100\nAB = [0] * N\nfor i in range(N):\n AB[i] = list(map(int, input().split()))\nAB = sorted(AB)\nCD = [0] * N\nfor i in range(N):\n CD[i] = list(map(int, input().split()))\nCD = sorted(CD)\n#print(AB, CD)\n\nans = 0\n\nused = [0] * N\nfor i in range(N):\n now_x, now_y = CD[i][0], CD[i][1]\n max_y = -1\n nn = -1\n for j in range(N):\n if (now_x > AB[j][0]) and (used[j] == 0):\n if now_y > AB[j][1]:\n if max_y < AB[j][1]:\n max_y = AB[j][1]\n nn = j\n if max_y != -1:\n ans += 1\n used[nn] = 1\n \nprint(ans) \n \n \n \n \n \n \n \n", "def main():\n from sys import stdin\n def input():\n return stdin.readline().strip()\n \n n = int(input())\n red = [tuple(map(int, input().split())) for _ in range(n)]\n blue = [tuple(map(int, input().split())) for _ in range(n)]\n\n red.sort()\n blue.sort()\n\n now = 0\n for i in blue:\n while now < len(red) and red[now] < i:\n now += 1\n \n l = red[:now]\n if l == []:\n continue\n\n l = sorted(l, key=lambda x: x[1])\n if l[0][1] > i[1]:\n continue\n \n # binary search\n left = 0\n right = len(l) - 1\n while left < right:\n center = (left + right + 1) // 2\n if l[center][1] < i[1]:\n left = center\n else:\n right = center - 1\n\n red.remove(l[left])\n now -= 1\n\n print(n - len(red))\n\nmain()", "n = int(input())\nab = []\nfor i in range(n):\n ab.append(list(map(int, input().split())))\ncd = []\nfor i in range(n):\n cd.append(list(map(int, input().split())))\ncd.sort()\nab.sort(key = lambda x: x[1], reverse = True)\nflag_ab = [False for i in range(n)]\ncount = 0\nfor i in range(n):\n c, d = cd[i][0], cd[i][1]\n for j in range(n):\n if flag_ab[j] == True:\n continue\n a, b = ab[j][0], ab[j][1]\n if c > a and d > b:\n flag_ab[j] = True\n count += 1\n break\nprint(count)", "import networkx as nx\nN = int(input())\nAB = [[int(_) for _ in input().split()] for _ in range(N)]\nCD = [[int(_) for _ in input().split()] for _ in range(N)]\nG = nx.DiGraph()\nfor a, b in AB:\n G.add_edge(-1, a * 1000 + b, capacity=1)\nfor c, d in CD:\n G.add_edge(c * 1000 + d, -2, capacity=1)\nfor a, b in AB:\n for c, d in CD:\n if a < c and b < d:\n G.add_edge(a * 1000 + b, c * 1000 + d, capacity=1)\nflow_value, flow_dict = nx.maximum_flow(G, -1, -2)\nprint(flow_value)\n", "N = int(input())\nab = [tuple(map(int, input().split())) for _ in range(N)]\ncd = [tuple(map(int, input().split())) for _ in range(N)]\n\nab.sort(key=lambda xy: xy[1], reverse=True)\ncd.sort()\n\nans = 0\nfor c, d in cd:\n for index, (a, b) in enumerate(ab):\n if a < c and b < d:\n ab[index] = (201, 201)\n ans += 1\n break\n\nprint(ans)\n", "from heapq import heapify, heappush, heappop\nN = int(input())\nA = []\nfor i in range(N):\n A.append(tuple(map(int, input().split())))\nA.sort()\n\nB = []\nfor i in range(N):\n B.append(tuple(map(int, input().split())))\nB.sort()\n\nheap = []\nheapify(heap)\naindex = count = 0\nfor b in B:\n while aindex < len(A) and A[aindex][0] < b[0]:\n heappush(heap, -A[aindex][1])\n aindex += 1\n buf = []\n while heap and b[1] <= -heap[0]:\n ay = heappop(heap)\n buf.append(ay)\n if heap and -heap[0] < b[1]:\n count += 1\n heappop(heap)\n for ay_ in buf:\n heappush(heap, ay_)\nprint(count)", "import collections, itertools, copy\n\n\nclass MaximumFlow:\n def ford_fulkerson(self, G, s, t):\n G_residue = copy.deepcopy(G)\n\n def dfs(start, used):\n if start == t:\n return [start]\n for end, cap in list(G_residue[start].items()):\n if cap > 0 and end not in used:\n used.add(end)\n ret = dfs(end, used)\n if ret:\n return ret + [start]\n return []\n\n flow_value = 0\n while True:\n root = dfs(s, set([s]))\n if root:\n root = root[::-1]\n residue = min(\n [G_residue[a][b] for a, b in zip(root, root[1:])])\n flow_value += residue\n for a, b in zip(root, root[1:]):\n G_residue[a][b] -= residue\n G_residue[b][a] += residue\n else:\n return (flow_value, G_residue)\n\n\nN = int(input())\nAB = [[int(_) for _ in input().split()] for _ in range(N)]\nCD = [[int(_) for _ in input().split()] for _ in range(N)]\nG = collections.defaultdict(lambda: collections.defaultdict(int))\nfor a, b in AB:\n G[-1][1000 * a + b] = 1\nfor c, d in CD:\n G[1000 * c + d][-2] = 1\nfor ab, cd in itertools.product(AB, CD):\n a, b = ab\n c, d = cd\n if a < c and b < d:\n G[1000 * a + b][1000 * c + d] = 1\nflow_value, flow_dict = MaximumFlow().ford_fulkerson(G, -1, -2)\nprint(flow_value)\n", "n, *ABCD = map(int, open(0).read().split())\nAB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])], key=lambda x:-x[1])\nCD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])\n\nfor c, d in CD:\n for i in range(len(AB)):\n a, b = AB[i]\n if a < c and b < d:\n _ = AB.pop(i)\n break\nprint(n-len(AB))", "N=int(input())\nAB=sorted([list(map(int, input().split())) for _ in range(N)])\nCD=sorted([list(map(int, input().split())) for _ in range(N)])\n\npaira=-1\npairb=-1\nans=0\n\nfor i in range(N):\n\ttempcd=CD[i]\n\tfor h in range(len(AB)):\n\t\ttempab=AB[h]\n\t\tif tempab[0]<tempcd[0] and tempab[1]<tempcd[1]:\n\t\t\tif pairb<tempab[1]:\n\t\t\t\tpaira=tempab[0]\n\t\t\t\tpairb=tempab[1]\n\t\t\t\tpairnum=h\n\tif paira!=-1 and pairb!=-1:\n\t\tans+=1\n\t\tAB.pop(pairnum)\n\t\tpaira=-1\n\t\tpairb=-1\n\nprint(ans)\n\t\t\t\n", "def resolve():\n '''\n code here\n '''\n import collections\n N = int(input())\n reds = [[int(item) for item in input().split()] for _ in range(N)]\n blues = [[int(item) for item in input().split()] for _ in range(N)]\n\n reds = sorted(reds, key=lambda x:x[1], reverse=True)\n blues.sort()\n\n que = collections.deque(blues)\n cnt = 0\n\n while que:\n\n bx, by = que.popleft()\n\n for rx, ry in reds[:]:\n if rx <= bx and ry <= by:\n cnt += 1\n reds.remove([rx, ry])\n break\n print(cnt)\n\n\ndef __starting_point():\n resolve()\n\n\n\n__starting_point()", "import sys\nINF = 1 << 60\nMOD = 10**9 + 7 # 998244353\nsys.setrecursionlimit(2147483647)\ninput = lambda:sys.stdin.readline().rstrip()\nfrom scipy.sparse import csr_matrix\nfrom scipy.sparse.csgraph import maximum_bipartite_matching\ndef resolve():\n n = int(input())\n A = [tuple(map(int, input().split())) for _ in range(n)]\n B = [tuple(map(int, input().split())) for _ in range(n)]\n\n graph = csr_matrix([[int(A[i][0] < B[j][0] and A[i][1] < B[j][1]) for j in range(n)] for i in range(n)])\n ans = 0\n for a in maximum_bipartite_matching(graph):\n if a != -1:\n ans += 1\n print(ans)\nresolve()", "n = int(input())\ncr = [tuple(map(int, input().split())) for _ in range(n)]\ncb = [tuple(map(int, input().split())) for _ in range(n)]\n\ncb.sort(key=lambda xy: xy[0])\ncr.sort(key=lambda xy: xy[1], reverse=True)\n\nnpair = 0\nfor (bx, by) in cb:\n for (rx, ry) in cr:\n if rx < bx and ry < by:\n npair += 1\n cr.remove((rx, ry))\n break\n\nprint(npair)\n\n\n\n", "N= int(input())\nred=[list(map(int,input().split())) for i in range(N)]\nred.sort()\nblue=[list(map(int,input().split())) for i in range(N)]\nblue.sort()\nans=0\nfrom operator import itemgetter\nfor i in range(N):\n x,y=blue[i]\n l=[]\n for j in range(N):\n try:\n if x>red[j][0] and y>red[j][1]:\n l.append(red[j])\n except IndexError:\n break\n try:\n l.sort(key=itemgetter(1),reverse=True)\n red.remove(l[0])\n except IndexError:\n pass\nprint(N-len(red))", "n=int(input())\nred=[list(map(int,input().split())) for _ in range(n)]\nblue=[list(map(int,input().split())) for _ in range(n)]\nred.sort()\nblue.sort()\n \np=0\nfor bb in blue:\n lis=[-1,-1]\n for rr in red:\n if rr[0]<bb[0] and rr[1]<bb[1] and lis[1]<rr[1]:\n lis=rr\n if lis!=[-1,-1]:\n red.remove(lis)\n p+=1\nprint(p)", "import sys\ninput = sys.stdin.readline\n\nclass FordFulkerson:\n def __init__(self, n):\n self.N = n\n self.G = [[] for _ in range(n)]\n \n def add_edge(self, fr, to, cap):\n forward = [to, cap, None]\n forward[2] = backward = [fr, 0, forward]\n self.G[fr].append(forward)\n self.G[to].append(backward)\n \n def add_multi_edge(self, v1, v2, cap1, cap2):\n edge1 = [v2, cap1, None]\n edge1[2] = edge2 = [v1, cap2, edge1]\n self.G[v1].append(edge1)\n self.G[v2].append(edge2)\n \n def dfs(self, v, t, f):\n if v == t:\n return f\n used = self.used\n used[v] = 1\n for e in self.G[v]:\n w, cap, rev = e\n if cap and not used[w]:\n d = self.dfs(w, t, min(f, cap))\n if d:\n e[1] -= d\n rev[1] += d\n return d\n return 0\n \n\n def flow(self, s, t):\n flow = 0\n f = INF = 10**9 + 7\n N = self.N\n while f:\n self.used = [0]*N\n f = self.dfs(s, t, INF)\n flow += f\n return flow\n \ndef main():\n n = int(input())\n red = [list(map(int, input().split())) for _ in range(n)]\n blue = [list(map(int, input().split())) for _ in range(n)]\n \n flow = FordFulkerson(n*2+2)\n for i in range(n):\n flow.add_edge(0, i+1, 1)\n flow.add_edge(n+i+1, 2*n+1, 1)\n for j in range(n):\n if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:\n flow.add_edge(i+1, n+j+1, 1)\n \n \n ans = flow.flow(0, 2*n+1)\n print(ans)\n \ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nred = [tuple(map(int, input().split())) for _ in range(n)]\nblue = [tuple(map(int, input().split())) for _ in range(n)]\nred.sort(key=lambda x:-x[1])\nblue.sort()\ncount = 0\nfor xb, yb in blue:\n for i in range(n):\n if xb > red[i][0] and yb > red[i][1]:\n red[i] = (201, 201)\n count += 1\n break\nprint(count)\n", "N = int(input())\nRed = sorted([tuple(map(int, input().split())) for _ in range(N)])\nBlue = sorted([tuple(map(int, input().split())) for _ in range(N)])\n\nans = 0\nfor bx,by in Blue:\n C = [(y,x) for x,y in Red if x<bx and y<by] #\u5019\u88dc\n if len(C) == 0:\n continue\n ans += 1\n C.sort(reverse=True)\n Red.remove((C[0][1],C[0][0]))\nprint(ans)", "import collections, itertools\n\n\nclass MaximumFlow:\n def __init__(self, G):\n self.G = G\n\n def ford_fulkerson(self, s, t):\n def dfs(start, used):\n G = self.G\n if start == t:\n return [start]\n for end, cap in list(G[start].items()):\n if cap > 0 and end not in used:\n used.add(end)\n ret = dfs(end, used)\n if ret:\n return ret + [start]\n return []\n\n fmax = 0\n cnt = 0\n while True:\n G = self.G\n cnt += 1\n root = dfs(s, set([s]))\n if root:\n root = root[::-1]\n residue = min([G[a][b] for a, b in zip(root, root[1:])])\n fmax += residue\n for a, b in zip(root, root[1:]):\n G[a][b] -= residue\n G[b][a] += residue\n else:\n return (fmax, G)\n\n\nN = int(input())\nAB = [[int(_) for _ in input().split()] for _ in range(N)]\nCD = [[int(_) for _ in input().split()] for _ in range(N)]\nG = collections.defaultdict(lambda: collections.defaultdict(int))\nfor a, b in AB:\n G[-1][1000 * a + b] = 1\nfor c, d in CD:\n G[1000 * c + d][-2] = 1\nfor ab, cd in itertools.product(AB, CD):\n a, b = ab\n c, d = cd\n if a < c and b < d:\n G[1000 * a + b][1000 * c + d] = 1\nflow = MaximumFlow(G)\nfmax, Gres = flow.ford_fulkerson(-1, -2)\nprint(fmax)\n", "#\n# abc091 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\nimport bisect\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\"\"\"\n output = \"\"\"2\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5\"\"\"\n output = \"\"\"2\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"2\n2 2\n3 3\n0 0\n1 1\"\"\"\n output = \"\"\"0\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7\"\"\"\n output = \"\"\"5\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_5(self):\n input = \"\"\"5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9\"\"\"\n output = \"\"\"4\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N = int(input())\n AB = [list(map(int, input().split())) for _ in range(N)]\n CD = [list(map(int, input().split())) for _ in range(N)]\n\n AB.sort(reverse=True)\n CD.sort()\n\n ans = 0\n for ab in AB:\n a, b = ab\n ok = len(CD)\n ng = -1\n while abs(ok-ng) > 1:\n mid = (ok+ng)//2\n\n if CD[mid][0] >= a:\n ok = mid\n else:\n ng = mid\n\n if ok == len(CD):\n continue\n\n NCD = CD[ok:]\n NCD.sort(key=lambda x: x[1])\n ok = len(NCD)\n ng = -1\n while abs(ok-ng) > 1:\n mid = (ok+ng)//2\n\n if NCD[mid][1] >= b:\n ok = mid\n else:\n ng = mid\n\n if ok == len(NCD):\n continue\n else:\n ans += 1\n CD.remove(NCD[ok])\n\n print(ans)\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "n = int(input())\nred = [tuple(map(int, input().split())) for _ in range(n)]\nblue = [tuple(map(int, input().split())) for _ in range(n)]\n\nred.sort(key=lambda x:x[1])\nblue.sort()\n\ncount = 0\nfor xb, yb in blue:\n max_y = -1\n max_i = -1\n for i in range(n):\n xr, yr = red[i]\n if xb > xr and yb > yr and max_y < yr:\n max_y, max_i = yr, i\n if max_y >= 0:\n red[max_i] = (201, 201)\n count += 1\nprint(count)\n\n\n", "n=int(input())\nR=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])\nB=sorted([list(map(int,input().split())) for i in range(n)])\nans=0\nfor c,d in B:\n for a,b in R:\n if a<c and b<d:\n R.remove([a,b]);ans+=1\n break\nprint(ans)", "import collections, itertools, copy\n\n\nclass MaximumFlow:\n def ford_fulkerson(self, G, s, t):\n G_residue = copy.deepcopy(G)\n\n def dfs(start, used):\n if start == t:\n return [start]\n for end, cap in list(G_residue[start].items()):\n if cap > 0 and end not in used:\n used.add(end)\n ret = dfs(end, used)\n if ret:\n return ret + [start]\n return []\n\n flow_value = 0\n while True:\n root = dfs(s, set([s]))\n if root:\n root = root[::-1]\n residue = min(\n [G_residue[a][b] for a, b in zip(root, root[1:])])\n flow_value += residue\n for a, b in zip(root, root[1:]):\n G_residue[a][b] -= residue\n G_residue[b][a] += residue\n else:\n return (flow_value, G_residue)\n\n\nN = int(input())\nAB = [[int(_) for _ in input().split()] for _ in range(N)]\nCD = [[int(_) for _ in input().split()] for _ in range(N)]\nG = collections.defaultdict(lambda: collections.defaultdict(int))\nfor a, b in AB:\n G[-1][1000 * a + b] = 1\nfor c, d in CD:\n G[1000 * c + d][-2] = 1\nfor ab, cd in itertools.product(AB, CD):\n a, b = ab\n c, d = cd\n if a < c and b < d:\n G[1000 * a + b][1000 * c + d] = 1\nflow_value, G_residue = MaximumFlow().ford_fulkerson(G, -1, -2)\nprint(flow_value)\nflow_dict = collections.defaultdict(lambda: collections.defaultdict(int))\nfor a in G:\n for b in G[a]:\n if G_residue[b][a] > 0:\n flow_dict[a][b] = G_residue[b][a]\n", "n=int(input())\nrs=[list(map(int,input().split())) for _ in range(n)]\nbs=[list(map(int,input().split())) for _ in range(n)]\nrs.sort(key=lambda x:x[1],reverse=True)\nbs.sort()\nans=0\nfor c,d in bs:\n for a,b in rs:\n if a<c and b<d:\n ans+=1\n rs.remove([a,b])\n break\nprint(ans)\n", "N = int(input())\nR = [[0, 0] for _ in range(N)]\nB = [[0, 0] for _ in range(N)]\nMap = [['.' for __ in range(2*N)] for _ in range(2*N)]\nfor i in range(N):\n R[i][1], R[i][0] = map(int, input().split())\n Map[R[i][1]][R[i][0]] = 'R'\nfor i in range(N):\n B[i][0], B[i][1] = map(int, input().split())\n Map[B[i][0]][B[i][1]] = 'B'\nR.sort(reverse=True)\nB.sort()\nRF = [True for _ in range(N)]\nBF = [True for _ in range(N)]\ncnt = 0\nfor i in range(N):\n for j in range(N):\n if BF[j] == True:\n if R[i][1] < B[j][0] and R[i][0] < B[j][1]:\n cnt += 1\n RF[i] = False\n BF[j] = False\n break\nprint(cnt)", "n = int(input())\na = [list(map(int, input().split())) for _ in range(n)]\nb = [list(map(int, input().split())) for _ in range(n)]\nx = []\nfor i,j in a:\n x.append((i,j,1))\nfor i,j in b:\n x.append((i,j,2))\nx.sort()\n#print(x)\nfor i in range(2*n):\n x[i] = (x[i][1],x[i][2])\n#print(x)\nans = 0\nwhile len(x):\n maxindex = 0\n maxvalue = -1\n flag = 0\n for i in range(len(x)):\n if x[i][0]>maxvalue and x[i][1]==1:\n flag = 1\n maxvalue = x[i][0]\n maxindex = i\n if flag == 0:\n break\n #if (x[maxindex][1]==1):\n #x.pop(i)\n #else:\n #maxindex2 = 0\n #maxvalue2 = -1\n flag = 0\n for i in range(maxindex+1,len(x)):\n if (x[i][1]==2):\n if (x[i][0]>maxvalue):\n ans += 1\n x.pop(i)\n x.pop(maxindex)\n flag=1\n break\n if (flag==0):\n x.pop(maxindex)\nprint(ans)", "n = int(input())\nab = [tuple(map(int, input().split())) for _ in range(n)]\ncd = [tuple(map(int, input().split())) for _ in range(n)]\nab.sort(key=lambda x: (-x[1], x[0]))\ncd.sort(key=lambda x: (x[0], x[1]))\ns = [0] * n\n\nfor i in range(n):\n for j in range(n):\n if s[j] == 0 and ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:\n s[j] = 1\n break\nprint((sum(s)))\n", "def c_2d_plane_2n_points_bipartite_graph():\n import networkx as nx\n from networkx.algorithms.flow import dinitz\n N = int(input())\n Red_point_pos = [[int(i) for i in input().split()] for j in range(N)]\n Blue_point_pos = [[int(i) for i in input().split()] for j in range(N)]\n\n # 1 \u304b\u3089 N \u756a\u3092\u8d64\u3044\u70b9\u306b\u5272\u308a\u5f53\u3066\uff0cN+1 \u756a\u304b\u3089 2N \u756a\u3092\u9752\u3044\u70b9\u306b\u5272\u308a\u5f53\u3066\u308b\n # \u30bd\u30fc\u30b9\u3092 0 \u756a\u3068\u3057\uff0c\u30b7\u30f3\u30af\u3092 2N+1 \u756a\u3068\u3059\u308b\n graph = nx.DiGraph()\n graph.add_nodes_from(range(2 * N + 2))\n for i in range(N):\n for j in range(N):\n a, b = Red_point_pos[i]\n c, d = Blue_point_pos[j]\n if a < c and b < d: # i \u756a\u306e\u8d64\u3044\u70b9\u3068 j \u756a\u306e\u9752\u3044\u70b9\u306f\u30da\u30a2\u306b\u3067\u304d\u3046\u308b\n graph.add_edge(i + 1, j + N + 1, capacity=1)\n for i in range(1, N + 1):\n graph.add_edge(0, i, capacity=1)\n for j in range(N + 1, 2 * N + 1):\n graph.add_edge(j, 2 * N + 1, capacity=1)\n return dinitz(graph, 0, 2 * N + 1).graph['flow_value']\n\nprint(c_2d_plane_2n_points_bipartite_graph())", "import sys\nmod=10**9+7 ; inf=float(\"inf\")\nfrom math import sqrt, ceil\nfrom collections import deque, Counter, defaultdict #\u3059\u3079\u3066\u306ekey\u304c\u7528\u610f\u3055\u308c\u3066\u308b defaultdict(int)\u3067\u521d\u671f\u5316\ninput=lambda: sys.stdin.readline().strip()\nsys.setrecursionlimit(11451419)\nfrom decimal import ROUND_HALF_UP,Decimal #\u5909\u63db\u5f8c\u306e\u672b\u5c3e\u6841\u30920\u30840.01\u3067\u6307\u5b9a\n #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))\nfrom functools import lru_cache\nfrom bisect import bisect_left as bileft, bisect_right as biright\n#\u30e1\u30e2\u5316\u518d\u5e30def\u306e\u5192\u982d\u306b\u6bce\u56de @lru_cache(maxsize=10**10)\n#\u5f15\u6570\u306blist\u306f\u3060\u3081\n#######\u3053\u3053\u307e\u3067\u30c6\u30f3\u30d7\u30ec#######\n#\u30bd\u30fc\u30c8\u3001\"a\"+\"b\"\u3001\u518d\u5e30\u306a\u3089Python3\u306e\u65b9\u304c\u3044\u3044\n#######\u3053\u3053\u304b\u3089\u5929\u3077\u3089########\nfrom collections import deque\nclass Dinic:\n def __init__(self, N):\n self.N= N\n self.G = [[] for i in range(N)]\n def add_edge(self,fr,to,cap=1): #\u3064\u306a\u3050\u30ce\u30fc\u30c92\u3064\u3001\u5bb9\u91cf\n forward=[to, cap, None]\n forward[2] = backward = [fr, 0, forward]\n self.G[fr].append(forward)\n self.G[to].append(backward)\n\n def add_multi_edge(self, v1, v2, cap1, cap2):\n edge1 = [v2, cap1, None]\n edge1[2] = edge2 = [v1, cap2, edge1]\n self.G[v1].append(edge1)\n self.G[v2].append(edge2)\n\n def bfs(self, s, t):\n self.level = level = [None]*self.N\n deq = deque([s])\n level[s] = 0\n G = self.G\n while deq:\n v = deq.popleft()\n lv = level[v] + 1\n for w, cap, _ in G[v]:\n if cap and level[w] is None:\n level[w] = lv\n deq.append(w)\n return level[t] is not None\n\n def dfs(self, v, t, f):\n if v == t:\n return f\n level = self.level\n for e in self.it[v]:\n w, cap, rev = e\n if cap and level[v] < level[w]:\n d = self.dfs(w, t, min(f, cap))\n if d:\n e[1] -= d\n rev[1] += d\n return d\n return 0\n\n def flow(self, s, t):\n flow = 0\n INF = inf\n G = self.G\n while self.bfs(s, t):\n *self.it, = map(iter, self.G)\n f = INF\n while f:\n f = self.dfs(s, t, INF)\n flow += f\n return flow\nn=int(input())\ndinic=Dinic(2*n+2)\n\n\nA=[] ; B=[]\nfor i in range(n):\n a,b=map(int,input().split())\n A.append([a,b])\nfor i in range(n):\n a,b=map(int,input().split())\n B.append([a,b])\nfor i in range(n):\n dinic.add_edge(2*n,i,1)\n dinic.add_edge(i+n, 2*n+1,1)\nfor i in range(n):\n for j in range(n):\n if A[i][0]<B[j][0] and A[i][1]<B[j][1]:\n dinic.add_edge(i,j+n)\n\nprint(dinic.flow(2*n,2*n+1))", "from operator import itemgetter\nN=int(input())\nR=[list(map(int,input().split())) for n in range(N)]\nB=[list(map(int,input().split())) for n in range(N)]\nR.sort(key=itemgetter(1),reverse=True)\nB.sort()\nans=0\n\nfor c,d in B :\n for a,b in R :\n if a<c and b<d :\n ans+=1\n R.remove([a,b])\n break\n\nprint(ans)", "def abc091_c():\n n = int(input())\n red = []\n blue = []\n for _ in range(n):\n a, b = (int(x) for x in input().split())\n red.append((a, b))\n for _ in range(n):\n c, d = (int(x) for x in input().split())\n blue.append((c, d))\n blue = sorted(blue, key=lambda x: x[0])\n\n ans = 0\n r_used = [False]*n\n for c, d in blue:\n match = -1\n y_high = -1\n for i, (a, b) in enumerate(red):\n if r_used[i]: continue\n if not (a < c and b < d): continue\n if y_high < b:\n match = i\n y_high = b\n if match != -1:\n ans += 1\n r_used[match] = True\n print(ans)\n\ndef __starting_point():\n abc091_c()\n__starting_point()", "N = int(input())\nred = [list(map(int, input().split())) for _ in range(N)]\nblue = [list(map(int, input().split())) for _ in range(N)]\nblue = sorted(blue, key=lambda x: x[0])\n\nused = []\nfor i in range(N):\n c, d = blue[i]\n m, tmp = -1, -1\n for j in range(N):\n if j in used:\n continue\n a, b = red[j]\n if a < c and b < d:\n if b > m:\n m = b\n tmp = j\n if tmp != -1:\n used.append(tmp)\nprint((len(used)))\n", "import sys\nINF = 1 << 60\nMOD = 10**9 + 7 # 998244353\nsys.setrecursionlimit(2147483647)\ninput = lambda:sys.stdin.readline().rstrip()\nimport networkx as nx\ndef resolve():\n n = int(input())\n A = [tuple(map(int, input().split())) for _ in range(n)]\n B = [tuple(map(int, input().split())) for _ in range(n)]\n G = nx.Graph()\n G.add_nodes_from(range(n))\n G.add_nodes_from(range(n, 2 * n))\n for i in range(n):\n ax, ay = A[i]\n for j in range(n):\n bx, by = B[j]\n if ax < bx and ay < by:\n G.add_edge(i, n + j)\n\n A = nx.algorithms.bipartite.matching.hopcroft_karp_matching(G, top_nodes = range(n))\n print(len(A) // 2)\nresolve()", "import sys\ndef input(): return sys.stdin.readline().strip()\ndef mapint(): return map(int, input().split())\nsys.setrecursionlimit(10**9)\n\nfrom bisect import bisect_right\nN = int(input())\nab = [list(mapint()) for _ in range(N)]\ncd = [list(mapint()) for _ in range(N)]\nab.sort(reverse=True)\ncd.sort(key=lambda x: x[1])\nchecked = [0]*N\n\nans = 0\nfor n in range(N):\n a, b = ab[n]\n for i in range(N):\n if checked[i]:\n continue\n c, d = cd[i]\n if a<c and b<d:\n ans += 1\n checked[i] = 1\n break\n\nprint(ans)", "n = int(input())\nab=[]\nfor i in range(n):\n ab.append(list(map(int, input().split())))\nab = sorted(ab, key=lambda x:x[1], reverse=True)\n\ncd=[]\nfor i in range(n):\n cd.append(list(map(int, input().split())))\ncd = sorted(cd, key=lambda x:x[0])\n# print(ab, flush=True)\n# print(cd, flush=True)\n\n\nans = 0\nfor i in cd:\n for ji, j in enumerate(ab):\n if i[0]>j[0] and i[1]>j[1]:\n # print(i, j, flush=True)\n ans+=1\n ab.pop(ji)\n break;\nprint(ans, flush=True)\n\n", "import operator\nimport bisect\n\nn=int(input())\nred=[tuple(map(int,input().split())) for _ in range(n)]\nblue=[tuple(map(int,input().split())) for _ in range(n)]\n\nred.sort(key=operator.itemgetter(0,1))\nblue.sort(key=operator.itemgetter(0,1))\n#print(red)\n#print(blue)\ncount=0\nfor i in range(n):\n for j in reversed(list(range(len(red)))):\n #print(\"j\",j)\n if not red:\n break\n if red[j][0]<blue[i][0]:\n tmp=red[:j+1]\n tmp.sort(key=lambda x:x[1],reverse=True)\n for t in tmp:\n if t[1]<blue[i][1]:\n count+=1\n red.pop(red.index(t))\n #print(\"t\",t,\"blue[i]\",blue[i])\n break\n else:\n continue\n break\n\nprint(count)\n", "import sys\nsys.setrecursionlimit(10**8)\ndef ii(): return int(sys.stdin.readline())\ndef mi(): return map(int, sys.stdin.readline().split())\ndef li(): return list(map(int, sys.stdin.readline().split()))\ndef li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]\ndef dp2(ini, i, j): return [[ini]*i for _ in range(j)]\n#import bisect #bisect.bisect_left(B, a)\n#from collections import defaultdict #d = defaultdict(int) d[key] += value\n#from collections import Counter # a = Counter(A).most_common()\n#from itertools import accumulate #list(accumulate(A))\n\nN = ii()\nA = li2(N)\nB = li2(N)\n\nA = sorted(A, key=lambda x:x[1])\nB = sorted(B, key=lambda x:x[0])\n\nflag = [0] * N\n\nfor i in range(N):\n ind = -1\n for j in range(N):\n if A[j][1] < B[i][1]:\n ind = j\n while ind >= 0:\n if not flag[ind] and A[ind][0] < B[i][0]:\n flag[ind] = 1\n break\n ind -= 1\n\n#print(flag)\nprint(sum(flag))", "import bisect\nN = int(input())\nR = [tuple(map(int,input().split())) for i in range(N)]\nB = [tuple(map(int,input().split())) for i in range(N)]\n\n#\u30bd\u30fc\u30c8\u3057\u3066R<B\u3068\u306a\u308b\u70b9\u3092Greedy\u3067\u63a2\u7d22\nR.sort()\nB.sort()\ni=0\nans=0\nred_y = []\nfor b_x,b_y in B:\n #b_x\u3088\u308ax\u304c\u5c0f\u3055\u3044R\u3092\u3059\u3079\u3066red_y\u306b\u8ffd\u52a0\n while i<N and R[i][0]<b_x:\n bisect.insort_right(red_y,R[i][1])\n i+=1\n #r_x<b_x,r_y<b_y\u3092\u6e80\u305f\u3059\u70b9\u304c\u3042\u308c\u3070\u30ab\u30a6\u30f3\u30c8\n if red_y and red_y[0]<b_y:\n idx = bisect.bisect_right(red_y,b_y)-1\n ans+=1\n red_y.pop(idx)\nprint(ans)", "n = int(input())\nAB = list(list(map(int,input().split())) for _ in range(n))\nCD = list(list(map(int,input().split())) for _ in range(n))\n\nCD.sort() # sort x in ascending order\nAB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order\n\ndim_b = [[] for _ in range(n)]\nfor b in range(n):\n bx, by = CD[b]\n for r in range(n):\n rx, ry = AB[r]\n if rx < bx and ry < by: dim_b[b] += [r]\n\nvis_r = [False]*(n)\nfor b in range(n): # ascending order of x\n max_ry = max_r = -1\n for r in dim_b[b]: # descending order of y\n if vis_r[r]: continue\n rx, ry = AB[r]\n if max_ry < ry:\n max_ry = ry\n max_r = r\n if max_r >= 0: vis_r[max_r] = True\nprint((sum(vis_r)))\n", "from collections import deque\nN=int(input())\nstart = 0\nend = 2*N+1\n\nR = {}\nB = {}\nad_matrix = [[0]*(2*N+2) for i in range(2*N+2)]\nad_dict = {}\nad_dict[start]=[]\nad_dict[end]=[]\nfor n in range(N):\n R[n+1] = (list(map(int,input().split())))\n ad_dict[n+1]=[]\n \nfor n in range(N):\n B[N+n+1] = (list(map(int,input().split())))\n ad_dict[N+n+1]=[]\n\n# \u96a3\u63a5\u884c\u5217\u3092\u4f5c\u6210(ad_matrix[start][end] = 1\uff1a\u63a5\u7d9a)\nfor r_ in R.keys():\n ad_dict[start].append(r_)\n ad_dict[r_].append(start)\nfor b_ in B.keys():\n ad_dict[end].append(b_)\n ad_dict[b_].append(end)\n\nfor r_ in R.keys():\n ad_matrix[start][r_] = 1\n \n r = R[r_]\n for b_ in B.keys():\n ad_matrix[b_][end] = 1\n\n b = B[b_]\n \n if r[0] < b[0] and r[1] < b[1]:\n ad_matrix[r_][b_] = 1\n ad_dict[r_].append(b_)\n\nans = 0\nwhile True:\n start = 0\n end = 2*N+1\n\n color = {}\n for n in range(end+1):\n color[n] = -1\n\n visit = deque([start])\n color[start] = 0\n\n while visit:\n start = visit[-1]\n for v in ad_dict[start]:\n if color[v] == -1:\n visit.append(v)\n color[v] = 0\n break\n else:\n visit.pop()\n color[start] = 1\n\n# print(visit,color)\n\n if color[end] == 0:\n #\u30b3\u30b9\u30c8\u306e\u66f4\u65b0\n visit = list(visit)\n flow = 10**10\n for d1,d2 in zip(visit[:-1],visit[1:]):\n flow = min(flow,ad_matrix[d1][d2])\n\n for d1,d2 in zip(visit[:-1],visit[1:]):\n ad_matrix[d1][d2] -= flow\n ad_matrix[d2][d1] += flow\n if ad_matrix[d1][d2] <= 0:\n ad_dict[d1].remove(d2)\n ad_dict[d2].append(d1)\n break\n# print(visit)\n if not visit:\n break\n ans += 1\nprint(ans)", "n = int(input())\nAB = list(list(map(int,input().split())) for _ in range(n))\nCD = list(list(map(int,input().split())) for _ in range(n))\n\n# print(*CD,sep='\\n',end='\\n---\\n')\n# print(*sorted(CD, key=lambda x: x[0]),sep='\\n',end='\\n---\\n')\n# CD.sort(key=lambda x: x[1])\n# CD.sort(key=lambda x: x[0])\nCD.sort()\n# print(*CD,sep='\\n',end='\\n---\\n')\n# print(*AB,sep='\\n',end='\\n---\\n')\nAB.sort(key=lambda x: x[1], reverse=True)\n# print(*AB,sep='\\n',end='\\n---\\n')\n\ndim_r = [[] for _ in range(n)]\ndim_b = [[] for _ in range(n)]\n# cnt_r = [0]*n\n# cnt_b = [0]*n\nfor b in range(n):\n bx, by = CD[b]\n for r in range(n):\n rx, ry = AB[r]\n if rx < bx and ry < by:\n dim_r[r] += [b]\n dim_b[b] += [r]\n # cnt_b[b] += 1\n # cnt_r[r] += 1\n\n# print(n)\n# print(*AB,sep='\\n',end='\\n---\\n')\n# print(*CD,sep='\\n',end='\\n---\\n')\n# print(*dim_r,sep='\\n',end='\\n---\\n')\n# print(*dim_b,sep='\\n',end='\\n---\\n')\n# # print(cnt_b,end='\\n---\\n')\n\nans = 0\n\ninf = 1000000000\nvis_r = [False]*(n)\nfor b in range(n):\n bx, by = CD[b]\n # print('b,bx,by',b,bx,by)\n max_ry = -1\n max_r = -1\n for r in dim_b[b]:\n if vis_r[r]: continue\n # print('r,rx,ry',r,rx,ry)\n rx, ry = AB[r]\n if max_ry < ry:\n max_ry = ry\n max_r = r\n if max_r >= 0:\n # print('max_r,max_ry',max_r,max_ry)\n vis_r[max_r] = True\n ans += 1\n # print('---')\nprint(ans)\n", "N=int(input())\na=[list(map(int,input().split())) for _ in range(N)]\nc=[list(map(int,input().split())) for _ in range(N)]\nX=[(q,w,0) for q,w in a]+[(e,r,1) for e,r in c]\nX.sort()\nans=0\ndp=[0]*(2*N)\nfor x,y,z in X:\n if z==0:\n dp[y]+=1\n else:\n for v in range(y-1,-1,-1):\n if dp[v]>0:\n ans+=1\n dp[v]-=1\n break\nprint(ans)", "import sys\nfrom collections import deque\ninput = sys.stdin.readline\n\nclass Dinic:\n def __init__(self, v):\n self.vertice = v\n self.inf = int(1e9)\n self.graph = [[] for i in range(v)]\n self.level = [0]*v\n self.iter = [0]*v\n \n def add_edge(self, fr, to, cap):\n self.graph[fr].append([to, cap, len(self.graph[to])])\n self.graph[to].append([fr, 0, len(self.graph[fr])-1])\n \n def bfs(self, s):\n self.level = [-1]*self.vertice\n que = deque([])\n self.level[s] = 0\n que.append(s)\n\n while que:\n v = que.popleft()\n for i in range(len(self.graph[v])):\n e = self.graph[v][i]\n if e[1] > 0 and self.level[e[0]] < 0:\n self.level[e[0]] = self.level[v] + 1\n que.append(e[0])\n \n def dfs(self, v, t, f):\n if v == t:\n return f\n for i in range(self.iter[v], len(self.graph[v])):\n self.iter[v] = i\n e = self.graph[v][i]\n if e[1] > 0 and self.level[v] < self.level[e[0]]:\n d = self.dfs(e[0], t, min(f, e[1]))\n if d > 0:\n e[1] -= d\n self.graph[e[0]][e[2]][1] += d\n return d\n return 0\n \n def max_flow(self, s, t):\n flow = 0\n while True:\n self.bfs(s)\n if self.level[t] < 0:\n return flow\n self.iter = [0]*self.vertice\n\n f = self.dfs(s, t, self.inf)\n while f:\n flow += f\n f = self.dfs(s, t, self.inf)\n \ndef main():\n n = int(input())\n red = [list(map(int, input().split())) for _ in range(n)]\n blue = [list(map(int, input().split())) for _ in range(n)]\n \n flow = Dinic(n*2+2)\n for i in range(n):\n flow.add_edge(0, i+1, 1)\n flow.add_edge(n+i+1, 2*n+1, 1)\n for j in range(n):\n if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:\n flow.add_edge(i+1, n+j+1, 1)\n \n \n ans = flow.max_flow(0, 2*n+1)\n print(ans)\n \ndef __starting_point():\n main()\n__starting_point()", "N=int(input())\nred=[]\nblue=[]\nfor _ in range(N):\n a,b = map(int,input().split())\n red.append((a,b))\nfor _ in range(N):\n c,d = map(int,input().split())\n blue.append((c,d))\n\nblue.sort(key=lambda x:x[0])\nfor bx, by in blue:\n c = None\n for rx, ry in red:\n if rx < bx and ry < by:\n if c is None or c[1] < ry:\n c = (rx, ry)\n if c:\n red.remove(c)\n\nprint(N-len(red))", "def main():\n n = int(input())\n R, B = [], []\n for i in range(n):\n R.append(list(map(int, input().split())) + [0, i])\n for _ in range(n):\n B.append(list(map(int, input().split())))\n B.sort(key = lambda x: x[0])\n ans = 0\n for b in B:\n f = list([x for x in R if x[0] < b[0] and x[1] < b[1] and x[2] == 0])\n if len(f) != 0:\n f.sort(key = lambda x: x[1], reverse = True)\n p = f[0]\n ans += 1\n R[p[3]][2] = 1\n print(ans) \n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nab = [list(map(int, input().split())) for _ in range(n)]\ncd = [list(map(int, input().split())) for _ in range(n)]\n\ng = [[0 for _ in range(2*n+2)] for _ in range(2*n+2)]\n\nfor (i, (a, b)) in enumerate(ab):\n fr = i+2\n g[0][fr] = 1\n for (j, (c, d)) in enumerate(cd):\n to = n+j+2\n g[to][1] = 1\n if a < c and b < d:\n g[fr][to] = 1\n\nused = [False for _ in range(2 * n + 2)]\npath = []\ngoal = 1\nflow = [[0 for _ in range(2*n+2)] for _ in range(2*n+2)]\n\n\ndef bfs(v):\n used[v] = True\n for next in range(2 * n + 2):\n if g[v][next] == 0 or used[next]:\n pass\n elif next == goal:\n path.append(v)\n return True\n elif bfs(next):\n path.append(v)\n return True\n return False\n\n\nans = 0\nwhile bfs(0):\n path.reverse()\n path.append(1)\n for i in range(len(path) - 1):\n g[path[i]][path[i + 1]] -= 1\n g[path[i + 1]][path[i]] += 1\n used = [False for _ in range(2 * n + 2)]\n path = []\n ans += 1\nprint(ans)\n", "n=int(input())\nred=[[] for i in range(n)]\nblue=[[] for i in range(n)]\nfor i in range(n):\n a,b=list(map(int,input().split()))\n red[i].append(a)\n red[i].append(b)\nfor i in range(n):\n a,b=list(map(int,input().split()))\n blue[i].append(a)\n blue[i].append(b)\nred=sorted(red)\nblue=sorted(blue)\nans=0\nfor i in range(n):\n x=blue[i][0]\n y=blue[i][1]\n maxy=-1\n for j in range(n):\n if x>red[j][0] and y>red[j][1]:\n maxy=max(maxy,red[j][1])\n for j in range(n):\n if x>red[j][0] and maxy==red[j][1]:\n ans+=1\n red[j][0]=1000\n break\nprint(ans)\n", "def resolve():\n import sys\n \n readline = sys.stdin.readline # 1\u884c\u3060\u3051\u6587\u5b57\u5217\u306b\u3059\u308b\n\n N = int(readline())\n\n # \u8d64\uff0c\u9752\u70b9\u3092x,y\u5ea7\u6a19\u306e2\u6b21\u5143\u30ea\u30b9\u30c8\u3068\u3057\u3066\u5165\u529b\n red = [list(map(int, readline().split())) for _ in [0] * N]\n blue = [list(map(int, readline().split())) for _ in [0] * N]\n\n # \u8d64\u306fy\u5ea7\u6a19\u3067\u964d\u9806\u30bd\u30fc\u30c8\uff0c\u9752\u306fx\u5ea7\u6a19\u3067\u6607\u9806\u30bd\u30fc\u30c8\n red.sort(key=lambda x: x[1], reverse=True)\n blue.sort()\n\n ans = 0\n for c, d in blue:\n for a, b in red:\n if a <= c and b <= d:\n ans += 1\n red.remove([a, b])\n break\n print(ans)\n\n\nresolve()\n", "import networkx as nx\n\nn = int(input())\ngraph = nx.DiGraph()\nAB = [list(map(int, input().split())) for _ in range(n)]\nCD = [list(map(int, input().split())) for _ in range(n)]\n\nstart = 10 ** 4\ngoal = 10 ** 4 + 1\nfor i in range(n):\n a, b = AB[i]\n graph.add_edge(start, i, weight=0, capacity=1)\n for j in range(n):\n c, d = CD[j]\n graph.add_edge(200 + j, goal, weight=0, capacity=1)\n if c > a and d > b:\n graph.add_edge(i, 200 + j, weight=0, capacity=1)\n\nans = nx.maximum_flow(graph, start, goal, capacity=\"capacity\")\nprint((ans[0]))\n\n", "n = int(input())\nAB = list(list(map(int,input().split())) for _ in range(n))\nCD = list(list(map(int,input().split())) for _ in range(n))\n\nCD.sort() # sort x in ascending order\nAB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order\n\ndim_b = [[] for _ in range(n)]\nfor b in range(n):\n for r in range(n):\n if AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:\n dim_b[b] += [r]\n\nvis_r = [False]*(n)\nfor b in range(n): # ascending order of x\n max_ry = max_r = -1\n for r in dim_b[b]: # descending order of y\n if vis_r[r]: continue\n if max_ry < AB[r][1]: max_ry = AB[r][1]; max_r = r\n if max_r >= 0: vis_r[max_r] = True\nprint((sum(vis_r)))\n", "ma = lambda :map(int,input().split())\nlma = lambda :list(map(int,input().split()))\ntma = lambda :tuple(map(int,input().split()))\nni = lambda:int(input())\nyn = lambda fl:print(\"YES\") if fl else print(\"NO\")\nimport collections\nimport math\nimport itertools\nimport heapq as hq\nn = ni()\nab = []\nfor i in range(n):\n ab.append(lma())\nab.sort(key=lambda x:x[1],reverse=True)\nab.sort(reverse=True)\ncd = []\nfor i in range(n):\n cd.append(lma())\ncd.sort()\ncd.sort(key=lambda x:x[1])\ncnt=0\nINF=10**9\nfor a,b in ab:\n #print(\"ab\",a,b)\n for i in range(n):\n c,d = cd[i]\n if a<c and b<d:\n #print(\"cd\",c,d)\n cnt+=1\n cd[i][0]=-INF\n cd[i][1]=-INF\n break\nprint(cnt)\n#print(cd)\n", "def c_2d_plane_2n_points_bipartite_graph():\n import networkx as nx\n from networkx.algorithms.flow import dinitz\n N = int(input())\n A, B, C, D = [], [], [], []\n for _ in range(N):\n a, b = [int(i) for i in input().split()]\n A.append(a)\n B.append(b)\n for _ in range(N):\n c, d = [int(i) for i in input().split()]\n C.append(c)\n D.append(d)\n\n # \u8d64\u3044\u70b9\u306e\u756a\u53f7\u306f 1~N \u3068\u3057\uff0c\u9752\u3044\u70b9\u306e\u756a\u53f7\u306f N+1~2N \u3068\u3059\u308b\n # \u30bd\u30fc\u30b9\u3092 0 \u756a\u3068\u3057\uff0c\u30b7\u30f3\u30af\u3092 2N+1 \u756a\u3068\u3059\u308b\n graph = nx.DiGraph()\n graph.add_nodes_from(range(2 * N + 2))\n for i in range(N):\n for j in range(N):\n if A[i] < C[j] and B[i] < D[j]:\n graph.add_edge(i + 1, j + N + 1, capacity=1)\n for i in range(1, N + 1):\n graph.add_edge(0, i, capacity=1)\n for j in range(N + 1, 2 * N + 1):\n graph.add_edge(j, 2 * N + 1, capacity=1)\n\n return dinitz(graph, 0, 2 * N + 1).graph['flow_value']\n\nprint(c_2d_plane_2n_points_bipartite_graph())", "N = int(input())\n\nreds = []\nfor i in range(N):\n a, b = list(map(int, input().split()))\n reds.append([a,b])\nreds.sort(key=lambda x: x[1], reverse=True)\n\nblues = []\nfor i in range(N):\n c, d = list(map(int, input().split()))\n blues.append([c,d])\nblues.sort()\n\nflag = [False for i in range(N)]\nans = 0\nfor i in range(N):\n c, d = blues[i][0], blues[i][1]\n for j in range(N):\n if flag[j] == True:\n continue\n a, b = reds[j][0], reds[j][1]\n if c>a and d>b:\n flag[j] = True\n ans += 1\n break\nprint(ans)\n", "N = int(input())\nab = [[int(i) for i in input().split()] for _ in range(N)]\ncd = [[int(i) for i in input().split()] for _ in range(N)]\n\nab.sort(key = lambda x: x[1], reverse=True)\ncd.sort()\n\nx = 0\nfor c, d in cd:\n for a, b in ab:\n if a < c and b < d:\n x += 1\n ab.remove([a, b])\n break\n\nprint(x)\n", "def main():\n n = int(input())\n red = []\n red_used = [[False for _ in range(2 * n)] for _ in range(2 * n)]\n for _ in range(n):\n rp = list(map(int, input().split()))\n red.append(rp)\n red_used[rp[0]][rp[1]] = True\n ans = 0\n red.sort(key=lambda x: x[1], reverse=True)\n blue = [list(map(int, input().split())) for _ in range(n)]\n blue.sort(key=lambda x: x[0])\n for bx, by in blue:\n for rx, ry in red:\n if rx < bx and ry < by and red_used[rx][ry]:\n red_used[rx][ry] = False\n ans += 1\n break\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nab = []\ncd = []\nfor i in range(n):\n ab.append(tuple(map(int,input().split())))\n\nfor g in range(n):\n cd.append(tuple(map(int,input().split())))\n\nab.sort(key=lambda x: x[1], reverse = True)\ncd.sort()\nused = [False]*n\n\nans = 0\nfor i in range(n):\n for g in range(n):\n if ab[i][0] < cd[g][0] and ab[i][1] < cd[g][1] and not used[g]:\n used[g] = True\n ans += 1\n break\nprint(ans)", "n = int(input())\nR = []\nfor i in range(n):\n a,b = list(map(int,input().split()))\n R.append((a,b))\nB = []\nfor i in range(n):\n c,d = list(map(int,input().split()))\n B.append((c,d))\n\nR.sort(reverse=True)#a\u3092x\u5ea7\u6a19\u3067\u30bd\u30fc\u30c8\nB.sort(key = lambda x:x[1])#b\u3092\uff59\u5ea7\u6a19\u3067\u30bd\u30fc\u30c8\nans = 0\nfor i in R:\n for j in range(len(B)):\n if i[0] < B[j][0] and i[1] < B[j][1]:\n ans += 1\n B.pop(j)\n break\n\nprint(ans)\n", "from operator import itemgetter\nn, *ABCD = map(int, open(0).read().split())\nAB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])])\nCD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])\n\nfor c, d in CD:\n t_AB = [(a, b) for a, b in AB if a < c and b < d]\n if t_AB:\n t_AB.sort(key=itemgetter(1))\n AB.remove(t_AB[-1])\nprint(n-len(AB))", "import networkx as nx\n\nN=int(input())\nab=[list(map(int,input().split())) for _ in range(N)]\nab=sorted(ab)\ncd=[list(map(int,input().split())) for _ in range(N)]\ncd=sorted(cd,reverse=True)\n\nG = nx.DiGraph()\nfor i in range(N):\n G.add_edge('x',i, capacity=1)\n for j in range(N):\n if i == 0:\n G.add_edge(N+j,'y', capacity=1)\n a,b=ab[i]\n c,d=cd[j]\n if a<c and b<d:\n G.add_edge(i,N+j, capacity=1)\n elif a>=c:break\n\nflow_value, flow_dict = nx.maximum_flow(G, 'x', 'y')\nprint(flow_value)", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N = int(readline())\n P = [0] * (2 * N)\n for i in range(N):\n a, b = list(map(int, readline().split()))\n P[i] = (a, b, 0)\n for i in range(N, 2 * N):\n c, d = list(map(int, readline().split()))\n P[i] = (c, d, 1)\n\n P.sort(reverse=True)\n\n vec = [0] * (2 * N + 1)\n ans = 0\n\n for x, y, p in P:\n if p == 0:\n for i in range(y + 1, 2 * N + 1):\n if vec[i] > 0:\n vec[i] -= 1\n ans += 1\n break\n else:\n vec[y] += 1\n\n print(ans)\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\naka = [[0 for i in range(2*n)] for j in range(2*n)]\nfor i in range(n):\n a, b = list(map(int,input().split()))\n aka[a][b] = 1\nao = [tuple(map(int,input().split())) for i in range(n)]\nao.sort()\nans = 0\nfor x , y in ao:\n flag = False\n for j in reversed(list(range(y))):\n if flag:\n break\n for i in reversed(list(range(x))):\n if aka[i][j] == 1:\n ans += 1\n aka[i][j] = 0\n flag = True\n break\nprint(ans)\n", "import collections, itertools, copy\n\n\nclass MaximumFlow:\n def __init__(self, G):\n self.G = G\n\n def ford_fulkerson(self, s, t):\n G = self.G\n G_residue = copy.deepcopy(G)\n\n def dfs(start, used):\n if start == t:\n return [start]\n for end, cap in list(G_residue[start].items()):\n if cap > 0 and end not in used:\n used.add(end)\n ret = dfs(end, used)\n if ret:\n return ret + [start]\n return []\n\n flow_value = 0\n while True:\n root = dfs(s, set([s]))\n if root:\n root = root[::-1]\n residue = min(\n [G_residue[a][b] for a, b in zip(root, root[1:])])\n flow_value += residue\n for a, b in zip(root, root[1:]):\n G_residue[a][b] -= residue\n G_residue[b][a] += residue\n else:\n flow_dict = collections.defaultdict(\n lambda: collections.defaultdict(int))\n for a in G:\n for b in G[a]:\n if G_residue[b][a] > 0:\n flow_dict[a][b] = G_residue[b][a]\n return (flow_value, flow_dict)\n\n\nN = int(input())\nAB = [[int(_) for _ in input().split()] for _ in range(N)]\nCD = [[int(_) for _ in input().split()] for _ in range(N)]\nG = collections.defaultdict(lambda: collections.defaultdict(int))\nfor a, b in AB:\n G[-1][1000 * a + b] = 1\nfor c, d in CD:\n G[1000 * c + d][-2] = 1\nfor ab, cd in itertools.product(AB, CD):\n a, b = ab\n c, d = cd\n if a < c and b < d:\n G[1000 * a + b][1000 * c + d] = 1\nflow_value, G_residue = MaximumFlow(G).ford_fulkerson(-1, -2)\nprint(flow_value)\n", "N = int(input())\nR = []\nB = []\nfor i in range(2 * N):\n a, b = list(map(int, input().split()))\n if i < N:\n R.append((a, b))\n else:\n B.append((a, b))\nB = sorted(B)\n\nans = 0\nchecked = set()\np = []\nfor b in B:\n x1, y1 = b\n tR = [(x2, y2) for x2, y2 in R if x2 < x1]\n tR = sorted(tR, key=lambda p: p[1], reverse=True)\n for x2, y2 in tR:\n if (x2, y2) in checked:\n continue\n if x1 > x2 and y1 > y2:\n ans += 1\n checked.add((x2, y2))\n p.append((b, (x2, y2)))\n break\nprint(ans)\n", "n = int(input())\nreds = sorted([list(map(int,input().split())) for i in range(n)],key=lambda reds: -reds[1])\nblues = sorted([list(map(int,input().split())) for i in range(n)])\n\nres = 0\n\nfor c,d in blues:\n for a,b in reds:\n if a<c and b<d:\n reds.remove([a,b])\n res+=1\n break\n \nprint(res)\n", "import sys\nINF = 1 << 60\nMOD = 10**9 + 7 # 998244353\nsys.setrecursionlimit(2147483647)\ninput = lambda:sys.stdin.readline().rstrip()\nfrom scipy.sparse import coo_matrix\nfrom scipy.sparse.csgraph import maximum_bipartite_matching\ndef resolve():\n n = int(input())\n A = [tuple(map(int, input().split())) for _ in range(n)]\n B = [tuple(map(int, input().split())) for _ in range(n)]\n\n weights = []\n rows = []\n columns = []\n for i in range(n):\n ax, ay = A[i]\n for j in range(n):\n bx, by = B[j]\n if ax < bx and ay < by:\n weights.append(1)\n rows.append(i)\n columns.append(j)\n\n graph = coo_matrix((weights, (rows, columns)), shape = (n, n))\n ans = sum(maximum_bipartite_matching(graph) >= 0)\n print(ans)\nresolve()", "from sys import stdin\ninput = stdin.readline\n\n\ndef main():\n N = int(input())\n R = [tuple(map(int, input().split())) for _ in range(N)]\n B = [tuple(map(int, input().split())) for _ in range(N)]\n\n num_friends = 0\n B.sort(key=lambda x: x[0])\n\n for ib, b in enumerate(B):\n bx, by = b[0], b[1]\n\n tmp_r = (-1, -1)\n\n for ir, r in enumerate(R):\n rx, ry = r[0], r[1]\n\n if rx < bx and \\\n ry < by and \\\n tmp_r[1] < ry:\n # b[0] - r[0] < tmp_b[0] - r[0] and \\\n # b[1] - r[1] < tmp_b[1] - r[1]:\n tmp_r = r\n\n if tmp_r == (-1, -1):\n continue\n num_friends += 1\n R.remove(tmp_r)\n\n print(num_friends)\n\n\nif(__name__ == '__main__'):\n main()", "N = int(input())\nab = [[int(i) for i in input().split()] for _ in range(N)]\ncd = [[int(i) for i in input().split()] for _ in range(N)]\n \nab.sort(key = lambda x: x[1], reverse=True)\ncd.sort()\n \nx = 0\nfor c, d in cd:\n for a, b in ab:\n if a < c and b < d:\n x += 1\n ab.remove([a, b])\n break\n \nprint(x)", "n = int(input())\nab = [list(map(int,input().split())) for i in range(n)]\ncd = [list(map(int,input().split())) for i in range(n)]\n\nab = sorted(ab, key=lambda x:(x[1], x[0]), reverse=True)\ncd = sorted(cd, key=lambda x:(x[0], x[1]))\n\ncnt = 0\ni = j = 0\nfree_ab = [True] * n\nwhile j < n:\n a, b = ab[i][0], ab[i][1]\n c, d = cd[j][0], cd[j][1]\n if a < c and b < d and free_ab[i]:\n cnt += 1\n free_ab[i] = False\n i = 0 \n j += 1\n continue\n elif j <= n-1 and i < n-1:\n i += 1\n elif j < n-1 and i == n-1:\n i = 0\n j += 1\n else:\n break\nprint(cnt)", "n = int(input())\nAB = list(list(map(int,input().split())) for _ in range(n))\nCD = list(list(map(int,input().split())) for _ in range(n))\n\nCD.sort() # sort x in ascending order\nAB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order\n\nvis_r = [False]*(n)\nfor b in range(n): # ascending order of x\n for r in range(n): # descending order of y\n if not vis_r[r] and AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:\n vis_r[r] = True; break\n\nprint((sum(vis_r)))\n", "import sys\nsys.setrecursionlimit(10**8)\ndef ii(): return int(sys.stdin.readline())\ndef mi(): return map(int, sys.stdin.readline().split())\ndef li(): return list(map(int, sys.stdin.readline().split()))\ndef li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]\ndef dp2(ini, i, j): return [[ini]*i for _ in range(j)]\n#import bisect #bisect.bisect_left(B, a)\n#from collections import defaultdict #d = defaultdict(int) d[key] += value\n#from collections import Counter # a = Counter(A).most_common()\n#from itertools import accumulate #list(accumulate(A))\n'''\nN = ii()\nA = li2(N)\nB = li2(N)\n\nA = sorted(A, key=lambda x:x[0])\nB = sorted(B, key=lambda x:x[0])\n\na_ind = 0\nb_ind = 0\ncnt = 0\n\nwhile b_ind < N:\n if A[a_ind][0] < B[b_ind][0] and A[a_ind][1] < B[b_ind][1]:\n cnt += 1\n a_ind += 1\n b_ind += 1\n else:\n b_ind += 1\n\nprint(cnt)\n'''\n'''\n#nonlocal ans\nans = 0\n\ndef dfs(a_ind, b_ind, cnt):\n if a_ind >= N or b_ind >= N:\n nonlocal ans\n ans = max(ans, cnt)\n return\n if A[a_ind][0] < B[b_ind][0] and A[a_ind][1] < B[b_ind][1]:\n dfs(a_ind+1, b_ind+1, cnt+1)\n else:\n dfs(a_ind+1, b_ind, cnt)\n dfs(a_ind, b_ind+1, cnt)\n dfs(a_ind+1, b_ind+1, cnt)\n\ndfs(0, 0, 0)\n\nprint(ans)\n'''\n\n# X\u3068Y\u306e\u4e8c\u90e8\u30b0\u30e9\u30d5\u306e\u6700\u5927\u30de\u30c3\u30c1\u30f3\u30b0 X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}\n# edges[x]: x\u3068\u3064\u306a\u304c\u308bY\u306e\u9802\u70b9\u306eset\n# matched[y]: y\u3068\u30de\u30c3\u30c1\u30f3\u30b0\u3055\u308c\u305fX\u306e\u9802\u70b9(\u66ab\u5b9a)\n\ndef dfs(v, visited):\n \"\"\"\n :param v: X\u5074\u306e\u672a\u30de\u30c3\u30c1\u30f3\u30b0\u306e\u9802\u70b9\u306e1\u3064\n :param visited: \u7a7a\u306eset\u3092\u6e21\u3059\uff08\u5916\u90e8\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\u6642\uff09\n :return: \u5897\u5927\u8def\u304c\u898b\u3064\u304b\u308c\u3070True\n \"\"\"\n for u in edges[v]:\n if u in visited:\n continue\n visited.add(u)\n if matched[u] == -1 or dfs(matched[u], visited):\n matched[u] = v\n return True\n return False\n \n \n# \u6a19\u6e96\u5165\u529b\u304b\u3089\u306e\u30b0\u30e9\u30d5\u8aad\u307f\u53d6\u308a\n#xn, yn, e = map(int, input().split())\nN = ii()\nxn = N\nyn = N\nedges = [set() for _ in range(xn)]\nmatched = [-1] * yn\n \n#for _ in range(e):\n #x, y = map(int, input().split())\n #edges[x].add(y)\n\nA = li2(N)\nB = li2(N)\n\nfor i in range(N):\n for j in range(N):\n if A[i][0] < B[j][0] and A[i][1] < B[j][1]:\n edges[i].add(j)\n \n# \u5897\u5927\u8def\u767a\u898b\u306b\u6210\u529f\u3057\u305f\u3089True(=1)\u3002\u5408\u8a08\u3059\u308b\u3053\u3068\u3067\u30de\u30c3\u30c1\u30f3\u30b0\u6570\u3068\u306a\u308b\nprint(sum(dfs(s, set()) for s in range(xn)))", "import sys\nINF = 1 << 60\nMOD = 10**9 + 7 # 998244353\nsys.setrecursionlimit(2147483647)\ninput = lambda:sys.stdin.readline().rstrip()\nimport networkx as nx\ndef resolve():\n n = int(input())\n A = [tuple(map(int, input().split())) for _ in range(n)]\n B = [tuple(map(int, input().split())) for _ in range(n)]\n G = nx.Graph()\n G.add_nodes_from(range(n))\n G.add_nodes_from(range(n, 2 * n))\n for i in range(n):\n ax, ay = A[i]\n for j in range(n):\n bx, by = B[j]\n if ax < bx and ay < by:\n G.add_edge(i, n + j)\n\n A = nx.algorithms.bipartite.maximum_matching(G, top_nodes = range(n))\n print(len(A) // 2)\nresolve()", "n = int(input())\nred, blue = [], []\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n red.append([a, b, min(a, b)])\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n blue.append([a, b, min(a, b)])\n \nred.sort(key=lambda x: x[1])\nblue.sort(key=lambda x: x[0])\nstatus = [False for _ in range(n)]\nans = 0\nfor i in range(n):\n for j in range(n-1, -1, -1):\n if not status[j]:\n if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:\n ans += 1\n status[j] = True\n break\nprint(ans)\n", "N = int(input())\nr = []\nfor i in range(N):\n r.append(list(map(int, input().split())))\nb = []\nfor i in range(N):\n b.append(list(map(int, input().split())))\nr = sorted(r, key=lambda x: x[0])\nb = sorted(b, key=lambda x: x[0])\nr_selected = [False] * N\nans = 0\nfor i in range(N):\n y_max = -1\n j_selected = -1\n for j in range(N):\n if r_selected[j]:\n continue\n if b[i][0] > r[j][0] and b[i][1] > r[j][1]:\n if y_max < r[j][1]:\n y_max = r[j][1]\n j_selected = j\n if y_max == -1:\n continue\n else:\n r_selected[j_selected] = True\nprint(r_selected.count(True))", "N = int(input())\nab = [list(map(int, input().split())) for _ in range(N)]\ncd = [list(map(int, input().split())) for _ in range(N)]\nab.sort(reverse=True)\ncd.sort()\np = 0\nfor c in cd:\n ac = [-1, -1]\n for a in ab:\n if c[0] > a[0] and c[1] > a[1] and ac[1] < a[1]:\n ac = a\n if ac != [-1, -1]:\n p += 1\n ab.remove(ac)\n\nprint(p)", "N = int(input())\nreds = [tuple(map(int, input().split())) for _ in range(N)]\nblues = [tuple(map(int, input().split())) for _ in range(N)]\n\nreds.sort(key=lambda x: -x[1])\nblues.sort(key=lambda x: x[0])\n\nans = 0\nusedreds = [False]*N\nusedblues = [False]*N\nfor i in range(N):\n if usedreds[i]:\n continue\n a, b = reds[i]\n for j in range(N):\n if usedblues[j]:\n continue\n c, d = blues[j]\n if not (a < c and b < d):\n continue\n ans += 1\n usedreds[i] = True\n usedblues[j] = True\n break\n\nprint(ans)", "from operator import itemgetter\nn, *ABCD = map(int, open(0).read().split())\nAB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])], key=itemgetter(1))\nCD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])\n\nfor c, d in CD:\n t_AB = [(a, b) for a, b in AB if a < c and b < d]\n if t_AB:\n AB.remove(t_AB[-1])\nprint(n-len(AB))", "n = int(input())\nred, blue = [], []\nans = 0\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n red.append((max(a, b), a, b))\nfor _ in range(n):\n c, d = list(map(int, input().split()))\n blue.append((min(c, d), c, d))\nred.sort(key=lambda x: x[0], reverse=True)\nblue.sort(key=lambda x: x[0])\nfor i in range(n):\n _, xb, yb = blue[i]\n for j in range(n):\n if red[j]:\n _, xr, yr = red[j]\n if xb > xr and yb > yr:\n red[j] = False\n ans += 1\n break\nprint(ans)\n", "import sys\n\n\ndef resolve():\n readline = sys.stdin.readline # 1\u884c\u3060\u3051\u6587\u5b57\u5217\u306b\u3059\u308b\n\n N = int(readline())\n NN = 2 * N + 1\n\n # \u9752\u8272\u306fx\u5ea7\u6a19\u3092list\u306eindex,y\u5ea7\u6a19\u3092list\u306evalue\u3068\u3057\u3066\u5165\u529b\uff0c\u8d64\u306f\u9006\n red = [[] for _ in [0] * NN]\n blue = [[] for _ in [0] * NN]\n for _ in [0] * N:\n a, b = list(map(int, readline().split()))\n red[b].append(a)\n for _ in [0] * N:\n c, d = list(map(int, readline().split()))\n blue[c].append(d)\n\n # \u9752\u8272\u3067value\u306ey\u5ea7\u6a19\u306b\u3064\u3044\u3066\u964d\u9806(\u5927\u304d\u3044\u9806)\u3067\u30bd\u30fc\u30c8\n # \u8d64\u8272\u3067\u306fvalue\u306ex\u5ea7\u6a19\u306b\u3064\u3044\u3066\u964d\u9806\u3067\u30bd\u30fc\u30c8\n # \u3053\u308c\u3067\u9752\u8272\u306fx\u5ea7\u6a19\u306f\u6607\u9806(index)\uff0cy\u5ea7\u6a19\u306f\u964d\u9806(value)\u306b\u30bd\u30fc\u30c8\u3055\u308c\u308b\n # \u8d64\u8272\u306fy\u5ea7\u6a19\u304c\u6607\u9806(index)\uff0cx\u5ea7\u6a19\u304c\u964d\u9806(value)\n for i in range(NN):\n r = red[i]\n b = blue[i]\n r.sort(reverse=True)\n b.sort(reverse=True)\n r[0:0] = [i]\n b[0:0] = [i]\n\n # \u9752\u70b9\u306fx\u5ea7\u6a19\u306e\u6607\u9806\u3067\uff0c\u8d64\u70b9\u306fy\u5ea7\u6a19\u306e\u964d\u9806\n # \u6700\u5c0f\u306ex\u306e\u9752\u70b9\u3067\u6700\u5927\u306ey\u3092\u6301\u3064\u8d64\u70b9\u3092\u9078\u629e\n ans = 0\n flag = False\n while blue:\n cd_blue = blue.pop(0)\n c = cd_blue.pop(0)\n if cd_blue:\n for d in cd_blue:\n for ba_red in red[::-1]:\n b = ba_red[0]\n if ba_red[1:]:\n for i in range(1, len(ba_red)):\n a = ba_red[i]\n if a <= c and b <= d:\n ans += 1\n del red[b][i]\n flag = True\n break\n if flag:\n break\n if flag:\n flag = False\n break\n print(ans)\n\n\nresolve()\n", "\"\"\"\n\u9752\u306fx\u306e\u6607\u9806\u3001\u8d64\u306fy\u306e\u964d\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001x\u306e\u5c0f\u3055\u3044\u9752\u304b\u3089\u30da\u30a2\u3092\u63a2\u3057\u3066\u3044\u304f\u3002x\u5ea7\u6a19\u306e\u691c\u8a3c\u306b\u304a\u3044\u3066\u3001\u5c0f\u3055\u3044\u9752\u306e\u5019\u88dc\u306b\u5165\u308b\u8d64\u306f\u4eca\u5f8c\u306e\u9752\u306e\u5019\u88dc\u306b\u3082\n\u306a\u308b\u305f\u3081\u3001y\u5ea7\u6a19\u304c\u3067\u304d\u308b\u3060\u3051\u5927\u304d\u3044\u8d64\u3068\u30da\u30a2\u3092\u4f5c\u308b\u3088\u3046\u306b\u3059\u308b\u3002\n\n\"\"\"\nn = int(input())\nred = [[0] * 2 for _ in range(n)]\nblue = [[0] * 2 for _ in range(n)]\nfor i in range(n):\n red[i][1], red[i][0] = list(map(int, input().split()))\nfor i in range(n):\n blue[i][0], blue[i][1] = list(map(int, input().split()))\n\nred.sort(reverse=True)\nblue.sort()\nans = 0\nusedred = [False] * n\nfor i in range(n):\n for j in range(n):\n if blue[i][0] > red[j][1] and blue[i][1] > red[j][0] and usedred[j] != True:\n ans += 1\n usedred[j] = True\n break\n\nprint(ans)\n", "from heapq import heappop, heappush\n\nN = int(input())\nR = []\nB = []\nYFlag = [True]*(2*N)\n\nfor _ in range(N):\n a, b = map(int, input().split())\n R.append((a, b))\n\nfor _ in range(N):\n c, d = map(int, input().split())\n B.append((c, d))\n\nB.sort()\n\nans = 0\nfor c, d in B:\n cand = []\n for a, b in R:\n if a < c and b < d and YFlag[b]:\n cand.append(b)\n if cand:\n ans += 1\n YFlag[max(cand)] = False\n\nprint(ans)", "\nn = int(input().strip())\nred = [list(map(int, input().split())) for i in range(n)]\nblue = [list(map(int, input().split())) for j in range(n)]\n\nfor i in range(n):\n '''\n kagi_r = [min(red[i][0], red[i][1]), max(red[i][0], red[i][1])]\n kagi_b = [min(blue[i][0], blue[i][1]), max(blue[i][0], blue[i][1])]\n red[i] = red[i] + kagi_r\n blue[i] = blue[i] + kagi_b\n '''\nred.sort(key=lambda x: (x[0], x[1]), reverse=True)\nblue.sort(key=lambda x: x[1])\nflg_r = [0]*n\ncnt = 0\n\nfor i in range(n):\n for j in range(n):\n if flg_r[j]:\n continue\n if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:\n flg_r[j] = 1\n cnt += 1\n break\n\nprint(cnt)\n\n", "N = int(input())\nred = [list(map(int, input().split())) for _ in range(N)]\nblue = [list(map(int, input().split())) for _ in range(N)]\nblue = sorted(blue, key=lambda x: x[0])\n\nused = []\nfor i in range(N):\n c, d = blue[i]\n m, tmp = -1, -1\n for j in range(N):\n if j in used:\n continue\n a, b = red[j]\n if a < c and b < d:\n if b > m:\n m = b\n tmp = j\n if tmp != -1:\n used.append(tmp)\nprint(len(used))", "import networkx as nx\n\nN = int(input())\nABs = [tuple(map(int, input().split())) for _ in range(N)]\nCDs = [tuple(map(int, input().split())) for _ in range(N)]\n\n# 0 <= i < N -> i: ABs[i]\n# N <= i < 2*N -> i: CDs[i-N]\n# i == 2*N+1 -> start\n# i == 2*N+2 -> goal\n\nDG = nx.DiGraph()\nDG.add_nodes_from(list(range(2 * N + 3)))\nfor i in range(N):\n for j in range(N):\n if ABs[i][0] < CDs[j][0] and ABs[i][1] < CDs[j][1]:\n DG.add_edge(i, j + N, capacity = 1)\n\nDG.add_edges_from([(2 * N + 1, i, {\"capacity\":1}) for i in range(N)])\nDG.add_edges_from([(i, 2 * N + 2, {\"capacity\":1}) for i in range(N, 2*N)])\n\nprint((nx.maximum_flow_value(DG, 2 * N + 1, 2 * N + 2)))\n", "def main():\n n = int(input())\n B = []\n g = [[0]*(2*n) for _ in range(2*n)]\n for _ in range(n):\n a,b = map(int,input().split())\n g[b][a] = 1\n for _ in range(n):\n c,d = map(int,input().split())\n B.append((c,d))\n B.sort()\n ans = 0\n for i,j in B:\n f = 0\n for y in range(j,-1,-1):\n for x in range(i,-1,-1):\n if g[y][x]:\n ans += 1\n f = 1\n g[y][x] = 0\n break\n if f:\n break\n print(ans)\n\nmain()", "import sys\ninput=sys.stdin.readline\n\nfrom collections import deque\nclass HopcroftKarp:\n def __init__(self, N0, N1):\n self.N0 = N0\n self.N1 = N1\n self.N = N = 2+N0+N1\n self.G = [[] for i in range(N)]\n for i in range(N0):\n forward = [2+i, 1, None]\n forward[2] = backward = [0, 0, forward]\n self.G[0].append(forward)\n self.G[2+i].append(backward)\n self.backwards = bs = []\n for i in range(N1):\n forward = [1, 1, None]\n forward[2] = backward = [2+N0+i, 0, forward]\n bs.append(backward)\n self.G[2+N0+i].append(forward)\n self.G[1].append(backward)\n\n def add_edge(self, fr, to):\n #assert 0 <= fr < self.N0\n #assert 0 <= to < self.N1\n v0 = 2 + fr\n v1 = 2 + self.N0 + to\n forward = [v1, 1, None]\n forward[2] = backward = [v0, 0, forward]\n self.G[v0].append(forward)\n self.G[v1].append(backward)\n\n def bfs(self):\n G = self.G\n level = [None]*self.N\n deq = deque([0])\n level[0] = 0\n while deq:\n v = deq.popleft()\n lv = level[v] + 1\n for w, cap, _ in G[v]:\n if cap and level[w] is None:\n level[w] = lv\n deq.append(w)\n self.level = level\n return level[1] is not None\n\n def dfs(self, v, t):\n if v == t:\n return 1\n level = self.level\n for e in self.it[v]:\n w, cap, rev = e\n if cap and level[v] < level[w] and self.dfs(w, t):\n e[1] = 0\n rev[1] = 1\n return 1\n return 0\n\n def flow(self):\n flow = 0\n G = self.G\n bfs = self.bfs; dfs = self.dfs\n while bfs():\n *self.it, = map(iter, G)\n while dfs(0, 1):\n flow += 1\n return flow\n\n def matching(self):\n return [cap for _, cap, _ in self.backwards]\n\nn=int(input())\n\nsolve=HopcroftKarp(n,n)\n\nred,blue=[],[]\n\nfor i in range(n):\n a,b=map(int,input().split())\n red.append([a,b])\n\nfor i in range(n):\n c,d=map(int,input().split())\n blue.append([c,d])\n\n\nfor i in range(n):\n for j in range(n):\n if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:\n solve.add_edge(i,j)\n\n\nprint(solve.flow())"] | {"inputs": ["3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\n", "3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5\n", "2\n2 2\n3 3\n0 0\n1 1\n", "5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7\n", "5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9\n"], "outputs": ["2\n", "2\n", "0\n", "5\n", "4\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 78,229 | |
3b4ee669a0d1542af196a396b188800c | UNKNOWN | In a public bath, there is a shower which emits water for T seconds when the switch is pushed.
If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total?
-----Constraints-----
- 1 β€ N β€ 200,000
- 1 β€ T β€ 10^9
- 0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N β€ 10^9
- T and each t_i are integers.
-----Input-----
Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N
-----Output-----
Assume that the shower will emit water for a total of X seconds. Print X.
-----Sample Input-----
2 4
0 3
-----Sample Output-----
7
Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds. | ["n,T = map(int,input().split())\nt = list(map(int,input().split()))\nans = 0\nfor i in range(n-1):\n ans += min(T,t[i+1]-t[i])\nprint(ans+T)", "n, t = map(int, input().split())\nT = list(map(int, input().split()))\n\nans = 0\nfor i in range(1, n):\n if T[i] - T[i - 1] >= t:\n ans += t\n else:\n ans += T[i] - T[i - 1]\nprint(ans + t)", "import math\n\nn, t = list(map(int, input().split()))\na = list(map(int, input().split()))\nans = 0\na.append(math.inf)\nfor i in range(n):\n ans += min(t, a[i + 1] - a[i])\nprint(ans)\n", "N,T = map(int,input().split())\nt = list(map(int,input().split()))\nans = 0\n\nfor i in range(N-1):\n if t[i+1]-t[i] > T:\n ans += T\n else:\n ans += t[i+1]-t[i]\n\nprint(T+ans)", "n, t = map(int, input().split())\nts = list(map(int, input().split()))\n\nans = 0\nnow = 0\nfor i in ts[1:]:\n if i<=now+t:\n ans += i-now\n else:\n ans += t\n now = i\nprint(ans+t)", "n,t = map(int,input().split())\nT = list(map(int,input().split()))\n\ns = n * t\nfor i in range(1,n):\n if T[i] - T[i-1] < t:\n s -= (t-(T[i]-T[i-1]))\nprint(s)", "N, T = map(int,input().split())\nlsT = list(map(int,input().split()))\ntend = T\nans = T\nfor i in range(1,N):\n if lsT[i] <= tend:\n ans += lsT[i]+T-tend\n tend = lsT[i]+T\n else:\n ans += T\n tend = lsT[i]+T\nprint(ans)", "N,T = map(int,input().split())\nt = list(map(int,input().split()))\nans = T\nfor i in range(N-1):\n now = t[i+1]-t[i]\n ans += min(now,T)\n\n\nprint(ans)", "N,T = map(int,input().split())\nL = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n ans += min(L[i+1]-L[i],T)\nprint(ans+T)", "N, T = [int(x) for x in input().split()]\nt_list = [int(x) for x in input().split()]\nt_s = t_e = ans = 0\nfor t in t_list:\n if t > t_e:\n ans += t_e - t_s\n t_s = t\n t_e = t + T\nans += t_e - t_s\nprint(ans)", "n, t = list(map(int, input().split()))\ntn = list(map(int, input().split()))\nres = t\nfor i in range(1, n):\n tmp = min(tn[i] - tn[i - 1], t)\n res += tmp\n\nprint(res)\n", "n, t = map(int, input().split())\nT = tuple(map(int, input().split()))\nans = 0\nfor i in range(0, n-1):\n dt = T[i+1] - T[i]\n ans += min(dt, t)\nprint(ans + t)", "N,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n ans+=min(t[i]-t[i-1],T)\nprint(ans+T)", "N, T = map(int, input().split())\nX = list(map(int, input().split()))\nS = 0\nfor i in range(1, N):\n if X[i]-X[i-1]>=T:\n S += T\n else:\n S += X[i]-X[i-1]\nprint(S+T)", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = T\n\nfor i in range(N-1):\n if t[i+1] - t[i] >= T:\n ans += T\n else: # t[i+1]-t[i]<T\n ans += t[i+1] - t[i]\n\nprint(ans)", "n, t = map(int, input().split())\nl = list(map(int, input().split()))\nold = 0\nans = t\nfor i in range(1,n):\n ans += l[i] + t - max(old + t,l[i])\n old = l[i]\nprint(ans)", "import sys\ninput = sys.stdin.readline\n\nN,T = list(map(int,input().split()))\nt = list(map(int,input().split()))\nt_stop = []\nfor i in range(N):\n t_stop.append(t[i]+T)\ncum_flow = T*N\nfor i in range(N-1):\n cum_flow -= max(t_stop[i] - t[i+1],0)\nprint(cum_flow)\n", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N, T, *t = list(map(int, read().split()))\n\n ans = 0\n for i in range(N - 1):\n if t[i] + T > t[i + 1]:\n ans += t[i + 1] - t[i]\n else:\n ans += T\n ans += T\n\n print(ans)\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "#\n# abc060 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"2 4\n0 3\"\"\"\n output = \"\"\"7\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"2 4\n0 5\"\"\"\n output = \"\"\"8\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"4 1000000000\n0 1000 1000000 1000000000\"\"\"\n output = \"\"\"2000000000\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"1 1\n0\"\"\"\n output = \"\"\"1\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_5(self):\n input = \"\"\"9 10\n0 3 5 7 100 110 200 300 311\"\"\"\n output = \"\"\"67\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N, T = list(map(int, input().split()))\n t = list(map(int, input().split()))\n\n ans = T\n for i in range(N-2, -1, -1):\n ans += min(T, t[i+1]-t[i])\n\n print(ans)\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "import numpy as np\n\n\ndef main():\n n, t = list(map(int, input().split()))\n ts = list(map(int, input().split()))\n ans = t\n for i in range(n-1):\n now = ts[i+1] - ts[i]\n ans += min(now, t)\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N, T = map(int, input().split())\nt_List = [int(x) for x in input().split()]\npre = 0\nans = T\nfor t in t_List:\n if t - pre <= T:\n ans += t - pre\n else:\n ans += T\n pre = t\nprint(ans)", "# C - Sentou\ndef main():\n n, t = map(int, input().split())\n s = list(map(int, input().split()))\n cnt = n*t\n\n for i in range(n-1):\n if s[i+1] - s[i] < t:\n cnt -= s[i]+t-s[i+1]\n else:\n print(cnt)\n\n\nif __name__ == \"__main__\":\n main()", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 03:05:21 2020\n\n@author: liang\n\"\"\"\n\nN ,T = map(int,input().split())\n\ntime = [int(x) for x in input().split()]\n\nans = 0\nfor i in range(N-1):\n ans += min(T, time[i+1]-time[i])\nans += T\nprint(ans)", "n,t = map(int, input().split())\nT = list(map(int, input().split()))\n\nprev,now,ans = T[0],0,0\n\nfor i in range(n):\n if not i:\n continue\n now = T[i]\n if now-prev > t:\n ans += t\n else:\n ans += now-prev\n prev = now\nans += t\nprint(ans)", "N, T = list(map(int, input().split()))\nt = list(map(int, input().split()))\nd = []\n\nfor i in range(N-1):\n tmp = t[i+1] - t[i]\n if tmp > T:\n d.append(T)\n else:\n d.append(tmp)\n\nprint(sum(d)+T)", "n, t = map(int, input().split())\ntime = [int(i) for i in input().split()]\nsum = 0\nfor i in range(len(time)-1):\n if (time[i+1]-time[i]) < t:\n sum += (time[i+1]-time[i])\n else:\n sum += t\nprint(sum+t)", "n , t = map(int, input().split())\nlis = list(map(int, input().split()))\n\nans = t\nfor i in range(1, n):\n if lis[i] - lis[i-1] >= t:\n ans += t\n else:\n ans += lis[i] - lis[i-1]\n\nprint(ans)", "n, t = list(map(int, input().split()))\ntl = list(map(int, input().split()))\nans = 0\nfor i in range(1, n):\n ans += min(tl[i]-tl[i-1], t)\nans += t\nprint(ans)\n", "N,T=map(int,input().split())\nt = list(map(int,input().split()))\n\nans=0\nfor i in range(N):\n if i == 0:\n start = t[i]\n finish = t[i]+T\n continue\n \n if t[i]<finish:\n finish = t[i]+T\n continue\n \n else:\n ans += finish - start\n start = t[i]\n finish = t[i]+T\n \nans += finish - start\n\nprint(ans)", "n, t = map(int, input().split())\nL = list(map(int, input().split()))\n\nans = 0\nfor i in range(n-1):\n ans += min(t, L[i+1] - L[i])\nans += t\nprint(ans)", "n,t = map(int,input().split())\ntl = list(map(int,input().split()))\nans = 0\nfor i in range(1,n):\n if tl[i] >= t and tl[i] - tl[i-1] >= t:\n ans+=t\n else:\n ans+=tl[i] - tl[i-1]\nprint(ans+t)", "N,K = (int(T) for T in input().split())\nPer = [int(T) for T in input().split()]\nWat = 0\nfor X in range(0,N-1):\n if Per[X]+K<=Per[X+1]:\n Wat += K\n else:\n Wat += Per[X+1]-Per[X]\nprint(Wat+K)", "n, t = map(int, input().split())\ntn = [int(num) for num in input().split()]\n\nsum = 0\nfor i in range(len(tn)):\n if i < len(tn)-1:\n if tn[i]+t < tn[i+1]:\n sum += t\n else :\n sum += tn[i+1] - tn[i]\n else :\n sum += t\n\nprint(sum)", "n,t=map(int,input().split())\nl=list(map(int,input().split()))\ns=0\npre_end=0\nfor tt in l:\n time=t-max(0, pre_end - tt)\n s+=time\n pre_end=tt+t\nprint(s)", "from typing import List\n\n\ndef answer(N: int, T: int, t: List[int]) -> int:\n ans = 0\n for i in range(N - 1):\n ans += min(T, t[i + 1] - t[i])\n return ans + T\n\n\ndef main():\n N, T = list(map(int, input().split()))\n t = list(map(int, input().split()))\n print((answer(N, T, t)))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N, T = map(int, input().split())\ntime = list(map(int, input().split()))\n\ncnt = 0\nfor i in range(1,N):\n cnt += min(T, time[i] - time[i-1])\nprint(cnt+T)", "n, t = map(int, input().split())\nlst = list(map(int, input().split())) + [10 ** 12]\nsec = 0\nfor i in range(n):\n sec += min(t, lst[i + 1] - lst[i])\nprint(sec)", "n, t = map(int, input().split())\narr = list(map(int, input().split()))\n\ntotal = t\ntime = 0\nfor i in arr[1:]:\n total += min(t, (i - time))\n time = i\n\nprint(total)", "n, t = list(map(int, input().split()))\nl = list(map(int, input().split()))\nnow = 0\nlatest = 0\nans = 0\n\nfor i in l:\n now = i\n #print(now,latest,t)\n if now-latest >= t:\n ans += t\n else:\n ans += now-latest\n \n latest = now\nans += t\nprint(ans)\n", "N,T = map(int,input().split())\ntime = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n if time[i+1] - time[i] >= T:\n ans += T\n else:\n ans += time[i+1] - time[i]\nprint(ans+T)", "n, t = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(1,n):\n ans += min(a[i] - a[i-1],t)\nprint(ans+t)", "n,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=0\nfor i in range(n-1):\n if t[i+1]-t[i]>T:\n ans+=T\n else:\n ans+=t[i+1]-t[i]\nprint(ans+T)", "N,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n d=t[i]-t[i-1]\n if d < T:\n ans+=d\n else:\n ans+=T\nprint(ans+T)", "n,t=map(int,input().split());a=list(map(int,input().split()))\nprint(sum([min(t,a[i]-a[i-1]) for i in range(1,n)])+t)", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n n, T = inl()\n t = inl()\n assert len(t) == n\n assert t[0] == 0\n p = 0\n ans = 0\n for i in range(1, n):\n x = t[i]\n ans += min(x - p, T)\n p = x\n ans += T\n return ans\n\n\nprint(solve())\n", "n, t = map(int, input().split())\nl = list(map(int, input().split()))\ntotal=0\nfor i in range(n):\n if i==n-1:# last element\n total+=t\n break\n if l[i+1]-l[i]>=t:\n total+=t\n else:\n total+=l[i+1]-l[i]\nprint(total)", "n,m = map(int, input().split())\nt = list(map(int, input().split()))\nnum = 0\nfor i in range(n-1):\n if t[i+1]-t[i] < m:\n num += t[i+1]-t[i]\n else:\n num += m\nprint(num+m)", "n, t = map(int, input().split())\narr = list(map(int, input().split()))\nsumm = t\nfor i in range(n-1):\n summ += min(t, arr[i+1] - arr[i])\nprint(summ)", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = 0\nfor n in range(1, N):\n timeD = t[n] - t[n-1]\n if T >= timeD:\n ans += timeD\n else:\n ans += T\nans += T\nprint(ans)", "n,T=list(map(int,input().split()))\nt=list(map(int,input().split()))\n\nans=0\nfor i in range(n-1):\n ans+=min(t[i+1]-t[i],T)\nans+=T\nprint(ans)\n", "n,t = map(int,input().split())\ntlist = list(map(int,input().split()))\ntime = t\nfor i in range(0,n-1):\n if tlist[i+1]- tlist[i] <= t :\n time += tlist[i+1]- tlist[i]\n else:\n time += t\nprint(time)", "N,T = map(int,input().rstrip().split(\" \"))\nt = list(map(int,input().rstrip().split(\" \")))\nans = 0\nfor i in range(N-1):\n ans += min(T,t[i+1] - t[i])\nans += T\nprint(ans)", "N, T = list(map(int,input().split()))\nA = list(map(int,input().split()))\n\nans = 0 \nfor i in range(len(A)-1):\n ans += min(T,A[i+1]-A[i])\n\nprint(ans+T)", "n,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=0\nfor i in range(n-1):\n if t[i+1]-t[i]>=T:\n ans+=T\n else:\n ans+=t[i+1]-t[i]\n\nans+=T\nprint(ans)", "N, T = map(int,input().split())\nt_lis = list(map(int,input().split()))\n\nans = 0\nfor i in range(1,N):\n t = t_lis[i] - t_lis[i-1]\n ans += min(t, T)\n \nprint(ans + T)", "a,b=input().split()\na=int(a)\nb=int(b)\nc=list(map(int,input().split()))\nm=a*b\nfor i in range(a-1):\n if c[i+1]-c[i]<b:\n m=m-(b-(c[i+1]-c[i]))\nprint(m)", "n,t = map(int, input().split())\nl = list(map(int ,input().split()))\n\nnums = [0]*(n-1)\nfor i in range(n-1): nums[i] = l[i+1] - l[i]\n\nans = t\nm = 0\nfor i in nums:\n ans += min(i,t)\nprint(ans)", "N,T=map(int,input().split())\nt=list(map(int,input().split()))\nt.append(10**10)\nans=0\nflg=0\ntemp=0\n\nfor i in range(N):\n if t[i]+T > t[i+1]:\n if flg==0:\n temp=t[i]\n flg=1\n continue\n else:\n if flg==0:\n ans+=T\n else:\n ans+=t[i]-temp+T\n flg=0\nprint(ans)", "import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy,deepcopy\nfrom collections import deque,Counter\nfrom decimal import Decimal\ndef s(): return input()\ndef i(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef L(): return list(map(int,input().split()))\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nINF = 10**9\nmod = 10**9+7\n\nN,T = I()\nt = l()\nans = T\nfor i in range(N-1):\n ans += min(t[i+1]-t[i],T)\nprint(ans)", "N,S = map(int,input().split())\nT = list(map(int,input().split()))\na = S\n\nfor n in range(N-1):\n a+=min(S,T[n+1]-T[n])\n\nprint(a)", "n,t = map(int,input().split())\ntm = list(map(int,input().split()))\nstart_time = -1\nstop_time = -1\nans = 0\nfor i in range(0,n):\n if start_time <= tm[i] <= stop_time:\n stop_time += (t + tm[i]) - stop_time\n else:\n ans += (stop_time - start_time)\n start_time = tm[i]\n stop_time = tm[i] + t\n if i == n-1:\n ans += (stop_time - start_time)\nprint(ans)", "import math\nfrom math import gcd,pi,sqrt\nINF = float(\"inf\")\n\nimport sys\nsys.setrecursionlimit(10**6)\nimport itertools\nfrom collections import Counter,deque\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\n\ndef main():\n N,T = i_map()\n t = i_list()\n\n ans = 0\n for i,k in enumerate(t[1:], start=1):\n if k - t[i-1] <= T:\n ans += k - t[i-1]\n else:\n ans += T\n ans += T\n print(ans)\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "def test():\n arr=[]\n ans=0\n first_input=input()\n first_num=first_input.split()\n a=int(first_num[0])\n b=int(first_num[1])\n sec_input=input()\n sec_num=sec_input.split()\n if len(sec_num)==a:\n pass\n else:\n print('Wrong input')\n\n\n for i in sec_num:\n arr.append(int(i))\n\n for i in range(0,len(arr)-1):\n num=arr[i]\n num_2=arr[i+1]\n if num_2-num>b:\n ans+=b\n else:\n ans+=num_2-num\n\n ans+=b\n print(ans)\n\n\ntest()", "n,t=list(map(int,input().split()))\nl=list(map(int,input().split()))\ns=0\nz=0\nfor i in l:\n if z-i>0:\n s+=i+t-z\n else:\n s+=t\n z=i+t\nprint(s)\n", "N, T, *t = map(int, open(0).read().split())\nans = sum(y-x if y-x < T else T for x,y in zip(t[:N-1],t[1:])) + T\nprint(ans)", "N, T = list(map(int, input().split()))\nt = list(map(int, input().split()))\nans = 0\nfor i in range(N-1):\n ans += min(T, t[i+1]-t[i])\nans += T\nprint(ans)\n", "#!/usr/bin/env python3\nN, T = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nans = 0\nfor i in range(N - 1):\n if t[i + 1] - t[i] > T:\n ans += T\n else:\n ans += t[i + 1] - t[i]\nans += T\nprint(ans)\n", "N,T = map(int,input().split())\nt = list(map(int,input().split()))\nans = 0\nfor i in range(1,N):\n ans += min(T,t[i]-t[i-1])\nans += T\nprint(ans)", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans, now = 0, 0\nfor i in t:\n if i < now:\n ans -= now - i\n ans += T\n now = i + T\nprint(ans)", "N, T = [int(i) for i in input().split(\" \")]\nt = [int(j) for j in input().split(\" \")]\n\ndt = []\nfor i in range(N - 1):\n dt.append(t[i + 1] - t[i])\nelse:\n dt.append(T)\n\nprint(sum([min([dti, T]) for dti in dt]))", "n,t=map(int,input().split())\nt_list=list(map(int,input().split()))\ns = 0\nfor i in range(1, n):\n if t_list[i]-t_list[i-1] >= t:\n s += t\n else:\n s += t_list[i]-t_list[i-1]\nprint(s+t)", "n, t = map(int, input().split())\na = list(map(int, input().split())) + [10**10]\n\nans = 0\nfor i in range(n):\n ans += min(a[i+1] - a[i], t)\n\nprint(ans)", "N, T = [int(x) for x in input().split()]\nt = [int(x) for x in input().split()]\n\nT_start = 0\nT_end = T\nT_total = 0\n\nfor i in range(1, N):\n if t[i] <= T_end:\n T_end = t[i] + T\n else: # t[i] > T_end\n T_total += T_end - T_start\n T_start = t[i]\n T_end = t[i] + T\n\nT_total += T_end - T_start\n\nprint(T_total)", "n, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = 0\nfor i in range(n-1):\n ans += min(T, t[i+1]-t[i])\nans += T\n\nprint(ans)", "N, T = list(map(int,input().split()))\nt = list(map(int,input().split()))\n\ntime = T\nfor i in range(N-1):\n if t[i+1]-t[i]>=T:\n time += T\n else:\n time += t[i+1]-t[i]\nprint(time)\n", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\nans = T\nfor i in range(N-1):\n if t[i] + T <= t[i+1]:\n ans += T\n else:\n ans += t[i+1] - t[i] \nprint(ans)", "n,t=list(map(int,input().split()))\nl=list(map(int,input().split()))\ns=0\nfor i in range(len(l)-1):\n s+=min(t,l[i+1]-l[i])\ns+=t\nprint(s)\n", "'''\nCreated on 2020/08/16\n\n@author: harurun\n'''\nN,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=T\ns=t[0]\nfor i in range(1,N):\n if t[i]-s>=T:\n ans+=T \n else:\n ans-=T-(t[i]-s)\n ans+=T\n s=t[i]\nprint(ans) ", "N,T = map(int,input().split())\nN_List = list(map(int,input().split()))\n\nans = 0\nfor i in range(1,N):\n ans += (T,N_List[i]-N_List[i-1])[N_List[i]-N_List[i-1]<=T]\n\nans += T\nprint(ans)", "n,t = map(int,input().split())\ntl = list(map(int,input().split()))\nans = t\nfor i in range(n-1):\n\tif tl[i+1]-tl[i] >= t:\n\t\tans += t\n\telse:\n\t\tans += t-(t-(tl[i+1]-tl[i]))\nprint(ans)", "n, m = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(n):\n if i == n-1:\n ans += m\n elif t[i+1] - t[i] > m:\n ans += m\n else:\n ans += t[i+1] - t[i]\n\nprint(ans)\n\n\n", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\nSum = T\n\nfor i in range(1, N):\n if t[i] - t[i - 1] < T:\n Sum += t[i] - t[i - 1]\n else:\n Sum += T\n\nprint(Sum)", "n, t = map(int, input().split())\nt_lst = list(map(int, input().split()))\naccumulate = 0\n\nfor i in range(n - 1):\n time = t_lst[i + 1] - t_lst[i]\n accumulate += min(time, t)\n\naccumulate += t\nprint(accumulate)", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = T\nfor i in range(1, N):\n diff = t[i] - t[i-1]\n ans += min(diff, T)\nprint(ans)", "N,T = map(int,input().split())\nt = list(map(int,input().split()))\nX = T\n\nfor n in range(1,N):\n d = t[n]-t[n-1]\n if d<=T:\n X+=d\n else:\n X+=T\n \nprint(X)", "n,t = map(int, input().split())\nl = list(map(int, input().split()))\n\nans = t\nfor i in range(n-1):\n ans += min(t,l[i+1]-l[i])\nprint(ans)", "N,T=map(int,input().split())\nList = list(map(int, input().split()))\nres = 0\nfor i in range(1,N):\n sumsum = List[i]-List[i-1]\n if sumsum >= T:\n res += T\n else:\n res += sumsum\nres += T\nprint(res)", "N, T = list(map(int, input().split()))\nt = list(map(int, input().split()))\nans = 0\n\nfor i in range(N-1):\n tmp = t[i+1] - t[i]\n ans += min(tmp, T)\n\nprint(ans+T)", "N,T=list(map(int,input().split()))\nt=list(map(int,input().split()))\n\nans=0\nfor i in range(0,N-1):\n if t[i]+T>t[i+1]:\n ans+=t[i+1]-t[i]\n else:\n ans+=T\nans+=T\nprint(ans)\n", "N, T = map(int,input().split())\ntime = list(map(int, input().split())) + [float('inf')]\n\nnow = 0\nprev = 0\nans = 0\nfor t in time:\n if t - prev >= T:\n ans += T\n else:\n ans += t - prev\n prev = t\n\nprint(ans)", "N, T = list(map(int, input().split()))\nt = list(map(int, input().split()))\nt.append(float('inf'))\nans = 0\nfor i in range(len(t)-1): \n ans += min(T, t[i+1] - t[i])\nprint(ans)\n", "numbers = list([int(x) for x in input().split()])\nnums = list([int(x) for x in input().split()])\nt = numbers[1]\n\ntotal = t\nfor i in range(1, len(nums)):\n check = nums[i] - nums[i - 1] \n total += check if check <= t else t\n\nprint(total)\n \n", "N, T = list(map(int, input().split()))\ntt = list(map(int, input().split()))\nans = 0\n\nfor i in range(N - 1):\n nn = tt[i + 1] - tt[i]\n if nn > T:\n ans += T\n else:\n ans += nn\n \nans += T\nprint(ans)\n \n", "from sys import stdin\n\ndef main():\n N,T=list(map(int,stdin.readline().strip().split()))\n t=list(map(int,stdin.readline().strip().split()))\n\n x=0\n for i in range(N-1):\n x+=min(T,t[i+1]-t[i])\n print((x+T))\n\ndef __starting_point():\n main()\n\n__starting_point()", "n,t=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nfor i in range(n):\n if i==0:\n ans+=t\n elif a[i-1]+t<=a[i]:\n ans+=t\n else:\n ans+=a[i]-a[i-1]\nprint(ans)", "N, T = map(int, input().split())\nt = list(map(int, input().split()))\nans = 0\nfor i in range(N-1):\n if t[i]+T <= t[i+1]:\n ans += T\n else:\n ans += t[i+1]-t[i]\nans += T\nprint(ans)", "N,T=map(int,input().split())\nt=list(map(int,input().split()))\nans=0\nm=0\nfor i in range(1,N):\n if T<t[i]-t[i-1]:\n ans+=T\n else:\n ans+=t[i]-t[i-1]\nprint(ans+T)", "n, k = map(int,input().split())\nt = list(map(int,input().split()))\n\nans = n*k\nfor i in range(1, n):\n diff = k - min(t[i] - t[i-1], k)\n ans -= diff\nprint(ans)", "n,T = list(map(int, input().split()))\n\nt = list(map(int, input().split()))\nans = 0\nfor i, j in zip(t,t[1:]):\n ans += min(j-i,T)\nprint((ans + T))\n", "N,T = list(map(int, input().split()))\nt = list(map(int,input().split()))\nans = 0\nfor i in range(N):\n if i == 0:\n continue\n\n if t[i] - t[i-1] < T:\n ans += t[i] - t[i-1]\n else:\n ans += T\n\nans += T\nprint (ans)\n"] | {"inputs": ["2 4\n0 3\n", "2 4\n0 5\n", "4 1000000000\n0 1000 1000000 1000000000\n", "1 1\n0\n", "9 10\n0 3 5 7 100 110 200 300 311\n"], "outputs": ["7\n", "8\n", "2000000000\n", "1\n", "67\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 24,249 | |
bc965a4a6108663b9ef2f9a1307a73a3 | UNKNOWN | You have got a shelf and want to put some books on it.
You are given $q$ queries of three types: L $id$ β put a book having index $id$ on the shelf to the left from the leftmost existing book; R $id$ β put a book having index $id$ on the shelf to the right from the rightmost existing book; ? $id$ β calculate the minimum number of books you need to pop from the left or from the right in such a way that the book with index $id$ will be leftmost or rightmost.
You can assume that the first book you will put can have any position (it does not matter) and queries of type $3$ are always valid (it is guaranteed that the book in each such query is already placed). You can also assume that you don't put the same book on the shelf twice, so $id$s don't repeat in queries of first two types.
Your problem is to answer all the queries of type $3$ in order they appear in the input.
Note that after answering the query of type $3$ all the books remain on the shelf and the relative order of books does not change.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) β the number of queries.
Then $q$ lines follow. The $i$-th line contains the $i$-th query in format as in the problem statement. It is guaranteed that queries are always valid (for query type $3$, it is guaranteed that the book in each such query is already placed, and for other types, it is guaranteed that the book was not placed before).
It is guaranteed that there is at least one query of type $3$ in the input.
In each query the constraint $1 \le id \le 2 \cdot 10^5$ is met.
-----Output-----
Print answers to queries of the type $3$ in order they appear in the input.
-----Examples-----
Input
8
L 1
R 2
R 3
? 2
L 4
? 1
L 5
? 1
Output
1
1
2
Input
10
L 100
R 100000
R 123
L 101
? 123
L 10
R 115
? 100
R 110
? 115
Output
0
2
1
-----Note-----
Let's take a look at the first example and let's consider queries: The shelf will look like $[1]$; The shelf will look like $[1, 2]$; The shelf will look like $[1, 2, 3]$; The shelf looks like $[1, \textbf{2}, 3]$ so the answer is $1$; The shelf will look like $[4, 1, 2, 3]$; The shelf looks like $[4, \textbf{1}, 2, 3]$ so the answer is $1$; The shelf will look like $[5, 4, 1, 2, 3]$; The shelf looks like $[5, 4, \textbf{1}, 2, 3]$ so the answer is $2$.
Let's take a look at the second example and let's consider queries: The shelf will look like $[100]$; The shelf will look like $[100, 100000]$; The shelf will look like $[100, 100000, 123]$; The shelf will look like $[101, 100, 100000, 123]$; The shelf looks like $[101, 100, 100000, \textbf{123}]$ so the answer is $0$; The shelf will look like $[10, 101, 100, 100000, 123]$; The shelf will look like $[10, 101, 100, 100000, 123, 115]$; The shelf looks like $[10, 101, \textbf{100}, 100000, 123, 115]$ so the answer is $2$; The shelf will look like $[10, 101, 100, 100000, 123, 115, 110]$; The shelf looks like $[10, 101, 100, 100000, 123, \textbf{115}, 110]$ so the answer is $1$. | ["n = int(input())\nd = {}\nmatr = [0] * (2 * n + 1)\nhead = n - 1\ntail = n\nfor i in range(n):\n\tst, n = input().split()\n\tn = int(n)\n\tif st == 'L':\n\t\tmatr[head] = n\n\t\td[n] = head\n\t\thead -= 1\n\telif st == 'R':\n\t\tmatr[tail] = n\n\t\td[n] = tail\n\t\ttail += 1\n\telse:\n\t\tprint(min(d[n] - head, tail - d[n]) - 1)\n", "n=int(input())\na=[0]*200001\nmi=0\nma=0\ninput()\nfor i in range(n-1):\n r,id=input().split()\n id=int(id)\n if r=='L':\n mi-=1\n a[id]=mi\n elif r=='R':\n ma+=1\n a[id]=ma\n else:\n print(min(a[id]-mi,ma-a[id]))", "q = int(input())\n\nif q > 0:\n\tleft = 0\n\tright = 0\n\n\td = dict()\n\n\t[q_type, q_id] = input().split()\n\td[q_id] = 0\n\n\tfor i in range(q-1):\n\t\t[q_type, q_id] = input().split()\n\t\tif q_type == 'L':\n\t\t\tleft -=1\n\t\t\td[q_id] = left\n\t\telif q_type == 'R':\n\t\t\tright += 1\n\t\t\td[q_id] = right\n\t\telif q_type == '?':\n\t\t\tp = d[q_id]\n\t\t\tprint(min(p-left, right-p))", "n=int(input())\nbooklist={}\na=input().split()\nbooklist[a[1]]=0\nleft=0\nright=0\nfor i in range(n-1):\n a=input().split()\n if a[0]==\"L\":\n left-=1\n booklist[a[1]]=left\n elif a[0]==\"R\":\n right+=1\n booklist[a[1]]=right\n else:\n print(min(booklist[a[1]]-left,right-booklist[a[1]]))", "leftmost = 1000000\nrightmost = leftmost-1\nall_books = dict()\nq = int(input())\nfor _ in range(q):\n\tq_type, q_book = input().split()\n\tif q_type == \"L\":\n\t\tleftmost -= 1\n\t\tall_books[q_book] = leftmost\n\telif q_type == \"R\":\n\t\trightmost += 1\n\t\tall_books[q_book] = rightmost\n\telse:\n\t\tprint(min(rightmost-all_books[q_book], all_books[q_book]-leftmost))\n", "n = int(input())\nshelf, L, R = {}, 0, 0\np, d = input().split()\nshelf[d] = 0\nfor i in range(n-1):\n p, d = input().split()\n if p == 'L':\n shelf[d] = L - 1\n L -= 1 \n elif p == 'R':\n shelf[d] = R + 1\n R += 1\n else:\n a = -(L - shelf[d]) \n b = R - shelf[d] \n print(min(a, b))\n\n", "n = int(input())\nd = {}\nl = 0\nr = 0\nfor i in range(n):\n s = input().split()\n if s[0] == 'R':\n d[s[1]] = [1, r]\n r += 1\n if s[0] == 'L':\n d[s[1]] = [0, l]\n l += 1\n if s[0] == '?':\n if d[s[1]][0] == 0:\n print(min(l - d[s[1]][1] - 1, d[s[1]][1] + r))\n else:\n print(min(r - d[s[1]][1] - 1, l + d[s[1]][1]))", "TOT = 2*10**5\n# print(TOT)\na = [-1] * (TOT + 1)\n\nq = int(input())\nfp = input().split()\na[int(fp[1])] = 0\nL = -1\nR = 1\nfor _ in range(q-1):\n qq = input().split()\n pos = int(qq[1])\n if (qq[0]=='L'):\n a[pos] = L\n L -= 1\n elif qq[0]=='R':\n a[pos] = R\n R += 1\n else:\n print(min(a[pos] - L - 1,R - a[pos] - 1))\n \n", "import sys\nf=sys.stdin\nout=sys.stdout\n\nq=int(f.readline().rstrip('\\r\\n'))\npos,id=f.readline().rstrip('\\r\\n').split()\nmid=int(id)\n\nleft=[]\nright=[]\ndleft={}\ndright={}\n\nfor i in range(q-1):\n\tpos,id=f.readline().rstrip('\\r\\n').split()\n\tid=int(id)\n\tif pos==\"L\":\n\t\tleft.append(id)\n\t\tdleft[id]=len(dleft)+1\n\telif pos==\"R\":\n\t\tright.append(id)\n\t\tdright[id]=len(dright)+1\n\telse:\n\t\tif id==mid:\n\t\t\tout.write(str(min(len(dleft),len(dright)))+\"\\n\")\n\t\telif id in dleft:\n\t\t\tz=len(dleft)-dleft[id]+1\n\t\t\tout.write(str(min(z-1,1+len(dright)+dleft[id]-1))+\"\\n\")\n\t\telse:\n\t\t\tz=dright[id]\n\t\t\t#print(z)\n\t\t\tout.write(str(min(len(dleft)+z,len(dright)-z))+\"\\n\")", "mini, maxi = 1, 0\nindexes = {}\nans = []\nfor q in range(int(input())):\n\tcmd = input().split()\n\tidx = int(cmd[1])\n\tif cmd[0]==\"L\":\n\t\tmini-=1\n\t\tindexes[idx]=mini\n\telif cmd[0]==\"R\":\n\t\tmaxi+=1\n\t\tindexes[idx]=maxi\n\telse:\n\t\tind = indexes[idx]\n\t\tans.append(min(ind-mini,maxi-ind))\nprint(*ans,sep=\"\\n\")\n", "n = int(input())\narr = {}\nmi = 0\nma = 0\nt, i = input().split()\narr[i] = 0\nfor _ in range(n-1):\n\tt, i = input().split()\n\tif t == 'L':\n\t\tmi -= 1\n\t\tarr[i] = mi\n\telif t == 'R':\n\t\tma += 1\n\t\tarr[i] = ma\n\telse:\n\t\tprint(min(ma-arr[i], arr[i]-mi))\n", "q = int(input())\nminimum = 0\nmaximum = -1\nd = {}\nfor i in range(q):\n a, b = input().split()\n b = int(b)\n if a == 'L':\n minimum -= 1\n d[b] = minimum\n elif a == 'R':\n maximum += 1\n d[b] = maximum\n elif a == '?':\n print(min(d[b] - minimum, maximum - d[b]))\n \n", "q = int(input())\nlm = 0\nrm = 0\nidx = {}\nans = []\nfor i in range(q):\n c,id = [s for s in input().split()]\n if i == 0:\n idx[id] = 0\n else:\n if c == 'L':\n lm -= 1\n idx[id] = lm\n elif c == 'R':\n rm += 1\n idx[id] = rm\n elif c == '?':\n ans.append(min(idx[id]-lm, rm-idx[id]))\nprint(*ans, sep='\\n')", "n=int(input())\nln=0\nrn=0\nids={}\nbel={}\n\nfor i in range(n):\n s=input().split()\n op=s[0]\n id=int(s[1])\n\n if op=='L' or op=='R':\n if op=='L':\n ln+=1\n ids[id]=ln\n bel[id]='l'\n else:\n rn+=1\n ids[id]=rn\n bel[id]='r'\n else:\n if bel[id]=='l':\n l=ln-ids[id]\n r=ids[id]+rn-1\n print(min(l,r))\n else:\n r=rn-ids[id]\n l=ids[id]+ln-1\n print(min(l,r))\n\n\n # if op=='L' or op=='R':\n # if op=='L':\n # ln+=1\n # ids[id]=-ln\n # else:\n # rn+=1\n # ids[id]=rn\n # else:\n # if ids[id]<0:\n # ll=ln-abs(ids[id])+1\n # rr=abs(ids[id])+rn\n # print(min(ll,rr)-1)\n # else:\n # rr=rn-abs(ids[id])+1\n # ll=abs(ids[id])+rn\n # print(min(ll,rr)-1)\n", "import sys\n\nq=int(sys.stdin.readline())\nQ=[sys.stdin.readline().split() for i in range(q)]\n\nLcount=0\nRcount=0\nBOOK=[None]*(2*10**5+1)\nfor i in range(q):\n if Q[i][0]==\"L\":\n Lcount+=1\n BOOK[int(Q[i][1])]=(\"L\",Lcount,Rcount)\n \n \n elif Q[i][0]==\"R\":\n Rcount+=1\n BOOK[int(Q[i][1])]=(\"R\",Lcount,Rcount)\n \n\n else:\n l=BOOK[int(Q[i][1])][1]\n r=BOOK[int(Q[i][1])][2]\n #print(l,r)\n if BOOK[int(Q[i][1])][0]==\"R\":\n ANS=min(Rcount-r,Lcount-l+(r+l-1))\n elif BOOK[int(Q[i][1])][0]==\"L\":\n ANS=min(Lcount-l,Rcount-r+(r+l-1))\n\n\n sys.stdout.write(str(ANS)+\"\\n\")\n\n#print(Lcount)\n \n", "#!/usr/bin/env python3\nimport sys\n\ndef rint():\n return list(map(int, sys.stdin.readline().split()))\n#lines = stdin.readlines()\n\nq = int(input())\n\norder = [0]*(2*10**5+1)\nlm_order = 0\nrm_order = 0\n\nnot_init = 1\nfor i in range(q):\n cmd, id = sys.stdin.readline().split()\n id = int(id)\n if cmd == 'L':\n order[id] = lm_order - 1\n lm_order = lm_order - 1\n if not_init:\n rm_order = lm_order\n not_init = 0\n elif cmd == 'R':\n order[id] = rm_order + 1\n rm_order = rm_order + 1\n if not_init:\n lm_order = rm_order\n not_init = 0\n else:\n print(min(order[id]- lm_order, rm_order - order[id]))\n\n", "'''input\n10\nL 100\nR 100000\nR 123\nL 101\n? 123\nL 10\nR 115\n? 100\nR 110\n? 115\n'''\nfrom sys import stdin, stdout\n\ndef myfunction(mydict, current, second):\n\ta = mydict[second]\n\tif a[2] == 'R':\n\t\treturn min( current[1] - a[1], current[0] + a[1] - 1)\n\telse:\n\t\treturn min(current[0] - a[0], current[1] + a[0] - 1)\n\nq = int(stdin.readline())\nmydict = dict()\ncurrent = [0, 0, 0]\n\nwhile q > 0:\n\t\n\tfirst, second = stdin.readline().split()\n\tif first == 'L':\n\t\tmydict[second] = [current[0] + 1, current[1], 'L']\n\t\tcurrent = [current[0] + 1, current[1], 'L']\n\telif first == 'R':\n\t\tmydict[second] = [current[0], current[1] + 1, 'R']\n\t\tcurrent = [current[0], current[1] + 1, 'R']\n\telse:\n\t\tprint(myfunction(mydict, current, second))\n\t#print(current)\n\n\tq -= 1", "# use this as the main template for python problems\nimport sys\n\ndef solution(q):\n\n placed = False;\n lind = 0;\n rind = 0;\n book_map = {};\n for i in range(q):\n \n op, book_ind = [val for val in sys.stdin.readline().split()]\n book_ind = int(book_ind)\n\n if(op == 'R'):\n book_map[book_ind] = rind;\n rind += 1;\n if(not placed):\n placed = True;\n lind -= 1;\n\n elif(op == 'L'):\n book_map[book_ind] = lind;\n lind -= 1;\n if(not placed):\n placed = True;\n rind += 1;\n \n elif(op == '?'):\n ldist = book_map[book_ind] - lind;\n rdist = rind - book_map[book_ind];\n print((min(ldist, rdist) - 1));\n\n\ndef __starting_point():\n\n q = [int(val) for val in sys.stdin.readline().split()][0]\n solution(q);\n \n\n\n\n\n\n__starting_point()", "import collections\narr = [0]*200010\nquery = int(input())\ntotal = 0\nl = 0\nr = 0\nans = []\nfor test in range(query):\n\tty,idd = [(x) for x in input().split()]\n\tidd = int(idd)\n\tif ty=='L':\n\t\tl+=1\n\t\tarr[idd] = (1,l-1)\n\t\ttotal+=1\n\telif ty=='R':\n\t\tr+=1\n\t\tarr[idd] = (0,r-1)\n\t\ttotal+=1\n\telse:\t\n\t\tleft = 0\n\t\tright = 0\n\t\tx = arr[idd]\n\t\tif x[0]==0:\n\t\t\tleft = l+x[1]\n\t\t\tright = r-x[1]-1\n\t\telse:\n\t\t\tleft = l-x[1]-1\n\t\t\tright = r+x[1]\n\t\tans.append(min(left,right))\n\t#print(arr)\nfor i in range(len(ans)):\n\tprint(ans[i])", "n = int(input())\ns, e = 0, 0\nc = True\nw = dict()\nfor _ in range(n):\n q, d = input().split()\n if q == \"R\":\n if c:\n s += 1\n c = False\n e += 1\n w[d] = e\n elif q == \"L\":\n if c:\n e -= 1\n c = False\n s -= 1\n w[d] = s\n else:\n i = w[d]\n if i > e:\n i -= n\n print(min(e - i, i - s))\n", "n = int(input())\nr = l = 0\nright_pos = {}\nleft_pos = {}\nfor _ in range(n):\n com,id = input().split()\n if com == 'R':\n right_pos[id] = r\n r += 1\n elif com == 'L':\n left_pos[id] = l\n l += 1\n else:\n if id in right_pos:\n ind = right_pos[id]\n output = min(l+ind,r-ind-1)\n print(output)\n else:\n ind = left_pos[id]\n output = min(l-ind-1,ind+r)\n print(output)", "q = int(input())\nl = 0\nr = 0\nall_ = 0\narr = [0] * (1000000 * 2)\npos = [0] * 1000000\nfor i in range(q):\n s = input().split()\n id_ = int(s[1])\n op = s[0]\n if op == 'L':\n if all_ == 0:\n l = 1000001\n r = l + 1\n arr[l] = id_\n pos[id_] = l\n l -= 1\n all_ += 1\n if op == 'R':\n if all_ == 0:\n r = 1000001\n l = r - 1\n arr[r] = id_\n pos[id_] = r\n r += 1\n all_ += 1\n if op == '?':\n print(min(pos[id_] - l, r - pos[id_]) - 1)", "q = int(input())\ndc = dict()\nl = 0\nr = 0\nz, n = input().split()\nn = int(n)\ndc[n] = l\nfor i in range(q - 1):\n z, n = input().split()\n n = int(n)\n if z == 'L':\n l -= 1\n dc[n] = l\n elif z == 'R':\n r += 1\n dc[n] = r\n else:\n print(min(dc[n] - l, r - dc[n]))\n", "# coding=utf-8\n\nq = int(input())\n\na = [0 for i in range(2 * 10 ** 5 + 1)]\nbase = 0\nl = -1\nr = 1\ninput()\nk = 0\n\nfor i in range(q - 1):\n s = input().split()\n b = int(s[1])\n\n if s[0] == 'L':\n a[b] = l\n l -= 1\n base += 1\n k += 1\n elif s[0] == 'R':\n a[b] = r\n r += 1\n k += 1\n else:\n ind = a[b] + base\n print(min(ind, k - ind))"] | {
"inputs": [
"8\nL 1\nR 2\nR 3\n? 2\nL 4\n? 1\nL 5\n? 1\n",
"10\nL 100\nR 100000\nR 123\nL 101\n? 123\nL 10\nR 115\n? 100\nR 110\n? 115\n",
"6\nL 1\nR 2\nR 3\n? 2\nL 4\n? 1\n",
"7\nL 1\nR 2\nR 3\nL 4\nL 5\n? 1\n? 2\n"
],
"outputs": [
"1\n1\n2\n",
"0\n2\n1\n",
"1\n1\n",
"2\n1\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 12,035 | |
efeae55d1ecbb0f9a01f827da38dce54 | UNKNOWN | You are given an integer $n$.
You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: Replace $n$ with $\frac{n}{2}$ if $n$ is divisible by $2$; Replace $n$ with $\frac{2n}{3}$ if $n$ is divisible by $3$; Replace $n$ with $\frac{4n}{5}$ if $n$ is divisible by $5$.
For example, you can replace $30$ with $15$ using the first operation, with $20$ using the second operation or with $24$ using the third operation.
Your task is to find the minimum number of moves required to obtain $1$ from $n$ or say that it is impossible to do it.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 1000$) β the number of queries.
The next $q$ lines contain the queries. For each query you are given the integer number $n$ ($1 \le n \le 10^{18}$).
-----Output-----
Print the answer for each query on a new line. If it is impossible to obtain $1$ from $n$, print -1. Otherwise, print the minimum number of moves required to do it.
-----Example-----
Input
7
1
10
25
30
14
27
1000000000000000000
Output
0
4
6
6
-1
6
72 | ["for i in range(int(input())):\n \n n=int(input())\n moves=0\n while n%2==0:\n n=n//2\n moves+=1\n while n%3==0:\n n=n//3\n moves+=2\n while n%5==0:\n n=n//5\n moves+=3\n if n==1:\n print(moves)\n else :\n print(-1)", "#!/usr/bin/env python\nfor _ in range(int(input())):\n n = int(input())\n a, b, c = 0, 0, 0\n while n % 2 == 0:\n a += 1\n n //= 2\n while n % 3 == 0:\n a += 1\n b += 1\n n //= 3\n while n % 5 == 0:\n a += 2\n c += 1\n n //= 5\n if n > 1:\n print(-1)\n else:\n print(a + b + c)\n", "q = int(input())\nfor i in range(q):\n n = int(input())\n num = 0\n while n % 2 == 0:\n num += 1\n n //= 2\n while n % 3 == 0:\n num += 2\n n //= 3\n while n % 5 == 0:\n num += 3\n n //= 5\n\n if n == 1:\n print(num)\n else:\n print(-1)", "def main():\n q = int(input())\n for i in range(q):\n t = int(input())\n ans = 0\n while t % 5 == 0:\n t = (4 * t) // 5\n ans += 1\n while t % 3 == 0:\n t = (2 * t) // 3\n ans += 1\n while t % 2 == 0:\n t //= 2\n ans += 1\n if t != 1:\n print(-1)\n else:\n print(ans)\n\n\nmain()\n", "def solve(n):\n\tc = 0\n\tif n == 1:\n\t\treturn c\n\twhile n != 1:\n\t\tif n%2 == 0:\n\t\t\tn //= 2\n\t\telif n%3 == 0:\n\t\t\tn = 2*n//3\n\t\telif n%5 == 0:\n\t\t\tn = 4*n//5\n\t\telse:\n\t\t\treturn -1\n\t\tc += 1\n\treturn c\n\n\nfor _ in range(int(input().strip())):\n\tn = int(input().strip())\n\tprint(solve(n))\n\n", "q = int(input())\nfor _ in range(q):\n n = int(input())\n c = 0\n while n > 1:\n c += 1\n if n % 2 == 0:\n n //= 2\n elif n % 3 == 0:\n n = (n // 3) * 2\n elif n % 5 == 0:\n n = (n // 5) * 4\n else:\n break\n if n == 1:\n print(c)\n else:\n print(-1)\n", "# @author \n\nimport sys\n\n\nclass ADivideIt:\n def solve(self):\n for _ in range(int(input())):\n n = int(input())\n cnt = 0\n while n != 1:\n if n % 2 == 0:\n n //= 2\n elif n % 3 == 0:\n n //= 3\n n *= 2\n elif n % 5 == 0:\n n *= 4\n n //= 5\n else:\n print(-1)\n break\n cnt += 1\n else:\n print(cnt)\n\n\n\n\nsolver = ADivideIt()\ninput = sys.stdin.readline\n\nsolver.solve()\n", "def f(n):\n s=0\n while n%2==0:\n n//=2\n s+=1\n while n%3==0:\n n//=3\n s+=2\n while n%5==0:\n n//=5\n s+=3\n if n!=1:\n return -1\n else:\n return s\nfor k in range(int(input())):\n print(f(int(input())))\n", "def ain():\n return map(int,input().split())\ndef lin():\n return list(ain())\n\n\ndef plist(l):\n for x in l:\n print(x, end= ' ')\n print()\n\ndef indexof(l,v,l3):\n return l3[v]\n\n\nfor _ in range(int(input())):\n n = int(input())\n c = 0\n f= 0\n while n != 1:\n if n%2 == 0:\n n =n //2\n elif n%3 == 0:\n n = (2*n)//3\n elif n%5 == 0:\n n = (4*n) //5\n else:\n f = 1\n print(-1)\n break\n c+=1\n if f == 0:\n print(c)\n\n\n", "q = int(input())\nfor q in range(q):\n n = int(input())\n ans = 0\n while (n != 1):\n if n % 5 == 0:\n n = n // 5 * 4\n elif n % 3 == 0:\n n = n // 3 * 2\n elif n & 1 == 0:\n n >>= 1\n else:\n break\n ans += 1\n if n != 1:\n print(-1)\n else:\n print(ans)\n", "def calc(n):\n re = 0\n while n % 5 == 0:\n n = n//5*4\n re += 1\n while n % 3 == 0:\n n = n//3*2\n re += 1\n while n % 2 == 0:\n n = n//2\n re += 1\n if n == 1:\n return re\n else:\n return -1\n\nQ = int(input())\nfor _ in range(Q):\n print(calc(int(input())))\n", "q = int(input())\nfor i in range(q):\n n = int(input())\n ops = 0\n while not n%2:\n n = n//2\n ops += 1\n while not n%3:\n n = n//3\n ops += 2\n while not n%5:\n n = n//5\n ops += 3\n print(-1 if n>1 else ops)\n", "def solve(n):\n p2, p3, p5 = 0, 0, 0\n while n % 2 == 0:\n n //= 2;\n p2 += 1\n while n % 3 == 0:\n n //= 3\n p3 += 1\n while n % 5 == 0:\n n //= 5\n p5 += 1\n if n != 1:\n return -1\n return 2 * p3 + 3 * p5 + p2\n\nq = int(input())\nfor i in range(q):\n n = int(input())\n print(solve(n))", "q = int(input())\nfor _ in range(q):\n n = int(input())\n ans = 0\n while n % 5 == 0:\n ans += 3\n n //= 5\n while n % 3 == 0:\n ans += 2\n n //= 3\n while n % 2 == 0:\n ans += 1\n n //= 2\n if n != 1:\n print(-1)\n else:\n print(ans)\n\n \n", "n = int(input())\nfor i in range(n):\n q = int(input())\n s = 0\n while(q%5==0):\n q = q//5\n s+=3\n while(q%3==0):\n q = q//3\n s+=2\n while(q%2==0):\n q = q//2\n s+=1\n if(q==1):\n print(s)\n else:\n print(-1)\n", "def fix(a):\n c = 0\n while a != 1:\n if a % 2 == 0:\n a = a // 2\n c += 1\n elif a % 3 == 0:\n a = 2 * a // 3\n c += 1\n elif a % 5 == 0:\n a = 4 * a // 5\n c += 1\n else:\n return -1\n return c\n\ndef go():\n q = int(input())\n o = ''\n for i in range(q):\n o += str(fix(int(input()))) + '\\n'\n return o\n\nprint(go())\n", "q = int(input())\nfor i in range(q):\n n = int(input())\n ans = 0\n while n % 2 == 0:\n n //= 2\n ans += 1\n while n % 3 == 0:\n n //= 3\n ans += 2\n while n % 5 == 0:\n n //= 5\n ans += 3\n if n == 1:\n print(ans)\n else:\n print(-1)", "for i in range(int(input())):\n n = int(input()) \n cnt = 0\n while n > 1:\n cnt += 1\n if n % 2 == 0:\n n //= 2\n elif n % 3 == 0:\n n = 2 * n // 3\n elif n % 5 == 0:\n n = 4 * n // 5\n else:\n cnt = -1\n break\n print(cnt) \n \n", "n = int(input())\nfor i in range(n):\n x = int(input())\n k = 0\n while x != 1:\n if x % 2 == 0:\n x = x // 2\n k += 1\n elif x % 3 == 0:\n x = x - x// 3\n k += 1\n elif x % 5 == 0:\n x = x - x // 5\n k+= 1\n else:\n k = -1\n break\n print(k)", "\"\"\"\nNTC here\n\"\"\"\nfrom sys import setcheckinterval,stdin\nsetcheckinterval(1000)\n\n#print(\"Case #{}: {} {}\".format(i, n + m, n * m))\n\niin=lambda :int(stdin.readline())\nlin=lambda :list(map(int,stdin.readline().split()))\n\nfor _ in range(iin()):\n n=iin()\n ans=0\n while n!=1:\n ans+=1\n if n%2==0:\n n//=2\n elif n%3==0:\n n=2*(n//3)\n elif n%5==0:\n n=4*(n//5)\n else:\n print(-1)\n break\n else:\n print(ans)", "q = int(input())\n\nfor _ in range(q):\n n = int(input())\n\n moves = 0\n\n while n % 5 == 0:\n moves += 1\n n = n // 5 * 4\n\n while n % 3 == 0:\n moves += 1\n n = n // 3 * 2\n while n % 2 == 0:\n moves += 1\n n //= 2\n\n if n == 1:\n print(moves)\n else:\n print(-1)\n", "q = int(input())\n\nfor t in range(q):\n n = int(input())\n ans = 0\n while n%5 == 0:\n n //= 5\n ans += 3\n while n%3 == 0:\n n //= 3\n ans += 2\n while n%2 == 0:\n n //= 2\n ans += 1\n if n == 1:\n print(ans)\n else:\n print(-1)", "for i in range(int(input())):\n x = int(input())\n k = 0\n fl = True\n while fl:\n fl = x % 2 == 0 or x % 3 == 0 or x % 5 == 0\n if fl:\n if x % 2 == 0:\n while x % 2 == 0:\n x //= 2\n k += 1\n elif x % 3 == 0:\n x *= 2\n x //= 3\n k += 1\n elif x % 5 == 0:\n x *= 4\n x //= 5\n k += 1\n if x != 1:\n print(-1)\n else:\n print(k)\n \n"] | {
"inputs": [
"7\n1\n10\n25\n30\n14\n27\n1000000000000000000\n",
"1\n22876792454961\n",
"1\n70745089028899904\n",
"1\n576460752303423487\n"
],
"outputs": [
"0\n4\n6\n6\n-1\n6\n72\n",
"56\n",
"-1\n",
"-1\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,885 | |
0fb976ff5a86613e4558c8531695b61f | UNKNOWN | You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive.
You are allowed to do the following changes: Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $a_{n - i + 1}$; Choose any index $i$ ($1 \le i \le n$) and swap characters $b_i$ and $b_{n - i + 1}$.
Note that if $n$ is odd, you are formally allowed to swap $a_{\lceil\frac{n}{2}\rceil}$ with $a_{\lceil\frac{n}{2}\rceil}$ (and the same with the string $b$) but this move is useless. Also you can swap two equal characters but this operation is useless as well.
You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.
In one preprocess move you can replace a character in $a$ with another character. In other words, in a single preprocess move you can choose any index $i$ ($1 \le i \le n$), any character $c$ and set $a_i := c$.
Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings $a$ and $b$ equal by applying some number of changes described in the list above.
Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string $b$ or make any preprocess moves after the first change is made.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 10^5$) β the length of strings $a$ and $b$.
The second line contains the string $a$ consisting of exactly $n$ lowercase English letters.
The third line contains the string $b$ consisting of exactly $n$ lowercase English letters.
-----Output-----
Print a single integer β the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $a$ equal to string $b$ with a sequence of changes from the list above.
-----Examples-----
Input
7
abacaba
bacabaa
Output
4
Input
5
zcabd
dbacz
Output
0
-----Note-----
In the first example preprocess moves are as follows: $a_1 := $'b', $a_3 := $'c', $a_4 := $'a' and $a_5:=$'b'. Afterwards, $a = $"bbcabba". Then we can obtain equal strings by the following sequence of changes: $swap(a_2, b_2)$ and $swap(a_2, a_6)$. There is no way to use fewer than $4$ preprocess moves before a sequence of changes to make string equal, so the answer in this example is $4$.
In the second example no preprocess moves are required. We can use the following sequence of changes to make $a$ and $b$ equal: $swap(b_1, b_5)$, $swap(a_2, a_4)$. | ["from math import ceil\n\nn = int(input())\n\nword1 = input()\nword2 = input()\n\ncombined = []\nfor i in range(ceil(n / 2)):\n if i > n / 2 - 1:\n combined.append([word1[i], word2[i]])\n else:\n combined.append([word1[i], word1[- i - 1], word2[i], word2[- i - 1]])\n\ncount = 0\nfor l in combined:\n s = set(l)\n if len(s) == 4:\n count += 2\n elif len(s) == 3:\n count += 1\n if l[0] == l[1]:\n count += 1\n elif len(s) == 2:\n counter = 0\n first_letter = l[0]\n for letter in l:\n if letter == first_letter:\n counter += 1\n if counter != 2:\n count += 1\nprint(count)", "def f( a, b, c, d ):\n if (a==b and c==d) or (a==c and b==d) or (a==d and b==c): return 0\n if c==d or b==c or b==d or a==c or a==d: return 1\n return 2\n\nn = int(input())\na, b, s = input(), input(), 0\nfor i in range(n//2):\n s += f(a[i], a[n-1-i], b[i], b[n-1-i])\nif (n & 1) and a[n//2]!=b[n//2]: s += 1\nprint( s )\n", "length = int(input())\nstring1 = input()\nstring2 = input()\n\nchanges = 0\nfor i in range(length // 2):\n c1 = string1[i]\n c2 = string1[length - 1 - i]\n\n c3 = string2[i]\n c4 = string2[length - 1 - i]\n\n if c1 == c2 and c3 == c4:\n continue\n if c1 == c3 and c2 == c4:\n continue\n if c1 == c4 and c2 == c3:\n continue\n if c3 == c4:\n changes += 1\n continue\n if c1 == c3 or c2 == c4:\n changes += 1\n continue\n if c1 == c4 or c2 == c3:\n changes += 1\n continue\n changes += 2\nif length % 2 == 1 and string1[length // 2] != string2[length // 2]:\n changes += 1\nprint(changes)\n\n", "n = int(input().strip())\na = input().strip()\nb = input().strip()\nans = 0\nv = n//2\nfor i in range(v):\n\tj = n-i-1\n\tif a[i]==b[i]:\n\t\tif a[j]!=b[j]:\n\t\t\tans+=1\n\telif a[i]==b[j]:\n\t\tif a[j]!=b[i]:\n\t\t\tans+=1\n\telif a[j]==b[j]:\n\t\tif a[i]!=b[i]:\n\t\t\tans+=1\n\telif a[j]==b[i]:\n\t\tif a[i]!=b[j]:\n\t\t\tans+=1\n\telif a[i]==a[j]:\n\t\tif b[i]!=b[j]:\n\t\t\tans+=2\n\telif b[i]==b[j]:\n\t\tif a[i]!=a[j]:\n\t\t\tans+=1\n\telse:\n\t\tans+=2\nif n&1:\n\ti = (n)//2\n\tif a[i]!=b[i]:\n\t\tans+=1\nprint(ans)", "#from math import ceil, log\n\nt = 1#int(input())\nfor test in range(t):\n n = int(input())\n a = input()\n b = input()\n count = 0\n for i in range(n//2):\n \tarr = [a[i], a[n-i-1], b[i], b[n-i-1]]\n \ttmp = len(set(arr))\n \tif tmp==4:\n \t\tcount+=2\n \telif tmp==1:\n \t\tcontinue\n \telif tmp == 2: \t\t\n \t\t\n \t\tarr.sort()\n \t\tif arr[0] == arr[2] or arr[1]==arr[3]:\n \t\t\tcount+=1\n \telse:\n \t\tif a[i] == a[n-i-1]:\n \t\t\tcount+=2\n \t\telse:\n \t\t\tcount+=1\n\n if n%2==1 and a[n//2]!=b[n//2]:\n \tcount+=1\n print(count)\n\n\n\n\n", "n = int(input())\na = input()\nb = input()\nans = 0\nif n % 2 == 1 and a[n // 2] != b[n // 2]:\n ans += 1\nfor i in range(0, (n // 2) ):\n s = sorted([a[i],a[n - 1 - i],b[i],b[n - 1 - i]])\n l = len(set(s))\n if l == 4:\n ans += 2\n if l == 3:\n if a[i] == a[n - 1 - i] :\n ans += 2\n else:\n ans += 1\n if l == 2:\n if s.count(s[0]) != 2:\n ans += 1\n #print(i,ans)\nprint(ans)", "n=int(input())\na=input()\nb=input()\ncount=0\nfor i in range(n//2):\n d={}\n for c in [a[i],a[n-i-1],b[i],b[n-i-1]]:\n d[c]=d.get(c,0)+1\n if a[i]==a[n-i-1]==b[i]==b[n-i-1]:\n continue\n count+=2\n if a[i]==a[n-i-1] and b[i]!=b[n-i-1] and a[i]!=b[i] and a[i]!=b[n-i-1]:\n continue\n for v in d.values():\n if v>=2:count-=1\nif n%2==1 and a[n//2]!=b[n//2]:\n count+=1\nprint(count)", "from sys import stdin\nfrom math import *\n\nline = stdin.readline().rstrip().split()\nn = int(line[0])\n\nnumbers = stdin.readline().rstrip().split()[0]\nnumbers2 = stdin.readline().rstrip().split()[0]\n\nmoves = 0\nfor i in range(int(ceil(len(numbers)/2))):\n if i == int(ceil(len(numbers)/2))-1 and len(numbers)%2 == 1:\n if numbers[i] != numbers2[i]:\n moves+=1\n break\n else:\n if numbers2[i] == numbers2[n-(i+1)]:\n if numbers[i] != numbers[n - (i + 1)]:\n moves+=1\n else:\n if numbers[i] == numbers2[i] and numbers[n-(i+1)] == numbers2[n-(i+1)]:\n moves +=0\n elif numbers[i] == numbers2[n-(i+1)] and numbers[n-(i+1)] == numbers2[i]:\n moves+=0\n elif numbers[i] == numbers2[i] or numbers[i] == numbers2[n-(i+1)] or numbers[n-(i+1)] == numbers2[i] or numbers[n-(i+1)] == numbers2[n-(i+1)]:\n moves+=1\n else:\n moves+=2\nprint(moves)", "n = int(input())\nst1 = list(input())\nst2 = list(input())\nans = 0\nfor i in range(n // 2 + n % 2):\n if i == (n - i - 1):\n if st1[i] != st2[i]:\n ans += 1\n break\n if st2[i] == st2[n - i - 1]:\n if st1[i] != st1[n - i - 1]:\n ans += 1\n else:\n if (st1[i] != st2[i]) and (st1[n - i - 1] != st2[i]):\n ans += 1\n if (st1[i] != st2[n - i - 1]) and (st1[n - i - 1] != st2[n - i - 1]):\n ans += 1\n\nprint(ans)\n", "n=int(input())\na=input()\nb=input()\no=0\nfor i in range(n//2):\n if b[i]==b[n-1-i]:\n o+=int(a[i]!=a[n-1-i])\n else:\n o+=2-len(set([a[i],a[n-1-i]])&set([b[i],b[n-1-i]]))\nif n%2:\n o+=int(a[n//2]!=b[n//2])\nprint(o)", "n = int(input())\na = list(input())\nb = list(input())\nx, y = [0] * n, [0] * n\nans = 0\nif n % 2 == 1 and a[n // 2] != b[n // 2]: ans += 1\n\nfor i in range(n // 2):\n t = [a[i], a[n-i-1], b[i], b[n-i-1]]\n tmp = 0\n tmp1 = 0\n tmp2 = 0\n tmp3 = 0\n xx = 0\n if t[0] != t[2]: tmp1 += 1\n if t[1] != t[3]: tmp1 += 1\n t[0], t[1] = t[1], t[0]\n\n if t[0] != t[2]: tmp2 += 1\n if t[1] != t[3]: tmp2 += 1\n\n if t[0] != t[1]:\n t[0] = t[1]\n xx = 1\n if t[0] != t[2]: tmp3 += 1\n if t[1] != t[3]: tmp3 += 1\n\n if t[0] == t[1] and t[2] == t[3]:\n ans += xx\n else:\n ans += min(tmp1, tmp2, tmp3)\n\n # print(tmp1, tmp2, t)\n # check = False\n # for i in range(1, 4):\n # if t[i-1] == t[i]:\n # if check: check = False\n # else:\n # tmp += 1\n # check = True\n # else:\n # if check: check = False\n\n # print(t, tmp)\n # ans += 2 - tmp\n\nprint(ans)", "n = int(input())\ns1 = input()\ns2 = input()\n\nx = []\ni = 0\nj = n - 1\nwhile i < j:\n x += [[s1[i], s1[j], s2[i], s2[j]]]\n i += 1\n j -= 1\n\ncount = 0\nfor elem in x:\n a1 = elem[0]\n a2 = elem[1]\n b1 = elem[2]\n b2 = elem[3]\n q = set(elem)\n if len(q) == 2:\n if len(set([a1, a2])) * len(set([b1, b2])) == 2:\n count += 1\n elif len(q) == 4:\n count += 2\n elif len(q) == 3:\n if a1 == b2 or a2 == b1 or a1 == b1 or a2 == b2 or b1 == b2:\n count += 1\n else:\n count += 2\nif n % 2 == 1:\n if s1[i] != s2[i]:\n count += 1\nprint(count)\n \n \n", "from collections import Counter\nR = lambda: map(int, input().split())\n\nn = int(input())\ns1 = input()\ns2 = input()\n\nans = 0\nfor i in range(n//2):\n t = [s1[i], s1[n-i-1], s2[i], s2[n-i-1]]\n c = sorted(list(Counter(t).values()))\n m = len(c)\n if m == 4:\n ans += 2\n elif m == 3:\n ans += 1\n if s1[i] == s1[n-i-1]:\n ans += 1\n elif m == 2 and c[-1] == 3:\n ans += 1\n\nif n % 2:\n p = (n - 1) // 2\n if s1[p] != s2[p]:\n ans += 1\nprint(ans)", "n = int(input())\n\na = input()\nb = input()\n\ntos = []\n\nfor i in range(n):\n if i > n-i-1:\n break\n if i == n-i-1:\n tos.append([ a[i], b[i], \"aa\", \"aa\" ] )\n break\n else:\n x = [ a[i], a[n-i-1], b[i], b[n-i-1] ]\n tos.append(x)\n\n\n\ndef nos(x):\n a = x[:2]\n b = x[2:]\n\n a.sort()\n b.sort()\n\n a = \"\".join(a)\n b = \"\".join(b)\n\n if ( a == b ):\n return 0\n if ( b[0] == b[1] ):\n if ( a[0] == a[1] ):\n return 0\n else:\n return 1\n if ( a[0] == b[0] ):\n return 1\n if ( a[0] == b[1] ):\n return 1\n if ( a[1] == b[0] ):\n return 1\n if ( a[1] == b[1] ):\n return 1\n return 2\n\n\nif ( n == 1):\n if a == b:\n print(0)\n else:\n print(1)\nelse:\n changes = 0\n for i in tos:\n changes += nos(i)\n\n print(changes)\n", "n=int(input())\ns=input()\ns1=input()\nans=0\nfor i in range(n//2):\n a=s[i]\n b=s[n-1-i]\n x=s1[i]\n y=s1[n-1-i]\n st=set()\n st1=set()\n st2=set()\n st.add(a)\n st.add(b)\n st1.add(x)\n st1.add(y)\n st2.add(a)\n st2.add(b)\n st2.add(x)\n st2.add(y)\n if len(st2)==4:\n ans+=2\n elif len(st2)==3:\n if len(st)==1 and len(st1)==2:\n ans+=2\n if len(st1)==1 and len(st)==2:\n ans+=1\n if len(st1)==2 and len(st)==2:\n ans+=1\n \n elif len(st2)==2:\n if (len(st)==2 or len(st1)==2 ) and (len(st)!=len(st1)):\n ans+=1\nif n%2!=0:\n if s[n//2]!=s1[n//2]:\n ans+=1\nprint(ans)\n", "from collections import Counter\nn = int(input())\na = input()[:n]\nb = input()[:n]\nprelim =0\nfor i in range(n//2):\n c = Counter([a[i],a[n-1-i],b[i],b[n-1-i]])\n k = len(c)\n if k == 4:\n \"\"\"\n a x +2op\n b y\n \"\"\"\n prelim +=2\n elif k == 3:\n \"\"\"\n a c +1op\n a b\n \n a a +2op\n b c\n \n a c +1op\n b b\n \"\"\"\n prelim += 2 if a[i]==a[n-1-i] else 1\n elif k==2:\n \"\"\"\n 3 3\n 3 5\n \n 3 5\n 3 3\n \n 2 5\n 2 5\n \"\"\"\n if 3 in list(c.values()):\n prelim += 1\nif n%2:\n if a[n//2]!=b[n//2]:\n prelim +=1\n\nprint(prelim)\n\n\n\n", "from collections import Counter\n\n\ndef main():\n\tn = int(input())\n\ta = input()\n\tb = input()\n\ta1, b1 = a[::-1], b[::-1]\n\tn2 = n // 2\n\tif n % 2 and a[n2] != b[n2]:\n\t\tres = 1\n\telse:\n\t\tres = 0\n\tfor i in range(n2):\n\t\tai, a1i = a[i], a1[i]\n\t\tbi, b1i = b[i], b1[i]\n\t\tif bi == b1i:\n\t\t\tif ai != a1i:\n\t\t\t\tres += 1\n\t\t\tcontinue\n\t\tcnt1 = Counter((ai, a1i))\n\t\tcnt2 = Counter((bi, b1i))\n\t\tres += sum((cnt1 - cnt2).values())\n\tprint(res)\n\n\nmain()\n", "n=int(input())\na=input()\nb=input()\nc=int()\nfor i in range(n//2):\n v=a[i]\n u=a[n-i-1]\n x=b[i]\n y=b[n-i-1]\n if v==x:\n if u!=y:\n c+=1\n elif v==y:\n if u!=x:\n c+=1\n elif x==y:\n if u!=v:\n c+=1\n else:\n if u!=x and u!=y:\n c+=2\n else:\n c+=1\nif n%2==1:\n if a[n//2]!=b[n//2]:\n c+=1\nprint(c)\n", "\nn = int(input())\n\na = input()\nb = input()\n\nans = 0\n\nif n % 2 != 0 and a[n//2] != b[n//2]:\n ans = 1\n\nfor i in range(n // 2):\n s = [a[i], b[i], a[n - i - 1], b[n - i - 1]]\n d = dict()\n for j in s:\n if d.get(j):\n d[j] += 1\n else:\n d[j] = 1\n if list(d.values()) != [2, 2] and list(d.values()) != [4]:\n if list(d.values()) == [1, 1, 1, 1]:\n ans += 2\n continue\n if a[i] == a[n - i - 1]:\n if list(d.values()) == [3, 1]:\n ans += 1\n else:\n ans += 2\n continue\n if b[i] == b[n - i - 1]:\n ans += 1\n continue\n ans += 1\n\n\n\nprint(ans)", "n = int(input())\na = input()\nb = input()\np = 0\nfor i in range(n//2):\n if((a[i] != b[i]) and (a[i] != b[n-i-1]) and (a[i] != a[n-i-1])):\n p+=1\n if((b[i] != b[n-i-1]) and (a[n-1-i] != b[i]) and (a[n-1-i] != b[n-i-1]) and (a[n-1-i] != a[i])):\n p+=1\n else:\n if(a[i] == b[i]):\n if(a[n-i-1] != b[n-i-1]):\n p+=1\n elif(a[i] == b[n-i-1]):\n if(a[n-i-1] != b[i]):\n p+=1\n else:\n if(b[n-i-1] != b[i]):\n p+=2\nif((a[n//2] != b[n//2]) and (n%2==1)):\n p+=1\nprint(p)\n", "from collections import defaultdict\n\nn = int(input())\na = input()\nb = input()\n\ncount = 0\nm = n // 2\np = (n - 1) // 2\nif n % 2 == 1:\n if a[m] != b[m]:\n count += 1\n\nfor i in range(m + (n) % 2):\n d = defaultdict(int)\n\n d[a[m + i]] += 1\n d[a[p - i]] += 1\n d[b[m + i]] += 1\n d[b[p - i]] += 1\n\n if all([(i + 1) % 2 for i in list(d.values())]):\n continue\n\n if b[m + i] == b[p - i] or a[m + i] == b[m + i] or a[m + i] == b[p - i] or a[p - i] == b[m + i] or a[p - i] == b[\n p - i]:\n count += 1\n else:\n count += 2\n\nprint(count)\n", "input()\na, b = [], []\nfor i in input():\n a.append(i)\nfor i in input():\n b.append(i)\nl, r = 0, len(a)-1\nans = 0\nwhile l < r:\n ji = 0\n if a[l] == b[l] or a[r] == b[r] or a[l] == b[r] or a[r] == b[l] or b[l] == b[r]:\n ji = 1\n\n if (a[l] == b[l] and a[r] == b[r]) or (a[l] == b[r] and a[r] == b[l]):\n ji = 2\n if b[l] == b[r] and a[r] == a[l]:\n ji = 2\n ans += 2-ji\n l += 1\n r -= 1\nif l == r and a[l] != b[l]:\n ans += 1\nprint(ans)\n", "len_str = int(input())\na_str = list(input())\nb_str = list(input())\n\nans = 0\n\n\nidx_range = int(len_str / 2) if len_str % 2 == 0 else int(len_str/2) + 1\nfor idx in range(idx_range):\n a_char = [a_str[idx], a_str[len_str - idx - 1]]\n b_char = [b_str[idx], b_str[len_str - idx - 1]]\n\n char_dict = dict()\n for a in a_char:\n if a in char_dict:\n char_dict[a] += 1\n else:\n char_dict[a] = 1\n for b in b_char:\n if b in char_dict:\n char_dict[b] += 1\n else:\n char_dict[b] = 1\n \n if len(char_dict) == 1 or (len(char_dict) == 2 and char_dict[a_char[0]] == 2):\n continue\n else:\n if b_char[0] == b_char[1]:\n ans += 1\n else:\n if char_dict[b_char[0]] == 2 or char_dict[b_char[1]] == 2:\n ans += 1\n elif char_dict[b_char[0]] == 3 or char_dict[b_char[1]] == 3:\n ans += 1\n else:\n ans += 2\n\nif len_str % 2 == 1:\n mid_idx = int(len_str/2)\n if a_str[mid_idx] != b_str[mid_idx]:\n ans += 1\n\nprint(ans)", "n = int(input())\na = input()\nb = input()\n\ni = n//2\nif(n%2 == 0):\n i -= 1\ncnt = 0\nwhile i > -1:\n set_a = {a[i], a[-i-1]}\n set_b = {b[i], b[-i-1]}\n if len(set_a) == 1:\n if len(set_b) != 1:\n if (a[i] == b[i]) or (a[i] == b[-i-1]):\n cnt += 1\n else:\n cnt += 2\n if (len(set_b) == 1) and (n%2 == 1) and (n//2 == i) and (set_a != set_b):\n cnt += 1\n if len(set_a) == 2:\n if len(set_b) == 1:\n cnt += 1\n if len(set_b) == 2:\n common = set_a.intersection(set_b)\n if len(common) == 0:\n cnt += 2\n if len(common) == 1:\n cnt += 1\n \n i -= 1\nprint(cnt) \n"] | {
"inputs": [
"7\nabacaba\nbacabaa\n",
"5\nzcabd\ndbacz\n",
"1\na\nb\n",
"5\nahmad\nyogaa\n"
],
"outputs": [
"4\n",
"0\n",
"1\n",
"3\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 15,536 | |
06196cff10555275036c396fced78dae | UNKNOWN | A frog is currently at the point $0$ on a coordinate axis $Ox$. It jumps by the following algorithm: the first jump is $a$ units to the right, the second jump is $b$ units to the left, the third jump is $a$ units to the right, the fourth jump is $b$ units to the left, and so on.
Formally: if the frog has jumped an even number of times (before the current jump), it jumps from its current position $x$ to position $x+a$; otherwise it jumps from its current position $x$ to position $x-b$.
Your task is to calculate the position of the frog after $k$ jumps.
But... One more thing. You are watching $t$ different frogs so you have to answer $t$ independent queries.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 1000$) β the number of queries.
Each of the next $t$ lines contain queries (one query per line).
The query is described as three space-separated integers $a, b, k$ ($1 \le a, b, k \le 10^9$) β the lengths of two types of jumps and the number of jumps, respectively.
-----Output-----
Print $t$ integers. The $i$-th integer should be the answer for the $i$-th query.
-----Example-----
Input
6
5 2 3
100 1 4
1 10 5
1000000000 1 6
1 1 1000000000
1 1 999999999
Output
8
198
-17
2999999997
0
1
-----Note-----
In the first query frog jumps $5$ to the right, $2$ to the left and $5$ to the right so the answer is $5 - 2 + 5 = 8$.
In the second query frog jumps $100$ to the right, $1$ to the left, $100$ to the right and $1$ to the left so the answer is $100 - 1 + 100 - 1 = 198$.
In the third query the answer is $1 - 10 + 1 - 10 + 1 = -17$.
In the fourth query the answer is $10^9 - 1 + 10^9 - 1 + 10^9 - 1 = 2999999997$.
In the fifth query all frog's jumps are neutralized by each other so the answer is $0$.
The sixth query is the same as the fifth but without the last jump so the answer is $1$. | ["t = int(input())\nfor i in range(t):\n a, b, k = list(map(int, input().split()))\n ans = (a - b) * (k // 2)\n if k % 2 == 1:\n ans += a\n print(ans)\n", "t = int(input())\nfor i in range(t):\n\ta, b, k = list(map(int, input().split()))\n\tif k % 2 == 0:\n\t\tprint((a - b) * k // 2)\n\telse:\n\t\tprint((a - b) * (k // 2) + a)\n", "T = int(input())\nfor t in range(T):\n a, b, c = list(map(int, input().split()))\n ans = a * ((c + 1) // 2) - b * (c // 2)\n print(ans)\n", "#from operator import itemgetter\n#int(input())\n#map(int,input().split())\n#[list(map(int,input().split())) for i in range(q)]\n#print(\"YES\" * ans + \"NO\" * (1-ans))\nt = int(input())\nfor i in range(t):\n a,b,k = list(map(int,input().split()))\n num0 = k // 2\n num1 = k - num0\n print(num1 * a - num0 * b )\n", "t = int(input())\nfor i in range(t):\n T = input().split(' ')\n a,b,k = int(T[0]), int(T[1]), int(T[2])\n s = (k//2+k%2)*a - (k//2) * b\n print(s)\n", "t = int(input())\nfor i in range(t):\n a, b, k = map(int, input().split())\n n = k // 2\n mod = k % 2\n print(n * (a - b) + mod * a)", "t = int(input())\nfor cas in range(t):\n a, b, k = map(int, input().split())\n ans = (a-b)*(k//2)\n if(k%2==1):\n ans += a\n print(ans)", "t = int(input())\n\nfor i in range(t):\n\ta,b,k = map(int,input().split())\n\tbc = k//2\n\tac = k - bc\n\tprint(a*ac-b*bc)", "import sys\nfrom math import floor, ceil\n\ninput = sys.stdin.readline\n\nt = int(input())\n\nfor zzz in range(t):\n r, l, k = list(map(int, input().split()))\n\n print(ceil(k/2)*r - floor(k/2)*l)\n", "import math\nfor _ in range(int(input())):\n a,b,k=list(map(int,input().split()))\n ans=a*math.ceil(k/2)-b*(k//2)\n print(ans)\n", "t = int(input())\nfor i in range(t):\n a,b,k = map(int, input().split())\n print(a*(k//2 + k%2) - b*(k//2))", "I=lambda:list(map(int,input().split()))\nfor _ in range(int(input())):\n a,b,k=I()\n if k%2==0:\n print((k//2)*(a-b))\n else:\n print((k//2)*(a-b)+a)\n", "import sys\ninput = sys.stdin.readline\n\ndef main():\n t = int(input())\n for i in range(t):\n a, b, k = list(map(int, input().split()))\n if k % 2 == 0:\n answer = a*(k//2) - b*(k//2)\n else:\n answer = a*((k//2) + 1) - b*(k//2)\n print(answer)\n return\n\ndef __starting_point():\n main()\n\n__starting_point()", "t=int(input())\nQ=[list(map(int,input().split())) for i in range(t)]\n\nfor a,b,k in Q:\n if k%2==0:\n print((a-b)*k//2)\n else:\n print((a-b)*(k//2)+a)\n", "for _ in range(int(input())):\n a,b,k = map(int,input().split())\n if a == b:\n print(0 if k%2 == 0 else a)\n else:\n if k % 2 == 1:\n print(((k//2)+1)*a - (k//2)*b)\n else:\n print(k//2* a - k//2 * b)", "gcd = lambda a, b: gcd(b, a % b) if b else a\n\n\ndef main():\n t = int(input())\n for _ in range(t):\n a, b, c = map(int, input().split())\n total = 0\n total -= b * (c // 2)\n total += a * (c // 2)\n if c % 2:\n total += a\n print(total)\n\n\n\n\nmain()", "n=int(input())\nQ = []\nfor _ in range(n):\n Q.append(list(map(int,input().split())))\n\nfor a,b,k in Q:\n\ty = int(k/2)\n\tx = k - y\n\tprint(a*x - b*y)\n\n\n", "def main():\n t = int(input())\n for i in range(t):\n a, b, k = map(int, input().split())\n pos = (a - b) * (k // 2)\n pos += a * (k % 2)\n print(pos)\n\nmain()", "t = int(input())\nfor i in range(t):\n a, b, k = list(map(int, input().split()))\n ak = (k + 1) // 2\n bk = k - ak\n print(ak * a - bk * b)\n", "for i in range(int(input())):\n a, b, k=map(int, input().split())\n if (k==0):\n print (0)\n continue\n if (k%2==0):\n print (a*(k//2)-b*(k//2))\n else:\n print (a*(k//2+1)-b*(k//2))", "#a = map(int, input().split())\nt = int(input())\nfor i in range(t):\n a, b, k = list(map(int, input().split()))\n print((k + 1) // 2 * a - (k // 2) * b)\n"] | {
"inputs": [
"6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999\n",
"1\n19280817 1 1\n",
"1\n598 56 799\n",
"1\n599 56 799\n"
],
"outputs": [
"8\n198\n-17\n2999999997\n0\n1\n",
"19280817\n",
"216856\n",
"217256\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 4,092 | |
7dec43d7305f7c0eda962fb18e0525d7 | UNKNOWN | The only difference between easy and hard versions is the maximum value of $n$.
You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$.
The positive integer is called good if it can be represented as a sum of distinct powers of $3$ (i.e. no duplicates of powers of $3$ are allowed).
For example:
$30$ is a good number: $30 = 3^3 + 3^1$, $1$ is a good number: $1 = 3^0$, $12$ is a good number: $12 = 3^2 + 3^1$, but $2$ is not a good number: you can't represent it as a sum of distinct powers of $3$ ($2 = 3^0 + 3^0$), $19$ is not a good number: you can't represent it as a sum of distinct powers of $3$ (for example, the representations $19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$ are invalid), $20$ is also not a good number: you can't represent it as a sum of distinct powers of $3$ (for example, the representation $20 = 3^2 + 3^2 + 3^0 + 3^0$ is invalid).
Note, that there exist other representations of $19$ and $20$ as sums of powers of $3$ but none of them consists of distinct powers of $3$.
For the given positive integer $n$ find such smallest $m$ ($n \le m$) that $m$ is a good number.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 500$) β the number of queries. Then $q$ queries follow.
The only line of the query contains one integer $n$ ($1 \le n \le 10^{18}$).
-----Output-----
For each query, print such smallest integer $m$ (where $n \le m$) that $m$ is a good number.
-----Example-----
Input
8
1
2
6
13
14
3620
10000
1000000000000000000
Output
1
3
9
13
27
6561
19683
1350851717672992089 | ["for _ in range(int(input())):\n\tn = int(input())\n\n\tbits = ['1']\n\twhile int(''.join(bits), 3) < n:\n\t\tbits.append('1')\n\t\n\t\n\tfor i in range(len(bits)):\n\t\tbits[i] = '0'\n\t\tif int(''.join(bits), 3) < n:\n\t\t\tbits[i] = '1'\n\t\n\tprint(int(''.join(bits), 3))\n", "q = int(input())\nfor i in range(q):\n n = int(input())\n prod = 1\n prods = [1]\n sum1 = 0\n a = []\n while prod < n:\n sum1 += prod\n a.append(1)\n prod *= 3\n prods.append(prod)\n if sum1 < n:\n print(prod)\n else:\n for i in range(len(prods) - 1, -1, -1):\n if sum1 - prods[i] >= n:\n sum1 -= prods[i]\n print(sum1)", "from math import log\nfor _ in range(int(input())):\n n = int(input())\n s = []\n x = int(log(n, 3))\n while x >= 0:\n if n >= 2 * 3 ** x:\n n -= 2 * 3 ** x\n s.append(2)\n elif n >= 3 ** x:\n n -= 3 ** x\n s.append(1)\n else:\n s.append(0)\n x -= 1\n s = s[::-1]\n l2 = 2229222\n for i in range(len(s)):\n if s[i] == 2:\n l2 = i\n if l2 != 2229222:\n f = 1\n for i in range(len(s)):\n if i <= l2:\n s[i] = 0\n else:\n if s[i] == 0:\n s[i] = 1\n f = 0\n break\n else:\n s[i] = 0\n if f:\n s.append(1)\n ans = 0\n for i in range(len(s)):\n ans += 3 ** i * int(s[i])\n print(ans)", "def base3(n):\n # 17 -> [2, 2, 1] (reversedd)\n array = []\n while n > 0:\n array.append(n % 3)\n n //= 3\n return array\ndef good(n):\n return 2 not in base3(n)\ndef convert(array):\n return sum(array[i] * 3 ** i for i in range(len(array)))\n\nfor _ in range(int(input())):\n n = base3(int(input()))\n i = 0\n # print(n)\n # [1, 1, 2, 1, 2, 1, 0, 0, 1, 2, 0, 2, 1] ->\n # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1]\n for i in range(len(n) - 1, -1, -1):\n if n[i] == 2:\n for j in range(i - 1, -1, -1):\n n[j] = 0\n break\n i = 0\n while i < len(n):\n # Carry\n if n[i] > 2:\n if i < len(n) - 1:\n n[i + 1] += n[i] // 3\n else:\n n.append(n[i] // 3)\n n[i] %= 3\n # Is it 2\n if n[i] == 2:\n if i < len(n) - 1:\n n[i + 1] += 1\n else:\n n.append(1)\n n[i] = 0\n i += 1\n print(convert(n))\n # print()\n", "# coding: utf-8\n# Your code here!\ndef tobase3(n):\n a = []\n while(n>0):\n a.append(n%3)\n n//=3\n a.reverse()\n return a\n \ndef todec(a):\n sum=0;\n for i in range(len(a)):\n sum*=3\n sum+=a[i]\n return sum\n \n \nt = int(input())\nfor _ in range(t):\n n = int(input())\n a = tobase3(n)\n j=0\n flag = False\n for i in range(len(a)):\n if(a[i]==2):\n flag = True\n j=i\n while(j>=0 and a[j]!=0):\n j-=1\n break\n if(j<0 and flag):\n print(3**len(a))\n elif(flag):\n print(todec(a[:j]+[1]+[0]*(len(a)-j-1)))\n else:\n print(n)", "arr = [3**i for i in range(40)]\ns = sum(arr)\nt = int(input())\nfor _ in range(t):\n n = int(input())\n m = s\n for i in arr[::-1]:\n if m - i >= n:\n m -= i\n print(m)\n", "q = int(input())\nfor fwewfe in range(q):\n\tn = int(input())\n\tsk = 1\n\tsu = 0\n\twhile su < n:\n\t\tsu += sk\n\t\tsk *= 3\n\twhile su >= n and sk > 0:\n\t\tif su - sk >= n:\n\t\t\tsu -= sk\n\t\tsk //= 3\n\tprint(su)", "import sys\ninput = sys.stdin.readline\n\nq=int(input())\n\ndef calc(n):\n for i in range(40):\n if n<=3**i:\n break\n \n if n==3**i:\n return n\n \n elif n>(3**i-1)//2:\n return 3**i\n \n else:\n n-=3**(i-1)\n return 3**(i-1)+calc(n)\n\n \n\nfor testcases in range(q):\n n=int(input())\n print(calc(n))\n\n \n", "import bisect\n\n\nt = int(input())\n\ntmp_ans = [0]*40\nfor i in range(40):\n tmp_ans[i] = 3**i\nruiseki = [0]*41\nfor i in range(40):\n ruiseki[i+1] = ruiseki[i] + tmp_ans[i]\n\nfor _ in range(t):\n n = int(input())\n ind = bisect.bisect_left(ruiseki, n)\n ans = ruiseki[ind]\n \n for i in range(ind)[::-1]:\n if ans - tmp_ans[i] >= n:\n ans -= tmp_ans[i]\n print(ans)", "def main():\n q = int(input())\n thirds = [1]\n while thirds[-1] < 1e19:\n thirds.append(thirds[-1] * 3)\n for t in range(q):\n a = int(input())\n deg = 0\n subans = 0\n while subans < a:\n subans += thirds[deg]\n deg += 1\n while deg != -1:\n if subans - thirds[deg] >= a:\n subans -= thirds[deg]\n deg -= 1\n print(subans)\n\n\nmain()\n", "\nq = int(input())\nN = [int(input()) for i in range(q)]\nt = [3**i for i in range(10)]\n\ndef d(x):\n ans = 0\n m = 1\n while x > 0:\n if x % 2 == 1:\n ans += m\n m *= 3\n x //= 2\n return(ans)\n\n# print(d(2))\n\n\nfor i in range(q):\n n = N[i]\n m = 0\n t = 0\n l = 0\n r = 2**50\n mid = (l+r)//2\n while r - l > 1:\n \n m = d(mid)\n if m >= n:\n r = mid\n else:\n l = mid\n mid=(l+r)//2\n\n print(d(l+1))\n\n\n\n", "t = int(input(''))\n\ndef ternary (n):\n if n == 0:\n return '0'\n nums = []\n while n:\n n, r = divmod(n, 3)\n nums.append(str(r))\n return ''.join(reversed(nums))\n\nfor _ in range(t):\n n = int(input(''))\n b = ternary(n)\n l = len(b)\n #print(b)\n ind = -1\n ans = ''\n for i in range(l):\n if(b[i] == '2'):\n ans = '0'*(l-i)\n ind = i\n break\n if(ind == 0):\n ans = '1'+ans\n elif(ind == -1):\n ans = b\n else:\n ind1 = -1\n for i in range(ind-1,-1,-1):\n if(b[i] == '1'):\n ans = '0'+ans\n else:\n ans = '1'+ans\n ind1 = i\n break\n if(ind1 == -1):\n ans = '1'+ans\n else:\n ans = b[0:ind1]+ans\n \n print(int(ans,3))\n \n \n", "q = int(input())\nfor i in range(q):\n n = int(input())\n s = 0\n i = -1\n while s < n:\n i += 1\n s += 3 ** i\n if s == n:\n print(s)\n else:\n for j in range(i, -1, -1):\n if s - 3 ** j >= n:\n s -= 3 ** j\n print(s)", "\"\"\"\nNTC here\n\"\"\"\nfrom sys import stdin, setrecursionlimit\nsetrecursionlimit(10**7)\n\n\ndef iin(): return int(stdin.readline())\n \n \ndef lin(): return list(map(int, stdin.readline().split()))\n\n\n# range = xrange\n# input = raw_input\n\nMAX_INT=99999999\n\ndef p3(a):\n ans=[]\n while a:\n ans.append(a%3)\n a//=3\n return ans\ndef main():\n t=iin()\n while t:\n t-=1\n n=iin()\n pw=p3(n)+[0,0]\n # print(pw)\n l=len(pw)\n ch=1\n for i in range(l-3,-1,-1):\n if pw[i]>1 :\n if ch:\n pw[i]=0\n pw[i+1]+=1\n ch=0\n else:\n pw[i]=0\n if ch==0:\n pw[i]=0\n for i in range(l-1):\n if pw[i]>1:pw[i]=0;pw[i+1]+=1\n ans=0\n pw=pw[::-1]\n for i in pw:\n ans=ans*3+i\n print(ans)\n\n\n\n \n\n\n\n\n\n\n\nmain()\n# try:\n# main()\n# except Exception as e: print(e)\n", "tc = int(input())\n\ndef ternary (n):\n if n == 0:\n return '0'\n nums = []\n while n:\n n, r = divmod(n, 3)\n nums.append(str(r))\n return list(reversed(nums))\n\n# print(\"here --> \" + ternary(6561))\n# print(\"here --> \" + ternary(3620))\n# print(ternary(4))\nwhile tc > 0:\n\ttc -= 1\n\tn = int(input());\n\trep = ['0'] + ternary(n)\n\tidx = -1\n\tfor i in range(len(rep)):\n\t\tif rep[i] == '2':\n\t\t\tidx = i - 1;\n\n\t\t\twhile rep[idx] != '0':\n\t\t\t\tidx -= 1\n\t\t\trep[idx] = '1'\n\t\t\tfor j in range(idx + 1 , len(rep)):\n\t\t\t\trep[j] = '0'\n\t\n\t# print(rep)\n\tans = 0\n\tfor j in rep:\n\t\tx = ord(j) - ord('0')\n\t\tans = ans * 3 + x\n\tprint(ans)\n", "#started 20 minutes late !\n\n# print(len(str(3**36)))\narr=[]\nfor i in range(40):\n arr.append(3**i)\n# print(arr)\n\nn=int(input())\nfor i in range(n):\n sb=[0]*40\n a=int(input())\n x=a\n xx=a\n for j in range(39,-1,-1):\n if(a-arr[j]>=0):\n a-=arr[j]\n sb[j]=1\n # print(x-a,1)\n x=x-a\n # print(sb)\n if(a==0):\n print(x)\n continue\n for j in range(40):\n if(sb[j]==0):\n x=x+3**j\n # if(x>xx):\n break\n else:\n x=x-3**j\n print(x)\n# print(3**8)\n", "import sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nN = 39\np = [ 3 ** i for i in range( N ) ]\n\nq = int( I() )\nfor _ in range( q ):\n n = int( I() )\n a = [ 0 ] * N\n for i in range( N - 1, -1, -1 ):\n d = n // p[ i ]\n n -= d * p[ i ]\n if d == 2:\n j = i + 1\n while a[ j ]:\n a[ j ] = 0\n j += 1\n a[ j ] = 1\n break\n a[ i ] = d\n n = 0\n for i in range( N ):\n if a[ i ]:\n n += p[ i ]\n print( n )\n", "# -*- coding: utf-8 -*-\n# @Author: apikdech\n# @Date: 22:07:23 22-10-2019\n# @Last Modified by: apikdech\n# @Last Modified time: 22:15:02 22-10-2019\ndef to_string(n):\n\tres = ''\n\twhile(n):\n\t\tres = str(n%3) + res\n\t\tn //= 3\n\tres = list(res)\n\treturn res\n\ndef to_int(s):\n\tres = 0\n\tfor i in range(len(s)):\n\t\tres *= 3\n\t\tres += int(s[i])\n\treturn res\n\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts = to_string(n)\n\tgood = False\n\twhile(not good):\n\t\tcnt = 0\n\t\tidx = 10000\n\t\tfor i in range(len(s)):\n\t\t\tif (s[i] == '2'):\n\t\t\t\tcnt += 1\n\t\t\t\tidx = min(idx, i)\n\t\tif (cnt == 0) : good = True\n\t\tif (not good):\n\t\t\tfor i in range(idx+1, len(s)):\n\t\t\t\ts[i] = '0'\n\t\t\tn = to_int(s)\n\t\t\tn += 3**(len(s) - idx - 1)\n\t\t\ts = to_string(n)\n\tprint(n)", "# for _ in range(int(input())):\n# n=int(input())\n# print((3**38)//10**18) \na=[3**i for i in range(39)]\nfor _ in range(int(input())):\n n=int(input())\n ans=0\n for i in range(38,-1,-1):\n if n-a[i]>=0:\n n-=a[i]\n ans+=a[i]\n elif n-a[i]<0 and (3**i - 1)//2 <n:\n n-=a[i]\n ans+=a[i]\n print(ans) \n \n \n\n", "from bisect import *\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nfrom decimal import *\nfrom copy import *\nfrom heapq import *\nfrom fractions import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 1000010\nMOD = 10**9+7\nspf = [i for i in range(MAXN)]\ndef sieve():\n for i in range(2,MAXN,2):\n spf[i] = 2\n for i in range(3,int(MAXN**0.5)+1):\n if spf[i]==i:\n for j in range(i*i,MAXN,i):\n if spf[j]==j:\n spf[j]=i\ndef fib(n,m):\n if n == 0:\n return [0, 1]\n else:\n a, b = fib(n // 2)\n c = ((a%m) * ((b%m) * 2 - (a%m)))%m\n d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m\n if n % 2 == 0:\n return [c, d]\n else:\n return [d, c + d]\n\ndef charIN(x= ' '):\n return(sys.stdin.readline().strip().split(x))\n\ndef arrIN(x = ' '):\n return list(map(int,sys.stdin.readline().strip().split(x)))\n\ndef ncr(n,r):\n num=den=1\n for i in range(r):\n num = (num*(n-i))%MOD\n den = (den*(i+1))%MOD\n\n return (num*(pow(den,MOD-2,MOD)))%MOD\n\ndef flush():\n return sys.stdout.flush()\n\n'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''\n\ndef ternary (n):\n if n == 0:\n return '0'\n nums = []\n while n:\n n, r = divmod(n, 3)\n nums.append(str(r))\n return ''.join(reversed(nums))\n\n\nfor _ in range(int(input())):\n n = int(input())\n x = ternary(n)\n if '2' not in x:\n print(n)\n else:\n car = 0\n x = x[::-1]\n ans = [i for i in x]\n for i in range(len(x)):\n if x[i]=='2':\n for j in range(i,-1,-1):\n ans[j] = '0'\n car = 1\n elif x[i]=='1':\n if car == 1:\n for j in range(i,-1,-1):\n ans[j] = '0'\n else:\n if car==1:\n ans[i] = '1'\n car = 0\n if car==1:\n ans.append('1')\n ans = ''.join(ans[::-1])\n print(int(ans,3))\n\n", "T = int(input())\nwhile T>0:\n T-=1\n n=int(input())\n ss = n\n a=[]\n while n>0:\n a.append(n%3)\n n=n//3\n fd = -1\n a.append(0)\n p = len(a)\n for i in range(p-1,-1,-1):\n if a[i]==2:\n fd = i\n break\n if fd ==-1:\n print(ss)\n else:\n for i in range(fd,p):\n if a[i]==0:\n a[i]=1\n for j in range(0,i):\n a[j]=0\n break\n ans,k=0,1\n for i in range(0,p):\n ans += a[i]*k\n k*=3\n print(ans)\n", "q = int(input())\n\n\ndef dec_to_base(N, base):\n if not hasattr(dec_to_base, 'table'):\n dec_to_base.table = '0123456789ABCDEF'\n x, y = divmod(N, base)\n return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]\n\n\nfor i in range(q):\n n = int(input())\n s = list(str(dec_to_base(n, 3)))\n balance = n\n for i in range(len(s) - 1, -1, -1):\n if s[i] == \"2\":\n balance -= 3 ** (len(s) - i - 1)\n s[i] = \"1\"\n for i in range(len(s) - 1, -1, -1):\n if balance >= n:\n break\n if s[i] == \"0\" and balance < n:\n s[i] = \"1\"\n balance += 3 ** (len(s) - i - 1)\n while balance < n:\n balance *= 3\n s.append(\"0\")\n if balance < n:\n s[-1] = \"1\"\n balance += 1\n else:\n break\n for i in range(len(s)):\n if balance - 3 ** (len(s) - i - 1) >= n:\n balance -= 3 ** (len(s) - i - 1)\n s[i] = '0'\n print(int(''.join(s), 3))\n", "q = int(input())\nout = []\nfor i in range(q):\n n = int(input())\n mm = 1\n sts = []\n while mm < n:\n sts.append(mm)\n mm *= 3\n sts.append(mm)\n m = sum(sts)\n for i in range(len(sts) - 1, -1, -1):\n if m - sts[i] < n:\n continue\n else:\n m -= sts[i]\n out.append(str(m))\nprint('\\n'.join(out))", "for _ in range(int(input())):\n n = int(input())\n l = []\n j = -1\n while (n):\n temp1 = n % 3\n n = n // 3\n if (temp1 == 2):\n temp1 = 0\n j = len(l)\n l.append(temp1)\n l.append(0)\n # print(l, j)\n if (j != -1):\n for i in range(j):\n l[i] = 0\n l[j + 1] += 1\n while (l[j + 1] == 2):\n j = j + 1\n l[j] = 0\n l[j + 1] += 1\n # print(l)\n s = ''\n for i in l[::-1]:\n s += str(i)\n print(int(s, 3))\n"] | {
"inputs": [
"8\n1\n2\n6\n13\n14\n3620\n10000\n1000000000000000000\n",
"1\n450283905890997363\n",
"1\n387420490\n",
"100\n1\n8\n4\n6\n5\n4\n4\n6\n8\n3\n9\n5\n7\n8\n8\n5\n9\n6\n9\n4\n5\n6\n4\n4\n7\n1\n2\n2\n5\n6\n1\n5\n10\n9\n10\n9\n3\n1\n2\n3\n2\n6\n9\n2\n9\n5\n7\n7\n2\n6\n9\n5\n1\n7\n8\n3\n7\n9\n3\n1\n7\n1\n2\n4\n7\n2\n7\n1\n1\n10\n8\n5\n7\n7\n10\n8\n1\n7\n5\n10\n7\n6\n6\n6\n7\n4\n9\n3\n4\n9\n10\n5\n1\n2\n6\n9\n3\n8\n10\n9\n"
],
"outputs": [
"1\n3\n9\n13\n27\n6561\n19683\n1350851717672992089\n",
"450283905890997363\n",
"387420490\n",
"1\n9\n4\n9\n9\n4\n4\n9\n9\n3\n9\n9\n9\n9\n9\n9\n9\n9\n9\n4\n9\n9\n4\n4\n9\n1\n3\n3\n9\n9\n1\n9\n10\n9\n10\n9\n3\n1\n3\n3\n3\n9\n9\n3\n9\n9\n9\n9\n3\n9\n9\n9\n1\n9\n9\n3\n9\n9\n3\n1\n9\n1\n3\n4\n9\n3\n9\n1\n1\n10\n9\n9\n9\n9\n10\n9\n1\n9\n9\n10\n9\n9\n9\n9\n9\n4\n9\n3\n4\n9\n10\n9\n1\n3\n9\n9\n3\n9\n10\n9\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 15,797 | |
86ed981bdd7d9e96c998140a263c28da | UNKNOWN | You are given four integers $a$, $b$, $x$ and $y$. Initially, $a \ge x$ and $b \ge y$. You can do the following operation no more than $n$ times:
Choose either $a$ or $b$ and decrease it by one. However, as a result of this operation, value of $a$ cannot become less than $x$, and value of $b$ cannot become less than $y$.
Your task is to find the minimum possible product of $a$ and $b$ ($a \cdot b$) you can achieve by applying the given operation no more than $n$ times.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The only line of the test case contains five integers $a$, $b$, $x$, $y$ and $n$ ($1 \le a, b, x, y, n \le 10^9$). Additional constraint on the input: $a \ge x$ and $b \ge y$ always holds.
-----Output-----
For each test case, print one integer: the minimum possible product of $a$ and $b$ ($a \cdot b$) you can achieve by applying the given operation no more than $n$ times.
-----Example-----
Input
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
Output
70
77
177177
999999999000000000
999999999
55
10
-----Note-----
In the first test case of the example, you need to decrease $b$ three times and obtain $10 \cdot 7 = 70$.
In the second test case of the example, you need to decrease $a$ one time, $b$ one time and obtain $11 \cdot 7 = 77$.
In the sixth test case of the example, you need to decrease $a$ five times and obtain $5 \cdot 11 = 55$.
In the seventh test case of the example, you need to decrease $b$ ten times and obtain $10 \cdot 1 = 10$. | ["t = int(input())\n# a = list(map(int, input().split()))\nfor _ in range(t):\n a,b,x,y,n = map(int,input().split())\n \n options = []\n a2 = max(a-n,x)\n b2 = max(b-(n-(a-a2)),y)\n options.append(a2*b2)\n \n b2 = max(b-n,y)\n a2 = max(a-(n-(b-b2)),x)\n options.append(a2*b2)\n \n print(min(options))", "for i in range(int(input())):\n\ta, b, x, y, n = list(map(int, input().split()))\n\n\ta1, b1, x1, y1, n1 = a, b, x, y, n\n\ttoRemove = min(a1-x1, n1)\n\tn1 -= toRemove\n\ta1 -= toRemove\n\ttoRemove = min(n1, b1-y1)\n\tn1 -= toRemove\n\tb1 -= toRemove\n\tans1 = a1*b1\n\n\ta1, b1, x1, y1, n1 = a, b, x, y, n\n\ttoRemove = min(b1-y1, n1)\n\tn1 -= toRemove\n\tb1 -= toRemove\n\ttoRemove = min(n1, a1-x1)\n\tn1 -= toRemove\n\ta1 -= toRemove\n\tans2 = a1*b1\n\n\tprint(min(ans1, ans2))\n\n", "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush,heappop,heapify\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\n\nfrom itertools import accumulate\nfrom functools import lru_cache\n\nM = mod = 998244353\ndef factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))\ndef inv_mod(n):return pow(n, mod - 2, mod)\n\ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef li2():return [i for i in input().rstrip('\\n')]\ndef li3():return [int(i) for i in input().rstrip('\\n')]\n\n\ndef giveanswer(a, b, x, y, n):\n temp = min(a - x, n)\n a -= temp\n n -= temp\n temp = min(b - y, n)\n b -= temp\n n -= temp\n return a * b\nfor _ in range(val()):\n a, b, x, y, n = li()\n print(min(giveanswer(a , b, x, y, n), giveanswer(b, a, y, x, n)))\n", "def solve(a, b, x, y, n):\n x = a-x\n y = b-y\n m = min(x, n)\n n -= m\n a -= m\n m = min(y, n)\n b -= m\n return a*b\n \nfor _ in range(int(input())):\n a, b, x, y, n = list(map(int, input().split()))\n print(min(solve(a, b, x, y, n), solve(b, a, y, x, n)))\n", "t = int(input())\nfor i in range(t):\n a, b, x, y, n = [int(i) for i in input().split()]\n ans = a * b\n\n ck = min(a - x, n)\n ca = a - ck\n cn = n - ck\n cb = b - min(b - y, cn)\n ans = min(ans, ca * cb)\n\n ck = min(b - y, n)\n cb = b - ck\n cn = n - ck\n ca = a - min(a - x, cn)\n ans = min(ans, ca * cb)\n\n print(ans)\n", "for _ in range(int(input())):\n a, b, x, y, n = list(map(int, input().split()))\n posa = max(a - n, x)\n posb = max(b - n, y)\n if posa < posb:\n n -= a - posa\n a = posa\n b = max(b - n, y)\n else:\n n -= b - posb\n b = posb\n a = max(a - n, x)\n print(a * b)\n", "#Bhargey Mehta (Senior)\n#DA-IICT, Gandhinagar\nimport sys, math\nmod = 10**9 + 7\n\ndef goSolve(a, b, x, y, n):\n d = min(n, a-x)\n a -= d\n n -= d\n d = min(n, b-y)\n b -= d\n return a * b\n\ndef solve(test_index):\n a, b, x, y, n = list(map(int, input().split()))\n print(min(goSolve(a, b, x, y, n), goSolve(b, a, y, x, n)))\n return\n\nif 'PyPy' not in sys.version:\n sys.stdin = open('input.txt', 'r')\n\nsys.setrecursionlimit(100000)\nnum_tests = 1\nnum_tests = int(input())\nfor test in range(1, num_tests+1):\n #print(\"Case #{}: \".format(test), end=\"\")\n solve(test)\n", "\"\"\"T=int(input())\nfor _ in range(0,T):\n n=int(input())\n a,b=map(int,input().split())\n s=input()\n s=[int(x) for x in input().split()]\n for i in range(0,len(s)):\n a,b=map(int,input().split())\"\"\"\n\n\nT=int(input())\nfor _ in range(0,T):\n a,b,x,y,n=list(map(int,input().split()))\n\n A=a\n B=b\n N=n\n\n d1 = (a-x)\n d2 = (b-y)\n\n t1=min(d1,n)\n a-=t1\n n-=t1\n t2=min(d2,n)\n b-=t2\n n-=t2\n #print(a,b)\n ans=(a*b)\n\n d1 = (A-x)\n d2 = (B-y)\n\n t2=min(d2,N)\n B-=t2\n N-=t2\n t1=min(d1,N)\n A-=t1\n N-=t1\n\n \n #print(A,B)\n ans=min(ans,A*B)\n print(ans)\n\n\n \n \n", "import sys\n\n\ndef read_int():\n return int(sys.stdin.readline())\n\n\ndef read_ints():\n return list(map(int, sys.stdin.readline().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n a, b, x, y, n = read_ints()\n n1 = min(n, a - x)\n ans = (a - n1) * (b - min(n - n1, b - y))\n n2 = min(n, b - y)\n ans = min(ans, (b - n2) * (a - min(n - n2, a - x)))\n print(ans)\n", "import sys\ninput=sys.stdin.readline\n\n\ndef fmin(a,b,x,y,n):\n v=max(a-n,x)\n val=n-(a-v)\n v1=max(b-val,y)\n return v*v1\n\nT=int(input())\nfor _ in range(T):\n a,b,x,y,n=list(map(int,input().split()))\n v=min(fmin(a,b,x,y,n),fmin(b,a,y,x,n))\n print(v)\n", "for i in range(int(input())):\n\ta, b, x, y, n = (int(j) for j in input().split())\n\tans = 10 ** 18\n\n\td1 = a - x\n\td2 = b - y\n\tif (d1 > n):\n\t\tans = min(ans, (a - n) * b)\n\telif (d1 + d2 > n):\n\t\tans = min(ans, x * (b - n + d1))\n\telse:\n\t\tans = min(ans, x * y)\n\n\tx, y = y, x\n\ta, b = b, a\n\n\td1 = a - x\n\td2 = b - y\n\tif (d1 > n):\n\t\tans = min(ans, (a - n) * b)\n\telif (d1 + d2 > n):\n\t\tans = min(ans, x * (b - n + d1))\n\telse:\n\t\tans = min(ans, x * y)\n\n\tprint(ans)", "t = int(input())\nfor _ in range(t):\n a, b, x, y, n = map(int, input().split())\n a1 = a - min(a - x, n)\n n1 = n - min(a - x, n)\n b1 = b - min(b - y, n1)\n \n b2 = b - min(b - y, n)\n n2 = n - min(b - y, n)\n a2 = a - min(a - x, n2)\n print(min(a1 * b1, a2 * b2))", "import sys, math\nimport io, os\n#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\nfrom bisect import bisect_left as bl, bisect_right as br, insort\nfrom heapq import heapify, heappush, heappop\nfrom collections import defaultdict as dd, deque, Counter\n# from itertools import permutations,combinations\ndef data(): return sys.stdin.readline().strip()\ndef mdata(): return list(map(int, data().split()))\ndef outl(var): sys.stdout.write('\\n'.join(map(str, var)) + '\\n')\ndef out(var): sys.stdout.write(str(var) + '\\n')\nfrom decimal import Decimal\n# from fractions import Fraction\n# sys.setrecursionlimit(100000)\nmod = int(1e9) + 7\nINF=2**32\n\nfor t in range(int(data())):\n a,b,x,y,n=mdata()\n m1=max(a-n,x)\n m2=max(b-n,y)\n if m1<m2:\n m2=max(b-(n-(a-m1)),y)\n else:\n m1=max(a-(n-(b-m2)),x)\n out(m1*m2)", "# Fast IO (be careful about bytestring)\n\n# import os,io\n# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\n\n\nfor _ in range(int(input())):\n a,b,x,y,n = list(map(int,input().split()))\n if a + b - x - y < n:\n print(x * y)\n else:\n minProduct = 10 ** 20\n # Decreasing a first\n if a - n >= x:\n product = (a - n) * b\n if product < minProduct:\n minProduct = product\n else:\n product = x * max(y,b - n + a - x)\n if product < minProduct:\n minProduct = product\n # Decreasing b first\n if b - n >= y:\n product = (b - n) * a\n if product < minProduct:\n minProduct = product\n else:\n product = y * max(x,a - n + b - y)\n if product < minProduct:\n minProduct = product\n print(minProduct)\n", "for _ in range(int(input())):\n a,b,x,y,n=list(map(int,input().split()))\n c=max(a-n,x)\n d=max(b-n,y)\n if c<d:\n ans=c\n n-=a-c\n d=max(b-n,y)\n print(ans*d)\n else:\n ans=d\n n-=b-d\n c=max(a-n,x)\n print(ans*c)\n\n", "def find(a,b,x,y,n):\n req = a-x\n min_val = min(req,n)\n a -= min_val\n n -= min_val\n b -= n\n\n return a*b\n\ndef solve(a,b,x,y,n,ans):\n req1 = a-x\n req2 = b-y\n if req1+req2 <= n:\n a = x\n b = y\n ans.append(str(a*b))\n else:\n min_val = find(a,b,x,y,n)\n min_val = min(min_val,find(b,a,y,x,n))\n ans.append(str(min_val))\n\ndef main():\n t = int(input())\n ans = []\n for i in range(t):\n a,b,x,y,n = list(map(int,input().split()))\n solve(a,b,x,y,n,ans)\n\n print('\\n'.join(ans))\n \n\nmain()\n", "import sys, math, heapq, collections, itertools, bisect\nsys.setrecursionlimit(101000)\n\ndef solve(a, b, x, y, n):\n diffa = a - x\n diffb = b - y\n first = min(diffb, n)\n b -= first\n n -= first\n second = min(diffa, n)\n a -= second\n n -= second\n return a*b\n\nt = int(input())\nfor _ in range(t):\n # n = int(input())\n a, b, x, y, n = map(int, input().split())\n # a = list(map(int, input().split()))\n print(min(solve(a, b, x, y, n), solve(b, a, y, x, n)))", "import sys\nimport math\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef MI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef SI():\n\treturn sys.stdin.readline().strip()\nt = II()\nfor q in range(t):\n\ta,b,x,y,n = MI()\n\tif a-min(n,a-x)<b-min(n,b-y):\n\t\tb,a = a,b\n\t\ty,x = x,y\n\ttemp=min(n,b-y)\n\tn-=temp\n\tb-=temp\n\ta-=min(a-x,n)\n\tprint(a*b)\n\n\n\t\n", "t=int(input())\nfor _ in range(t):\n a,b,x,y,n=map(int,input().split())\n mina1 = max(x, a-n)\n minb1 = max(y, b-(n-a+mina1))\n minb2 = max(y, b-n)\n mina2 = max(x, a-(n-b+minb2))\n print(min(mina1*minb1,mina2*minb2))", "t = int(input())\nfor _ in range(t):\n a, b, x, y, n = list(map(int, input().split()))\n if max(a-n, x) > max(b-n, y):\n a, b = b, a\n x, y = y, x\n d = a - x\n a = max(a - n, x)\n if a > x:\n print(a * b)\n continue\n n -= d\n b = max(b - n, y)\n print(a * b)\n", "t=int(input())\nfor _ in range(t):\n a,b,x,y,n=list(map(int,input().split()))\n min_a=max(a-n,x)\n min_b=max(b-n,y)\n if min_a<min_b:\n n = n - (a - min_a)\n a=min_a\n\n b=max(b-n,y)\n else:\n n = n - (b - min_b)\n b = min_b\n\n a = max(a - n, x)\n print(a*b)", "from sys import stdin\n\ntt = int(stdin.readline())\n\nfor loop in range(tt):\n\n a,b,x,y,n = map(int,stdin.readline().split())\n\n ans = float(\"inf\")\n\n if a-x + b-y < n:\n print (x*y)\n continue\n \n #first a\n if a-x >= n:\n ans = min(ans , (a-n) * b)\n else:\n rem = n - (a-x)\n ans = min(ans , x * (b-rem))\n\n #b\n if b-y >= n:\n ans = min(ans , (b-n) * a)\n else:\n rem = n - (b-y)\n ans = min(ans , y * (a-rem))\n\n print (ans)"] | {
"inputs": [
"7\n10 10 8 5 3\n12 8 8 7 2\n12343 43 4543 39 123212\n1000000000 1000000000 1 1 1\n1000000000 1000000000 1 1 1000000000\n10 11 2 1 5\n10 11 9 1 10\n",
"1\n10 10 8 5 3\n",
"11\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n",
"3\n5 6 3 4 4\n10 10 2 2 4\n10 10 2 2 4\n"
],
"outputs": [
"70\n77\n177177\n999999999000000000\n999999999\n55\n10\n",
"70\n",
"70\n70\n70\n70\n70\n70\n70\n70\n70\n70\n70\n",
"12\n60\n60\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 10,743 | |
68fa59a6b70ec09483e8d03b62c0cacf | UNKNOWN | You are given two positive integers $a$ and $b$.
In one move, you can change $a$ in the following way:
Choose any positive odd integer $x$ ($x > 0$) and replace $a$ with $a+x$; choose any positive even integer $y$ ($y > 0$) and replace $a$ with $a-y$.
You can perform as many such operations as you want. You can choose the same numbers $x$ and $y$ in different moves.
Your task is to find the minimum number of moves required to obtain $b$ from $a$. It is guaranteed that you can always obtain $b$ from $a$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Then $t$ test cases follow. Each test case is given as two space-separated integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain $b$ from $a$ if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain $b$ from $a$.
-----Example-----
Input
5
2 3
10 10
2 4
7 4
9 3
Output
1
0
2
2
1
-----Note-----
In the first test case, you can just add $1$.
In the second test case, you don't need to do anything.
In the third test case, you can add $1$ two times.
In the fourth test case, you can subtract $4$ and add $1$.
In the fifth test case, you can just subtract $6$. | ["for _ in range(int(input())):\n a, b = list(map(int, input().split()))\n if a == b:\n print(0)\n else:\n if a < b:\n if (b - a) % 2:\n print(1)\n else:\n print(2)\n else:\n if (b - a) % 2 == 0:\n print(1)\n else:\n print(2)\n", "import sys\n\ndef fast_input():\n return sys.stdin.readline().strip()\n\ndef data_input():\n return [int(x) for x in fast_input().split()]\n\ndef binary_search(array, x):\n left, right = -1, len(array)\n while left + 1 != right:\n middle = (left + right) // 2\n if array[middle] >= x:\n right = middle\n elif array[middle] < x:\n left = middle\n return right\n\ndef solve_of_problem():\n a, b = data_input()\n if (b - a) % 2 == 1 and a < b:\n print(1)\n elif (b - a) % 2 == 0 and b < a:\n print(1)\n elif a == b:\n print(0)\n else:\n print(2)\n return\n\nfor ______ in range(int(fast_input())):\n solve_of_problem()", "q = int(input())\nfor wrere in range(q):\n\ta,b = map(int,input().split())\n\tif a<b:\n\t\tif (a-b)%2 == 1:\n\t\t\tprint(1)\n\t\telse:\n\t\t\tprint(2)\n\telse:\n\t\tif a == b:\n\t\t\tprint(0)\n\t\telse:\n\t\t\tif (a-b)%2 == 0:\n\t\t\t\tprint(1)\n\t\t\telse:\n\t\t\t\tprint(2)", "for nt in range(int(input())):\n\ta,b=map(int,input().split())\n\tif b==a:\n\t\tprint (0)\n\t\tcontinue\n\tif b>a:\n\t\tif (b-a)%2==1:\n\t\t\tprint (1)\n\t\t\tcontinue\n\t\telse:\n\t\t\tprint (2)\n\t\t\tcontinue\n\telse:\n\t\tif (a-b)%2==0:\n\t\t\tprint (1)\n\t\t\tcontinue\n\t\telse:\n\t\t\tprint (2)", "t = int(input())\nfor z in range(t):\n\ta,b = list(map(int,input().split()))\n\tans = 0\n\tif a>b:\n\t\tif (a-b)%2 == 0:\n\t\t\tans = 1\n\t\telse:\n\t\t\tans = 2\n\telif a<b:\n\t\tif (b-a)%2 == 0:\n\t\t\tans = 2\n\t\telse:\n\t\t\tans = 1\n\tprint(ans)\n", "from sys import stdin\n\n\ndef solve():\n a, b = list(map(int, input().split()))\n if a == b:\n print(0)\n elif (b - a) % 2 and a < b:\n print(1)\n elif (a - b) % 2 == 0 and a > b:\n print(1)\n else:\n print(2)\n\n\nfor i in range(int(input())):\n solve()\n", "def main():\n a, b = list(map(int, input().split()))\n if a == b:\n print(0)\n elif a > b:\n if (b - a) % 2 == 0:\n print(1)\n else:\n print(2)\n else:\n if (b - a) % 2 == 0:\n print(2)\n else:\n print(1)\n\n\ndef __starting_point():\n t = int(input())\n for i in range(t):\n main()\n\n__starting_point()", "import math\n\n\nclass Read:\n @staticmethod\n def string():\n return input()\n\n @staticmethod\n def int():\n return int(input())\n\n @staticmethod\n def list(sep=' '):\n return input().split(sep)\n\n @staticmethod\n def list_int(sep=' '):\n return list(map(int, input().split(sep)))\n\n\ndef solve():\n a, b = Read.list_int()\n if a == b:\n print(0)\n elif a > b:\n if (a - b) % 2 == 0:\n print(1)\n else:\n print(2)\n else:\n if (b - a) % 2 == 1:\n print(1)\n else:\n print(2)\n\n\n# query_count = 1\nquery_count = Read.int()\nwhile query_count:\n query_count -= 1\n solve()\n", "t = int(input())\nwhile t:\n t += -1\n a, b = map(int, input().split())\n if b == a: print(0)\n elif b > a:\n if (b - a) % 2: print(1)\n else: print(2)\n else:\n if (a - b) % 2: print(2)\n else: print(1)", "t = int(input())\nfor _ in range(t):\n a, b = list(map(int, input().split()))\n if a==b:\n print(0)\n elif a%2==b%2:\n if a>b:\n print(1)\n else:\n print(2)\n else:\n if a>b:\n print(2)\n else:\n print(1)\n", "t = int(input())\nfor iii in range(t):\n\ta, b = list(map(int, input().split()))\n\ttmp = b - a\n\tif tmp == 0:\n\t\tprint(0)\n\telif (a < b and tmp % 2 == 1) or (a > b and tmp % 2 == 0):\n\t\tprint(1)\n\telse:\n\t\tprint(2)\n", "T = int(input())\n\nfor t in range(T):\n a, b = list(map(int, input().split()))\n res = 0\n if b > a:\n if (b % 2) != (a % 2):\n res = 1\n else:\n res = 2\n elif b < a:\n if (b % 2) == (a % 2):\n res = 1\n else:\n res = 2\n print(res)\n", "#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())\nfor tt in range(t):\n #n=int(input())\n a,b= map(int, sys.stdin.readline().split(' '))\n\n if(a==b):\n print(0)\n elif(a>b):\n if((a-b)%2==0):\n print(1)\n else:\n print(2)\n else:\n if((a-b)%2):\n print(1)\n else:\n print(2)\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()", "t=int(input())\nfor _ in range(t):\n a,b=[int(x) for x in input().split()]\n if(a==b):\n print(0)\n elif(a>b):\n if((a-b)%2==0):\n print(1)\n else:\n print(2)\n else:\n if((b-a)%2==0):\n print(2)\n else:\n print(1)\n", "t = int(input())\nfor i in range(t):\n a, b = map(int, input().split())\n if a == b:\n print(0)\n elif (a & 1) == (b & 1):\n if a < b:\n print(2)\n else:\n print(1)\n elif a < b:\n print(1)\n else:\n print(2)", "for _ in range(int(input())):\n a,b = list(map(int,input().split()))\n if b==a:\n print(0)\n elif b>a:\n if (b-a)%2==0:\n print(2)\n else:\n print(1)\n else:\n if (a-b)%2==0:\n print(1)\n else:\n print(2)\n \n", "t = int(input().strip())\nfor _ in range(t):\n a,b = list(map(int,input().strip().split()))\n #nums = [int(i) for i in input().strip().split()]\n if a == b:\n print(0)\n elif a > b:\n if (a - b)%2 == 0:\n print(1)\n else:\n print(2)\n else:\n if (b - a)%2 != 0:\n print(1)\n else:\n print(2)\n", "import sys\nimport math\nimport itertools\nimport functools\nimport collections\nimport operator\nimport fileinput\n\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 revn(n): return str(n)[::-1]\ndef dd(): return collections.defaultdict(int)\ndef ddl(): return collections.defaultdict(list)\ndef sieve(n):\n if n < 2: return list()\n prime = [True for _ in range(n + 1)]\n p = 3\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 += 2\n r = [2]\n for p in range(3, n + 1, 2):\n if prime[p]:\n r.append(p)\n return r\ndef divs(n, start=2):\n r = []\n for i in range(start, int(math.sqrt(n) + 1)):\n if (n % i == 0):\n if (n / i == i):\n r.append(i)\n else:\n r.extend([i, n // i])\n return r\ndef divn(n, primes):\n divs_number = 1\n for i in primes:\n if n == 1:\n return divs_number\n t = 1\n while n % i == 0:\n t += 1\n n //= i\n divs_number *= t\ndef prime(n):\n if n == 2: return True\n if n % 2 == 0 or n <= 1: return False\n sqr = int(math.sqrt(n)) + 1\n for d in range(3, sqr, 2):\n if n % d == 0: return False\n return True\ndef convn(number, base):\n newnumber = 0\n while number > 0:\n newnumber += number % base\n number //= base\n return newnumber\ndef cdiv(n, k): return n // k + (n % k != 0)\n\n\nfor _ in range(ii()):\n a, b = mi()\n if a == b:\n print(0)\n elif a < b and (b - a) % 2 == 0 or a > b and (a - b) % 2:\n print(2)\n else:\n print(1)", "t = int(input())\nfor _ in range(t):\n\ta, b = map(int, input().split())\n\tif a == b:\n\t\tprint(0)\n\telif a < b and (b-a)%2 == 1:\n\t\tprint(1)\n\telif a > b and (a-b)%2 == 0:\n\t\tprint(1)\n\telse:\n\t\tprint(2)", "t = int(input())\nfor i in range(t):\n a, b = list(map(int, input().split()))\n if (a == b):\n print(0)\n elif (a % 2 == b % 2 and a > b):\n print(1)\n elif (a % 2 != b % 2 and b > a):\n print(1)\n else:\n print(2)\n", "t = int(input())\n\nfor _ in range(t):\n a, b = map(int, input().split())\n if a == b:\n print(\"0\")\n elif a > b:\n if (a - b) % 2:\n print(2)\n else:\n print(1)\n else:\n if (b - a) % 2:\n print(1)\n else:\n print(2)", "import sys\ninput = sys.stdin.readline\n\ndef main():\n for _ in range(int(input())):\n a, b = map(int,input().split()) \n if a == b:\n print(0)\n continue\n if a < b:\n if a % 2 == b % 2:\n print(2)\n else:\n print(1)\n \n else:\n if a % 2 == b % 2:\n print(1)\n else:\n print(2)\n\n\nmain()", "for _ in range(int(input())):\n \n a,b = map(int,input().split())\n \n if(a==b):\n print(0)\n elif(a>b):\n h = a-b\n if(h%2 == 0):\n print(1)\n else:\n print(2)\n else:\n h = b-a\n if(h%2 == 1):\n print(1)\n else:\n print(2)", "t = int(input())\n\nfor _ in range(t):\n a, b = map(int, input().split(' '))\n\n if a == b:\n print(0); continue\n \n if b > a:\n if a & 1 == b & 1:\n print(2); continue\n else:\n print(1); continue\n else:\n if a & 1 == b & 1:\n print(1); continue\n else:\n print(2); continue", "# -*- coding: utf-8 -*-\n\nimport sys\nfrom collections import Counter\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\n# sys.setrecursionlimit(10 ** 9)\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nfor _ in range(INT()):\n a, b = MAP()\n\n if a == b:\n print(0)\n elif a < b:\n if abs(a - b) % 2 == 0:\n print(2)\n else:\n print(1)\n else:\n if abs(a - b) % 2 == 0:\n print(1)\n else:\n print(2)\n", "def getarr(): return(list(map(int, input().split())))\n\ndef solve():\n\ta, b = getarr()\n\tif (a==b):\n\t\tprint(0)\n\tif (a < b):\n\t\tdiff = abs(a - b)\n\t\tif (diff % 2 == 1): print(1)\n\t\telse: print(2)\n\n\tif (a > b):\n\t\tdiff = abs(a - b)\n\t\tif (diff % 2 == 0): print(1)\n\t\telse: print(2)\n\nfor t in range(int(input())): solve()", "t=int(input())\nfor _ in range(t):\n a,b=list(map(int,input().split()))\n if a==b:\n print(0)\n elif b-a>0 and (b-a)%2!=0:\n print(1)\n elif b-a>0 and (b-a)%2==0:\n print(2)\n elif a-b>0 and (b-a)%2==0:\n print(1)\n elif a-b>0 and (b-a)%2!=0:\n print(2)", "import sys\ninput = sys.stdin.readline\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\nt = getInt()\nfor i in range(t):\n a, b = getVars()\n if a == b:\n print(0)\n elif a > b:\n if a%2 == b%2:print(1)\n else: print(2)\n else:\n if a%2 == b%2:print(2)\n else:print(1)\n", "t = int(input())\n\nfor i in range(t):\n line = input()\n [a, b] = [int(x) for x in line.split(' ')]\n \n if a == b:\n print(0)\n \n if a > b:\n if a % 2 == b % 2:\n print(1)\n else:\n print(2)\n \n elif a < b:\n if a % 2 == b % 2:\n print(2)\n else:\n print(1)\n", "from math import ceil as cc\ndef mi():\n return map(int, input().split())\n'''\n5\n2 3\n10 10\n2 4\n7 4\n9 3\n'''\nn = int(input())\nfor i in range(n):\n a,b = mi()\n if a==b:\n print(0)\n elif (b-a)%2==0 and b>a:\n print(2)\n elif (b-a)%2 and b>a:\n print(1)\n elif (b-a)%2==0 and b<a:\n print(1)\n else:\n print(2)"] | {
"inputs": [
"5\n2 3\n10 10\n2 4\n7 4\n9 3\n",
"1\n19260817 114514\n",
"1\n484887 54\n",
"1\n55678978 55678978\n"
],
"outputs": [
"1\n0\n2\n2\n1\n",
"2\n",
"2\n",
"0\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 13,634 | |
53a03e610ff7b19f1d0ed9632e76ad34 | UNKNOWN | There is a building consisting of $10~000$ apartments numbered from $1$ to $10~000$, inclusive.
Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $11, 2, 777, 9999$ and so on.
Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order:
First he calls all apartments consisting of digit $1$, in increasing order ($1, 11, 111, 1111$). Next he calls all apartments consisting of digit $2$, in increasing order ($2, 22, 222, 2222$) And so on.
The resident of the boring apartment $x$ answers the call, and our character stops calling anyone further.
Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.
For example, if the resident of boring apartment $22$ answered, then our character called apartments with numbers $1, 11, 111, 1111, 2, 22$ and the total number of digits he pressed is $1 + 2 + 3 + 4 + 1 + 2 = 13$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 36$) β the number of test cases.
The only line of the test case contains one integer $x$ ($1 \le x \le 9999$) β the apartment number of the resident who answered the call. It is guaranteed that $x$ consists of the same digit.
-----Output-----
For each test case, print the answer: how many digits our character pressed in total.
-----Example-----
Input
4
22
9999
1
777
Output
13
90
1
66 | ["# ========== //\\\\ //|| ||====//||\n# || // \\\\ || || // ||\n# || //====\\\\ || || // ||\n# || // \\\\ || || // ||\n# ========== // \\\\ ======== ||//====|| \n# code\n\n\ndef solve():\n x = int(input())\n ans = 0\n ok = 0\n\n for i in range(1, 10):\n n = 0\n for j in range(4):\n n = n * 10 + i\n ans += (j + 1)\n if n == x:\n ok = 1\n break\n if ok:\n break\n print(ans)\n\ndef main():\n t = 1\n t = int(input())\n for _ in range(t):\n solve()\n\ndef __starting_point():\n main()\n__starting_point()", "def solve():\n n = input()\n print(int(n) % 10 * 10 + len(n) * (len(n) + 1) // 2 - 10)\nfor i in range(int(input())):\n solve()", "from math import *\nfrom bisect import *\nfrom collections import *\nfrom random import *\nfrom decimal import *\nfrom itertools import *\nimport sys\ninput=sys.stdin.readline\ndef inp():\n return int(input())\ndef st():\n return input().rstrip('\\n')\ndef lis():\n return list(map(int,input().split()))\ndef ma():\n return list(map(int,input().split()))\nt=inp()\nwhile(t):\n t-=1\n n=inp()\n x=n%10\n s=10*(x-1)\n l=len(str(n))\n s+=(l*(l+1))//2\n print(s)\n", "rn=lambda:int(input())\nrl=lambda:list(map(int,input().split()))\nrns=lambda:map(int,input().split())\nrs=lambda:input()\nyn=lambda x:print('Yes') if x else print('No')\nYN=lambda x:print('YES') if x else print('NO')\n\nfor _ in range(rn()):\n x=rs()\n n=int(x[0])\n ans=10*(n-1)\n for i in range(len(x)+1):\n ans+=i\n print(ans)\n", "for _ in range(int(input())):\n\tn=int(input())\n\tans=0\n\tfor i in range(1,10):\n\t\tf=0\n\t\tfor j in range(1,5):\n\t\t\tk=int(str(i)*j)\n\t\t\tans+=len(str(k))\n\t\t\tif k==n:f=1;break\n\t\tif f:break\n\tprint(ans)", "import sys\ninput = sys.stdin.readline\n\ndef main():\n x = input().strip()\n n = int(x[0])\n l = len(x)\n ans = 10 * (n - 1) + l * (l + 1) // 2\n print(ans)\n \nfor _ in range(int(input())):\n main()", "for t in range(int(input())):\n x = input()\n ans = []\n for i in range(1,10):\n for j in range(1,5):\n ans.append(str(i)*j)\n cnt = 0\n for i in ans:\n if i==x:\n cnt+=len(i)\n break\n else:\n cnt+=len(i)\n print(cnt)", "t = int(input())\nfor _ in range(t):\n x = input()\n ans = 0\n ans += (int(x[0])-1)*10\n ans += len(x)*(len(x)+1)//2\n print(ans)", "for __ in range(int(input())):\n n = input()\n ans = (int(n[0]) - 1) * 10 + 1\n if len(n) >= 2:\n ans += 2\n if len(n) >= 3:\n ans += 3\n if len(n) >= 4:\n ans += 4\n print(ans)", "import sys, math\nimport io, os\n#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\n#from bisect import bisect_left as bl, bisect_right as br, insort\n#from heapq import heapify, heappush, heappop\n#from collections import defaultdict as dd, deque, Counter\n#from itertools import permutations,combinations\ndef data(): return sys.stdin.readline().strip()\ndef mdata(): return list(map(int, data().split()))\ndef outl(var) : sys.stdout.write(' '.join(map(str, var))+'\\n')\ndef out(var) : sys.stdout.write(str(var)+'\\n')\n#from decimal import Decimal\n#from fractions import Fraction\n#sys.setrecursionlimit(100000)\n#INF = float('inf')\nmod = int(1e9)+7\n\n\nfor t in range(int(data())):\n s=data()\n ans=10*int(s[0])-10+(len(s)*(len(s)+1))//2\n out(ans)\n", "for _ in range(int(input())):\n x = int(input())\n\n c = 0\n for i in range(1, 10):\n k = i\n\n while i <= 10000:\n c += len(str(i))\n\n if i == x:\n break\n\n i *= 10\n i += k\n\n else:\n continue\n\n break\n\n print(c)\n", "from sys import stdin, stdout\ninput = stdin.readline\nfrom collections import defaultdict as dd\nimport math\ndef geti(): return list(map(int, input().strip().split()))\ndef getl(): return list(map(int, input().strip().split()))\ndef gets(): return input()\ndef geta(): return int(input())\ndef print_s(s): stdout.write(s+'\\n')\n\ndef solve():\n for _ in range(geta()):\n a=geta()\n ans=0\n ans=10*(a%10-1)\n while a:\n ans+=len(str(a))\n a//=10\n print(ans)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "t=int(input())\nfor _ in range(t):\n x=input()\n a=int(x[0])\n b=len(x)\n print(10*(a-1)+(b*(b+1))//2)", "import math\nimport string\nimport random\nfrom random import randrange\nfrom collections import deque\nfrom collections import defaultdict\n\ndef solve(n):\n ans = 0\n\n k = n%10\n \n ans += 10*(k-1)\n \n f = len(str(n))\n \n for i in range(1, f+1):\n ans += i\n\n print(ans)\n return \n\ndef main():\n t = int(input())\n while t>0:\n t-=1\n \n n = int(input())\n # s = input().strip()\n # x,y = map(int, input().strip().split(\" \"))\n # arr = list(map(int, input().strip().split(\" \")))\n \n solve(n)\n \n return\n\ndef test():\n arr_size = 25\n test_cases = 100\n min_range = -100\n max_range = 100\n str_size = 30\n step = 1\n \n for i in range(test_cases):\n k = []\n # s = ''.join(random.choices(string.ascii_lowercase, k = str_size))\n \n for j in range(arr_size):\n num = randrange(min_range, max_range, step)\n k.append(num)\n \n solve(n, arr)\n print(\"<-------- DEBUG ----------->\")\n\n return \n\ndef __starting_point():\n main()\n # test()\n \n\n__starting_point()", "import sys\ninput=sys.stdin.readline\nfrom collections import defaultdict as dc\nfrom bisect import bisect_right\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=n%10\n c=10*(x-1)\n s=str(n)\n for i in range(len(s)):\n c+=i+1\n print(c)", "for _ in range(int(input())):\n s=input()\n ans=10*(int(s[0])-1)\n l=len(s)\n if l==1:\n ans+=1\n elif l==2:\n ans+=3\n elif l==3:\n ans+=6\n else:\n ans+=10\n print(ans)\n", "t=int(input())\nfor i in range(t):\n n=input()\n z=len(n)\n k=int(n)%10\n print(round((k-1)*10+(z*(z+1))/2))", "import math\ntest = int(input())\nfor t in range(test):\n tt = 0\n pp = 0\n cc = \"\"\n ss = \"\"\n dd = 1\n cnttt = 0\n #write yoour code here\n x = int(input())\n a = x;cnt = 0\n while(a!=0):\n a=a//10\n cnt+=1\n a = x%10\n ans = (a-1)*10+cnt*(cnt+1)//2\n print(ans)\n \n\n", "'''\n Auther: ghoshashis545 Ashis Ghosh\n College: jalpaiguri Govt Enggineering College\n\n'''\nfrom os import path\nimport sys\nfrom heapq import heappush,heappop\nfrom functools import cmp_to_key as ctk\nfrom collections import deque,defaultdict as dd \nfrom bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right\nfrom itertools import permutations\nfrom datetime import datetime\nfrom math import ceil,sqrt,log,gcd\ndef ii():return int(input())\ndef si():return input().rstrip()\ndef mi():return list(map(int,input().split()))\ndef li():return list(mi())\nabc='abcdefghijklmnopqrstuvwxyz'\nmod=1000000007\n# mod=998244353\ninf = float(\"inf\")\nvow=['a','e','i','o','u']\ndx,dy=[-1,1,0,0],[0,0,1,-1]\n\ndef bo(i):\n return ord(i)-ord('a')\n\nfile = 1\n\n\n\n \ndef solve():\n\n\n \n\n for _ in range(ii()):\n\n s = si()\n x = [1,3,6,10]\n n = len(s)\n x1 = int(s[0]) \n print(10*(x1-1) + x[n-1])\n \n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \ndef __starting_point():\n\n if(file):\n\n if path.exists('input.txt'):\n sys.stdin=open('input.txt', 'r')\n sys.stdout=open('output.txt','w')\n else:\n input=sys.stdin.readline\n solve()\n\n__starting_point()", "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n counting = 0\n is_done = False\n for i in range(1,10):\n for c in range(1,5):\n curr_int = int(str(i) * c)\n counting += c\n if curr_int == n:\n print(counting)\n is_done= True\n break\n\n if is_done:\n break\n", "for _ in range(int(input())):\n n = input()\n c = int(n[0])\n ans = (c - 1) * 10\n k = len(n)\n for i in range(1, k + 1):\n ans += i\n print(ans)", "def main():\n x = int(input())\n n = int(str(x)[0])\n l = len(str(x))\n ans = 10 * (n-1)\n ans += l * (l+1) // 2\n print(ans)\n\n\n\nfor _ in range(int(input())):\n main()", "for _ in range(int(input())):\n x = int(input())\n a = x;cnt = 0\n while(a!=0):\n a=a//10\n cnt+=1\n a = x%10\n ans = (a-1)*10+cnt*(cnt+1)//2\n print(ans)\n", "t = int(input())\n\nfor test in range(t):\n x = int(input())\n a = len(str(x))\n print((x % 10 - 1) * 10 + a * (a + 1) // 2)", "import sys\n\n\ndef read(func=int):\n return func(sys.stdin.readline().strip())\n\ndef readList(func=int):\n return list(map(func, sys.stdin.readline().strip().split()))\n\n\nt = read()\nfor _ in range(t):\n num = read()\n tot = ((num % 10) - 1) * 10\n for i in range(len(str(num))):\n tot += i + 1\n print(tot)\n"] | {
"inputs": [
"4\n22\n9999\n1\n777\n",
"36\n1\n2\n3\n4\n5\n6\n7\n8\n9\n11\n22\n33\n44\n55\n66\n77\n88\n99\n111\n222\n333\n444\n555\n666\n777\n888\n999\n1111\n2222\n3333\n4444\n5555\n6666\n7777\n8888\n9999\n",
"36\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n",
"20\n999\n33\n2222\n22\n2222\n333\n4\n99\n11\n444\n8888\n444\n2222\n6666\n666\n7\n555\n5\n8\n9999\n"
],
"outputs": [
"13\n90\n1\n66\n",
"1\n11\n21\n31\n41\n51\n61\n71\n81\n3\n13\n23\n33\n43\n53\n63\n73\n83\n6\n16\n26\n36\n46\n56\n66\n76\n86\n10\n20\n30\n40\n50\n60\n70\n80\n90\n",
"90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n90\n",
"86\n23\n20\n13\n20\n26\n31\n83\n3\n36\n80\n36\n20\n60\n56\n61\n46\n41\n71\n90\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,596 | |
e14cf4f9181a1a859f45989c7bcdd536 | UNKNOWN | You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals $0$) sequence is $0$.
-----Input-----
The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) β the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) β the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$.
The elements of sequences are integer numbers from $-10^4$ to $10^4$.
The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$.
-----Output-----
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line β two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line β two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$.
Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
-----Note-----
In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the sums are equal. | ["import sys\nk=int(input())\nL=[]\ndic=dict()\nflag=False\nfor i in range(k):\n L.append([int(input())])\n L[i].append(list(map(int,input().split())))\n s=sum(L[i][1])\n q=[]\n for j in range(L[i][0]):\n if flag:\n return\n t=s-L[i][1][j]\n if t in dic:\n x,y=dic[t]\n print(\"YES\")\n print(i+1,j+1)\n print(x,y)\n flag=True\n else:\n q.append((t,i+1,j+1))\n for a,b,c in q:\n dic[a]=(b,c)\nprint(\"NO\")\n", "import sys\n\nclass Scanner():\n def __init__(self):\n self.tokens = []\n self.index = -1\n\t\n for line in sys.stdin:\n self.tokens.extend(line.split())\n \n def next_token(self):\n self.index += 1\n return None if self.index == len(self.tokens) \\\n\t\t else self.tokens[self.index]\n\ndef main():\n scanner = Scanner()\n n = int(scanner.next_token())\n \n sequences = []\n for i in range(n):\n k = int(scanner.next_token())\n sequences.append([int(scanner.next_token()) for _ in range(k)])\n \n mp = dict()\n for i, ar in enumerate(sequences):\n s = sum(ar)\n for j, v in enumerate(ar):\n x = s - v\n if x in mp:\n print(\"YES\")\n print(\"{} {}\".format(mp[x][0] + 1, mp[x][1] + 1))\n print(\"{} {}\".format(i + 1, j + 1))\n return\n \n for j, v in enumerate(ar):\n mp[s - v] = (i, j)\n \n print(\"NO\")\n \ndef __starting_point():\n main()\n\n__starting_point()", "k = int(input())\na = []\nfor i in range(k):\n n = int(input())\n b = [int(i) for i in input().split()]\n s = sum(b)\n for j in range(n):\n x = s-b[j]\n a.append([x,i,j])\nf = True\na = sorted(a)\nfor i in range(1,len(a)):\n if a[i][0] == a[i-1][0] and a[i][1]!=a[i-1][1]:\n f = False\n print('YES')\n print(a[i][1]+1,a[i][2]+1)\n print(a[i-1][1]+1, a[i-1][2]+1)\n break\nif f:\n print('NO')", "m=int(input())\na=[]\nfor i in range(m):\n n=int(input())\n a.append(list(map(int,input().split())))\nd=dict()\nf=0\nfor i in range(m):\n summ=sum(a[i])\n for j in range(len(a[i])):\n if(summ-a[i][j] in d):\n if(d[summ-a[i][j]][0]!=i+1):\n print(\"YES\")\n print(*d[summ-a[i][j]])\n print(i+1,j+1)\n f=1\n break\n d[summ-a[i][j]]=[i+1,j+1]\n if(f):\n break\nif(f==0):\n print(\"NO\")", "n = int(input())\ncl = set()\ndic = {}\nfor i in range(n):\n m = int(input())\n s = list(map(int, input().split()))\n t = []\n sm = sum(s)\n for x in range(m):\n a = sm - s[x]\n if a in cl:\n print('YES')\n print('{} {}'.format(i + 1, x + 1))\n print('{} {}'.format(dic[a][0], dic[a][1]))\n return\n dic.update({a: (i+1, x+1)})\n t.append(a)\n for x in set(t):\n cl.add(x)\n\n\nprint('NO')", "read = lambda : list(map(int,input().split()))\n\nk = int(input())\na = []\ns = []\ndict = {}\nfor i in range(k):\n a.append([])\n input()\n s.append(0)\n for j in read():\n s[i] += j\n a[i].append(j)\nok = False\nfor i in range(k):\n if ok:\n break\n for j in range(len(a[i])):\n \n x = s[i] - a[i][j]\n tmp = dict.get(x)\n if ( tmp != None ):\n ok = True\n print(\"YES\")\n print(i+1,j+1)\n print(tmp[0]+1,tmp[1]+1)\n break\n\n for j in range(len(a[i])):\n x = s[i] - a[i][j]\n dict[x] = [i,j]\nif not ok:\n print(\"NO\")\n\n", "k = int(input())\nn = int(input())\na = list(map(int, input().split()))\nd = {}\nsuma = sum(a)\n\nfor i in range(n):\n d[suma - a[i]] = [1, i + 1]\n\nans = False\n\nfor i in range(k - 1):\n n = int(input())\n a = list(map(int, input().split()))\n suma = sum(a)\n for j in range(n):\n if (suma - a[j]) in d and not d[suma - a[j]][0] == i + 2:\n print('YES')\n print(i + 2, j + 1)\n print(d[suma - a[j]][0], d[suma - a[j]][1])\n ans = True\n break\n else:\n d[suma - a[j]] = [i + 2, j + 1]\n if ans:\n break\nif not ans:\n print('NO')", "k = int(input())\npossums = {}\nhave_ans = False\nfor i in range(k):\n if have_ans:\n break\n\n n = input()\n seq = list(map(int, input().split(' ')))\n s = sum(seq)\n for i_in_seq, n in enumerate(seq):\n v = s - n\n if v in possums and i != possums[v][0]:\n have_ans = True\n print('YES')\n print(i + 1, i_in_seq + 1)\n print(possums[v][0] + 1, possums[v][1] + 1)\n break\n else:\n possums[v] = (i, i_in_seq)\n\nif not have_ans:\n print('NO')\n", "k=int(input())\na,c=[],{}\nfor i in range(k):\n a.append([])\n n,a[i],s=int(input()),[],0\n for j in input().split():\n a[i]+=[-int(j)]\n s+=int(j)\n for j in range(n):\n a[i][j]+=s\n h=c.get(a[i][j])\n if h!=None and h[0]!=i+1:\n print(\"YES\")\n print(h[0],h[1])\n print(1+i,1+j)\n quit()\n c[a[i][j]]=[i+1,j+1]\nprint(\"NO\")\n"] | {
"inputs": [
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n",
"2\n2\n0 -10000\n2\n10000 0\n"
],
"outputs": [
"YES\n2 1\n1 4\n",
"NO\n",
"YES\n4 1\n2 5\n",
"YES\n2 1\n1 2\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 5,383 | |
e65c467896125636a8c9f0137cb67ff3 | UNKNOWN | Given an array A of integers, we mustΒ modify the array in the following way: we choose an iΒ and replaceΒ A[i] with -A[i], and we repeat this process K times in total.Β (We may choose the same index i multiple times.)
Return the largest possible sum of the array after modifying it in this way.
Β
Example 1:
Input: A = [4,2,3], K = 1
Output: 5
Explanation: Choose indices (1,) and A becomes [4,-2,3].
Example 2:
Input: A = [3,-1,0,2], K = 3
Output: 6
Explanation: Choose indices (1, 2, 2) and A becomes [3,1,0,2].
Example 3:
Input: A = [2,-3,-1,5,-4], K = 2
Output: 13
Explanation: Choose indices (1, 4) and A becomes [2,3,-1,5,4].
Β
Note:
1 <= A.length <= 10000
1 <= K <= 10000
-100 <= A[i] <= 100 | ["class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n \n i = 0\n while A[i] < 0 and K > 0:\n A[i] *= -1\n i += 1\n K -= 1\n \n if K % 2 == 1 and 0 not in A:\n return sum(A) - 2*min(A)\n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n i=0\n while(i<len(A) and A[i]<0 and i<K):\n A[i]=-A[i]\n i+=1\n \n return sum(A)-(K - i) % 2 * min(A) * 2", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n S=0\n negs=[]\n posmin=100\n negmax=-100\n for i in range(len(A)):\n S+=A[i]\n if A[i]<0:\n negs.append(A[i])\n negmax=max(negmax,A[i])\n else:\n posmin=min(posmin,A[i])\n if K is 0:\n return(S)\n negs.sort()\n if K <= len(negs):\n return(S-2*sum(negs[:K]))\n elif (K - len(negs))%2 is 0:\n return(S-2*sum(negs[:K]))\n elif posmin<-negmax:\n return(S-2*sum(negs[:K])-2*posmin)\n else:\n return(S-2*sum(negs[:K])+2*negmax)", "class Solution(object):\n def largestSumAfterKNegations(self, A, K):\n lst = sorted(A)\n count = K\n i = 0\n while count>0:\n if lst[i] <= lst[i + 1]:\n lst[i] = lst[i] * -1\n count -= 1\n else:\n i += 1\n return sum(lst)\n", "import heapq\nclass Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n heapq.heapify(A)\n for _ in range(K):\n heapq.heapreplace(A, -A[0])\n return sum(A)\n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n p = 0\n while A[p] < 0:\n A[p] = - A[p]\n p += 1\n K -= 1\n if K == 0:\n return sum(A)\n if K % 2 == 0:\n return sum(A)\n else:\n return sum(A) - 2 * min(A[p], A[p-1])", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n heapq.heapify(A)\n #heapify is in place algo so take linear time\n for x in range(K):\n #if x %2 :\n #heappreplace(A, -A[0])\n #heappush(A, -heapq.heappop(A))\n heapreplace(A, -A[0])\n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], k: int) -> int:\n d = collections.defaultdict(int)\n for x in A:\n d[x] += 1\n \n res = 0\n for i in range(-100, 0):\n if i in d and k > 0:\n x = min(k, d[i])\n k -= x\n d[i] -= x\n d[-i] += x\n \n res = 0\n if k % 2 == 1:\n j = 0\n while j not in d or d[j] <= 0:\n j += 1\n print(j)\n d[j] -= 1\n d[-j] += 1\n for i in range(-100, 101):\n res += d[i] * i\n return res\n \n \n \n \n \n\n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n res = 0\n A.sort()\n i = 0\n while i < len(A) and i < K and A[i] < 0:\n A[i] = -A[i]\n i += 1\n\n return sum(A) - (K - i) % 2 * 2 * min(A[i-1:i] + A[i:i+1])\n \n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n for i in range(K):\n A.sort()\n A[0] = -A[0]\n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n result = 0\n count = 0\n A.sort()\n \n if A[0] > 0:\n if K%2 == 1:\n A[0] = -A[0]\n for i in A:\n result += i\n return(result)\n elif A[0] == 0:\n for i in A:\n result += i\n return(result)\n else:\n for j in range (len(A)):\n if A[j] >= 0:\n break\n else:\n count += 1\n ra = K%count\n if K < count:\n for m in range(K):\n A[m] = -A[m]\n else:\n for m in range(count):\n A[m] = -A[m]\n K -= count\n A.sort()\n if K%2 == 1:\n A[0] = -A[0]\n for i in A:\n result += i\n \n return(result)", "class Solution:\n import heapq\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n heapq.heapify(A)\n for i in range(K):\n m = heapq.heappop(A)\n heapq.heappush(A, -m)\n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n newA = sorted(A)\n print(newA)\n count = 0\n for i in range(K):\n newA[0] = -newA[0]\n newA = sorted(newA)\n print(newA)\n return sum(newA)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n B = sorted(A)\n for i in range(K):\n B[0] = -B[0]\n B = sorted(B)\n return sum(B)", "class Solution:\n def largestSumAfterKNegations(self, arr: List[int], k: int) -> int:\n ra = k\n arr.sort()\n for _ in range(ra):\n for j in range(len(arr)):\n if arr[j] < 0:\n arr[j] = abs(arr[j])\n k -= 1\n arr.sort()\n break\n elif arr[j] == 0:\n return sum(arr)\n else:\n if k % 2 == 0:\n return sum(arr)\n else:\n arr.sort()\n arr[0] = -arr[0]\n return sum(arr)\n\n return sum(arr)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n while K > 0:\n t = A.index(min(A))\n if A[t] < 0:\n A[t] = abs(A[t])\n K -= 1\n continue\n if A[t] == 0:\n K = 0\n continue\n if A[t] > 0:\n if K % 2 == 0:\n K = 0\n continue\n else:\n A[t] = -A[t]\n K = 0\n continue\n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n for x in range(K):\n minNum=A.index(min(A))\n A[minNum]=A[minNum]*(-1)\n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n for i in range(K):\n variable = min(A)\n A.remove(variable)\n A.append(variable*-1)\n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n for i in range(K):\n \n val = min(A)\n \n A.remove(val)\n A.append(-1 * val)\n \n return sum(A)\n \n \n", "# 5:47 -> 5:50 slowwww\n# Seems greedy: pick smallest number and flip it\nclass Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n while K:\n m = min(A)\n m_i = A.index(m)\n A[m_i] = -m\n K -= 1\n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n\n for i in range(K):\n min_ = min(A)\n idx = A.index(min_)\n A[idx] = -A[idx]\n max_ = sum(A)\n return max_\n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n a1 =A\n sum1 =0\n while K > 0 :\n mina = min(a1)\n a1.remove(mina)\n a1.append(mina * (-1))\n K -=1\n \n \n \n return sum(a1)\n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n for i in range(K):\n A[0] = -1 * A[0]\n if A[0] > A[1]:\n A.append(A.pop(0))\n return sum(A) ", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n cur = sum(A)\n for i in range(K):\n # max_ = sum(A)\n min_ = min(A)\n idx = A.index(min_)\n A[idx] = -A[idx]\n max_ = sum(A)\n return max_\n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n max_sum = -999999\n for _ in range(K):\n A = sorted(A)\n min_index = A.index(min(A))\n \n A[min_index] = -A[min_index]\n\n max_ = sum(A)\n # print(max_)\n # max_sum = max(max_sum, max_)\n return max_", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n while K > 0:\n min_index = A.index(min(A))\n A[min_index] = - A[min_index]\n K = K - 1\n \n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n for i in range(K):\n \n val = min(A)\n \n #if val <= 0:\n A.remove(val)\n A.append(-1 * val)\n \n \n \n return sum(A)\n \n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n while K != 0:\n A[A.index(min(A))] = -min(A)\n K -= 1\n return(sum(A))\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n c = 0\n \n while c < K:\n c += 1\n min_ = min(A)\n index = A.index(min_)\n A[index] = -1 * min_\n \n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n while K>0:\n K-=1\n A[A.index(min(A))]=-min(A)\n return sum(A)", "class Solution:\n import heapq\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n ## find the min element and its index and negate it K times\n \n ## Complexity = O(kn)\n \n# def findMin(A):\n# minValue = float('inf')\n# minIndex = 0\n\n# for i, ele in enumerate(A):\n# if ele < minValue:\n# minValue = ele\n# minIndex = i\n \n# return minIndex\n\n# for k in range(K):\n# minIndex = findMin(A)\n# A[minIndex] = -A[minIndex]\n \n \n ### using min heap\n \n heapq.heapify(A)\n for k in range(K):\n A[0] = -A[0]\n heapq.heapify(A)\n \n return sum(A)\n \n ### let's do with heap, no need to pop just negate that element\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n for i in range(K) :\n check = min(A)\n t = A.index(check)\n A[t] = -A[t]\n \n return sum(A)\n \n \n \n \n \n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n for i in range(K):\n A[A.index(min(A))] *= -1\n \n return sum(A)\n", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n \n if not A: return sum(A)\n \n if K == 0: return sum(A)\n \n \n for i in range(K):\n \n A[A.index(min(A))] = - A[A.index(min(A))]\n \n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n if not A:\n return sum(A)\n if K==0:\n return sum(A)\n for i in range(K):\n A[A.index(min(A))] = -A[A.index(min(A))]\n return sum(A)\n", "# 5:47 ->\n# Seems greedy: pick smallest number and flip it\nclass Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n if K == 0:\n return sum(A)\n m = min(A)\n m_i = A.index(m)\n A[m_i] = -m\n return self.largestSumAfterKNegations(A, K - 1)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n for item in A :\n if item < 0 and K > 1:\n A[A.index(item)] = item * (-1)\n K-= 1\n elif item > 0 and K >= 2:\n K-=2\n else:\n A.sort()\n while K != 0:\n K -=1\n A[0] = A[0] * (-1)\n return sum(A)", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n for i in range(K):\n A[0] = -1 * A[0]\n if A[0] > 0:\n A.sort()\n return sum(A) ", "class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n for i in range(K):\n A.sort()\n A[0] = -A[0]\n \n return sum(A)", "\nclass Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n ans = sum(A)\n A.sort()\n \n for i in range(len(A)):\n if not K or A[i]==0:\n break\n if A[i]<0:\n ans -= 2*A[i]\n K-=1\n else:\n if K%2:\n if i and A[i]>abs(A[i-1]):\n ans += 2*A[i-1]\n else:\n ans -= 2*A[i]\n break\n \n return ans"] | {"fn_name": "largestSumAfterKNegations", "inputs": [[[-2, 3, 4], 1], [[4,2,3], 1], [[3,-1,0,2], 3], [[2,-3,-1,5,-4], 2]], "outputs": [9, 5, 6, 13]} | INTRODUCTORY | PYTHON3 | LEETCODE | 14,845 |
class Solution:
def largestSumAfterKNegations(self, A: List[int], K: int) -> int:
|
c7427873ee5b49b1af164b8d550a00c0 | UNKNOWN | Given an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i+1 < j with (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1])
Β
Example 1:
Input: A = [0,2,1,-6,6,-7,9,1,2,0,1]
Output: true
Explanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1
Example 2:
Input: A = [0,2,1,-6,6,7,9,-1,2,0,1]
Output: false
Example 3:
Input: A = [3,3,6,5,-2,2,5,1,-9,4]
Output: true
Explanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4
Β
Constraints:
3 <= A.length <= 50000
-10^4Β <= A[i] <= 10^4 | ["class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n# if len(A)<3:\n# return\n \n# i = 1\n# j = len(A)-2\n \n# tgtsum = sum(A)/3\n# sum1 = sum(A[:i])\n# while i<(len(A)-2) and sum1!=tgtsum:\n# sum1 = sum1 + A[i]\n# i+=1\n \n# sum3=sum(A[j+1:])\n# while j>1 and sum3!=tgtsum:\n# # print (tgtsum, sum1, sum3, A[j])\n# sum3 = sum3 + A[j]\n# j-=1\n# # print (i,j)\n# if j>=i and sum1==tgtsum and sum3==tgtsum:\n# return True\n# else:\n# return False\n\n if len(A)<3:\n return False\n suma = sum(A)\n if suma%3!=0:\n return False\n \n runsum,target, count = 0,suma/3,0\n \n for val in A[:-1]:\n runsum += val\n if runsum==target:\n count+=1\n runsum=0\n if count==2:\n return True\n else:\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n '''\n # first solution\n total = sum(A)\n if total%3!=0: False \n for i in range(1,len(A)): A[i] += A[i-1]\n if total==0 and A.count(0)<3: return False \n return True if A.count(total//3) and A.count(total//3*2) and A.index(total//3)<len(A)-A[::-1].index(total//3*2) else False\n '''\n # second solution\n total = sum(A)\n if total%3!=0: False\n count, temp, Sum = 1, total//3, 0\n for i in range(len(A)-1): \n Sum += A[i]\n if Sum == temp * count:\n count+=1\n if count==3: return True\n print(A)\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s=0\n res=0\n s1=sum(A)\n if s1%3 != 0:\n return False\n target=s1//3\n for a in A:\n s+=a\n if s == target:\n s=0\n res+=1\n return res >2\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n sum = 0\n for i in A:\n sum += i\n s = 0\n c = 0\n for i in A:\n s += i\n if s == int(sum/3):\n s = 0\n c += 1\n return c >= 3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n '''\n # first solution\n total = sum(A)\n if total%3!=0: False \n for i in range(1,len(A)): A[i] += A[i-1]\n if total==0 and A.count(0)<3: return False \n return True if A.count(total//3) and A.count(total//3*2) and A.index(total//3)<len(A)-A[::-1].index(total//3*2) else False\n '''\n # second solution\n total = sum(A)\n if total%3!=0: False\n count, temp, Sum = 1, total//3, 0\n for val in A[:-1]: \n Sum += val\n if Sum == temp:\n Sum = 0\n count+=1\n if count==3: return True\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n # first solution\n total = sum(A)\n if total%3!=0: False \n for i in range(1,len(A)): A[i] += A[i-1]\n if total==0 and A.count(0)<3: return False \n return True if A.count(total//3) and A.count(total//3*2) and A.index(total//3)<len(A)-A[::-1].index(total//3*2) else False\n \n # second solution\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n cusum = 0\n cusum_list = list()\n for i in range(len(A)):\n cusum += A[i]\n cusum_list.append(cusum)\n if sum(A)/3 in cusum_list:\n if sum(A)*2/3 in cusum_list[cusum_list.index(sum(A)/3) + 1:-1]:\n return True\n else:\n return False\n else:\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A)%3 != 0:\n return False\n required_sum = sum(A)//3\n count_partition = 0\n curr_sum = A[0]\n i = 1\n while i < len(A):\n while i < len(A) and curr_sum != required_sum:\n curr_sum += A[i]\n i += 1\n if curr_sum == required_sum:\n count_partition += 1\n if i < len(A):\n curr_sum = A[i]\n i += 1\n if i == len(A) and curr_sum == required_sum:\n count_partition += 1\n if count_partition > 3 and required_sum == 0:\n count_partition = 3\n return count_partition == 3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n avg = 0\n for i in A:\n avg += i\n if(avg%3 != 0): return False\n count = 0\n sum = 0\n for i in range(0,len(A)):\n if(sum == avg//3):\n if(i!=0):\n count += 1\n sum = A[i]\n elif(sum != avg//3):\n sum += A[i]\n if(sum == avg//3): count += 1\n return count >= 3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A)%3 != 0:\n return False\n \n count, tmp_sum, target = 0, 0, sum(A)//3\n \n for num in A:\n tmp_sum += num\n if tmp_sum == target:\n count += 1 \n tmp_sum = 0\n \n return count >= 3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if len(A) < 3 : return False\n prefixSumMap = defaultdict(list)\n sumUpto = {}\n total = 0\n for i in range(len(A)) :\n prefixSumMap[total].append(i)\n total += A[i]\n sumUpto[i] = total\n s = 0\n for i in range(len(A)-1, 1, -1) :\n s += A[i]\n target = total - 2*s\n if prefixSumMap.get(target) != None :\n for j in prefixSumMap[target] :\n if j < i and j > 0 and sumUpto[j-1] == s :\n return True\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n sumA = sum(A)\n if sumA % 3 != 0:\n return False\n tmpSum, isFound, eachPart = 0, 0 ,sumA//3\n for i in A:\n tmpSum += i\n if tmpSum == eachPart:\n tmpSum = 0 \n isFound += 1\n if isFound >=3 :\n return True\n else:\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: list) -> bool:\n ''' returns True if indices i and j can be found such that A[0]+...+A[i]==A[i+1]+...+A[j]==A[j+1]+...+A[-1]\n\n Algo: form [A[0], A[0]+A[1], A[0]+A[1]+A[2], ..., sum(A)]\n if A can be partitioned, then n=sum(A) is a multiple of 3,\n 2*n//3 must appear at some index j, and n//3 must appear at some index i<j'''\n if len(A)<3:\n return False\n for i in range(1,len(A)):\n A[i] = A[i-1]+A[i]\n end_value=A[-1]\n if end_value%3!=0:\n return False\n index=len(A)-2\n while A[index] != 2*end_value//3:\n index-=1\n if index==0:\n return False\n index-=1\n while A[index] != end_value//3:\n index-=1\n if index<0:\n return False\n return True", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n d = defaultdict(list)\n sumn = 0\n for i,num in enumerate(A) :\n sumn += num\n d[sumn].append(i)\n\n if sumn % 3 != 0 :\n return False\n div = sumn // 3\n\n return div in d and div*2 in d and d[div][0] < (d[div*2][-1] if d[div*2][-1] != len(A)-1 else d[div*2][-2])\n\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s%3 != 0: \n return False\n ps = s//3\n count = 0\n for x in A:\n ps -= x\n if not ps:\n ps = s//3\n count+=1\n if count > 2:\n return True\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s=sum(A)\n if s%3!=0:\n return 0\n n=len(A)\n cnt=[0]*n\n s//=3\n ss=0\n for i in range(n-1,-1,-1):\n ss+=A[i]\n if i==n-1:\n cnt[i]= 1 if ss==s else 0\n else:\n cnt[i]=cnt[i+1]+ (1 if ss==s else 0)\n ss=0\n ans=0\n print(cnt)\n for i in range(0,n-2):\n ss+=A[i];\n if ss==s:\n ans+=cnt[i+2]\n print(ans)\n return True if ans>0 else False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n '''\n # first solution\n total = sum(A)\n if total%3!=0: False \n for i in range(1,len(A)): A[i] += A[i-1]\n if total==0 and A.count(0)<3: return False \n return True if A.count(total//3) and A.count(total//3*2) and A.index(total//3)<len(A)-A[::-1].index(total//3*2) else False\n '''\n # second solution\n total = sum(A)\n if total%3!=0: False\n count, temp, Sum = 1, total//3, 0\n for val in A[:-1]: \n Sum += val\n if Sum == temp * count:\n count+=1\n if count==3: return True\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n s = sum(A)\n if s % 3 != 0:\n return False\n x = s // 3\n c = 0\n d = 0\n for a in A[:-1]:\n c += a\n if d == 0 and c == x:\n d = 1\n elif d == 1 and c == 2 * x:\n return True\n \n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A) % 3 != 0:\n return False\n targetSum = sum(A) // 3\n a = 1\n runningSum = A[0]\n while a < len(A) and runningSum != targetSum:\n runningSum += A[a]\n a += 1\n b = len(A) - 2\n runningSum = A[-1]\n while b > -1 and runningSum != targetSum:\n runningSum += A[b]\n b -= 1\n return not a > b", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if len(A) < 3: return False\n for i in range(1,len(A)):\n A[i] = A[i]+A[i-1]\n \n sumTarg = A[-1]/3\n \n first = False\n \n for i in range(len(A)):\n if A[i] == sumTarg and first == False:\n first = True\n elif (first == True and A[i] == 2*sumTarg and i != len(A)-1):\n return True\n \n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n cummulative_sum = 0\n counter = 0\n target = sum(A) / 3\n if target != int(target):\n return False\n print(target)\n for idx in range(len(A)):\n cummulative_sum += A[idx]\n if cummulative_sum == target:\n cummulative_sum = 0\n counter += 1\n \n if counter == 4 and target == 0:\n return True\n if counter == 3:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A)-(sum(A)//3)*3!=0:\n return 0\n else:\n s=sum(A)//3\n c=0\n ts=0\n j=0\n for i in range(len(A)):\n j=i\n ts+=A[i]\n if ts==s:\n c+=1\n ts=0\n if c==2 and j+1<len(A):\n for k in range(j+1,len(A)):\n ts+=A[k]\n if ts==s:\n return 1\n else:\n return 0\n return 0\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n partSum = sum(A)/3\n curSum = 0\n partNum = 0\n for i in A:\n curSum +=i\n if(curSum == partSum):\n curSum = 0\n partNum +=1\n if(partSum == 0):\n return partNum>=3\n else:\n return partNum == 3\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n total = sum(A)\n third = total // 3\n cumsum, count = 0, 0\n for i in range(0, len(A)):\n cumsum += A[i]\n if cumsum == third:\n count += 1\n cumsum = 0\n return count == 3 or count > 3 and total == 0", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n x= 0\n for i in A:\n x += i\n if x%3 !=0 :\n return False\n x = x/3\n count = 0\n sum1 = 0\n for i in A :\n sum1 += i\n if sum1 == x :\n count += 1\n sum1 = 0\n if count >= 3 :\n return True\n else:\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A)%3!=0:\n return False\n \n req=sum(A)//3\n \n s=0\n c=0\n print(sum(A))\n print(req)\n for i in A:\n s+=i\n if s==req:\n s=0\n c+=1\n \n return c>=3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n total = sum(A)\n if total % 3 != 0:\n return False\n i = 0\n count = A[i]\n while (i < len(A)-1) and (count != total/3):\n i += 1\n count += A[i]\n \n \n if (count != total/3) or (i+1 > len(A)-2):\n return False\n \n j = i +1\n count = A[j]\n while (j < len(A)-1) and (count != total/3):\n j += 1\n count += A[j]\n \n \n if (count != total/3) or (j+1 == len(A)):\n return False\n \n if sum(A[j+1:]) == total/3:\n return True\n else:\n return False\n \n \n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n #a + ....+ b = num \n # if 3 equal amount of indices have the same sum return true\n # how do we find the sum? \n # use the sum and then divide it by three thats the equal part sum\n # use len(A) - 1 to find the number of indexes and \n equalSum = sum(A) // 3\n part = 0\n numparts = 0\n r = sum(A) % 3\n for i in A:\n part += i \n if part == equalSum:\n part = 0\n numparts += 1\n return not r and numparts >= 3\n\n\n\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n sum1=sum(A)\n if sum1%3!=0:\n return False\n \n else:\n div=sum1//3\n print(div)\n i1,sum2=0,0\n for i in A:\n sum2=sum2+i\n print(sum2,i)\n if sum2==div:\n i1=i1+1\n print('sum2',sum2)\n sum2=0\n if i1>=3 and div==0:\n return True\n if i1==3:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s%3 != 0: \n return False\n ps = s//3\n count = 0\n for x in A:\n ps -= x\n if not ps:\n ps = s//3\n count+=1\n return count >= 3\n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n total = sum(A)\n isum = 0\n \n for i in range(0,len(A)-2):\n isum += A[i]\n if isum == total/3:\n jsum = 0\n for j in range(i+1,len(A)-1):\n jsum += A[j]\n if isum == jsum == total - isum - jsum:\n return True\n return False\n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n target = sum(A)//3\n \n temp = 0\n count = 0\n for i in range(len(A)):\n temp += A[i]\n if(temp == target):\n temp = 0\n count += 1\n if(count == 3):\n return True\n return False\n \n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n j = len(A)\n i = 0\n num= sum(A)//3\n \n print(num)\n sum1 = 0\n sum2 = 0\n sum3 = 0\n for i in range(0, j):\n sum1 = sum1 + A[i]\n i = i +1\n if sum1 == num:\n break\n for i in range(i, j):\n sum2 = sum2 + A[i]\n i = i +1\n if sum2 == num:\n break\n \n if i == j:\n return False\n sum3 = sum(A[i:])\n # for i in range(i, j):\n # sum3 = sum3 + A[i]\n # i = i +1\n # if sum3 == num:\n # break\n # print(\\\"sum=\\\",sum3)\n return sum1==sum2 and sum1 == sum3\n \n # return sum3\n# for i in range(0, floor(j/3)):\n# sum1 = sum1 + A[i]\n# i = i+1\n\n# sum2 =0 \n# print(\\\"sum1 = \\\" , sum1)\n# while sum2 is not sum1:\n# sum2 = sum2 + A[i]\n# print(sum2)\n# i= i+1\n \n# sum3 =0\n# for i in range(i,j):\n# sum3 = sum3 +A[i]\n# # print(sum3)\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n j = len(A)\n i = 0\n num= 0\n for i in range(0, j):\n num = num + A[i]\n num = floor(num /3);\n print(num)\n sum1 = 0\n sum2 = 0\n sum3 = 0\n for i in range(0, j):\n sum1 = sum1 + A[i]\n i = i +1\n if sum1 == num:\n break\n for i in range(i, j):\n sum2 = sum2 + A[i]\n i = i +1\n if sum2 == num:\n break\n \n if i == j:\n return False\n for i in range(i, j):\n sum3 = sum3 + A[i]\n i = i +1\n if sum3 == num:\n break\n print(sum1)\n return sum1==sum2 and sum1 == sum3\n \n # return sum3\n# for i in range(0, floor(j/3)):\n# sum1 = sum1 + A[i]\n# i = i+1\n\n# sum2 =0 \n# print(\\\"sum1 = \\\" , sum1)\n# while sum2 is not sum1:\n# sum2 = sum2 + A[i]\n# print(sum2)\n# i= i+1\n \n# sum3 =0\n# for i in range(i,j):\n# sum3 = sum3 +A[i]\n# # print(sum3)\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s % 3 != 0:\n return False\n flag = 0\n temp = 0\n for i in range(len(A)):\n temp += A[i]\n if flag == 0 and temp == s//3:\n flag += 1\n elif flag == 1 and temp == s*2/3 and i != len(A)-1:\n return True\n return False\n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n average, remainder, part, cnt = sum(A) // 3, sum(A) % 3, 0, 0\n for a in A:\n part += a\n if part == average:\n cnt += 1\n part = 0\n return not remainder and cnt >= 3", "\nclass Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n total = sum(A)\n curr_sum = 0\n first_found_flag = False\n \n for i in range(len(A) - 1): #will go until the last element.\n curr_sum += A[i]\n if not first_found_flag: #looking for the first group\n if curr_sum == total / 3: #we found the first group.\n first_found_flag = True\n else: #looking for the second group\n if curr_sum == total * 2 / 3:\n return True\n \n return False\n \n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n l,r,s=1, len(A)-2, sum(A)\n ls, rs, avgs = A[0], A[-1], s//3\n while l<r:\n if l < r and ls != avgs:\n ls+=A[l]\n l+=1\n if l<r and rs!=avgs:\n rs+=A[r]\n r-=1\n if ls == rs == avgs and s%3==0:\n return True\n \n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n t=sum(A)\n if t%3!=0:\n return False\n s=0\n p=0\n for i in range(len(A)):\n s+=A[i]\n if s==t//3:\n s=0\n p+=1\n if p>=3:\n return True\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n average, part, cnt = sum(A) // 3, 0, 0\n for a in A:\n part += a\n if part == average:\n cnt += 1\n part = 0\n return cnt >= 3\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s % 3 != 0:\n return False\n s = s / 3\n t = 0\n count = 0\n for x in A:\n t += x\n if t == s:\n t = 0\n count += 1\n if t == 0 and count >= 3:\n return True\n else:\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s % 3 != 0:\n return False\n target = s//3\n current = 0\n count = 0\n for v in A:\n current += v\n if current == target:\n count += 1\n current = 0\n if count >= 3:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n totalSum = sum(A)\n if totalSum % 3 != 0:\n return False\n \n target = totalSum // 3\n numPartitions = 0\n currSum = 0\n \n for num in A:\n currSum += num\n if currSum == target:\n numPartitions += 1\n currSum = 0\n if numPartitions == 3:\n return True\n \n return False\n", "class Solution:\n def canThreePartsEqualSum(self, li: List[int]) -> bool:\n s = sum(li)\n if s % 3: return False\n ts = s // 3\n ss = 0\n chunk = 0\n for n in li[:-1]:\n ss += n\n if ss == ts:\n chunk += 1\n if chunk == 2:\n return True\n ss = 0\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s % 3 != 0:\n return False\n curr, target = 0, s // 3\n count = 0\n for ix in range(len(A)):\n curr += A[ix]\n if curr == target:\n curr = 0\n count += 1\n \n if count == 2 and ix < len(A) - 1:\n return True\n \n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n total = sum(A)\n if total % 3 != 0:\n return False\n \n partition_sum = total/3\n numberofpartition=0\n tempsum=0\n for i in range(len(A)):\n tempsum+=A[i]\n if tempsum == partition_sum:\n numberofpartition+=1\n tempsum=0\n \n if numberofpartition == 3:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n S = sum(A)\n if S % 3 != 0:\n return False\n \n S_1 = S / 3\n S_2 = S_1 + S_1\n cur = A[0]\n for i in range(1, len(A)-2):\n if cur == S_1:\n cur += A[i]\n for j in range(i+1, len(A)-1):\n if cur == S_2:\n return True\n else:\n cur += A[j]\n \n if cur == S_2:\n return A[-1] == S_1\n else:\n cur += A[i]\n\n if cur == S_1:\n return A[-1] == S_1\n\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n tot = sum(A)\n if tot%3 != 0:\n return False\n flag = 0\n temp_tot = 0\n presum =[0] * (len(A) + 1)\n s = tot//3\n target = [2*s, s]\n for i in range(len(A)):\n if not target:\n return True\n \n presum[i + 1] = presum[i ] + A[i]\n if presum[i + 1] == target[-1]:\n target.pop()\n \n \n \n \n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if sum(A)%3: \n return False\n sumParts = sum(A)//3\n summ=0\n parts=0\n for num in A:\n summ+=num\n if summ==sumParts:\n parts +=1\n summ=0\n return parts>=3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n sum=0\n for a in A:\n sum+=a\n target=floor(sum/3)\n sum=0\n cnt=0\n j=len(A)-1\n i=0\n while j>0:\n sum+=A[j]\n if sum==target:\n cnt+=1\n sum=0\n break\n j-=1\n while i<j:\n sum+=A[i]\n if cnt<2 and sum==target:\n cnt+=1\n sum=0\n if j-i<=1:\n return False\n i+=1\n if i>=j:\n break\n if cnt==2 and sum==target:\n cnt+=1\n if cnt==3:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n \n average, remainder, part, cnt = sum(A) // 3, sum(A) % 3, 0, 0\n for a in A:\n part += a\n if part == average:\n cnt += 1\n part = 0\n return not remainder and cnt >= 3", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s % 3 != 0: return False\n return self.can_partition(A, 0, 3, s // 3) \n \n def can_partition(self, A: List[int], i: int, n_parts: int, target_sum: int) -> bool:\n #print(f'i={i}, n_parts={n_parts}')\n if n_parts == 1: return i < len(A) and sum(A[i:]) == target_sum\n if i >= len(A): return False\n partition_sum = A[i]\n j = i + 1\n while j < len(A) and partition_sum != target_sum:\n partition_sum += A[j]\n j += 1\n return self.can_partition(A, j, n_parts - 1, target_sum)", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n sum = 0\n for num in A:\n sum += num\n \n if sum%3 != 0:\n return False\n \n sum = sum/3\n total = 0\n currentSum = 0\n for num in A:\n currentSum += num\n if currentSum == sum:\n total += 1\n currentSum = 0\n \n return True if total>=3 else False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n tot = sum(A)\n if tot % 3 != 0:\n return False\n target = tot // 3\n curr_sum = 0\n check1, check2 = 0, 0\n for i, a in enumerate(A):\n curr_sum += a\n \n if check1 != 1 and curr_sum == target:\n check1 = 1\n continue\n # print(target, curr_sum)\n if check1 and curr_sum == target*2 and i < len(A) - 1:\n check2 = 1\n break\n if check1 and check2:\n return True\n else:\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n s1 = 0\n i = 0\n print((s//3))\n while i < len(A):\n s1 += A[i]\n if s1 == s//3:\n break\n i+=1\n s1 = 0\n i+=1\n while i < len(A):\n s1 += A[i]\n print(s1)\n if s1 == s//3:\n if i != len(A)-1:\n return True\n i+=1\n return False\n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n tot = 0\n bi = sum(A)//3\n count = 0\n \n for i in range(len(A) - 1):\n tot += A[i]\n if tot == bi:\n tot = 0\n count += 1\n \n if count == 2:\n return True\n return False", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n total = sum(A)\n \n if total%3 != 0 :\n return False\n \n target = total/3\n print (target)\n \n temp = 0\n res = []\n for i, v in enumerate(A):\n temp = temp + v\n \n if temp == target:\n res.append(i)\n temp = 0\n print (res)\n \n return len(res)>=3\n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n s = sum(A)\n if s%3!=0:\n return False\n target = s/3\n total = 0\n partitions = 0\n for num in A:\n total+=num\n if total == target:\n partitions+=1\n total = 0\n \n \n return total == 0 and partitions in [3,4]", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n n = len(A)\n sum_a = sum(A)\n if sum_a%3!=0:\n return False\n target = sum_a//3\n \n output = []\n temp_sum = 0\n temp_output = []\n for i in A:\n temp_output.append(i)\n temp_sum = temp_sum + i\n if temp_sum == target:\n if len(temp_output)>0 and len(output)<3:\n output.append(temp_output)\n temp_sum = 0\n temp_output = []\n if temp_sum!=0:\n return False\n if len(output)!=3:\n return False\n else:\n return True\n \n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n tot_sum = sum(A)\n if tot_sum % 3 != 0:\n return(False)\n else:\n cum_sum = 0\n target = tot_sum//3\n counter = 0\n for num in A[:-1]:\n cum_sum += num\n if cum_sum == target:\n counter += 1\n cum_sum = 0\n if counter == 2:\n return(True)\n return(False)\n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n total = sum(A)\n if total % 3 != 0:\n return False\n \n subtotal = total // 3\n \n pre_sum = 0\n k = 3\n for i in range(len(A)):\n pre_sum += A[i]\n if k > 1 and pre_sum == subtotal:\n k -= 1\n pre_sum = 0\n elif i == len(A)-1:\n k -= 1\n \n return k == 0 and pre_sum == subtotal\n \n \n \n", "class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n if(sum(A)%3!=0):\n return False\n val=sum(A)//3\n add=0\n count=0\n for x in range(len(A)):\n add+=A[x]\n if(add==val):\n add=0\n count+=1\n else:\n continue\n if(count>=3):\n return True\n return False\n \n"] | {"fn_name": "canThreePartsEqualSum", "inputs": [[[0, 2, 3, -3, 3, -4, 5, 6, 8, 8, 9]], [[0,2,1,-6,6,7,9,-1,2,0,1]], [[0,2,1,-6,6,-7,9,1,2,0,1]], [[3,3,6,5,-2,2,5,1,-9,4]]], "outputs": [false, false, true, true]} | INTRODUCTORY | PYTHON3 | LEETCODE | 34,189 |
class Solution:
def canThreePartsEqualSum(self, A: List[int]) -> bool:
|
70cd64cd1c5fc1a9ac35a02c8e4fcd4e | UNKNOWN | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.
Print all strings that are written on the most number of votes, in lexicographical order.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
- S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.
- The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).
-----Input-----
Input is given from Standard Input in the following format:
N
S_1
:
S_N
-----Output-----
Print all strings in question in lexicographical order.
-----Sample Input-----
7
beat
vet
beet
bed
vet
bet
beet
-----Sample Output-----
beet
vet
beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet. | ["from collections import Counter\nn = int(input())\nss = [input() for _ in range(n)]\nss.sort()\nc = Counter()\nmc = 0\nfor s in ss:\n c[s] += 1\n mc = max(mc, c[s])\nseen = set()\nfor s in ss:\n if c[s] == mc and s not in seen:\n print(s)\n seen.add(s)", "n = int(input())\ns_l = [ input() for _ in range(n) ]\n\nd = {}\nfor s in s_l:\n try:\n d[s] += 1\n except:\n d[s] = 1\n\nmax_c = max([ v for _,v in d.items() ])\nans = [ i for i, v in d.items() if v == max_c ]\n\nfor i in sorted(ans):\n print(i)", "n = int(input())\nd = {}\nfor i in range(n):\n s = input()\n if s in d:\n d[s] += 1\n else:\n d[s] = 1\nmx = max(d.values())\nans = ['']\nfor k, v in d.items():\n if v == mx:\n ans.append(k)\nans.sort()\nprint(*ans, sep='\\n')\n", "N = int(input())\nd = {}\nfor _ in range(N):\n p = input()\n if p in d:\n d[p] += 1\n else:\n d[p] = 1\nma = max(d.values())\nd2 = sorted(d.items())\nd.clear()\nd.update(d2)\nfor k, v in list(d.items()):\n if v == ma:\n print(k)\n", "import collections\nn=int(int(input()))\na=[input() for i in range(n)]\nm = collections.Counter(a).most_common() \nprint('\\n'.join(sorted([a for a,b in m if b==m[0][1]])))", "import collections\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(map(int, input().split()))\ndef i_row(N): return [int(input()) for _ in range(N)]\ndef i_row_list(N): return [list(input().split()) for _ in range(N)]\n\nn=i_input()\nss=[input() for _ in range(n)]\nss.sort()\n\ncss=collections.Counter()\nfor s in ss:\n css[s]+=1\nmaxapper=max(css.values())\n\nfor w in css:\n if css[w]==maxapper:\n print(w)\n\n\n\n", "n=int(input())\ndic={}\nfor i in range(n):\n s=input()\n if not s in dic:\n dic[s]=1\n else:\n dic[s]+=1\nmax_val=max(dic.values())\na=sorted([i for i, k in dic.items() if k == max_val])\nfor i in a:\n print(i)", "n = int(input())\nS = {}\nfor i in range(n):\n s = input()\n if s not in S.keys():\n S[s] = 1\n else:\n S[s] += 1\nm = max(S.values())\nans = []\n\nfor key, value in S.items():\n if value == m:\n ans.append(key)\nans.sort()\nprint(*ans, sep=\"\\n\")\n", "n=int(input())\nA=[]\nfor i in range(n):\n a=str(input())\n A.append(a)\nimport collections\nc = collections.Counter(A)\nma= c.most_common()[0][1]\nC=[i[0] for i in c.items() if i[1] >=ma ]\nC.sort(reverse=False)\nfor j in range(len(C)):\n print(C[j])", "from collections import defaultdict\ncharnums=defaultdict(int)\nN=int(input())\nfor _ in range(N):\n charnums[input()]+=1\nans=[]\nm=max(charnums.values())\nfor key,value in charnums.items():\n if value==m:\n ans.append(key)\nfor an in sorted(ans):\n print(an)", "import collections\nN=int(input())\nS=[]\nfor i in range(N):\n s=input()\n S.append(s)\n\nl=collections.Counter(S)\nkeys=l.keys()\nk=max(l.values())\nans=[]\nfor i in keys:\n if l[i]==k:\n ans.append(i)\n\nans.sort()\nn=len(ans)\n\nfor i in range(n):\n print(ans[i])", "import collections\nN = int(input())\nS = []\nans = []\nfor i in range(N):\n S.append(input())\nd = collections.Counter(S)\nome = max(d.values())\nfor k, v in list(d.items()):\n if v == ome:\n ans.append(k)\nans.sort()\nfor x in ans:\n print(x)\n", "N = int(input())\n\nd = {}\nfor _ in range(N):\n S = input()\n if S in d:\n d[S] += 1\n else:\n d[S] = 1\n\nm = max(d.values())\nfor s in sorted(k for k in d if d[k] == m):\n print(s)", "N = int(input())\nS = [input() for _ in range(N)]\n\ndic = {}\n\nfor i in range(N):\n if S[i] not in list(dic.keys()):\n dic[S[i]] = 1\n \n else:\n dic[S[i]] += 1\n \nmaxim = max(dic.values())\nans = []\n\nfor keys in list(dic.keys()):\n if dic[keys] == maxim:\n ans.append(keys)\n \nans.sort()\n\nfor i in range(len(ans)):\n print((ans[i]))\n", "N = int(input())\nS = []\nfor i in range(N) :\n S.append(input())\nS_set = set(S)\nS_sorted = sorted(S)\nS_sorted.append(\"null0\")\n\ncntlist = [[S_sorted[0],1]]\nj = 0\nfor i in range(len(S)-1) :\n if cntlist[j][0] != S_sorted[i+1] :\n cntlist.append([S_sorted[i+1],1])\n j = j + 1\n else :\n cntlist[j][1] += 1\n\nmaxnum = 0\nfor i in range(len(cntlist)) :\n maxnum = max(cntlist[i][1],maxnum)\ncntlist_new = []\nfor i in range(len(cntlist)) :\n if cntlist[i][1] == maxnum :\n cntlist_new.append(cntlist[i])\nfrom operator import itemgetter\nnew_cnt = sorted(cntlist_new,key = itemgetter(0),reverse = False)\n\n#print(S)\n#print(S_sorted)\n#print(cntlist_new)\n#print(new_cnt)\n\nfor i in range(len(new_cnt)) :\n print(new_cnt[i][0])", "import collections\n\nN = int(input())\n\nSlist = []\nfor i in range(N):\n Slist.append(input())\n#print (Slist)\n\nanslist =sorted(Slist)\nc = collections.Counter(anslist)\nvalues, counts = zip(*c.most_common())\nmaxcount = counts[0]\ni = 0\n#print (values)\n#print (counts)\nfor i in range(len(values)):\n if maxcount == counts[i]: \n print (values[i])\n maxcount = counts[i]\n i+=1\n else :\n break", "N = int(input())\ndic = {}\nfor _ in range(N):\n S = input()\n if S in dic:\n dic[S] += 1\n else:\n dic[S] = 1\n\nlst = []\nM = max(dic.values())\nfor k in dic.keys():\n if dic[k] == M:\n lst.append(k)\n\nlst.sort()\n\nfor i in range(len(lst)):\n print(lst[i])", "n = int(input())\ns = list(input() for _ in range(n))\nd = {}\nfor i in range(n):\n if s[i] in d:\n d[s[i]] += 1\n else:\n d[s[i]] = 1\nm = max(d.values())\nfor s in sorted(k for k in d if d[k] == m):\n print(s)", "N = int(input())\ndic, rst = {}, []\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "n = int(input())\ndata = {}\nfor i in range(n):\n s = str(input())\n if s in data.keys():\n data[s] += 1\n else:\n data[s] = 1\nm = max(list(data.values()))\nans = []\nfor j,k in data.items():\n if k == m:\n ans.append(j)\nfor l in sorted(ans):\n print(l)", "N = int(input())\n\nss = dict()\nfor i in range(N):\n s = input()\n ss[s] = ss.get(s, 0) + 1\nsss = [(-b, a) for a, b in list(ss.items())]\nsss.sort()\nmaxa = sss[0][0]\nfor a, b in sss:\n if maxa != a:\n break\n print(b)\n", "n = int(input())\nd = {}\nmax_value = 1\nfor i in range(n):\n\ts = input()\n\tif s in d:\n\t\td[s] += 1\n\t\tmax_value = max(max_value, d[s])\n\telse:\n\t\td[s] = 1\nl = []\nfor k in d:\n\tif d[k] == max_value:\n\t\tl.append(k)\nfor x in sorted(l):\n\tprint(x)", "\nn = int(input())\nl = [str(input()) for i in range(n)]\n\nl = sorted(l)\n\ncnt = 1\ncnt_max = 1\nmoji = []\n\nfor i in range(1, n):\n if l[i] == l[i-1]:\n cnt += 1\n if i == n-1:\n if cnt_max < cnt:\n cnt_max = cnt\n moji = [l[i-1]]\n elif cnt_max == cnt:\n moji.append(l[i-1])\n else:\n if cnt_max < cnt:\n cnt_max = cnt\n moji = [l[i-1]]\n elif cnt_max == cnt:\n moji.append(l[i-1])\n if cnt_max == 1 and i == n-1:\n moji.append(l[i])\n cnt = 1\n\nfor i in range(len(moji)):\n print((moji[i]))\n\n\n\n", "n = int(input())\nd = {}\n\nfor i in range(n):\n s = input()\n if s not in d:\n d.update({s: 1})\n else:\n d[s] += 1\n\nmax_val = max(d.values())\nkeys_of_max_val = [key for key in d if d[key] == max_val]\nprint((\"\\n\".join(sorted(keys_of_max_val))))\n", "from collections import Counter\nimport heapq\n\nn = int(input())\nsc = Counter()\n\nfor x in range(n):\n s = input()\n sc.update([s])\n\nmax_num = sc.most_common()[0][1]\nq = []\nfor v in list(sc.items()):\n if v[1] == max_num:\n heapq.heappush(q, v[0])\n\nfor _ in range(len(q)):\n print((heapq.heappop(q)))\n\n", "N = int(input())\nd = {}\nfor i in range(N):\n s = input()\n if s in d:\n d[s] += 1\n\n else:\n d[s] = 1\n\n\nl = sorted(d.items())\nM = max(d.values())\n\nfor i in l:\n if d[i[0]] == M:\n print(i[0])", "from collections import Counter\nn=int(input())\ns=Counter([input()for _ in[0]*n])\nm=s.most_common(1)[0][1]\nr=sorted((k for k,v in s.items() if v==m))\nfor a in r:print(a)", "from collections import Counter\nn = int(input())\ns = [input() for _ in range(n)]\ns = Counter(s)\ns = sorted(list(s.items()), reverse=True, key=lambda x: x[1])\nmax_count = max(list([x[1] for x in s]))\nans = sorted([l for l, c in s if c==max_count])\n\nfor a in ans:\n print(a)\n", "N = int(input())\nS = sorted([input() for _ in range(N)])\nA = []\ncount = 1\nfor i in range(N-1):\n if(i == N-2):\n A.append(S[N-1])\n if(S[i] != S[i+1]):\n A.append(S[i])\nA.sort()\nB = [1]*len(A)\na = 0\nfor i in range(N-1):\n if(S[i] == S[i+1]):\n B[a] += 1\n else:\n a += 1\nm = max(B)\nfor i in range(len(A)):\n if(B[i] == m):\n print(A[i])", "from collections import Counter\nn = int(input())\ns = list(input() for i in range(n))\nc = Counter(s)\nm = max(c.values())\ns = sorted(list(set(s)))\nfor i in range(len(s)):\n if c[s[i]] == m:\n print(s[i])", "N = int(input())\nS = dict()\nfor i in range(N):\n s = input()\n if s in S:\n S[s] += 1\n else:\n S[s] = 1\n\nmax_val = max(S.values())\nmax_key = [key for key in S if S[key] == max_val]\nprint((\"\\n\".join(sorted(max_key))))\n", "N = int(input())\nS = [input() for _ in range(N)]\ndict_s = dict()\nfor s in S:\n if s in dict_s:\n dict_s[s] += 1\n else:\n dict_s[s] = 1\n\nsorted_s = sorted(dict_s.items(), key=lambda x: x[1], reverse=True)\nmax_s = []\nmax_count = -1\nfor s in sorted_s:\n if s[1] >= max_count:\n max_s.append(s[0])\n max_count = s[1]\n\nfor s in sorted(max_s):\n print(s)", "'''n = int(input())\narr1 = []\narr2 = [0]*n\narr3 = []\nfor _ in range(n):\n x = input()\n if x not in arr1:\n arr1.append(x)\n arr2[arr1.index(x)] += 1\n else:\n arr2[arr1.index(x)] += 1\narr2 = set(arr2)\nmax_count = max(list(arr2.values()))\nans = []\nfor item in arr2.items():\n (key, value) = item\n if value == max_count:\n arr3.append(key)\narr3.sort()\nfor j in arr3:\n print(j)\n'''\nn = int(input())\ns = [input() for _ in range(n)]\ncount = {}\n\nfor word in s:\n if word not in count:\n count[word] = 1\n else:\n count[word] += 1\n\nmax_count = max(list(count.values()))\nans = []\nfor item in list(count.items()):\n (key, value) = item\n if value == max_count:\n ans.append(key)\n\nans = sorted(ans)\nfor w in ans:\n print(w)\n", "import collections\ndef i_input(): return int(input())\n\n\ndef i_map(): return list(map(int, input().split()))\n\n\ndef i_list(): return list(map(int, input().split()))\n\n\ndef i_row(N): return [int(input()) for _ in range(N)]\n\n\ndef i_row_list(N): return [list(map(int, input().split())) for _ in range(N)]\n\nn=i_input()\nss=[input() for _ in range(n)]\nss.sort()\nc = collections.Counter()\nfor word in ss:\n c[word] += 1\n\nprtcnt=max(c.values())\nfor word,cnt in list(c.items()):\n if cnt==prtcnt:\n print(word)\n", "d=dict()\nfor _ in range(int(input())):s=input();d[s]=d.get(s,0)+1\nm=max(d.values());i=[k for k,v in d.items()if v==m]\nfor v in sorted(i):print(v)", "import os, sys, re, math\n\nN = int(input())\nS = []\nfor i in range(N):\n S.append(input())\n\nd = {}\nfor s in S:\n if not s in d:\n d[s] = 0\n d[s] += 1\n\nd = sorted(list(d.items()), key=lambda x:x[1], reverse=True)\nnames = [v[0] for v in d if v[1] == d[0][1]]\n\nfor name in sorted(names):\n print(name)\n", "from collections import Counter\n\nn = int(input())\ns = []\nfor _ in range(n):\n s.append(input())\n\ns.sort()\nc = Counter(s)\n\nvalues = sorted(list(c.values()), reverse=True)\nkeys = sorted(list(c.keys()))\nfor item in c:\n if c[item] == values[0]:\n print(item)\n", "def N():\n return int(input())\ndef L():\n return list(map(int,input().split()))\ndef NL(n):\n return [list(map(int,input().split())) for i in range(n)]\nmod = pow(10,9)+7\n\n#import numpy as np\nimport sys\nimport math\nimport collections\n\nn = N()\ns = {}\nfor i in range(n):\n a = input()\n if a in s:\n s[a] += 1\n else:\n s[a] = 1\n\ns = sorted(s.items(),key=lambda x:x[1],reverse=True)\nm = s[0][1]\ns2 = []\nfor i in range(len(s)):\n if s[i][1] == m:\n s2.append(s[i][0])\n else:\n break\n\ns2.sort()\nfor i in s2:\n print(i)", "N = int(input())\nS = []\n\nfor i in range(N):\n\tS.append(str(input()))\nS.sort()\nS.append(0)\n\nprev_name = S[0]\ncnt = 1\nnames = []\ncnts = []\nfor i in range(1, N + 1):\n\tif prev_name == S[i]:\n\t\tcnt += 1\n\telse:\n\t\tnames.append(prev_name)\n\t\tcnts.append(cnt)\n\t\tprev_name = S[i]\n\t\tcnt = 1\nmax_cnt = max(cnts)\n\nfor i in range(len(names)):\n\tif cnts[i] == max_cnt:\n\t\tprint(names[i])", "\nn = int(input())\nd = {}\n\nfor i in range(n):\n st = input()\n if st in list(d.keys()):\n d[st] += 1\n else:\n d[st] = 1\n\nm = max(list(d.values()))\nl = []\n\nfor x,y in list(d.items()):\n if y == m:\n l.append(x)\nl.sort()\n\nfor v in l:\n print(v)\n\n", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\nimport collections\n\ndef main():\n words=[]\n word_dict=[]\n n = int(input())\n words=[input().rstrip() for _ in range(n)]\n answers=[]\n\n word_dict = collections.Counter(words)\n max_count=max(word_dict.values())\n [answers.append(values) for values,counts in word_dict.most_common() if counts==max_count]\n\n for answer in sorted(answers):\n print(answer)\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nS = []\nM = 1\ncount = 1\n\nfor _ in range(N):\n S.append(input())\n\nS.sort()\nans=[S[0]]\n\nfor i in range(N-1):\n if S[i] == S[i+1]:\n count += 1\n else:\n if M < count:\n M = count\n ans = [S[i]]\n elif M == count:\n ans.append(S[i])\n count = 1\nif M < count:\n M = count\n ans = [S[N-1]]\nelif M == count:\n ans.append(S[N-1])\n\nans = list(set(ans))\nans.sort()\n\nfor j in range(len(ans)):\n print(ans[j])", "import collections\nN = int(input())\nS = []\n\nfor i in range(N):\n S.append(input())\n\nc = collections.Counter(S).most_common()\nans = []\n\nif len(c) == 1:\n ans = c\nelse:\n for k in range(N):\n if c[0][1] == c[k][1]:\n ans.append(c[k])\n else:\n break\nfor x in sorted(ans):\n print(x[0])", "n = int(input())\ns = list(input() for _ in range(n))\nd = {}\nfor i in range(n):\n if s[i] in d:\n d[s[i]] += 1\n else:\n d[s[i]] = 1\n\nm = max(d.values())\nl=[]\nfor i in d:\n if d[i] == m:\n l.append(i)\nfor i in sorted(l):\n print(i)", "N = int(input())\n\nd = {}\nfor _ in (range(N)):\n s = input()\n if s not in d.keys():\n d[s] = 1\n else:\n d[s] += 1\n\nmax_n = max(d.values())\nans = []\nfor key,value in d.items():\n if value == max_n:\n ans.append(key)\n\nans.sort()\nfor i in ans:\n print(i)", "def main():\n\tn = int(input())\n\td = dict()\n\tfor _ in range(n):\n\t\ts = input()\n\t\tif s not in list(d.keys()):\n\t\t\td[s] =1\n\t\telse:\n\t\t\td[s] +=1\n\tmostFrequent = max(d.values())\n\tans = []\n\tfor key in list(d.keys()):\n\t\tif d[key] == mostFrequent:\n\t\t\tans.append(key)\n\tans.sort()\n\tfor i in ans:\n\t\tprint(i)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nimport statistics\nimport collections\na=int(input())\n#b,c=int(input()),int(input())\n# c=[]\n# for i in b:\n# c.append(i)\n#e1,e2 = map(int,input().split())\n# f = list(map(int,input().split()))\ng = [input() for _ in range(a)]\n# h = []\n# for i in range(e1):\n# h.append(list(map(int,input().split())))\n\ng.sort()\n\nma=0\ncount=1\n#\u6700\u5927\u5024\u6c42\u3081\u308b\nfor i in range(a-1):\n if g[i]==g[i+1]:\n count+=1\n else:\n ma=max(ma,count)\n count=1\n\nma=max(ma,count)\ncount=1\nans=[]\n#\u6700\u5927\u5024\u306e\u4f4d\u7f6e\nfor i in range(a-1):\n if g[i]==g[i+1]:\n count+=1\n else:\n if count==ma:\n ans.append(g[i])\n count=1\nif count==ma:\n ans.append(g[-1])\n\nfor i in ans:\n print(i)\n", "N = int(input())\ndic = {}\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "N=int(input())\nd=dict()\nfor _ in range(N):\n S=input()\n if S not in d:\n d[S]=0\n d[S]+=1\nM=max(d.values())\nans=[]\nfor S in list(d.keys()):\n if d[S]==M:\n ans.append(S)\nans.sort()\nfor S in ans:\n print(S)\n", "import collections\n\nN = int(input())\nS = sorted([input() for _ in range(N)])\n\nc = collections.Counter(S)\n\nvmax = max(c.values())\n\nfor k, v in c.items():\n if v == vmax:\n print(k)", "n = int(input())\n\ndct = {}\n\nfor i in range(n):\n s = input()\n if s in dct:\n dct[s] += 1\n else:\n dct[s] = 1\n\nmax_num = max(dct.values())\nans = []\nsorted_dct = sorted(dct.items())\n \nfor x in sorted_dct:\n if x[1] >= max_num:\n ans.append(x[0])\n \nprint(*ans, sep='\\n')", "N = int(input())\nS = [input() for _ in range(N)]\n\nd = {s: 0 for s in set(S)}\n\nfor i in range(N):\n d[S[i]] += 1\n\ncount = 0\nfor key in d:\n count = max(count, d[key])\n\nl = []\nfor key in d:\n if count == d[key]:\n l.append(key)\nl.sort()\n\nfor s in l:\n print(s)\n", "n = int(input())\ndd = {}\nfor i in range(n):\n\ts = input()\n\tif s in dd.keys():\n\t\tdd[s] += 1\n\telse:\n\t\tdd[s] = 1\nma = max(dd.values())\nlst = []\nfor k, v in dd.items():\n\tif v == ma:\n\t\tlst.append(k)\nfor l in sorted(lst):\n\tprint(l)", "from collections import defaultdict\nn = int(input())\ndic = defaultdict(int)\nfor i in range(n):\n dic[input()] += 1\ntmp = [(key, value) for key, value in dic.items()]\ntmp.sort(key=lambda x: (x[1], x[0]))\nm = tmp[-1][1]\nfor i in range(len(dic)):\n if tmp[i][1] == m:\n print (tmp[i][0])", "import collections\n\nn = int(input())\n\nli=[]\n\n\nfor i in range(n):\n li.append(input())\n\ncnt = collections.Counter(li)\nS = cnt.most_common()\n\n\nC =len(cnt)\n\nli_1 = [S[0][0]]\n\nfor i in range(C-1):\n if S[i][1] == S[i+1][1]:\n li_1.append(S[i+1][0])\n else:\n break\n\nli_1.sort()\n\nfor i in li_1:\n print(i)\n", "import collections as c\na=c.Counter(input() for _ in range(int(input())));b=a.most_common(1)[0][1]\nprint(*sorted([i for i,j in a.items() if j==b]),sep='\\n')", "n = int(input())\nd = {}\nt = 0\nfor i in range(n):\n s = input()\n d[s] = d.get(s, 0) + 1\n t = max(t, d[s])\n \nfor key in sorted(d):\n if d[key] == t:\n print(key)", "n = int(input())\nd = {}\nm = 0\nfor i in range(n):\n s = input()\n d[s] = d.get(s, 0) + 1\n if m <= d[s]:\n m = d[s]\nc = []\nfor i in d:\n if d[i]==m:\n c.append(i)\nc.sort()\nfor x in c:\n print(x)", "n = int(input())\ns = [input() for _ in range(n)]\ncount = {}\n\nfor word in s:\n if word not in count:\n count[word] = 1\n else:\n count[word] += 1\n\nmax_count = max(list(count.values()))\nans = []\nfor item in count.items():\n (key, value) = item\n if value == max_count:\n ans.append(key)\n\nans = sorted(ans)\nfor w in ans:\n print(w)", "n = int(input())\nL = list(input() for _ in range(n))\nD = dict.fromkeys(set(L),0)\n\nfor l in L:\n D[l] += 1\n\nm = max(D.values())\nSD = sorted(D.items(), key=lambda x:x[0])\n\nfor k, v in SD:\n if v == m:\n print(k)", "N = int(input())\ndic, rst = {}, []\nfor i in range(N):\n s = input()\n if not s in dic:\n dic[s] = 1\n else:\n dic[s] += 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "q=int(input())\ndic={}\nfor i in range(q):\n s=input()\n if not s in dic:\n dic[s]=1\n else:\n dic[s]+=1\nmax_val=max(dic.values())\na=sorted([i for i, k in list(dic.items()) if k == max_val])\nfor i in a:\n print(i)\n", "n = int(input())\ns = [input() for _ in range(n)]\nans = []\nd = {}\nfor i in s:\n try: d[i] += 1\n except KeyError: d[i] = 1\nmx = 0\nfor value in list(d.values()):\n if value > mx: mx = value\nfor key, value in list(d.items()):\n if value == mx:\n ans.append(key)\nfor v in sorted(ans):\n print(v)\n", "from collections import Counter\n\nn = int(input())\ns = [input() for _ in range(n)]\n\nc = Counter(s)\nm = c.most_common()[0][1]\nk = list(c.keys())\nv = list(c.values())\n\nl = []\nfor i in range(len(c)):\n if v[i] == m:\n l.append(k[i])\n\nl.sort()\n \nprint(*l,sep=\"\\n\")", "# C\nfrom collections import Counter\nN = int(input())\nS = [input() for _ in range(N)]\ncountS = Counter(S)\nmaxS = max(countS.values())\nans = []\nfor key,value in list(countS.items()):\n if value == maxS:\n ans.append(key)\n\nfor a in sorted(ans):\n print(a)\n", "n = int(input())\nS = dict()\nfor i in range(n):\n s = input()\n if s in S: S[s] += 1\n else: S[s] = 1\nans = []\ncnt = 0\nfor k,v in S.items():\n if v >= cnt:\n if v > cnt: ans = []\n ans.append(k)\n cnt = v\nprint(*sorted(ans), sep='\\n')\n", "N = int(input())\nA = {}\nfor i in range(N):\n s = input()\n if s in A:\n A[s] += 1\n else:\n A[s] = 1\ns_max = max(A.values())\nfor j in sorted(k for k in A if A[k] == s_max):\n print(j)", "def sovle():\n N = int(input())\n\n d = {}\n max = []\n max_count = 0\n for i in range(N):\n s = input()\n if s in d:\n d[s] += 1\n else:\n d[s] = 1\n \n if max_count < d[s]:\n max = [s]\n max_count=d[s]\n elif max_count == d[s]:\n max.append(s)\n \n max.sort()\n\n for i in max:\n print(i)\n \nsovle()", "N = int(input())\nS = [input() for _ in range(N)]\n\n# cnts = {key: S.count(key) for key in S}\ncnts = {key: 0 for key in S}\nfor key in S:\n cnts[key] += 1\n\nmax_cnt = max(cnts.values())\n\nans = [k for k, v in cnts.items() if v == max_cnt]\nans.sort()\n\nprint(*ans, sep='\\n')", "import collections\nn = int(input())\nl = []\nfor i in range(n):\n l.append(input())\nc = collections.Counter(l)\nm = max(c.values())\nchars = [key for key, value in c.items() if value == m]\nchars.sort()\nfor s in chars:\n print(s)", "from collections import Counter\n\nn = int(input())\nS = [input() for _ in range(n)]\nC = Counter(S)\nC_most = C.most_common()\n\nans = []\nfor key, val in C_most:\n if val == C_most[0][1]:\n ans.append(key)\n else:\n break\n \nprint(*sorted(ans), sep='\\n')", "import sys\nimport math\nfrom collections import defaultdict, deque, Counter\nfrom copy import deepcopy\nfrom bisect import bisect, bisect_right, bisect_left\nfrom heapq import heapify, heappop, heappush\n \ninput = sys.stdin.readline\ndef RD(): return input().rstrip()\ndef F(): return float(input().rstrip())\ndef I(): return int(input().rstrip())\ndef MI(): return map(int, input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int, input().split()))\ndef TI(): return tuple(map(int, input().split()))\ndef LF(): return list(map(float,input().split()))\ndef Init(H, W, num): return [[num for i in range(W)] for j in range(H)]\n \n \ndef main():\n N = I()\n D = defaultdict(int)\n for i in range(N):\n D[input().rstrip()]+=1\n D = D.items()\n D = sorted(D, key = lambda x:x[0])\n D = sorted(D, key = lambda x:x[1], reverse = True)\n num = D[0][1]\n \n for key, n in D:\n if n != num:\n return\n print(key)\n \ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\ndic = {}\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "N = int(input())\ndic = {}\nmax_count = 1\n\nfor i in range(N):\n s = input()\n if s not in dic:\n dic[s] = 1\n else:\n dic[s] += 1\n if max_count < dic[s]:\n max_count = dic[s]\n\nans_lis = []\n\nfor i, j in dic.items():\n if j == max_count:\n ans_lis.append(i)\n\nans_lis.sort()\n\nfor i in ans_lis:\n print(i)", "import numpy as np\nN, = map(int, input().split())\ndic = {}\nfor i in range(N):\n x = input()\n if x in dic:\n dic[x]+=1\n else:\n dic[x]=1\nc=max(dic.values())\nre =[]\nfor i in dic:\n if dic[i]==c:\n re+=[i]\nre.sort()\nfor i in re:\n print(i)", "N = int(input())\n\ndct = {}\n\nfor i in range(N):\n s = input()\n if not s in dct:\n dct[s] = 1\n\n else:\n dct[s] += 1\n \nm = max(dct.values())\nfor s in sorted(k for k in dct if dct[k] == m):\n print(s)", "import collections\nN=int(input())\ns=[str(input()) for i in range(N)]\nc=collections.Counter(s)\nmaximum =max(c.values()) \nmax_c_list = sorted(key for key,value in c.items() if value == maximum)\nfor s in max_c_list:\n print(s)", "n = int(input())\na = {}\nfor i in range(n):\n s = input()\n if s not in a:\n a.update({s: 0})\n else:\n temp = a[s] + 1\n a.update({s:temp})\nmax_val = max(list(a.values()))\nb = []\nfor key in a:\n if a[key] == max_val:\n b.append(key)\nb.sort()\nprint(*b, sep='\\n')", "n = int(input())\ncount_dict = {}\nfor i in range(n):\n i = input()\n if i in count_dict.keys():\n count_dict[i] +=1\n else:\n count_dict[i] = 0\nmax_value = max(count_dict.values())\nfor key,value in sorted(count_dict.items()):\n if value == max_value:\n print(key)", "# coding: utf-8\nfrom collections import defaultdict\n\n\ndef main():\n N = int(input())\n dic = defaultdict(int)\n max_p = 0\n\n for i in range(N):\n dic[input()] += 1\n\n d = dict(dic)\n l = []\n\n for key, value in list(d.items()):\n l.append([key, value])\n if max_p < value: max_p = value\n \n l.sort(key=lambda x: (-x[1], x[0]), reverse=False)\n\n for i, j in l:\n if j == max_p:\n print(i)\n else:\n break\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import collections\nN=int(input())\nL=[]\nfor i in range(N):\n L.append(input())\nC=collections.Counter(L)\nMax=C.most_common()[0][1]\nl = [i[0] for i in C.items() if i[1] == Max]\nprint(*sorted(l),sep='\\n')\n\n", "import collections\n\nn = int(input())\ns = [input() for _ in range(n)]\n\nc = collections.Counter(s)\nsorted_c = c.most_common()\nmax = sorted_c[0][1]\ndict_c = []\nfor i in range(len(sorted_c)):\n if sorted_c[i][1] == max:\n dict_c.append(sorted_c[i][0])\n else:\n break\n\ndict_c.sort()\nfor i in range(len(dict_c)):\n print((dict_c[i]))\n", "N = int(input())\ndic,rst = {}, []\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "N = int(input())\ndic, lis = {}, []\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\n\nM = max(dic.values())\n\nfor s in dic.keys():\n if dic[s] == M:\n lis.append(s)\nans = sorted(lis)\nfor s in ans:\n print(s)", "N = int(input())\ndic, rst = {}, []\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "N = int(input())\ndic = {}\nfor i in range(N):\n s = input()\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\nmax_val = max(dic.values())\nrst = [ key for key, val in dic.items() if val == max_val ]\n[ print(i) for i in sorted(rst) ]", "import collections\ndef resolve():\n n = int(input())\n s = [input() for _ in range(n)]\n c = collections.Counter(s)\n max_count = c.most_common()[0][1]\n ans = [i[0] for i in c.items() if i[1]==max_count]\n for i in sorted(ans): print(i)\nresolve()", "from collections import Counter\n\nN = int(input())\nS = [input() for _ in range(N)]\n\ncnts = Counter(S)\nmax_l = max(cnts.values())\n\nans = [s for s, c in cnts.items() if c == max_l]\nans.sort()\n\nprint(*ans, sep='\\n')", "n = int(input())\n\ncnt = {}\nfor i in range(n):\n s = input()\n if s in cnt:\n cnt[s] += 1\n else:\n cnt[s] = 1\n\nres = []\n\nmaks = max(list(cnt.items()), key=lambda x : x[1])\nfor item in list(cnt.items()):\n if item[1] == maks[1]:\n res.append(item[0])\n\nres.sort()\nfor s in res:\n print(s)\n\n", "N = int(input())\nS = [input() for _ in range(N)]\ndic = {}\nfor i in range(N):\n if S[i] not in list(dic.keys()):\n dic[S[i]] = 1\n else:\n dic[S[i]] += 1\n\nmaxI = max(dic.values())\nans = []\n\nfor keys in list(dic.keys()):\n if dic[keys] == maxI:\n ans.append(keys)\n\nans.sort()\n\nfor i in ans:\n print(i)\n", "n=int(input())\n\nl={}\na=0\n\nfor i in range(n):\n s=input()\n if s in l:\n l[s]+=1\n else:\n l[s]=1\n if a<l[s]:\n a=l[s]\nans=[]\n\nfor i in list(l.keys()):\n if l[i]==a:\n ans.append(i)\n\nans.sort()\n\nfor j in ans:\n print(j)\n", "N = int(input())\ndic = {}\nfor i in range(N):\n s = str(input())\n if s in dic:\n dic[s] += 1\n else:\n dic[s] = 1\n\nS = sorted(dic.values())\nt = S[-1]\n\nX = []\nfor key in dic:\n if dic[key] == t:\n X.append(key)\nx = sorted(X)\n\nfor i in range(len(X)):\n print(x[i])", "N = int(input())\ndic, rst = {}, []\nfor i in range(N):\n key = input()\n if key in dic:\n dic[key] += 1\n else:\n dic[key] = 1\nmax_val = max(dic.values())\nrst = [ key for key, value in dic.items() if value == max_val ]\n[ print(i) for i in sorted(rst) ]", "n = int(input())\ns = [input() for i in range(n)]\ndic = {}\nfor i in range(n):\n if s[i] in dic.keys():\n dic[s[i]] += 1\n else:\n dic[s[i]] = 1\nmax1 = max(dic.values())\nans = []\nfor keys in dic.keys():\n if dic[keys] == max1:\n ans.append(keys)\nans.sort()\nfor i in ans:\n print(i)", "import collections\nn = int(input())\nans = list(input() for i in range(n))\nans = collections.Counter(ans)\nm = max(ans.values())\nkeys = [k for k, v in ans.items() if v == m]\n[print(j) for j in sorted(keys)]", "import collections\nn = int(input())\nnames = [input() for _ in range(n)]\nc = collections.Counter(names)\nmaxv = max(c.values())\nans = []\nfor i in c.items():\n if i[1] == maxv:\n ans.append(i[0])\nans = sorted(ans)\nfor i in ans:\n print(i)", "n = int(input())\n\ndic = {}\n\nfor x in range(n):\n a = input()\n dic.setdefault(a,0)\n dic[a] += 1\n\ndic2 = sorted(list(dic.items()),key=lambda x:x[1],reverse=True)\n\nmax_word = [k for k,v in dic2 if v == dic2[0][1] ]\n\nmax_word.sort()\n\nfor x in max_word:\n print(x)\n", "N = int(input())\nS = [input() for _ in range(N)]\nS.sort()\n\nres = 0\ncnt = 1\nfor i in range(N-1):\n if S[i] == S[i+1]:\n cnt+=1\n else:\n res = max(res,cnt)\n cnt = 1\n\nres = max(res,cnt)\n\ncnt = 1\nans = []\nfor i in range(N-1):\n if S[i] == S[i+1]:\n cnt+=1\n else:\n if res == cnt:\n ans.append(S[i])\n cnt = 1\n\nif cnt == res:\n ans.append(S[i+1])\n\nfor i in range(len(ans)):\n print((ans[i]))\n"] | {"inputs": ["7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n", "8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n", "7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n", "4\nushi\ntapu\nnichia\nkun\n"], "outputs": ["beet\nvet\n", "buffalo\n", "kick\n", "kun\nnichia\ntapu\nushi\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 32,048 | |
7a9ee9413a6dd59ba4680756b0bdbfbc | UNKNOWN | Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (iβ j), he has to pay the cost separately for transforming each of them (See Sample 2).
Find the minimum total cost to achieve his objective.
-----Constraints-----
- 1β¦Nβ¦100
- -100β¦a_iβ¦100
-----Input-----
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
-----Output-----
Print the minimum total cost to achieve Evi's objective.
-----Sample Input-----
2
4 8
-----Sample Output-----
8
Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum. | ["n = int(input())\na = list(map(int, input().split()))\n\nans = 1e9\nfor p in range(-100, 101):\n sub = 0\n for q in a:\n sub += pow(p - q, 2)\n ans = min(ans, sub)\n\nprint(ans)\n", "n = int(input())\na = [int(x) for x in input().split()]\nres = 10 ** 9\n\nfor i in range(-100,101):\n cc = 0\n for j in range(n):\n cc += (i - a[j]) ** 2\n res = min(res,cc)\n\nprint(res)", "N = int(input())\na = list(map(int, input().split()))\navg = round(sum(a)/N)\nsums = []\nfor i in range(min(a), avg+1):\n s = 0\n for j in range(N):\n s += (i-a[j])**2\n sums.append(s)\nprint(min(sums))", "from typing import List\n\n\ndef answer(n: int, a: List[int]) -> int:\n cost = 0\n num = round(sum(a) / n)\n for i in a:\n cost += (i - num) ** 2\n\n return cost\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n print(answer(n, a))\n\n\ndef __starting_point():\n main()\n__starting_point()", "import math\nfrom statistics import mean\n\nn = int(input())\na = list(map(int, input().split()))\n\nm = mean(a)\nif m - math.floor(m) < 0.5:\n m = math.floor(m)\nelse:\n m = math.floor(m) + 1\n\ndiff = 0\nfor v in a:\n diff += (m - v) ** 2\n\nprint(diff)\n", "n = int(input())\na = list(map(int,input().split()))\n\na_u = round(sum(a)/n)\na_d = int(sum(a)/n)\nans_u = 0\nans_d = 0\nfor i in range(n):\n ans_u += (a[i]-a_u)**2\n ans_d += (a[i]-a_d)**2\nprint((min(ans_u,ans_d)))\n#print(round(-2.5),int(-2.5))\n", "import math\nn = int(input())\na = list(map(int,input().split()))\navg = sum(a)/n\nx = math.floor(avg)\ny = math.ceil(avg)\nsumx = 0\nsumy = 0\nfor i in a:\n sumx += (i - x) ** 2\n sumy += (i - y) ** 2\n\nprint(min([sumx,sumy]))", "N=int(input())\n*A,=list(map(int,input().split()))\n\nmx=max(A)\nmn=min(A)\n\n\nif len(set(A))==1:\n print((0))\nelse:\n ans=float('inf')\n for i in range(mn,mx):\n ans=min(ans, sum([(k-i)**2 for k in A]))\n print(ans)\n", "n = int(input())\na = list(map(int, input().split()))\n\nt = 10**9\nfor i in range(min(a),max(a)+1):\n num = 0\n for h in a:\n num += (h-i)**2\n if num <= t:\n t = num\nprint(t)", "s=input();a=list(map(int,input().split()));ans=0\nmean=round(sum(a)/len(a))\n\nfor i in a:\n p=(i-mean)**2\n ans+=p\n \nprint(ans)", "n=int(input())\nA=list(map(int,input().split()))\nans = [0]*201\nfor a in A:\n for i in range(-100,101):\n ans[i+100] += (a-i)**2\nprint(min(ans))", "maxa=(10)**11\nN=int(input())\nL=list(map(int,input().split()))\nfor i in range(-100,101):\n R=[(i-y)**2 for y in L]\n a=sum(R)\n maxa=min(maxa,a)\nprint(maxa)", "N=int(input())\nList = list(map(int, input().split()))\nsumS = 0\nfor i in range(N):\n sumS +=List[i]\ntrial = sumS // N\nmid = 0\nres = 10000000\nfor i in range(N):\n trial += i\n mid = 0 \n for j in range(N):\n mid += (trial - List[j])**2\n res = min(res, mid)\nprint(res)", "num = int(input())\nstr_line = input().split(\" \")\nnum_line = [int(n) for n in str_line]\n\nave = 0\nfor i in range(num):\n ave += num_line[i]\n\nif ave%num == 0:\n ave //= num\n\nelse:\n if ave%num <= num/2:\n ave //= num\n else:\n ave = -(-ave//num)\n\nwa = 0\nfor i in range(num):\n temp = num_line[i] - ave\n wa += temp*temp\n \nprint(wa)", "def main():\n n = int(input())\n al = list(map(int, input().split()))\n maxval = max(abs(max(al)), abs(min(al)))\n cost = []\n if len(list(set(al))) == 1 :\n print(\"0\")\n else :\n k = -1\n for i in range(-100,100) :\n k += 1\n cost.append(0)\n for j in range(n) :\n cost[k] = cost[k] + (al[j] - i) ** 2\n #print(cost[i])\n print((min(cost)))\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import statistics\nimport math\nn = int(input())\na = list(map(int,input().split()))\nans1,ans2 = 0,0\na_avr1 = math.ceil((statistics.mean(a)))\na_avr2 = math.floor((statistics.mean(a)))\nfor i in range(n):\n ans1 += (a[i] - a_avr1)**2\n ans2 += (a[i] - a_avr2)**2\nprint(min(ans1,ans2))", "n=int(input())\na=[int(i) for i in input().split()]\n\nans=10000000000000000\nfor criterion in range(-100,101):\n result=0\n for i in a:\n result+=(i-criterion)**2\n ans=min(ans,result)\nprint(ans)", "import numpy as np\nimport logging\nlogging.basicConfig(level=logging.DEBUG)\nlogging.disable(logging.CRITICAL)\n\nN=int(input())\n\nx=np.array(list(map(int,input().split())))\nlogging.debug('x={}'.format(x))\n\ni=np.amin(x)\nans=[]\nwhile i<=np.amax(x):\n\n logging.debug('i={}'.format(i))\n y=np.array([i]*N)\n ans.append(sum((x-y)**2))\n\n logging.debug('ans={}'.format(ans))\n i+=1\nprint((min(ans)))\n", "n = int(input())\na = list(map(int, input().split()))\navg_a = round(sum(a)/n)\n\nresult = 0\nfor num in a:\n result += (num-avg_a)**2\n\nprint(result)", "n = int(input())\na_list = list(map(int,input().split()))\nmid = round(sum(a_list)/n)\nans = 0\nfor a in a_list:\n ans += (a-mid) ** 2\nprint(ans)", "n = int(input())\na = [int(x) for x in input().split()]\na.sort()\nans = []\nfor i in range(a[0], a[-1]+1):\n cnt = 0\n for j in range(n):\n cnt += (a[j] - i)**2\n ans.append(cnt)\n\nprint(min(ans))", "N = int(input())\na = list(map(int, input().split()))\n\nmy_round_int = lambda x: int((x * 2 + 1) // 2)\nm = my_round_int(sum(a)/len(a))\n\ncost = 0\n\nfor i in a:\n cost += (i - m)**2\n\nprint(cost)", "N = int(input())\na = list(map(int, input().split()))\nb = []\nfor i in range(-100, 101):\n\tt = 0\n\tfor j in a:\n\t\tt += (j - i) ** 2\n\tb.append(t)\nprint(min(b))", "N = int(input())\nA = list(map(int,input().split()))\n\nmin_a = min(A)\nmax_a = max(A)\n\nans = float(\"inf\")\nfor i in range(min_a, max_a+1):\n tmp = 0\n for j in A:\n tmp += (i - j) ** 2\n ans = min(ans, tmp)\n \nprint(ans)", "n = int(input())\na = [ int(x) for x in input().split() ]\n\navg = round(sum(a) / n)\n\ncost = 0\n\nfor e in a:\n cost += (e-avg)**2\n\nprint(cost)\n", "n = int(input())\nlst = list(map(int, input().split()))\nm = 10 ** 10\nfor i in range(201):\n a = i - 100\n temp = 0\n for j in range(n):\n temp += ((lst[j] - a) ** 2)\n m = min(m, temp)\nprint(m)", "N = int(input())\na = list(map(int, input().split()))\nmi = min(a)\nma = max(a)\n\nans = float('inf')\nfor i in range(mi, ma + 1):\n ans = min(ans, sum((i - ai) ** 2 for ai in a))\n\nprint(ans)", "def cost(x):\n cost = (x - ave)**2\n return cost\n\n\nn = input()\na = list(map(int, input().split()))\nave = round(sum(a)/int(n))\nprint(sum(list(map(cost, a))))", "n = int(input())\nA = list(map(int, input().split()))\n\nans = float('inf')\nfor x in range(-100, 101, 1):\n c = 0\n for a in A:\n c += (a - x) ** 2\n ans = min(c, ans)\nprint(ans)", "N=int(input())\nn=list(map(int, input().split()))\nm=int(sum(n)/N)\n\ndef fun(x):\n ans=0\n for i in n:\n ans+=(i-x)**2\n return(ans)\n \np=fun(m)\nq=fun(m+1)\nif p<q:\n print(p)\nelse:\n print(q)", "n = int(input())\na = [int(x) for x in input().split()]\nA = min(a)\nB = max(a)\ntemp = 10000000000000000000000\nfor i in range(A,B+1):\n ans = 0\n for j in a:\n ans+= (abs(j-i))**2\n #print(ans)\n temp = min(temp,ans)\nprint(temp)\n", "n=int(input())\na=[int(i)for i in input().split()]\ncost=[]\nfor i in range(-100,101):\n tmp=0\n for j in a:\n tmp+=(j-i)**2\n cost.append(tmp)\nprint(min(cost))", "n = float(input())\n\na = list(map(int,input().split()))\n\nave = round(sum(a)/n)\n\nprint(sum(list(map(lambda x:(x-ave)**2,a))))", "n = int(input())\na_list = list(map(int,input().split()))\nmid = round(sum(a_list)/n)\nans = 0\nfor a in a_list:\n ans += (a-mid) ** 2\nprint(ans)", "N=int(input())\nn=list(map(int, input().split()))\nm=int(sum(n)/N)\n \ndef fun(x):\n ans=0\n for i in n:\n ans+=(i-x)**2\n return(ans)\n \ns=min(fun(m),fun(m+1))\nprint(s)", "N = int(input())\nA = list(map(int,input().split()))\ncosts = []\n\nfor i in range(101):\n cost = 0\n for j in range(N):\n cost += (A[j]-i)**2\n costs.append(cost)\n cost = 0\n for j in range(N):\n cost += (A[j]+i)**2\n costs.append(cost)\n\nprint(min(costs))", "N = int(input())\na = list(map(int, input().split()))\ns = sum(a)\nx = int(s / len(a))\n\nif (x + 1) - (s / len(a)) < (s / len(a)) - x:\n x += 1\ncost = 0\nfor y in a:\n cost += pow(y - x, 2)\n\nprint(cost)", "import math\nfrom datetime import date\n\ndef f(x, a):\n\tans = 0\n\tfor y in a:\n\t\tans += (x - y) ** 2\n\n\treturn ans\n\ndef main():\n\t\n\tn = int(input())\n\ta = [int(x) for x in input().split()]\n\ts = 0\n\tfor x in a:\n\t\ts += x\n\n\ts = s // n\n\tans = 10**17\n\n\tfor x in range(s - 2, s + 3):\n\t\tans = min(ans, f(x, a))\n\n\tprint(ans)\n\t\nmain()\n", "n=int(input())\na=list(map(int, input().split()))\n\nresult = 10**9\nfor num in range(-100,101):\n cost = 0\n for i in range(n):\n cost += (a[i] - num) ** 2\n result = min(result, cost)\nprint(result)", "\nN = int(input())\nlist = [int(a) for a in input().split()]\n\nA = sum(list)//N\nans = 0\n\nfor k in range(N):\n ans = ans + (list[k] - A) ** 2\n\nfor i in range(-100,100):\n sum_new = 0\n for j in range(N):\n sum_new = sum_new + (list[j] - i) ** 2\n if(ans > sum_new):\n ans = sum_new\n\nprint(ans)\n", "N=int(input())\na=sorted(list(map(int,input().split())))\n\nans=10**9\nfor i in range(a[0],a[-1]+1):\n s=0\n for j in range(N):\n x=(a[j]-i)**2\n s+=x\n ans=min(ans,s)\n\nprint(ans)\n", "n = int(input())\na = list(map(int,input().split()))\nb = 0\n\nfor i in range(n):\n b += a[i]\n\nc = int(b/n)\nd = c + 1\ne = 0\nf = 0\n\nfor i in range(n):\n e += (a[i]-c)**2\n f += (a[i]-d)**2\n\nprint((min(e,f)))\n\n", "N = int(input())\nint_list = [int(x) for x in input().split()]\n\n# int_list\u306e\u5404\u6574\u6570\u3092y\u306b\u66f8\u304d\u63db\u3048\u308b\u3068\u304d\u306e\u30b3\u30b9\u30c8\u306e\u7dcf\u548c\u3092\u8a08\u7b97\ndef calc_cost(int_list, y):\n cost = 0\n for x in int_list:\n cost += (x - y)**2\n return cost\n\ncost_list = [calc_cost(int_list, y) for y in range(min(int_list), max(int_list)+1)]\nprint(min(cost_list))", "N=int(input())\na=list(map(int,input().split()))\n\nA=sum(a)//N\nB=(sum(a)-1)//N+1\n\n\nprint((min(sum((x-A)*(x-A) for x in a),sum((x-B)*(x-B) for x in a))))\n", "input();a=list(map(int,input().split()));r=float('inf')\nfor i in range(min(a),max(a)+1):\n n=0\n for j in a:\n n+=(j-i)**2\n r=min(n,r)\nprint(r)", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, a: \"List[int]\"):\n ans = float(\"inf\")\n for m in range(-100, 101):\n ans = min(ans,\n sum((aa-m)**2 for aa in a))\n return ans\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n a = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"\n print((solve(N, a)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef __starting_point():\n #test()\n main()\n\n__starting_point()", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n n = ini()\n a = inl()\n s = sum(a)\n m1 = s // n\n m2 = (s + n - 1) // n\n\n s1 = sum((x - m1) ** 2 for x in a)\n s2 = sum((x - m2) ** 2 for x in a)\n return min(s1, s2)\n\n\nprint(solve())\n", "import sys\nimport math\n\nN = int(input())\n\na = list(map(int, input().split()))\n\na.sort()\nans = 10**9\nfor i in range(a[0], a[-1]+1):\n cost = 0\n for j in a:\n cost += (i-j)**2\n ans = min(cost, ans)\nprint(ans)", "inf = float('inf')\nn = int(input())\narr = list(map(int, input().split()))\n\nmin_cost = inf\nfor i in range(-100, 101):\n cost = 0\n for j in arr:\n cost += (j - i)**2\n min_cost = min(min_cost, cost)\nprint(min_cost)", "n=int(input())\na=list(map(int,input().split()))\n\ninf=float('inf')\n\nans=inf\n\nfor b in range(-100,101):\n ch=0\n for i in range(n):\n ch+=(b-a[i])**2\n \n ans=min(ans,ch)\n \nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\n# n=2\n# a=[4,8]\nminimum=10000000\nfor i in range(-100,101):\n cost=0\n for j in range(n):\n cost+=(i-(a[j]))**2\n if j==n-1:\n if cost<minimum:\n minimum=cost\n\nprint(minimum)\n\n\n", "from sys import stdin\ninput = stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\nif len(set(A)) != 1:\n cost = 2**20\n for i in range(-100, 101):\n tc = 0\n for a in A:\n tc += (a-i)**2\n if cost > tc:\n cost = tc\nelse:\n cost = 0\n\nprint(cost)", "N = int(input())\nl = list(map(int, input().split()))\ncal = []\nfor i in range(-100,101):\n a = 0\n for j in l:\n a += (i - j)**2\n cal.append(a)\n\nans = min(cal)\nprint(ans)", "n = int(input())\narr = list(map(int, input().split()))\n\nmini = min(arr)\nmaxi = max(arr)\ncost = 10000000000\n\nfor i in range(-100, 101+1):\n add = 0\n for j in range(n):\n add = add + (arr[j] - i)**2\n cost = min(cost, add)\nprint(cost)", "N,*a = open(0).read().split()\n\nN=int(N)\n\nlist1=list(map(int,a))\n\n#print(N)\n\n#print(list1)\n\na=[]\n\nfor i in range(-100,101):\n int1=0\n for n in range(N):\n x = (list1[n]-i)\n y = x**2\n int1+=y\n if n==N-1:\n a.append(int1)\n \n#print(a)\n\n#print(max(a))\n\nprint(min(a))", "def sam(lst):\n return lst[1:] == lst[:-1]\n\nn = int(input())\ns = [int(x) for x in input().split()]\nif(sam(s)):\n print(0)\nelse:\n x = round(sum(s)/n)\n n = 0\n for elem in s:\n n += (elem-x)**2\n print(n)", "N = int(input())\nnum_list = list(map(int, input().split()))\ncost_list = []\nmax_num = max(num_list)\nmin_num = min(num_list)\n\nfor i in range(min_num,max_num):\n cost = 0\n for j in num_list:\n cost += (i-j)**2\n cost_list.append(cost)\n\nif len(cost_list) == 0:\n cost_list.append(0)\n \nprint(min(cost_list))", "N = int(input())\nA = list(map(int, input().split()))\n\nmin_cost = 10 ** 9 + 7\nfor i in range(-100, 101):\n cost = 0\n for j in range(N):\n cost += (A[j] - i) ** 2\n min_cost = min(cost, min_cost)\n\nprint(min_cost)\n", "N = input()\nlist1 = list(map(int,input().split()))\nlist2 = []\nfor i in range(min(list1),max(list1)+1):\n a = 0\n for j in range(len(list1)):\n a += (list1[j] - i)**2\n list2.append(a)\nprint(min(list2))", "n=int(input())\na=list(map(int, input().split()))\na.sort()\nans=10**10\nfor x in range(a[0],a[-1]+1):\n tmp=0\n for i in range(n):\n tmp+=(a[i]-x)**2\n ans=min(ans,tmp)\nprint(ans)", "import math\nimport statistics\nN = int(input())\nA = [int(x) for x in input().split()]\navg = math.floor(statistics.mean(A))\na = 0\nb = 0\nfor i in range(len(A)):\n a += (A[i] - avg)**2\n b += (A[i] - avg - 1)**2\nprint(min(a,b))", "N=input()\n*A,=map(int,input().split())\n\na=float('inf')\nfor i in range(min(A),max(A)+1):a=min(a, sum([(k-i)**2 for k in A]))\nprint(a)", "n=int(input())\nl=list(map(int,input().split()))\nans=float('inf')\nfor v in range(min(l),max(l)+1):\n c=sum([(a-v)**2 for a in l])\n ans=min(ans,c)\nprint(ans)\n", "N = int(input())\nL = list(map(int, input().split()))[:N]\n\nstart = round(sum(L) / N)\nf = lambda x: (x - start)**2\n\nprint(sum(list(map(f, L))))", "N=int(input())\ns=list(map(int,input().split()))\ns_max=max(s)\ns_min=min(s)\nA=[]\nfor i in range(s_min,s_max+1):\n b=0\n for j in s:\n b+=(j-i)**2\n A.append(b)\nprint(min(A))", "N=int(input())\na=list(map(int,input().split()))\n\ndef calc_cost(x,avg):\n return (x-avg)**2\n\navg = sum(a)//N\n\ndelta = [-2,-1,0,1,2]\n\nans=10**20\nfor i in range(len(delta)):\n val = sum(map(lambda x:calc_cost(x,avg+delta[i]),a))\n ans = min(ans,val)\n \nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\nans = 10**10\nfor i in range(min(a), max(a)+1):\n cnt = 0\n for j in range(n):\n cnt += (a[j]-i) ** 2\n ans = min(ans, cnt)\nprint(ans)", "N=int(input())\nA=[int(x) for x in input().split()]\nmaxA=max(A)\nminA=min(A)\nans=10**9\nfor i in range(minA,maxA+1):\n kouho=0\n for j in range(N):\n kouho+=(i-A[j])**2\n ans=min(ans,kouho)\nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\nans=100000000\nfor i in range(-100,101):\n now=0\n for k in a:\n now+=(i-k)*(i-k)\n ans=min(ans,now)\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\n\nans = 10**9\nfor i in range(-100, 101):\n cost = 0\n for j in a:\n cost += (j-i)**2\n ans = min(ans, cost)\nprint(ans)", "N = int(input())\nA = [int(T) for T in input().split()]\nMin = 10**9\nfor TN in range(min(A),max(A)+1):\n Min = min(Min,sum((TN-TA)**2 for TA in A))\nprint(Min)", "ans=10**10\nn=int(input())\na=list(map(int,input().split()))\nfor i in range(-100,101):\n x=0\n for j in range(n):\n x+=(i-a[j])**2\n ans=min(x,ans)\nprint(ans)", "N=int(input())\n*A,=map(int,input().split())\n\nmx=max(A)\nmn=min(A)\n\nans=float('inf')\nfor i in range(mn,mx+1):\n ans=min(ans, sum([(k-i)**2 for k in A]))\nprint(ans)", "import sys\nimport math\n\ndef main():\n\n input()\n a = list(map(int, input().split()))\n\n y = round(sum(a)/len(a))\n\n ans = 0\n for i in a:\n ans += pow((i - y), 2)\n\n print(ans)\n\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nA = list(map(int, input().split()))\nans = 0\n\nif sum(A)%N == 0:\n x = sum(A)//N\n for i in range(N):\n ans += (x-A[i])**2\n print(ans)\nelse:\n x = sum(A)//N\n b = sum(A)//N+1\n if sum(A)/N - x > b - sum(A)/N:\n x = b\n for i in range(N):\n ans += (x-A[i])**2\n \n print(ans)\n\n", "def main():\n n = int(input())\n As = list(map(int, input().split()))\n ans = float(\"inf\")\n\n for i in range(-100, 101):\n ans_temp = 0\n for j in range(n):\n ans_temp += (As[j] + i)**2\n ans = min(ans, ans_temp)\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\n \nN = int(input())\nA = [int(a) for a in input().split(\" \")]\nave = sum(A) / N\ncan1 = math.floor(ave)\ncan2 = math.ceil(ave)\n \ncost1 = sum([(a - can1) ** 2 for a in A])\ncost2 = sum([(a - can2) ** 2 for a in A])\nprint(min([cost1, cost2]))", "N = int(input())\nlst = list(map(int, input().split()))\navg = round(sum(lst) / N)\n\nresult = 0\nfor i in lst:\n result += (i - avg)**2\n\nprint(result)\n", "N = int(input())\na = list(map(int,input().split()))\nb = 0\nfor i in range(N):\n b += a[i]\nr = round(b/N)\nans = 0\nfor i in range(N):\n ans += (a[i]-r)**2\nprint(ans)", "# C - \u3044\u3063\u3057\u3087\ndef main():\n import math\n _ = int(input())\n a = list(map(int, input().split()))\n t = float('inf')\n\n for i in range(min(a), max(a)+1):\n cnt = 0\n for j in a:\n cnt += (j-i)**2\n else:\n if cnt < t:\n t = cnt\n else:\n print(t)\n\n \nif __name__ == \"__main__\":\n main()", "def keisan(N,A):\n \n KAI = 0\n A.sort\n \n min = -100\n max = 101\n \n i = min\n \n while i <= max:\n kari = 0\n j = 0\n while j < N:\n kari += (A[j]-i)**2\n j += 1\n \n \n if kari <= KAI or i == min:\n KAI = kari\n i += 1\n \n \n return KAI\n \n \nN = int(input())\n \nA = input().split()\nint_list = list(map(int,A))\n \nprint(keisan(N,int_list))", "n = int(input())\na_list = [int(x) for x in input().split()]\n\na_sum = sum(a_list)\nf = a_sum // n\nc = (a_sum + n - 1) // n\nb = f if abs(a_sum - f * n) < abs(a_sum - c * n) else c\n\nans = 0\nfor a in a_list:\n ans += (a - b) ** 2\nprint(ans)", "n = int(input())\nl = list(input().split())\nsum = 0\nmin_sum = 10**10\nnum = 0\nfor i in range(-100,101):\n for j in range(len(l)):\n sum += (int(l[j]) - i)**2\n if min_sum > sum:\n min_sum = sum\n num = i\n sum = 0\n\nprint(min_sum)", "n = int(input())\na = list(map(int, input().split()))\nm1 = sum(a) // n\nm2 = (sum(a) + n - 1) // n\n\nres1 = 0\nres2 = 0\nfor i in range(n):\n res1 += (a[i] - m1) ** 2\n res2 += (a[i] - m2) ** 2\n\nprint((min(res1, res2)))\n", "\nclass Combination:\n def __init__(self, n, mod):\n self.n = n\n self.mod = mod\n self.fac = [1 for i in range(self.n + 1)]\n self.finv = [1 for i in range(self.n + 1)]\n for i in range(2, self.n+1):\n self.fac[i] = (self.fac[i - 1] * i) % self.mod\n self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod\n\n def comb(self, n, m):\n return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod\ndef iparse():\n return list(map(int, input().split()))\n\ndef __starting_point():\n n = int(input())\n a = iparse()\n ans = 10000000000\n for i in range(-100, 101):\n tmp = 0\n for e in a:\n tmp += (e - i)** 2\n ans = min(tmp, ans)\n print(ans)\n \n\n__starting_point()", "def main():\n n = int(input())\n a_lst = list(map(int, input().split()))\n minimum = min(a_lst)\n maximum = max(a_lst)\n\n cost = 10 ** 9\n for i in range(maximum - minimum + 1):\n tmp_cost = 0\n std = minimum + i\n for j in range(n):\n a = a_lst[j]\n tmp_cost += (a - std) ** 2\n cost = min(tmp_cost, cost)\n\n print(cost)\n\n\ndef __starting_point():\n main()\n__starting_point()", "def main():\n n = int(input())\n inlis = list(map(int, input().split()))\n\n ans = 10 ** 10\n\n for kouho1 in range(-100,101):\n tmp1 = 0\n for i in range(n):\n tmp1 += (inlis[i]- kouho1) ** 2\n if tmp1 < ans:\n ans = tmp1\n print(ans)\n\n\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nl = list(map(int,input().split()))\nl_ans = [[] for _ in range(201)]\n\nfor i in range(-100,101):\n sum = 0\n\n for j in range(N):\n sum = sum + (i-l[j])**2\n\n l_ans[i+100] = sum\n\nprint(min(l_ans))", "n = int(input())\nA = list(map(int,input().split()))\nans = 10**9\nfor i in range(-100,101):\n tmp = 0\n for a in A:\n tmp += (a-i)**2\n ans = min(ans, tmp)\nprint(ans)", "N = int(input())\na = list(map(int,input().split()))\n\navg = round((sum(a) / N))\nans = 0\nfor i in a:\n ans = ans + (i-avg) * (i-avg)\n\nprint(ans)", "n = int(input())\nnums = list(map(int, input().split()))\n\ndef cost(x,y):\n return (x-y)**2\n\navg = round(sum(nums)/len(nums))\n\nres = 0\nfor n in nums:\n res += cost(n, avg)\nprint(res)\n", "import numpy as np\n\ninput()\na = np.array(sorted(map(int, input().split())))\nprint(min(sum((a - i) ** 2) for i in range(min(a), max(a) + 1)))", "n=int(input())\na = list(map(int,input().split()))\n_sum =sum(a) / n\ns = round(_sum)\nans = 0\n#print(s)\nfor i in range(n):\n v =(a[i]-s)**2\n ans += v\nprint(ans)", "N = int(input())\nA = [int(x) for x in input().split()]\nfrom statistics import mean\nfrom math import floor, ceil\nmeanA = mean(A)\nif meanA < floor(meanA) + 0.5:\n meanA = floor(meanA)\nelse:\n meanA = ceil(meanA)\nans = 0\nfor a in A:\n ans += (a-meanA)**2\nprint(ans)", "n = input()\na = list(map(int, input().split()))\nans = list()\nfor i in range(min(a), max(a)+1):\n cost = 0\n for num in a:\n cost += (num - i)**2\n ans.append(cost)\nprint(min(ans))", "N=int(input())\na=list(map(int,input().split()))\nave=sum(a)/N\nif ave>=0 and ave%1>=0.5:\n ave=int(ave)+1\nelif ave<0 and -ave%1>=0.5:\n ave=int(ave)-1\nelse:\n ave=int(ave)\nans=0\nfor i in a:\n ans+=(i-ave)**2\nprint(ans)\n", "# N\u306e\u5165\u529b\u53d7\u4ed8\nN = int(input())\n# a\u306e\u5165\u529b\u53d7\u4ed8\naN = list(map(int, input().split()))\n# \u5e73\u5747\u306e\u5024\u3092\u8a08\u7b97\nS = 0\nA = 0\nfor i in aN:\n S += i\nA = S / N\nif A - int(A) < 0.5:\n A = int(A)\nelse:\n A = int(A) + 1\n# A\u306b\u3059\u3079\u3066\u66f8\u304d\u63db\u3048\u308b\u3068\u304d\u306e\u30b3\u30b9\u30c8\u3092\u8a08\u7b97\nR = 0\nfor i in aN:\n R += (i - A)**2\nprint(R)\n", "#!/usr/bin/env python\n\nn = int(input())\na = list(map(int, input().split()))\n\nans = 1000100\nch = 0 \nfor ch in range(min(a), max(a)+1):\n tmp = 0 \n for i in range(n):\n tmp += (a[i]-ch)**2\n if tmp <= ans:\n ans = tmp \nprint(ans)\n"] | {"inputs": ["2\n4 8\n", "3\n1 1 3\n", "3\n4 2 5\n", "4\n-100 -100 -100 -100\n"], "outputs": ["8\n", "3\n", "5\n", "0\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 25,001 | |
06075b50a085bd19e7f9acb2bb727661 | UNKNOWN | You went shopping to buy cakes and donuts with X yen (the currency of Japan).
First, you bought one cake for A yen at a cake shop.
Then, you bought as many donuts as possible for B yen each, at a donut shop.
How much do you have left after shopping?
-----Constraints-----
- 1 \leq A, B \leq 1 000
- A + B \leq X \leq 10 000
- X, A and B are integers.
-----Input-----
Input is given from Standard Input in the following format:
X
A
B
-----Output-----
Print the amount you have left after shopping.
-----Sample Input-----
1234
150
100
-----Sample Output-----
84
You have 1234 - 150 = 1084 yen left after buying a cake.
With this amount, you can buy 10 donuts, after which you have 84 yen left. | ["print((int(input()) - int(input())) % int(input()))", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint(X - A - B * ((X - A) // B))", "x=int(input())\na=int(input())\nb=int(input())\n\nprint((x-a)%b)", "x=int(input())\na=int(input())\nb=int(input())\nprint((x-a)%b)", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x-a)%b)", "# A - Buying Sweets\n\n# X\u5186\u3067\u3001A\u5186\u306e\u30b1\u30fc\u30ad1\u500b\u3068\u3001B\u5186\u306e\u30c9\u30fc\u30ca\u30c4\u3092\u8cb7\u3048\u308b\u3060\u3051\u8cb7\u3063\u305f\u5834\u5408\u3001\u6b8b\u308a\u306f\u4f55\u5186\u304b\n\n\nX = int(input())\nA = int(input())\nB = int(input())\n\nprint(((X - A) % B))\n", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "X=int(input())\nA=int(input())\nB=int(input())\nkeki=X-A\ndonatu=keki%B\nprint(donatu)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x - a) % b)", "X = int(input())\nA = int(input())\nB = int(input())\nprint((X-A)%B)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint((X - A) % B)", "X = int(input())\nA = int(input())\nB = int(input())\nprint((X-A)%B)", "X = int(input())\nA = int(input())\nB = int(input())\nprint((X-A)%B)", "# \u3042\u306a\u305f\u306f\u3001X \u5186\u3092\u6301\u3063\u3066\u30b1\u30fc\u30ad\u3068\u30c9\u30fc\u30ca\u30c4\u3092\u8cb7\u3044\u306b\u51fa\u304b\u3051\u307e\u3057\u305f\u3002\n# \u3042\u306a\u305f\u306f\u307e\u305a\u30b1\u30fc\u30ad\u5c4b\u3067 1\u500b A\u5186\u306e\u30b1\u30fc\u30ad\u3092 1\u500b\u8cb7\u3044\u307e\u3057\u305f\u3002\n# \u6b21\u306b\u3001\u30c9\u30fc\u30ca\u30c4\u5c4b\u3067 1\u500b B \u5186\u306e\u30c9\u30fc\u30ca\u30c4\u3092\u3067\u304d\u308b\u3060\u3051\u305f\u304f\u3055\u3093\u8cb7\u3044\u307e\u3057\u305f\u3002\n#\n# \u3053\u308c\u3089\u306e\u8cb7\u3044\u7269\u306e\u3042\u3068\u624b\u5143\u306b\u6b8b\u3063\u3066\u3044\u308b\u91d1\u984d\u306f\u4f55\u5186\u3067\u3059\u304b\u3002\n\n# \u5236\u7d04\n# 1 \u2266 A, B \u2266 1,000\n# A + B \u2266 X \u2266 10,000\n# X, A, B \u306f\u6574\u6570\u3067\u3042\u308b\n\n# \u6a19\u6e96\u5165\u529b\u304b\u3089\u3001X, A, B \u306e\u5024\u3092\u53d6\u5f97\u3059\u308b\nx = int(input())\na = int(input())\nb = int(input())\n\n# \u6b8b\u91d1\u3092\u8a08\u7b97\u3057\u3066\u51fa\u529b\u3059\u308b\nresult = 0\n\nresult = (x - a) % b\nprint(result)\n", "x = int(input())\na = int(input())\nb = int(input())\nx -= a\n\nwhile(1):\n x -= b\n if x - b < 0:\n print(x)\n break\n\n", "x = int(input())\na = int(input())\nb = int(input())\n\nx -= a\n\nwhile x >= b:\n x -= b\n\nprint(x)\n", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x - a) % b)", "x=int(input())\na=int(input())\nb=int(input())\nprint(((x-a)%b))\n", "x = int(input())\na = int(input())\nb = int(input())\n\nn = x - a\n\nprint(n % ((n // b) * b))", "x = int(input())\na = int(input())\nb = int(input())\n\nans = x-a - (x-a)//b*b\n\nprint(ans)", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x-a-((x-a)//b)*b))\n", "X, A, B = [int(input()) for _ in range(3)]\n \nprint((X-A) % B)", "x=int(input())\nprint((x-int(input()))%int(input()))", "with open(0) as f:\n x, a, b = map(int, f.read().split())\nprint(x - a - (x-a)//b*b)", "a=[]\nfor i in range(3):\n a.append(int(input()))\n \nprint((a[0]-a[1])%a[2])", "X = int(input())\nA = int(input())\nB = int(input())\nprint((X-A)%B)", "# 087_a\nX=int(input())\nA=int(input())\nB=int(input())\n\nif (1<= (A+B) and X<= 10000) and (1<=A and A<= 1000) and (1<=B and B<= 1000):\n a=X-A\n b=int(a/B)\n print((a-(b*B)))\n", "X=int(input())\nA=int(input())\nB=int(input())\nprint(((X-A)%B))\n", "a = int(input())\nb = int(input())\nc = int(input())\nprint(((a - b) % c))\n", "x, a, b = map(int, open(0).read().split())\nprint((x - a) % b)", "x,a,b = [int(input()) for i in range(3)]\nx -= a\nprint(x-b*(x // b))", "X = int(input())\nA = int(input())\nB = int(input())\n\nX = X - A\nprint(X - (X // B)*B)", "a = [int(input()) for i in range(3)]\nb = a[0]-a[1]\nsub = b % a[2]\n\nprint(sub)", "x = int(input())\na = int(input())\nb = int(input())\nx -= a\nprint(x%b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint((X - A) % B)", "import sys\n\ninput = sys.stdin.readline\nX = int(input())\nA = int(input())\nB = int(input())\n\nX -= A\nprint(X - X // B * B)", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x-a) % b)", "# A - Buying Sweets\n# https://atcoder.jp/contests/abc087/tasks/abc087_a\n\nX = int(input())\nA = int(input())\nB = int(input())\n\nprint(((X - A) % B))\n", "x = int(input())\na = int(input())\nb = int(input())\nx -= a\nx %= b\nprint(x)", "x,a,b = [int(input()) for i in range(3)]\nprint((x-a)%b)", "X = int(input())\nA = int(input())\nB = int(input())\nprint((X -A) % B)", "X = int(input())\nA = int(input())\nB = int(input())\n\na = (X-A)%B\n\nprint(a)", "#!/usr/bin/env python3\n\nx = int(input())\na = int(input())\nb = int(input())\n\n\nprint(((x-a) % b))\n", "x = int(input())\na = int(input())\nb = int(input())\n\nanswer = (x - a) % b\nprint(answer)", "x,a,b = [int(input()) for i in range(3)]\nprint(x-a-(x-a)//b*b)", "i = lambda: int(input())\nprint(((i() - i()) % i()))\n", "X = int(input())\nA = int(input())\nB = int(input())\nprint(((X - A) % B))\n", "#\n# abc087 a\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"1234\n150\n100\"\"\"\n output = \"\"\"84\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"1000\n108\n108\"\"\"\n output = \"\"\"28\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"579\n123\n456\"\"\"\n output = \"\"\"0\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"7477\n549\n593\"\"\"\n output = \"\"\"405\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n X = int(input())\n A = int(input())\n B = int(input())\n\n print(((X-A) % B))\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "x = int(input())\nA = int(input())\nB = int(input())\n\nans = (x - A) % B\nprint(ans)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint(X - A - B * ((X - A) // B))", "x=int(input())\na=int(input())\nb=int(input())\n\nx-=a\nnum=x//b\nx-=num*b\nprint(x)", "a=int(input())\nb=int(input())\nc=int(input())\nprint((a-b)%c)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "X = int(input())\nA = int(input())\nB = int(input())\n\n# \u3067\u304d\u308b\u3060\u3051\u8cb7\u3048\u308b\u500b\u6570\nn = (X - A) // B\n\nprint((X - A - B * n))\n", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "x=int(input())\na=int(input())\nb=int(input())\nx-=a\nprint(x%b)", "x = int(input())\na = int(input())\nb = int(input())\n\nx -= a\nwhile x >= b:\n x -= b\n \nprint(x)", "x=int(input())\na=int(input())\nb=int(input())\nprint(x-a-((x-a)//b)*b)", "\nX=int(input())\nA=int(input())\nB=int(input())\nX -= A\nY = X % B\nprint(Y)", "X = int(input())\nA = int(input())\nB = int(input())\nans = X - A\nans %= B\nprint(ans)", "x,a,b=[int(input()) for i in range(3)]\nprint(((x-a)%b))\n\n", "x=int(input())\na=int(input())\nb=int(input())\nprint((x-a)%b)", "X=int(input())\nA=int(input())\nB=int(input())\nkeiki=X-A\ndonatu=keiki%B\nprint(donatu)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "x=int(input())\na=int(input())\nb=int(input())\nx-=a\nwhile x>=0:\n x-=b\nprint(x+b)", "x = int(input())\na = int(input())\nb = int(input())\n\nans = (x - a) % b\n\nprint(ans)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "x = int(input())\na = int(input())\nb = int(input())\nprint((x - a) % b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint((X - A) % B)", "X = int(input())\nA = int(input())\nB = int(input())\n\n# \u7b54\u3048\u306f(X-A)\u3092B\u3067\u5272\u3063\u305f\u4f59\u308a\nX = X - A\nprint(X % B)", "def main():\n x, a, b = (int(input()) for _ in range(3))\n t = x - a\n print(t - b * (t // b))\n\n\nmain()", "x,a,b=int(input()),int(input()),int(input())\nprint(x-a-(x-a)//b*b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint((X - A) % B)", "# \u5165\u529b\nX = int(input())\nA = int(input())\nB = int(input())\n\n# A\u5186\u306e\u30b1\u30fc\u30ad\u30921\u500b\u8cb7\u3046\nbalance = X - A\n\n# \u6b8b\u91d1\u3067\u8cb7\u3048\u308b\u30b1\u30fc\u30adB\u306e\u6570\u3092\u6c42\u3081\u308b\nquantity = balance // B\n\n# B\u306e\u30b1\u30fc\u30ad\u3092\u5909\u3048\u308b\u3060\u3051\u8cb7\u3046\nbalance -= B * quantity\n\n# \u6b8b\u91d1\u3092\u51fa\u529b\u3059\u308b\nprint(balance)", "X = int(input())\nA = int(input())\nB = int(input())\nX -= A\nn = int(X / B)\nprint(X - B * n)", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x - a) % b)", "import sys\n\nsys.setrecursionlimit(10 ** 7)\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef resolve():\n x = int(input())\n a = int(input())\n b = int(input())\n\n x -= a\n res = x % b\n print(res)\n\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "x = int(input())\na = int(input())\nb = int(input())\nprint((x - a) % b)", "possesion=int(input())\ncake=int(input())\ndonut=int(input())\n\nremain_1=possesion-cake\nremain_2=remain_1-(remain_1//donut)*donut\n\nprint(remain_2)", "x=int(input())\na=int(input())\nb=int(input())\nx-=a\nx%=b\nprint(x)", "x = int(input())\na = int(input())\nb = int(input())\nprint(((x - a) % b))\n", "x,a,b = [int(input()) for i in range(3)]\nprint(((x - a) % b))\n\n\n", "x=int(input())\nx-=int(input())\nprint(x%int(input()))", "x=int(input())\na=int(input())\nb=int(input())\nprint((x-a)%b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nanswer = ( X - A ) % B\nprint(answer)\n", "x = int(input())\na = int(input())\nb = int(input())\nprint((x-a)%b)", "x=int(input())\na=int(input())\nb=int(input())\nprint((x-a)%b)", "#!/usr/bin/env python3\n\ndef main():\n x = int(input())\n a, b = (int(input()) for i in range(2))\n print(((x - a) % b))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a = int(input())\nb = int(input())\nc = int(input())\n\nprint((a - b) % c)", "x = int(input())\na = int(input())\nb = int(input())\nb = (x - a) // b * b\nprint(x - (a + b))", "\n# \u3042\u306a\u305f\u306f\u3001X\u5186\u3092\u6301\u3063\u3066\u30b1\u30fc\u30ad\u3068\u30c9\u30fc\u30ca\u30c4\u3092\u8cb7\u3044\u306b\u51fa\u304b\u3051\u307e\u3057\u305f\u3002\n# \u3042\u306a\u305f\u306f\u307e\u305a\u30b1\u30fc\u30ad\u5c4b\u30671\u500bA\u5186\u306e\u30b1\u30fc\u30ad\u30921\u500b\u8cb7\u3044\u307e\u3057\u305f\u3002 \u6b21\u306b\u3001\u30c9\u30fc\u30ca\u30c4\u5c4b\u30671\u500bB\u5186\u306e\u30c9\u30fc\u30ca\u30c4\u3092\u3067\u304d\u308b\u3060\u3051\u305f\u304f\u3055\u3093\u8cb7\u3044\u307e\u3057\u305f\u3002\n# \u3053\u308c\u3089\u306e\u8cb7\u3044\u7269\u306e\u3042\u3068\u624b\u5143\u306b\u6b8b\u3063\u3066\u3044\u308b\u91d1\u984d\u306f\u4f55\u5186\u3067\u3059\u304b\u3002\n\n\nX = int(input()) \nA = int(input())\nB = int(input())\n\nY = X - A # A\u30921\u500b\u8cb7\u3063\u3066\u3001\u6b8b\u3063\u305f\u304a\u91d1\u3092Y\u5186\u3068\u3059\u308b\u3002\n\nprint(Y % B) ", "X,A,B=[int(input()) for i in range(3)]\nprint((X-A)%B)", "X, A, B = int(input()), int(input()), int(input())\nans = (X-A)%B\nprint(ans)", "x = int(input())\na = int(input())\nb = int(input())\nprint(x - a - ((x-a)//b)*b)", "x = int(input())\na = int(input())\nb = int(input())\n\nprint((x-a)%b)", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint((X-A)%B)", "X = int(input())\nA = int(input())\nB = int(input())\nprint(((X-A) % B))\n"] | {"inputs": ["1234\n150\n100\n", "1000\n108\n108\n", "579\n123\n456\n", "7477\n549\n593\n"], "outputs": ["84\n", "28\n", "0\n", "405\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 12,309 | |
ac48d34557281b86a7f50e0ace78c22b | UNKNOWN | Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
-----Constraints-----
- 1 β€ N,M β€ 10^5
-----Input-----
Input is given from Standard Input in the following format:
N M
-----Output-----
Print the number of possible arrangements, modulo 10^9+7.
-----Sample Input-----
2 2
-----Sample Output-----
8
We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA. | ["import math\nn, m = map(int, input().split())\nmod = 10**9+7\nif abs(n-m) > 1:\n print(0)\n return\n\ndog = math.factorial(n)\nmonkey = math.factorial(m)\nif abs(n-m) == 1:\n ans = dog*monkey % mod\nelif n == m:\n ans = dog*monkey*2 % mod\nprint(ans%mod)", "N,M = map(int,input().split())\na = [0]*(max(N,M)+1)\na[0] = 1\na[1] = 1\nfor i in range(2,len(a)):\n a[i] = i * a[i-1] % 1000000007\n \nif N==M:\n print(a[N]*a[M]*2 % 1000000007)\nelif abs(N-M)==1:\n print(a[N]*a[M] % 1000000007)\nelse:\n print(0)", "N, M = map(int, input().split())\n\nx = abs(N-M)\nif x >= 2:\n print(0)\nelse:\n mod = 10**9+7\n a = 1\n for i in range(2, N+1):\n a *= i\n a %= mod\n b = 1\n for i in range(2, M+1):\n b *= i\n b %= mod\n \n if x == 0:\n print(a*b*2%mod)\n else:\n print(a*b%mod)", "N, M = list(map(int, input().split()))\nmod = 1000000007\n\nif abs(N - M) > 1:\n print((0))\nelif (N + M) % 2 == 1:\n x = max(N, M)\n y = min(N, M)\n Sum = 1\n for i in range(N + M):\n if i % 2 == 0:\n Sum *= x - (i // 2)\n Sum %= mod\n else:\n Sum *= y - (i // 2)\n Sum %= mod\n print(Sum)\nelse:\n Sum = 1\n for i in range(2 * N):\n Sum *= N - (i // 2)\n Sum %= mod\n Sum *= 2\n Sum %= mod\n print(Sum)\n", "import math\nn,m=map(int,input().split());r=10**9+7\nif n==m: print(2*math.factorial(n)*math.factorial(m)%r)\nelif abs(n-m)==1: print(math.factorial(n)*math.factorial(m)%r)\nelse: print(0)", "n, m = list(map(int, input().split()))\n\nmod = 10**9 + 7\nl = n+m\nans = 1\nb = max(n, m)\ns = min(n, m)\nfor i in range(l):\n if i % 2 == 0:\n tmp = b-i//2\n if tmp > 0:\n ans = (ans % mod) * (tmp % mod)\n else:\n print((0))\n return\n else:\n tmp = s-i//2\n if tmp > 0:\n ans = (ans % mod) * (tmp % mod)\n else:\n print((0))\n return\nif l%2 == 0: \n ans = (ans % mod) * (2 % mod)\nprint((ans%mod))\n", "n, m = list(map(int, input().split()))\n\ndef f(n):\n ans = n\n for i in range(1, n):\n ans *= i\n ans %= 1000000007\n return ans\n\nif n == m:\n print(((f(n))**2 *2)%1000000007)\nelif n == m+1 or m == n+1:\n print((f(n)*f(m))%1000000007)\nelse:\n print(0)", "from math import factorial\n\nn, m = map(int, input().split())\nif n == m:\n print((factorial(n) ** 2 * 2) % (10 ** 9 + 7))\nelif abs(n - m) == 1:\n print((factorial(n) * factorial(m)) % (10 ** 9 + 7))\nelse:\n print(0)", "n,m = map(int, input().split(\" \"))\nif abs(n-m) >= 2:\n print(0)\nelse:\n temp = 1\n mod = 10 ** 9 + 7\n for i in range(1, min(n,m)+1):\n temp *= i\n temp %= mod\n #print(temp)\n if n != m:\n print((temp**2*(max(n,m)) % mod))\n else:\n print((temp**2*2 % mod))", "import math\nn, m = map(int, input().split())\nmod = 10 ** 9 + 7\n\nif n == m:\n res = 2 * math.factorial(n) * math.factorial(m)\n print(res % mod)\nelif abs(n - m) == 1:\n res = math.factorial(n) * math.factorial(m)\n print(res % mod) \nelse:\n print(0)", "n,m = list(map(int,input().split()))\n\np = 10**9+7\ndef ka(t):\n an = 1\n for i in range(2,t+1):\n an = (an*i)%p\n return an\n\nif n==m+1 or n==m-1:\n print(((ka(n)*ka(m))%p))\nelif n==m:\n print(((ka(n)*ka(m)*2)%p))\nelse:\n print((0))\n", "n, m = [int(x) for x in input().split()]\nmod = 10 ** 9 + 7\n\ndef kaizyou(p):\n ans = 1\n for i in range(1,p+1):\n ans *= i\n if ans >= mod:\n ans %= mod\n return ans\n \nres = 0\nif abs(m - n) <= 1:\n res += kaizyou(m)\n res %= mod\n res *= kaizyou(n)\n res %= mod\n if n == m:\n res *= 2\n res %= mod\n\nprint(res)", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 02:58:21 2020\n\n@author: liang\n\"\"\"\n\nN, M = list(map(int,input().split()))\nMOD = 10**9 + 7\n\nif abs(N-M) >= 2:\n ans = 0\nelse:\n ans = 1\n for i in range(1,N+1):\n ans *= i\n ans %= MOD\n\n for i in range(1,M+1):\n ans *= i\n ans %= MOD\n \n if N == M:\n ans *= 2\n ans %= MOD\nprint(ans)\n", "#/usr/bin/env python\n\nn, m = list(map(int, input().split()))\nMOD = int(1e9)+7\nfac = [-1 for _ in range(100001)]\nfac[1] = 1 \n\nfor i in range(1, 100000):\n fac[i+1] = ((i+1)*fac[i])%MOD\n\nif abs(n-m) > 1:\n print((0))\n return\n\nans = 0 \nif n == m:\n ans = (fac[n]*fac[m]*2)%MOD\nelse:\n ans = (fac[n]*fac[m])%MOD\n\nprint(ans)\n", "import sys\ninput = sys.stdin.readline\n\n#l = list(map(int, input().split()))\n#import numpy as np\n#arr = np.array([int(i) for i in input().split()])\n'''\na,b=[],[]\nfor i in range():\n A, B = map(int, input().split())\n a.append(A) \n b.append(B)'''\n\nn,m=map(int,input().split())\nif abs(n-m)>1:\n print(0)\n return\n\nf=[1]\nfor i in range(1,max(n,m)+1):\n x=f[i-1]*i\n if x>10**9+7:\n x%=10**9+7\n f.append(x)\nif n!=m:\n print(f[n]*f[m]%(10**9+7))\nelse:\n print(f[n]*f[m]*2%(10**9+7))", "N, M = [int(x) for x in input().split()]\nMOD = 10**9+7\n\nif max(N, M) - min(N, M) > 1:\n print((0))\n return\n\n\ndef floor(n):\n result = n\n for i in range(n-1, 0, -1):\n result *= i\n result %= MOD\n\n return result\n\n\nr = floor(max(N, M))\nt = floor(min(N, M))\n\nif r == t:\n result = (r * t * 2) % MOD\nelse:\n result = (r * t) % MOD\n\nprint(result)\n", "import math\nn,m = map(int,input().split())\nmod = 10**9+7\nfact_n = math.factorial(n) % mod\nfact_m = math.factorial(m) % mod\n\nif abs(n-m) >= 2:\n print(0)\nelif n == m:\n print((fact_n * fact_m * 2) % mod)\nelse:\n print((fact_n * fact_m) % mod)", "import math\ndef ModFact(N,Mod):\n Num = 1\n for T in range(2,N+1):\n Num = (Num*T)%Mod\n return Num\n \nN,M = (int(T) for T in input().split())\nMod = 10**9+7\nif N==M:\n print((2*ModFact(N,Mod)*ModFact(M,Mod))%Mod)\nelif N==M+1 or M==N+1:\n print((ModFact(N,Mod)*ModFact(M,Mod))%Mod)\nelse:\n print(0)", "from math import factorial as fac\n\nN,M = map(int,input().split())\n\nif abs(N-M) > 1:\n print(0)\nelif abs(N-M) == 1:\n print((fac(N)*fac(M))%1000000007)\nelse:\n print((2*fac(N)*fac(M))%1000000007)", "n, m =list(map(int, input().split()))\n\nmod = 10**9+7\nans = 1\n\n\nif abs(n-m) >= 2:\n ans = 0\nelif abs(n-m) == 1:\n for i in range(1, max(n, m)+1):\n ans *= i\n ans %= mod\n for j in range(1, min(n, m)+1):\n ans *= j\n ans %= mod\nelif abs(n-m) == 0:\n for i in range(1, n+1):\n ans *= i\n ans %= mod\n ans **= 2\n ans*= 2\n ans %= mod\n\n\nprint(ans)\n", "n,m=list(map(int,input().split()))\nif abs(n-m)>1:\n print((0))\n return\n\nsm=1 if n!=m else 2\nwhile n>0:\n sm=(sm*n)%(10**9+7)\n n-=1\nwhile m>0:\n sm=(sm*m)%(10**9+7)\n m-=1\nprint(sm)\n", "from math import factorial\nN,M=map(int,input().split())\nans=0\nif abs(N-M)>1:\n ans=0\nelse:\n if N==M:\n a=N\n b=M\n ans=factorial(a)*factorial(b)*2\n else:\n a=max(N,M)\n b=min(N,M)\n ans=factorial(a)*factorial(b)\nprint(ans%(10**9+7))", "def prepare(n, MOD):\n \n # 1! - n! \u306e\u8a08\u7b97\n f = 1\n factorials = [1] # 0!\u306e\u5206\n for m in range(1, n + 1):\n f *= m\n f %= MOD\n factorials.append(f)\n # n!^-1 \u306e\u8a08\u7b97\n inv = pow(f, MOD - 2, MOD)\n # n!^-1 - 1!^-1 \u306e\u8a08\u7b97\n invs = [1] * (n + 1)\n invs[n] = inv\n for m in range(n, 1, -1):\n inv *= m\n inv %= MOD\n invs[m - 1] = inv\n \n return factorials, invs\n\nMOD = 10**9+7\nfact, fact_inv = prepare(2*10**5, MOD)\n\nn, m = map(int,input().split())\nif abs(n-m) > 1:\n print(0)\nelif abs(n-m) == 1:\n print(fact[n] * fact[m] % MOD)\nelse:\n print(2 * fact[n] % MOD * fact[m] % MOD)", "import math\n\nn, m = map(int, input().split())\n\nif abs(n - m) >= 2:\n print(0)\n\nelif abs(n - m) == 1:\n ans = math.factorial(n) * math.factorial(m)\n ans %= 10 ** 9 + 7\n print(ans)\n\nelse:\n ans = 2*math.factorial(n) * math.factorial(m)\n ans %= 10 ** 9 + 7\n print(ans)", "import math\nn,m = map(int,input().split())\nmod = 10**9+7\nfact_n = math.factorial(n) % mod\nfact_m = math.factorial(m) % mod\n\nif abs(n-m) >= 2:\n print(0)\n return\nelif n == m:\n print((fact_n * fact_m * 2) % mod)\nelse:\n print((fact_n * fact_m) % mod)", "with open(0) as f:\n N, M = map(int, f.read().split())\nmod = 1000000007\n\ndef factorial(n):\n res = 1\n for i in range(1,n+1):\n res = res * i %mod\n return res\n\nif abs(N-M) > 1:\n ans = 0\nelif N == M:\n ans = 2*factorial(M)**2 %mod \nelse:\n N, M = max(N, M), min(N, M)\n ans = N * factorial(M)**2 %mod\nprint(ans)", "MOD = 1_000_000_007\nn, m = map(int,input().split())\nif abs(n-m)>1:\n print(0)\nelse:\n if abs(n-m)==1:\n ans = 1\n else:\n ans = 2\n for i in range(n):\n ans = (ans*(i+1))%MOD\n for i in range(m):\n ans = (ans*(i+1))%MOD\n print(ans)", "import sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\nMOD = 10 ** 9 + 7\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef fact_mod(n, MOD):\n ret = 1\n for i in range(1, n + 1):\n ret *= i\n ret %= MOD\n return ret\n\ndef resolve():\n N, M = LI()\n\n if N == M:\n ans = 2 * pow(fact_mod(N, MOD), 2, MOD)\n ans %= MOD\n print(ans)\n elif abs(N - M) <= 1:\n ans = fact_mod(N, MOD) * fact_mod(M, MOD)\n ans %= MOD\n print(ans)\n else:\n print((0))\n\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "import math\nn,m=map(int,input().split())\nN=math.factorial(n)\nif abs(n-m)>1:\n print(0)\nelif abs(n-m)==0:\n print(2*N*N%(10**9+7))\nelif n>m:\n print((N*N//n)%(10**9+7))\nelse:\n print(N*N*m%(10**9+7))", "n, m = map(int, input().split())\n\nif abs(n-m) >= 2:\n print(0)\n return\n\nans = 1\ndiv = 10**9+7\n\nfor i in range(1, n+1):\n ans = (ans * i) % div\nfor i in range(1, m+1):\n ans = (ans * i) % div\n\nif n != m:\n print(ans)\nelse:\n print((ans*2)%div)", "N,M=map(int,input().split())\nmod = 10**9+7\n\nfactorial=[1 for i in range(10**5+5)]\nfor i in range(1,10**5+5):\n if i==1:factorial[i]=1\n else:factorial[i] = factorial[i-1]*i % mod\n \nif abs(N-M)>1:\n print(0)\n return\n\nif N==M:\n print(factorial[M]**2*2%mod)\nelse:\n print(factorial[M]*factorial[N]%mod)", "mod = 10**9+7\nn, m = map(int, input().split())\nif abs(n-m) >= 2:\n print(0)\n return\nx, y = 1, 1\nfor i in range(1, n+1):\n x *= i\n x %= mod\nfor i in range(1, m+1):\n y *= i\n y %= mod\nif n == m:\n print((2*x*y)%mod)\nelse:\n print((x*y)%mod)", "import math\nn, m = map(int, input().split())\nans = 0\nif n == m:\n ans = (math.factorial(n) * math.factorial(m)) * 2\nelif n + 1 == m or n == m + 1:\n ans = (math.factorial(n) * math.factorial(m))\nelse:\n ans = 0\nans = ans % (10 ** 9 + 7)\nprint(ans)", "import sys\nimport math\n\nmod = 10**9 + 7\nN, M = map(int, sys.stdin.readline().split())\ndiff = abs(N - M)\nif diff > 1:\n print(0)\n return\n\nn_p = 1\nfor i in range(1, N+1):\n n_p *= i\n n_p %= mod\nm_p = 1\nfor i in range(1, M+1):\n m_p *= i\n m_p %= mod\n\nif diff == 0:\n print(2 * n_p * m_p % mod)\nelse:\n print(n_p * m_p % mod)", "def main():\n N,M = list(map(int,input().split()))\n if abs(N-M) > 1:\n return 0\n N_mlt = 1\n M_mlt = 1\n for i in range(1,N+1,1):\n N_mlt *= i\n N_mlt = N_mlt%1000000007\n #print(i,N_mlt)\n for i in range(1,M+1,1):\n M_mlt *= i\n M_mlt = M_mlt%1000000007\n #print(i,M_mlt)\n #print(N_mlt,M_mlt)\n ans = (N_mlt*M_mlt)%1000000007\n if abs(N-M)==0:\n ans = (ans*2)%1000000007\n return ans\n else:\n return ans\n\nprint((main()))\n", "import math\na,b=map(int, input().split())\n\nif abs(a-b) == 1:\n c = math.factorial(a)%(10**9+7)\n d = math.factorial(b)%(10**9+7)\n print(c*d%(10**9+7))\nif abs(a-b) == 0:\n c = math.factorial(a)%(10**9+7)\n d = math.factorial(b)%(10**9+7)\n print(c*d*2%(10**9+7))\nif abs(a-b) >= 2:\n print(0)", "import math\nN,M = map(int,input().split())\nif abs(N-M) > 1:\n print(0)\n return\n\nfac = 1\nnum = 10**9 + 7\nfor i in range(1,N+1):\n fac *= i\n if fac > num:\n fac %= num\n\nfac2 = 1\nfor i in range(1,M+1):\n fac2 *= i\n if fac2 > num:\n fac2 %= num\n\nif N == M:\n print(fac**2*2%num)\nelse:\n print(fac*fac2%num)", "import math\nmod = 10**9+7\nans = 1\nn, m = map(int, input().split())\nif abs(n - m) > 1:\n print(0)\n return\nelif n == m:\n ans = 2\nans = ans * math.factorial(n) % mod\nans = ans * math.factorial(m) % mod\nprint(ans)", "import math\nn,m = map(int,input().split())\n\nx = 10**9+7\n\nans = 0\nif n == m:\n ans += math.factorial(n) * math.factorial(m) * 2\n print(ans % x)\n return\nelif n >= m and n -m == 1:\n ans += math.factorial(n) * math.factorial(m)\n print(ans % x)\n return\nelif m >= n and m -n== 1:\n ans += math.factorial(n) * math.factorial(m)\n print(ans % x)\n return\nelse:\n print(ans % x)", "import math as m\nN,M=map(int,input().split())\nw=1000000007\nif abs(N-M)<2:\n if N==M:\n print((m.factorial(N)**2*2)%w)\n else:\n print((m.factorial(N)*m.factorial(M))%w)\nelse:\n print(0)", "N, M = list(map(int, input().split()))\nmod = 10**9 + 7\n\ndef factorial(n):\n ans = 1\n i = 0\n while i < n:\n ans *= (n-i)\n ans %= mod\n i += 1\n return ans\n\nif abs(N-M) >= 2:\n print((0))\nelif N == M:\n ans = (factorial(N) * factorial(M) * 2) % mod\n print(ans)\nelse:\n ans = (factorial(N) * factorial(M)) % mod\n print(ans)\n", "N,M=map(int,input().split())\nabs_NM=abs(N-M)\nif abs_NM>1:\n print(0)\n return\n\np=10**9+7\nans=1\nfor i in range(1,N+1):\n ans=(ans*i)%p\nfor i in range(1,M+1):\n ans=(ans*i)%p\nif abs_NM==0:\n ans=(ans*2)%p\n\nprint(ans)", "MOD = pow(10,9)+7\ndef MODINV(n:int, MOD=MOD):\n return pow(n, MOD-2, MOD)\n\ndef perm(n, k, MOD):\n numer = 1\n for i in range(n, n-k, -1):\n numer *= i\n numer %= MOD\n return numer\n\ndef main():\n N, M = list(map(int, input().split()))\n if N == M+1 or N+1 == M:\n ans = (perm(N, N, MOD)*perm(M, M, MOD))%MOD\n elif N == M:\n ans = (2*(perm(N, N, MOD)*perm(M, M, MOD)))%MOD\n else:\n ans = 0\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nn, m = list(map(int, input().split()))\nif abs(n - m) >= 2:\n print((0))\nelif n == m:\n print(((2 * math.factorial(n) * math.factorial(m)) % (10**9 + 7)))\nelse:\n print((math.factorial(n) * math.factorial(m) % (10**9 + 7)))\n", "from math import factorial\n\nmod = 10 ** 9 + 7\nn, m = map(int, input().split())\nprint(\n ((factorial(n) % mod) ** 2 % mod) * 2 % mod\n if n == m\n else (factorial(n) % mod) * (factorial(m) % mod) % mod\n if abs(n - m) == 1\n else 0\n)", "from math import factorial as f\nn, m = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nif abs(n - m) == 1:\n res = f(n) * f(m)\n print((res % mod))\nelif n == m:\n res = f(n) * f(m) * 2\n print((res % mod))\nelse:\n print((0))\n", "def factorial(a):\n result = 1\n for i in range(1,a+1):\n result *= i\n result %= 1000000007\n return result\nN, M = map(int, input().split())\nif N == M:\n ans = 2*(factorial(N)**2) %1000000007\nelif abs(N-M) == 1:\n ans = max(N,M)*(factorial(min(N,M))**2) %1000000007\nelse:\n ans =0\nprint(ans)", "import math\n\nN, M = map(int, input().split())\n\ndef mod(num):\n return num % (10 ** 9 + 7)\n\ndef calc():\n dp[1] = 1\n for i in range(2, maxmn + 1):\n dp[i] = mod(dp[i-1] * i)\n\nabsnm = abs(N - M)\n\nmaxmn = max(N, M)\ndp = [0]*(maxmn + 1)\n\nif absnm > 1:\n print(0)\n\nelse:\n calc()\n\n if absnm == 1:\n r = mod(dp[M] * dp[N])\n\n elif absnm == 0:\n r = mod(dp[M] * dp[N] * 2)\n\n else:\n r = 0\n\n print(r)", "N,M =map(int,input().split())\na = abs(N-M)\nmod = 10**9 + 7\nn = 1\nfor i in range(N):\n n *= N-i\n n %= mod\nm = 1\nfor i in range(M):\n m *= M-i\n m %= mod\nif a > 1:\n print(0)\nelif a == 1:\n print(n * m % mod)\nelse:\n print(n*m*2%mod)", "import math\n\n\ndef main():\n N, M = list(map(int, input().split()))\n mod = 10 ** 9 + 7\n if abs(N - M) > 1:\n ans = 0\n elif N - M == 1:\n ans = (math.factorial(M)**2 * N) % mod\n elif N - M == -1:\n ans = (math.factorial(N)**2 * M) % mod\n else:\n ans = (math.factorial(N)**2 * 2) % mod\n\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N, M = list(map(int, input().split()))\nfrom math import factorial\nmod = 10**9+7\n\nif abs(N-M) > 1:\n print((0))\nelif abs(N-M) == 1:\n print((factorial(N)*factorial(M)%mod))\nelse:\n print((2*factorial(N)*factorial(M)%mod))\n\n\n", "import math\nn,m = list(map(int,input().split()))\nif abs(n-m)>1:\n print((0))\nelif abs(n-m)==1:\n print(((math.factorial(n) * math.factorial(m))%(10**9+7)))\nelse:\n print(((2 * math.factorial(n) * math.factorial(m))%(10**9+7)))\n", "n, m = list(map(int, input().split()))\nmod = 10 ** 9 + 7\n\n\ndef permitation(x):\n res = 1\n for i in range(1, x + 1):\n res = res * i % mod\n return res\n\n\npn = permitation(n)\npm = permitation(m)\n\nif n == m:\n res = pn * pm * 2 % mod\n print(res)\nelif n == m - 1 or n == m + 1:\n res = pn * pm % mod\n print(res)\nelse:\n print((0))\n", "N,M = map(int,input().rstrip().split(\" \"))\nif abs(N - M) > 1:\n print(0)\nelse:\n ans = 1\n for i in range(1,N + 1):\n ans *= i\n ans %= 10 ** 9 + 7\n for i in range(1,M + 1):\n ans *= i\n ans %= 10 ** 9 + 7\n if N == M:\n ans *= 2\n ans %= 10 ** 9 + 7\n print(ans)", "n, m = map(int, input().split())\nn, m = max(n, m), min(n, m)\ndiv = 10 ** 9 + 7\nres = 1\nif n - m == 0:\n for i in range(1, n + 1):\n res *= i\n res %= div\n res = res * res * 2\n print(res % div)\nelif n - m == 1:\n for i in range(1, n + 1):\n res *= i\n res %= div\n for i in range(1, m + 1):\n res *= i\n res %= div\n print(res)\nelse:\n print(0)", "n, m = map(int, input().split())\n\nif n < m: # n >= m\n n, m = m, n\n\nif m + 1 == n or m == n:\n # m! * 1 or 2 * n!\n if m + 1 == n:\n ans = 1\n else:\n ans = 2\n k = 1\n for i in range(1, n + 1):\n k *= i\n if i == m:\n ans *= k\n k = k % (10**9 + 7)\n ans *= k\n print(ans % (10**9 + 7))\nelse:\n print(0)", "import math\nn,m = map(int, input().split())\na = math.factorial(m)\nb = math.factorial(n)\nif 1 < abs(n-m):\n print(0)\nelif abs(n-m) == 0:\n print((a*b*2)%1000000007)\nelif abs(m-n) == 1:\n print((a*b)%1000000007)", "n, m = list(map(int, input().split()))\nif abs(n - m) > 1:\n print((0))\n return\nans = 1\nfor i in range(1, n + 1):\n ans *= i\n ans %= 10**9 + 7\nfor i in range(1, m + 1):\n ans *= i\n ans %= 10**9 + 7\nif abs(n - m) == 0:\n ans *= 2\n ans %= 10**9 + 7\nprint(ans)\n", "MOD=1000000007\n\ndef fac(x):\n ret=1\n for i in range(1,x+1):\n ret*=i\n ret%=MOD\n return ret\n\nN,M=list(map(int,input().split()))\n\nif N==M:\n print((fac(N)**2*2%MOD))\nelif abs(N-M)==1:\n print((fac(N)*fac(M)%MOD))\nelse:\n print((0))\n", "#79 C - Reconciled?\nN,M = map(int,input().split())\nMOD = 10**9 + 7\n\nif abs(N-M) >= 2:\n ans = 0\nelse:\n # M! * N!\n Mfact = 1\n for m in range(1,M+1):\n Mfact = (Mfact * m)%MOD\n Nfact = 1\n for n in range(1,N+1):\n Nfact = (Nfact * n)%MOD\n ans = (Nfact*Mfact)%MOD\n if abs(N-M) == 0:\n ans = (ans * 2)%MOD\nprint(ans)", "#!/usr/bin/env python3\n\n# from numba import njit\n\n# input = stdin.readline\n\nMOD = 10**9 + 7\n\ndef modFact(x):\n if x < 1:\n raise ValueError\n res = 1\n for i in range(x):\n res = res * (i+1) % MOD\n return res\n\n# @njit\ndef solve(n,m):\n if abs(n-m) > 1:\n return 0\n elif abs(n-m) == 1:\n return modFact(n) * modFact(m) % MOD\n else:\n return modFact(n) * modFact(m) * 2 % MOD\n\n\ndef main():\n N,M = list(map(int,input().split()))\n # a = list(map(int,input().split()))\n print((solve(N,M)))\n return\n\ndef __starting_point():\n main()\n\n__starting_point()", "import math\nN, M = map(int, input().split())\n\nmod = 10 ** 9 + 7\n\nif abs(N - M) > 1:\n ans = 0\nelif abs(N - M) == 1:\n ans = (math.factorial(N) % mod) * (math.factorial(M) % mod)\nelse:\n ans = (math.factorial(N) % mod) * (math.factorial(M) % mod) * 2\n \nprint(ans % mod)", "def solve():\n N, M = map(int, input().split())\n if abs(N-M)>1:\n return 0\n mod = 10**9+7\n ans = 2-abs(N-M)\n for i in range(N):\n ans *= i+1\n ans %= mod\n for i in range(M):\n ans *= i+1\n ans %= mod\n return ans\nprint(solve())", "n,m = list(map(int, input().split()))\nif n > m:\n n,m = m,n\nans = 1\nif m==n:\n\n while n > 0:\n ans *= n\n ans %= 10**9+7\n n -= 1\n ans = (2*(ans**2))%(10**9+7)\n print(ans)\n\nelif m - n == 1:\n while n > 0:\n ans *= n\n ans %= 10**9+7\n n -= 1\n \n \n ans = (ans * (ans*m % (10**9+7))) % (10**9+7)\n print(ans)\nelse:\n print((0))\n", "import math\nN,M=map(int,input().split())\np=10**9 +7\ndog=math.factorial(N)\nmon=math.factorial(M)\n\nif N==M:\n ans = ((dog*mon)*2) % p\nelif abs(N-M) == 1:\n ans = (dog*mon) % p\nelse:\n ans=0\nprint(ans)", "n, m = map(int, input().split())\nmod = 10**9+7\n\"\"\"\nabs(n-m)>1\u306e\u6642\u3001\u5fc5\u305a\u96a3\u308a\u5408\u3063\u3066\u3057\u307e\u3046\u306e\u30670\nn>m\u3068\u3057\u3066\u3082\u4e00\u822c\u6027\u3092\u5931\u308f\u306a\u3044\nif n<m: n, m = m, n\nn==mn\u306e\u6642\u306f\u3001\u3069\u3061\u3089\u3092\u5de6\u7aef\u306b\u7f6e\u304f\u304b\u9078\u3079\u308b\u306e\u30672\u500d\n\"\"\"\n\nif abs(n-m)>1: print(0)\nelse:\n if n<m: n, m = m, n\n n_parm = 1\n for i in range(n, 0, -1):\n n_parm = (n_parm*i)%mod\n m_parm = 1\n for i in range(m, 0, -1):\n m_parm = (m_parm*i)%mod\n ans = (n_parm * m_parm)%mod\n if m==n:\n ans = (ans*2)%mod\n print(ans)", "N,M=map(int,input().split())\nt=10**9+7\nimport math\nn=math.factorial(N)%t\nm=math.factorial(M)%t\n\nif 2<=abs(N-M):\n print(0)\nelif abs(N-M)==1:\n print((n*m)%t)\nelse:\n print((n*m*2)%t)", "n, m = list(map(int, input().split()))\n\nimport math\nif n == m:\n dog = math.factorial(n)\n mon = math.factorial(m)\n ans = dog * mon * 2\nelif n == m + 1 or n == m - 1:\n dog = math.factorial(n)\n mon = math.factorial(m)\n ans = dog * mon\nelse:\n ans = 0\n\nprint((ans % (10 ** 9 + 7)))\n", "n, m = list(map(int, input().split()))\nmod = 10**9+7\n\ndef fact(n, mod):\n ans = 1\n for i in range(2, n + 1):\n ans = ans * i\n ans = ans % mod\n\n return ans\n\n\nif abs(n - m) >= 2:\n print((0))\nelif abs(n - m) == 1:\n print((fact(n,mod)*fact(m,mod) % mod))\nelif abs(n - m) == 0:\n print((2 * fact(n, mod)*fact(m, mod) % mod))\n", "n,m = list(map(int,input().split()))\n\nans = 0\nrd = 10**9 + 7\nif(abs(n-m) > 1):\n ans = 0\n print(ans)\nelif(abs(n-m) == 1):\n tmp = min(n,m)\n tmp_mx = max(n,m)\n sm = 1\n for i in range(tmp):\n sm = (sm * (i+1))%rd\n \n ans = (sm * sm * tmp_mx)%rd\n print(ans)\nelse:\n sm = 1\n for i in range(n):\n sm = (sm * (i+1))%rd\n \n ans = (2*sm * sm)%rd\n print(ans)\n\n", "N,M=list(map(int,input().split()))\nif N==M+1:\n A=N\n B=M\n ans=1\nelif N+1==M:\n A=M\n B=N\n ans=1\nelif N==M:\n A=N\n B=M\n ans=2\nelse:\n print((0))\n return\nansa=1\nansb=1\nfor i in range(1,A+1):\n ansa=(ansa*i)%(10**9+7)\nfor j in range(1,B+1):\n ansb=(ansb*j)%(10**9+7)\n\nprint(((ansa*ansb*ans)%(10**9+7)))\n\n \n", "def factorial(n, mod=10**9 + 7):\n a = 1\n for i in range(1, n + 1):\n a = a * i % mod\n return a\n\n\ndef main():\n N, M = list(map(int, input().split()))\n mod = 10 ** 9 + 7\n if abs(N - M) > 1:\n ans = 0\n elif abs(N - M) == 1:\n ans = (factorial(min(N, M))**2 * max(N, M)) % mod\n else:\n ans = (factorial(N)**2 * 2) % mod\n\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n,m = map(int, input().split())\n\nif abs(n-m) > 1:\n print(0)\n return\n\nmod = 10**9+7\nans = 1\nfor i in range(1,n+1):\n ans *= i\n ans %= mod\nfor i in range(1,m+1):\n ans *= i\n ans %= mod\nif (n+m)%2 == 0:\n ans *= 2\n ans %= mod\nprint(ans)", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\nMOD = 10 ** 9 + 7\n\n\ndef fac(k):\n res = 1\n for i in range(2, k + 1):\n res = (res * i) % MOD\n return res\n\n\ndef solve():\n n, m = inl()\n if n < m:\n n, m = m, n\n if n - m > 1:\n return 0\n if n - m == 1:\n return fac(n) * fac(m) % MOD\n assert n == m\n a = fac(n)\n a = 2 * a * a % MOD\n return a\n\n\nprint(solve())\n", "mod = 10 ** 9 + 7\n\ndef factorial(n, mod):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n fact %= mod\n return fact\n\nN, M = map(int,input().split())\nif abs(N - M) > 1:\n print(0)\nelse:\n ans = 1\n ans *= factorial(N, mod)\n ans *= factorial(M, mod)\n ans *= 2 - abs(N - M)\n ans %= mod\n print(ans)", "N,M=map(int,input().split())\nabs_NM=abs(N-M)\nif abs_NM>1:\n print(0)\n return\n\np=10**9+7\nmin_=min(N,M)\nmax_=max(N,M)\nans=1\nfor i in range(1,min_+1):\n ans=(ans*i)%p\n ans=(ans*i)%p\n\nif abs_NM==1:\n ans=(ans*max_)%p\nelse:\n ans=(ans*2)%p\n\nprint(ans)", "#\n# abc065 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\nimport math\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"2 2\"\"\"\n output = \"\"\"8\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"3 2\"\"\"\n output = \"\"\"12\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"1 8\"\"\"\n output = \"\"\"0\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"100000 100000\"\"\"\n output = \"\"\"530123477\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N, M = list(map(int, input().split()))\n\n if abs(N-M) > 1:\n print(\"0\")\n elif N == M:\n print((2*math.factorial(N)*math.factorial(M) % (10**9+7)))\n else:\n print((math.factorial(N)*math.factorial(M) % (10**9+7)))\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "import math\nn, m = map(int, input().split())\np = 10**9 + 7\n\n\n\nnf = math.factorial(n) % p\nmf = math.factorial(m) % p\n\nif abs(n-m) > 1:\n ans = 0\n\nelif n == m:\n ans = nf * mf * 2\n \nelse:\n ans = nf * mf\n \nprint(ans % p)", "from math import factorial\nn,m=map(int,input().split())\nl=10**9+7\nif abs(n-m)>1:\n print(0)\n return\nif abs(n-m)==1:\n print((factorial(n)*factorial(m))%l)\nelse:\n print(((factorial(n)**2)*2)%l)", "import sys\n\n\ndef LI():\n return list(map(int, input().split()))\n\n\nN, M = LI()\nif abs(N-M) >= 2:\n print((0))\n return\nmod = pow(10, 9)+7\nx = 1\nif N == M:\n for i in range(1, N+1):\n x = (x*i) % mod\n ans = (x*x*2) % mod\nelse:\n A = max(N, M)\n B = min(N, M)\n for i in range(1, B+1):\n x = (x*i) % mod\n y = (x*A) % mod\n ans = (x*y) % mod\nprint(ans)\n", "n,m=[int(i) for i in input().split()]\nnew_n=min(n,m)\nnew_m=max(n,m)\nmod=10**9+7\ndef ans(n,m):\n\n if n==m:\n return 2*kaijyou(n,mod)*kaijyou(m,mod)\n elif m-n==1:\n return kaijyou(n,mod)*kaijyou(m,mod)\n else:\n return 0\n\n\ndef kaijyou(n,mod):\n ans=1\n for i in range(1,n+1):\n ans*=i\n ans=ans%mod\n return ans\nprint(ans(new_n,new_m)%mod)", "import math\nmod=10**9+7\nn,m=list(map(int,input().split()))\nif n+1<m or m+1<n:\n print((0))\n return\nelif n==m:\n print(((2*math.factorial(n)**2)%mod))\nelse:\n print(((math.factorial(n)*math.factorial(m))%mod))\n\n", "from math import factorial\ndef count(n, r):\n if n == r:\n return 2\n else:\n return 1\n\nN, M = map(int, input().split())\nmod = 10**9 + 7\nprint(((factorial(N) % mod) * (count(N, M) % mod) * (factorial(M) % mod)) % mod if abs(N - M) < 2 else 0)", "n,m = list(map(int, input().split()))\nf = [1] \np = 10**9 + 7\nfor i in range(1, max(n,m) + 1):\n f.append(f[-1] * i % p)\n\nif abs(n-m) == 1:\n print((f[n] * f[m] % p))\nelif abs(n-m) == 0:\n print((f[n] * f[m] * 2 % p))\nelse:\n print((0))\n", "import math\n\nN, M = list(map(int, input().split()))\nif abs(N - M) >= 2:\n print((0))\n return\n\n\nN = math.factorial(N) % (10 ** 9 + 7)\nM = math.factorial(M) % (10 ** 9 + 7)\nif N == M:\n print(((N * M * 2) % (10 ** 9 + 7)))\nelse:\n print(((N * M) % (10 ** 9 + 7)))\n", "import math\n\nn, m = map(int, input().split())\nif n==m:\n print((math.factorial(n)*math.factorial(m)*2)%1000000007)\nelif abs(n-m)==1:\n print((math.factorial(n)*math.factorial(m))%1000000007)\nelse:\n print(0)", "n, m = list(map(int, input().split()))\n\n\ndef facmod(a, mod):\n res = 1\n for i in range(1, a+1):\n res = (res*i) % mod\n return res\n\n\nmod = 10**9+7\nmn = min(m, n)\nmx = max(m, n)\nif abs(mn-mx) > 1:\n ans = 0\nelse:\n if n == m:\n ans = (2*facmod(m, mod)*facmod(n, mod)) % mod\n else:\n ans = (facmod(mx, mod)*facmod(mn, mod)) % mod\nprint(ans)\n", "def main():\n N, M = [int(n) for n in input().split(\" \")]\n\n if abs(N - M) >= 2:\n print((0))\n elif abs(N - M) == 1:\n print(((factorial(N) * factorial(M)) % 1000000007))\n else:\n print(((factorial(N) * factorial(M) * 2) % 1000000007))\n\ndef factorial(n):\n ret = 1\n for i in range(1, n + 1):\n ret = (ret * i) % 1000000007\n return ret\n \nmain()\n", "N,M=list(map(int,input().strip().split()))\ninf=10**9+7\nans=1\nfor n in range(1,N+1):\n ans*=n\n ans%=inf\nfor m in range(1,M+1):\n ans*=m\n ans%=inf\n\nif abs(N-M)>=2:\n print((0))\nelif abs(N-M)==1:\n print(ans)\nelse:\n print((ans*2%inf))\n", "import math\n\nn, m = map(int, input().split())\nn_f = math.factorial(n)\nm_f = math.factorial(m)\nmod = 1000000007\n\nif abs(n-m) > 1:\n print(0)\n return\nif n == m:\n print((n_f * m_f * 2) % mod)\nelse:\n print((n_f * m_f) % mod)", "def mod1(x):\n mod=10**9+7\n ans=1\n y=1\n while y<=x:\n ans=ans*y\n y+=1\n ans=ans%mod\n \n return ans%mod\n\nn,m=map(int,input().split())\nif n==m:\n print((2*mod1(n)*mod1(m))%(10**9+7))\nelif abs(n-m)==1:\n print((mod1(n)*mod1(m))%(10**9+7))\nelse:\n print(0)", "from math import factorial\nn,m=list(map(int,input().split()))\nif abs(n-m)>1:\n print((0))\n return\nmod=10**9+7\nif n==m:\n print(((2*factorial(n)*factorial(m))%mod))\nelse:\n print(((factorial(n)*factorial(m))%mod))\n", "from math import factorial\nn,m=map(int,input().split())\nl=10**9+7\nif abs(n-m)>1:\n print(0)\n return\nif abs(n-m)==1:\n print((factorial(n)*factorial(m))%l)\nelse:\n print(((factorial(n)**2)*2)%l)", "n,m=list(map(int,input().split()))\np=10**9+7\nif abs(n-m)>=2:\n print((0))\nelif n==m:\n ans=1\n for i in range(1,n+1):\n ans=(ans*i)%p\n print(((2*ans*ans)%p))\nelse:\n ans=1\n for i in range(1,n+1):\n ans=(ans*i)%p\n for i in range(1,m+1):\n ans=(ans*i)%p\n print((ans%p))\n", "def factorial(n, mod):\n num = 1\n for i in range(1, n + 1):\n i %= mod\n num *= i\n num %= mod\n return num\n\n\ndef main():\n n, m = map(int, input().split())\n md = 10 ** 9 + 7\n\n if abs(n - m) >= 2:\n ans = 0\n elif abs(n - m) == 1:\n ans = (factorial(n, md) * factorial(m, md))\n ans %= md\n else:\n ans = (factorial(n, md) * factorial(m, md)) * 2\n ans %= md\n\n print(ans)\n\n\ndef __starting_point():\n main()\n__starting_point()", "from math import factorial\nn, m = map(int, input().split())\nif n == m:\n print(factorial(n)*factorial(m)*2 % (10**9+7))\nelif abs(n-m) <= 1: \n print(factorial(n)*factorial(m) % (10**9+7))\nelse:\n print(0)", "def gyakugen(x,p):\n binp = str(bin(p-2))[::-1]\n ruijou = x\n \n result = 1\n for i in range(len(binp)-2):\n if binp[i] == \"1\":\n result *= ruijou\n result %= p\n ruijou *= ruijou\n ruijou %= mod\n return result\n\nN, M = [int(i) for i in input().split()]\nmod = 10**9+7\n\nif abs(N-M) > 1 :\n print(0)\n return\nelif N == M:\n ans = 1\n for i in range(1,N+1):\n ans *= i\n ans %= mod\n ans *= i\n ans %= mod\n ans *= 2\n ans %= mod\n print(ans)\nelse:\n ans = 1\n m = min(N,M)\n for i in range(1,m+1):\n ans *= i\n ans %= mod\n ans *= i\n ans %= mod\n ans *= max(N,M)\n ans %= mod\n print(ans)", "from math import factorial\n\nn, m = map(int, input().split())\nif n == m:\n ans = factorial(n) % (10 ** 9 + 7)\n ans = ans ** 2 % (10 ** 9 + 7)\n print(ans * 2 % (10 ** 9 + 7))\nelif abs(n - m) == 1:\n ans1 = factorial(n) % (10 ** 9 + 7)\n ans2 = factorial(m) % (10 ** 9 + 7)\n print(ans1 * ans2 % (10 ** 9 + 7))\nelse:\n print(0)", "N, M = map(int,input().split())\nans = 1\nif abs(N-M) >= 2:\n ans = 0\nelif N == M:\n for i in range(1,M+1):\n ans = (ans*i) % (10**9+7)\n for i in range(1,M+1):\n ans = (ans*i) % (10**9+7)\n ans = (ans*2) % (10**9+7)\nelse:\n for i in range(1,M+1):\n ans = (ans*i) % (10**9+7)\n for i in range(1,N+1):\n ans = (ans*i) % (10**9+7)\nprint(ans)", "# C - Reconciled?\ndef main():\n from math import factorial\n\n n, m = map(int, input().split())\n p = 10**9+7\n\n if abs(n-m) < 2:\n if n == m:\n print(2*factorial(n)*factorial(m)%p)\n else:\n print(factorial(n)*factorial(m)%p)\n else:\n print(0)\n\nif __name__ == \"__main__\":\n main()"] | {"inputs": ["2 2\n", "3 2\n", "1 8\n", "100000 100000\n"], "outputs": ["8\n", "12\n", "0\n", "530123477\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 35,439 | |
97a1c5bef6077e19fcb192e8556bdd0c | UNKNOWN | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
-----Constraints-----
- 3 β€ N β€ 200 000
- 1 β€ M β€ 200 000
- 1 β€ a_i < b_i β€ N
- (a_i, b_i) \neq (1, N)
- If i \neq j, (a_i, b_i) \neq (a_j, b_j).
-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
-----Output-----
If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.
-----Sample Input-----
3 2
1 2
2 3
-----Sample Output-----
POSSIBLE
| ["n,m=list(map(int,input().split()))\nM=[[] for i in range(n)]\nfor i in range(m):\n a,b=list(map(int,input().split()))\n a-=1;b-=1\n M[a].append(b)\n M[b].append(a)\nyes=\"POSSIBLE\";no=\"IMPOSSIBLE\"\n\nfor i in M[0]:\n if n-1 in M[i]:\n print(yes);return\nprint(no)\n\n", "import sys\n\ninput = sys.stdin.readline\nn, m = list(map(int, input().split()))\nx = set()\ny = set()\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n if a == 1:\n x.add(b)\n if b == n:\n y.add(a)\nprint(((\"POSSIBLE\", \"IMPOSSIBLE\")[len(x & y) == 0]))\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# FileName: \tC\n# CreatedDate: 2020-09-13 15:43:14 +0900\n# LastModified: 2020-09-13 15:49:14 +0900\n#\n\n\nimport os\nimport sys\n# import numpy as np\n# import pandas as pd\nfrom collections import deque\n\n\ndef main():\n N, M = list(map(int, input().split()))\n path = [[] for _ in range(N+1)]\n for _ in range(M):\n a, b = list(map(int, input().split()))\n path[a].append(b)\n path[b].append(a)\n Q = deque(path[1])\n flag = False\n while Q and flag is False:\n u = Q.popleft()\n for v in path[u]:\n if v == N:\n flag = True\n if flag:\n print(\"POSSIBLE\")\n else:\n print(\"IMPOSSIBLE\")\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "#!/usr/bin/env python\nfrom collections import deque\n\n# input\nn, m = list(map(int, input().split()))\na = [0 for _ in range(m)]\nb = [0 for _ in range(m)]\nfor i in range(m):\n a[i], b[i] = list(map(int, input().split()))\n\nif m == 1:\n print('IMPOSSIBLE')\n return\n\nto = [[] for _ in range(n+1)]\nfor i in range(m):\n to[a[i]].append(b[i])\n to[b[i]].append(a[i])\n#print('to =', to)\n\n# BFS\ninf = 200200\ndist = [inf for _ in range(n+1)]\nq = deque()\nq.append(1)\ndist[1] = 0 \n\nwhile q:\n v = q.popleft()\n for u in to[v]:\n if dist[u] == inf:\n dist[u] = dist[v]+1\n q.append(u)\n\nif dist[n] == 2:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n", "import collections as c\nn,m=map(int,input().split())\nprint(['POSSIBLE','IMPOSSIBLE'][not [1 for c in c.Counter([[a,b][a==1] for a,b in [[i,j] for i,j in [list(map(int,input().split())) for _ in range(m)] if i==1 or j==n]]).values() if c>1]])", "n, m = [int(x) for x in input().split()]\na = []\nfor i in range(m):\n a.append([int(x) for x in input().split()])\n \nres = \"IMPOSSIBLE\"\nflag = []\n\nfor i in range(m):\n if a[i][0] == 1:\n flag.append(a[i][1])\nflag = set(flag)\n\nfor i in range(m):\n if a[i][0] in flag and a[i][1] == n:\n res = \"POSSIBLE\"\nprint(res)", "import collections\n\nn,m=list(map(int,input().split()))\na,b,c=[],[],[]\nfor i in range(m):\n A=list(map(int,input().split()))\n a.append(A)\nfor i in range(m):\n if a[i][1]==n:\n b.append(a[i][0])\n elif a[i][0]==1:\n c.append(a[i][1])\nif len(set(b)&set(c))>0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "n,m=map(int,input().split())\nedge=[[] for _ in range(n)]\nfor i in range(m):\n x,y=map(int,input().split())\n edge[x-1].append(y-1)\n edge[y-1].append(x-1)\nfor i in edge[0]:\n if n-1 in edge[i]:\n print(\"POSSIBLE\")\n return\nprint(\"IMPOSSIBLE\")", "import math\nimport collections\nimport fractions\nimport itertools\nimport functools\nimport operator\nimport bisect\n\ndef solve():\n n, m = map(int, input().split())\n course = [[] for i in range(n)]\n for i in range(m):\n a, b = map(int, input().split())\n course[a-1].append(b)\n course[b-1].append(a)\n for i in course[0]:\n if n in course[i-1]:\n print(\"POSSIBLE\")\n break\n else:\n print(\"IMPOSSIBLE\")\n return 0\n\ndef __starting_point():\n solve()\n__starting_point()", "n, m = map(int, input().split())\narr_ = [tuple(map(int, input().split())) for _ in range(m)]\none = set([b for a, b in arr_ if a == 1])\nlast = set([a for a, b in arr_ if b == n])\nprint(\"POSSIBLE\" if len(one & last) >= 1 else \"IMPOSSIBLE\")", "import heapq\nimport sys\ninput = lambda :sys.stdin.readline().rstrip()\n\ndef INPUT(mode=int):\n return list(map(mode, input().split()))\n\ndef Dijkstra_heap(s, edge):\n # \u59cb\u70b9s\u304b\u3089\u5404\u9802\u70b9\u3078\u306e\u6700\u77ed\u8ddd\u96e2#\u59cb\u70b9s\u304b\u3089\u5404\u9802\u70b9\u3078\u306e\u6700\u77ed\u8ddd\u96e2\n d = [10**20] * n\n used = [False] * n\n d[s] = 0\n used[s] = True\n edgelist = []\n for i, j in edge[s]:\n heapq.heappush(edgelist, i+j*(10**6))\n while len(edgelist):\n minedge = heapq.heappop(edgelist)\n v = minedge % (10**6)\n # \u307e\u3060\u4f7f\u308f\u308c\u3066\u306a\u3044\u9802\u70b9\u306e\u4e2d\u304b\u3089\u6700\u5c0f\u306e\u8ddd\u96e2\u306e\u3082\u306e\u3092\u63a2\u3059\n if used[v]: continue\n d[v] = minedge // (10**6)\n used[v] = True\n for e in edge[v]:\n if not used[e[0]]:\n heapq.heappush(edgelist, e[0]+(e[1]+d[v]) * (10**6))\n return d\n\nn, m = INPUT()\nAB = [INPUT() for _ in range(m)]\nedge = [[] for _ in range(n)]\nfor a, b in AB:\n a -= 1\n b -= 1\n edge[a].append((b, 1))\n edge[b].append((a, 1))\n\ndist = Dijkstra_heap(0, edge)\nif dist[-1] <= 2:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "n, m = map(int, input().split())\nab = [list(map(int, input().split())) for _ in range(m)]\nini_1 = []\nend_n = []\nfor i in range(m):\n if ab[i][0] == 1:\n ini_1.append(ab[i][1])\n elif ab[i][1] == n:\n end_n.append(ab[i][0])\nif set(ini_1) & set(end_n):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "n, m = map(int,input().split())\nl1 = set()\nl2 = set()\nfor i in range(m):\n a,b = map(int,input().split())\n if a==1:\n l1.add(b)\n elif b==n:\n l2.add(a)\nprint('POSSIBLE' if len(l1&l2) >=1 else 'IMPOSSIBLE')", "N, M = map(int, input().split())\nship = [list(map(int, input().split())) for _ in range(M)]\n\ns1 = [False] * N\nsN = [False] * N\n\nfor i, s in enumerate(ship):\n if s[0] == 1:\n s1[s[1] - 1] = True\n\n if s[1] == N:\n sN[s[0] - 1] = True\n\nans = 'IMPOSSIBLE'\nif any([p1 * pN for p1, pN in zip(s1, sN)]):\n ans = 'POSSIBLE'\n\nprint(ans)", "import sys\ninput = sys.stdin.readline\n\n\ndef read():\n N, M = list(map(int, input().strip().split()))\n AB = []\n for i in range(M):\n a, b = list(map(int, input().strip().split()))\n AB.append((a, b))\n return N, M, AB\n\n\ndef solve(N, M, AB):\n S = [False for i in range(N+1)]\n T = [False for i in range(N+1)]\n for a, b in AB:\n if a > b:\n a, b = b, a\n if a == 1:\n S[b] = True\n elif b == N:\n T[a] = True\n for s, t in zip(S, T):\n if s and t:\n return \"POSSIBLE\"\n return \"IMPOSSIBLE\"\n\n\ndef __starting_point():\n inputs = read()\n print((\"%s\" % solve(*inputs)))\n\n__starting_point()", "#n = int(input())\nn, m = list(map(int, input().split()))\n#l = list(map(int,input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\n\ndic = {}\nfor i in range(m):\n a, b = list(map(int, input().split()))\n dic[(a, b)] = True\n dic[(b, a)] = True\nans = 'IMPOSSIBLE'\nfor i in range(2, n):\n if dic.get((1, i), False):\n if dic.get((i, n), False):\n ans = 'POSSIBLE'\n break\nprint(ans)\n", "N, M = list(map(int, input().split()))\na = []\nb = []\nfor i in range(M):\n x, y = list(map(int, input().split()))\n a.append(x)\n b.append(y)\n\nc = []\nd = []\n\nfor i in range(M):\n if a[i] == 1:\n c.append(b[i])\n\nfor i in range(M):\n if b[i] == N:\n d.append(a[i])\n\ne = set(c) & set(d)\n\nif len(e) != 0:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n\n\n", "n, m = map(int, input().split())\na1 = []\nbn = []\n\nfor i in range(m):\n a, b = map(int, input().split())\n if a == 1:\n a1.append(b)\n elif b == n:\n bn.append(a)\nla = len(a1)\nlb = len(bn)\nsa = set(a1)\nsb = set(bn)\nif len(sa | sb) < la + lb:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "n, m = map(int,input().split())\n \nl1 = []\nl2 = []\nfor i in range(m):\n a,b = map(int,input().split())\n if a==1:\n l1.append(b)\n elif b==n:\n l2.append(a)\n\nif len(set(l1)&set(l2)) >=1:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "import sys\nn, m = map(int, input().split())\n \ng = [[] for _ in range(n)]\nfor _ in range(m):\n u, v = map(int, input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\n\nN = n-1\nfor i in g[0]:\n if N in g[i]:\n print('POSSIBLE')\n return\n\nprint('IMPOSSIBLE')", "N,M = map(int,input().split())\nisland = [[] for i in range(N+1)]\nfor i in range(M):\n a,b = map(int,input().split())\n island[a].append(b)\n\nfor i in island[1]:\n if N in island[i]:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "n, m = map(int, input().split())\narr = []\nfor i in range(m):\n a, b = map(int, input().split())\n arr.append((a,b))\n\none = set([b for a, b in arr if a == 1])\nlast = set([a for a, b in arr if b == n])\nconnect = one & last\nif len(connect) >= 1:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "N,M=list(map(int,input().split()))\nG=[list() for _ in range(N)]\nfor _ in range(M):\n a,b=list(map(int,input().split()))\n a-=1\n b-=1\n G[a].append(b)\n G[b].append(a)\nG[0].sort()\nG[N-1].sort()\ni=0\nj=0\nwhile i<len(G[0]) and j<len(G[N-1]):\n if G[0][i]==G[N-1][j]:\n print(\"POSSIBLE\")\n break\n elif G[0][i]<G[N-1][j]:\n i+=1\n else:\n j+=1\nelse:\n print(\"IMPOSSIBLE\")\n", "n, m = list(map(int, input().split()))\nroot_map = dict()\nroot_map[1] = set()\nroot_map[n] = set()\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n if a == 1 or a == n:\n root_map[a].add(b)\n if b == 1 or b == n:\n root_map[b].add(a)\n\nif root_map[1] & root_map[n]:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "N,M=list(map(int,input().split()))\nnekotyann=[0]*N\nwanntyann=[0]*N\nans=\"IMPOSSIBLE\"\nfor i in range(M):\n a,b=list(map(int,input().split()))\n if a==1:\n nekotyann[b-1]+=1\n if b==N:\n wanntyann[a-1]+=1\nfor k in range(N):\n if nekotyann[k]!=0 and wanntyann[k]!=0:\n ans=\"POSSIBLE\"\n break\nprint(ans)\n", "N,M = map(int,input().split())\nans = ('IMPOSSIBLE')\nf1tob = []\nfbtoN = []\nfor i in range(M):\n a,b = map(int,input().split())\n if a == 1:\n f1tob.append(b)\n elif b == N:\n fbtoN.append(a)\nf1toba = set(f1tob)\nfbtoNa = set(fbtoN)\nif bool(fbtoNa & f1toba):\n ans = 'POSSIBLE'\nprint(ans)", "n, m = list(map(int, input().split()))\nroot_map = dict()\nroot_map[1] = set()\nroot_map[n] = set()\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n if a not in root_map:\n root_map[a] = set()\n root_map[a].add(b)\n else:\n root_map[a].add(b)\n if b not in root_map:\n root_map[b] = set()\n root_map[b].add(a)\n else:\n root_map[b].add(a)\n\nfor i in root_map[1]:\n if i in root_map[n]:\n print(\"POSSIBLE\")\n break\nelse:\n print(\"IMPOSSIBLE\")\n", "n, m = map(int, input().split())\nedges = [tuple(map(int, input().split())) for _ in range(m)]\n\nG = [[] for j in range(n + 1)]\n\nfor a, b in edges:\n G[a].append(b)\n G[b].append(a)\n\nfor b in G[1]:\n if n in G[b]:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "n,m = list(map(int,input().split()))\n#a_to = []\n#a_from = []\ndic = {}\nisOK = False\nfor i in range(m):\n a,b = list(map(int,input().split()))\n if a in [1,n]:\n dic.setdefault(b,0)\n dic[b] += 1\n if dic[b]==2:\n isOK = True\n break\n elif b in [1,n]:\n dic.setdefault(a,0)\n dic[a] += 1\n if dic[a]==2:\n isOK = True\n break\n# if a==1:\n# a_to.append(b)\n# if b==1:\n# a_to.append(a)\n# if a==n:\n# a_from.append(b)\n# if b==n:\n# a_from.append(a)\n\n#for j in range(len(a_to)):\n# if a_to[j] in a_from:\n# isOK = True\n# break\n#print(a_to)\n#print(a_from)\nif isOK:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n", "N,M = map(int,input().split())\n#\u96a3\u63a5\u30ea\u30b9\u30c8\ng = [[] for i in range(N)]\nfor i in range(M):\n a,b = map(int,input().split())\n g[a-1].append(b)\n g[b-1].append(a)\nls = g[0]\nflag = 0\nfor i in range(len(g[0])):\n ls2 = g[ls[i]-1]\n for j in range(len(ls2)):\n if ls2[j] == N:\n flag += 1\n print(\"POSSIBLE\")\n break\nif flag == 0:\n print(\"IMPOSSIBLE\")", "N, M = list(map(int, input().split()))\nfrom_one = []\nto_n = []\nfor _ in range(M):\n a, b = [int(x)-1 for x in input().split()]\n if a == 0:\n from_one += [b]\n elif b == 0:\n from_one += [a]\n elif a == N-1:\n to_n += [b]\n elif b == N-1:\n to_n += [a]\n\nfrom_one = set(from_one)\nto_n = set(to_n)\nif len(from_one & to_n) >= 1:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "N,M = map(int,input().split())\nI = set()\nn = set()\nfor i in range(M):\n a,b = map(int,input().split())\n if a == 1:\n I.add(b)\n if b == N:\n n.add(a)\nif I & n == set():\n print(\"IMPOSSIBLE\")\nelse:\n print(\"POSSIBLE\")", "N,M=map(int,input().split())\nl,r=[0]*N,[0]*N\nfor i in range(M):\n a,b=map(int,input().split())\n if a==1:\n l[b-1]=1\n if b==N:\n r[a-1]=1\nfor i in range(N):\n if l[i]+r[i]==2:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "N, M = map(int, input().split())\ngraph = [[] for _ in range(N)] \nfor _ in range(M):\n a, b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\n\ndef bfs(goal, graph, seen, next_v):\n for x in graph[next_v[0][0]]:\n if x == goal:\n return True\n if x in seen:\n continue\n next_v.append((x,next_v[0][1]+1))\n seen.add(x)\n return False\n\n\nnext_v = [(0,0)]\nseen = {0}\n#bfs\nwhile True:\n if len(next_v) == 0 or next_v[0][1] == 2:\n ans = \"IMPOSSIBLE\"\n break\n if bfs(N-1, graph, seen, next_v):\n ans = \"POSSIBLE\"\n break\n next_v.pop(0)\nprint(ans)", "N, M = [int(x) for x in input().split(\" \")]\nnext_to_1 = []\nnext_to_last = []\n\nfor i in range(M):\n tmp = input().split(\" \")\n if int(tmp[0]) == 1:\n next_to_1.append(int(tmp[1]))\n if int(tmp[1]) == N:\n next_to_last.append(int(tmp[0]))\n\nif len(list(set(next_to_1) & set(next_to_last))) > 0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "from collections import deque\nn, m = list(map(int, input().split()))\nedges = [[]*n for _ in range(n)]\n\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n a -= 1\n b -= 1\n edges[a].append(b)\n edges[b].append(a)\n#print(edges)\nd = deque()\nd.append(0)\nvisited = [False]*n\nvisited[0] = True\nfrom_0 = [0]*n\nwhile d:\n x = d.popleft()\n for child in edges[x]:\n if visited[child]:\n continue\n else:\n visited[child] = True\n d.append(child)\n from_0[child] = from_0[x] + 1\n#print(from_0)\nif from_0[n-1] == 2:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n\n", "n,m = map(int,input().split())\nvoyage = [set() for i in range(n+1)]\nfor i in range(m):\n a,b = map(int,input().split())\n voyage[a].add(b)\n voyage[b].add(a)\nans = 0\nfor v in voyage[1]:\n if v in voyage[n]:\n ans = 1\nprint('POSSIBLE' if ans else 'IMPOSSIBLE')", "n,m = list(map(int,input().split()))\nab = [list(map(int,input().split())) for i in range(m)]\n\nren = []\n\nfor i in range(m) :\n if ab[i][0] == 1 :\n ren.append(ab[i][1])\n elif ab[i][1] == n :\n ren.append(ab[i][0])\n\ncnt = len(ren)\n\nif len(set(ren)) == cnt :\n print(\"IMPOSSIBLE\")\nelse :\n print(\"POSSIBLE\")\n", "N,M = map(int,input().split())\nA = set()\nB = set()\nfor i in range(M):\n a,b = input().split()\n if a =='1':\n A.add(b)\n if b == str(N):\n B.add(a)\nif A&B:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "from collections import deque\n\nn, m = map(int,input().split())\n\ne = [[] for i in range(n)]\nfor i in range(m):\n f, t = map(int,input().split())\n f -= 1\n t -= 1\n e[f].append(t)\n e[t].append(f)\n\nINF = 10**9\ndist = [INF] * n\ndist[0] = 0\nd = deque()\nd.append([0, 0])\n\nwhile d:\n f, c = d.pop()\n if c >= 2:\n break\n for t in e[f]:\n if c + 1 < dist[t]:\n dist[t] = c + 1\n d.appendleft([t, c+1])\nprint('POSSIBLE') if dist[n-1] <= 2 else print('IMPOSSIBLE')", "n, m = list(map(int, input().split()))\nab = list(list(map(int, input().split())) for _ in range(m))\n\ngoal = [0] * n\nstart = [0] * n\n\nfor a, b in ab:\n if a == 1:\n start[b] = 1\n if b == n:\n goal[a] = 1\n\nflg = False\nfor i in range(n):\n if start[i] and goal[i]:\n flg = True\n\nprint(('POSSIBLE' if flg else 'IMPOSSIBLE'))\n", "n, m = map(int, input().split())\nli = [0]*200001\ns = \"IMPOSSIBLE\"\nfor i in range(m):\n a, b = map(int, input().split())\n if a == 1:\n if li[b] == 0:\n li[b] = 1\n else:\n s = \"POSSIBLE\"\n \n if b == n:\n if li[a] == 0:\n li[a] = 1\n else:\n s = \"POSSIBLE\"\n\nprint(s)", "#!/usr/bin/env python3\n# cython: profile=True\nimport sys\n\nYES = \"POSSIBLE\" # type: str\nNO = \"IMPOSSIBLE\" # type: str\n\n\ndef solve(N: int, M: int, a: \"List[int]\", b: \"List[int]\"):\n AB = sorted(zip(a, b))\n s = set([b for a, b in AB if a == 1])\n g = set([a for a, b in AB if b == N])\n return YES if s & g else NO\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n a = [int()] * (M) # type: \"List[int]\"\n b = [int()] * (M) # type: \"List[int]\"\n for i in range(M):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n print((solve(N, M, a, b)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef perf():\n import cProfile\n cProfile.run(\"main()\")\n\ndef __starting_point():\n #test()\n #perf()\n main()\n\n__starting_point()", "N,M = map(int,input().split())\nA = []\nB = []\n\nfor i in range(M):\n a,b = map(int,input().split())\n if a == 1:\n B.append(b)\n if b == N:\n A.append(a)\n\nif len(set(A) & set(B)) != 0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "import sys\ninput = sys.stdin.readline\n\n\ndef read():\n N, M = list(map(int, input().strip().split()))\n AB = []\n for i in range(M):\n a, b = list(map(int, input().strip().split()))\n AB.append((a, b))\n return N, M, AB\n\n\ndef solve(N, M, AB):\n is_ok = True\n mid_b = set()\n mid_a = set()\n for a, b in AB:\n if a == 1:\n mid_b.add(b)\n elif b == N:\n mid_a.add(a)\n is_ok = len(mid_a.intersection(mid_b)) > 0\n return \"POSSIBLE\" if is_ok else \"IMPOSSIBLE\"\n\n\ndef __starting_point():\n inputs = read()\n print((solve(*inputs)))\n\n__starting_point()", "n,m=map(int,input().split())\nA=[]\nB=[]\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1:\n A.append(b)\n if b==n:\n B.append(a)\nif len(set(A) & set(B))>0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "N, M = [int(x) for x in input().split()]\nAB = [[int(x) for x in input().split()] for _ in range(M)]\n\n\nx = set()\nfor a, b in AB:\n if a == 1:\n x.add(b)\n if b == 1:\n x.add(a)\n\nf = False\n\nfor a, b in AB:\n if (a in x and b == N) or (b in x and a == N):\n f = True\n\nif f:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "import sys\n\nN, M = [int(i) for i in input().split()]\nmap = {k: [] for k in range(1, N + 1)}\n\nfor _ in range(M):\n a, b = (int(i) for i in input().split())\n map[a].append(b)\n\n\nfor i in map[1]:\n if N in map[i]:\n print('POSSIBLE')\n return\n\n\nprint('IMPOSSIBLE')\n", "from collections import deque\n\nn,m = map(int, input().split())\nG = [[] for _ in range(n)]\nfor i in range(m):\n a,b = map(int, input().split())\n a-=1\n b-=1\n G[a].append(b)\n G[b].append(a)\n\nok = False\nfor v in G[0]:\n s = G[v]\n if n-1 in s:\n ok = True\n\nif ok:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "n, m = map(int, input().split())\narr_ = [tuple(map(int, input().split())) for _ in range(m)]\n\none = set([b for a, b in arr_ if a == 1])\nlast = set([a for a, b in arr_ if b == n])\nconnect = one & last\nif len(connect) >= 1:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "n, m = map(int,input().split())\ninit_island = set()\nlast_island = set()\nfor _ in range(m):\n a,b = map(int,input().split())\n a,b = min(a,b), max(a,b)\n if a == 1:\n init_island.add(b)\n elif b == n:\n last_island.add(a)\n else:\n continue\ncommon = init_island.intersection(last_island)\nif len(common) >= 1:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "N, M = list(map(int, input().split()))\nL = [list(map(int, input().split())) for i in range(M)]\ns = []\ng = []\nfor i in range(M):\n if 1 == L[i][0]:\n s.append(L[i][1])\n if 1 == L[i][1]:\n s.append(L[i][0])\n \nfor i in range(M):\n if N == L[i][0]:\n g.append(L[i][1])\n if N == L[i][1]:\n g.append(L[i][0])\n \nif set(g)&set(s):\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n", "n, m, *AB = map(int, open(0).read().split())\n\nC, D = set(), set()\nfor a, b in zip(AB[::2], AB[1::2]):\n if a == 1:\n C.add(b)\n if b == n:\n D.add(a)\n\nif len(C & D):\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "def main():\n N, M = map(int,input().split())\n fromOne = set()\n toM = set()\n for i in range(M):\n a, b = map(int,input().split())\n if a == 1:\n fromOne.add(b)\n elif b == N:\n toM.add(a)\n return 'POSSIBLE' if fromOne & toM else 'IMPOSSIBLE'\nprint(main())", "N, M = list(map(int, input().split()))\nstart = set()\ngoal = set()\n\nfor i in range(M):\n a, b = list(map(int, input().split()))\n if(a == 1):\n start.add(b)\n elif(b == N):\n goal.add(a)\nprint((\"IMPOSSIBLE\" if(len(start & goal) == 0) else \"POSSIBLE\"))\n", "N, M = list(map(int, input().split()))\nAB = [list(map(int, input().split())) for _ in range(M)]\nres = []\nfor a, b in AB:\n if a == 1:\n res.append(b)\n if b == N:\n res.append(a)\nprint(('IMPOSSIBLE' if len(res) == len(set(res)) else 'POSSIBLE'))\n", "#\n# abc068 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"3 2\n1 2\n2 3\"\"\"\n output = \"\"\"POSSIBLE\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"4 3\n1 2\n2 3\n3 4\"\"\"\n output = \"\"\"IMPOSSIBLE\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"100000 1\n1 99999\"\"\"\n output = \"\"\"IMPOSSIBLE\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"5 5\n1 3\n4 5\n2 3\n2 4\n1 4\"\"\"\n output = \"\"\"POSSIBLE\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N, M = list(map(int, input().split()))\n S = [0] * N\n E = [0] * N\n for i in range(M):\n a, b = list(map(int, input().split()))\n if a == 1:\n S[b-1] = 1\n if b == N:\n E[a-1] = 1\n\n ans = \"IMPOSSIBLE\"\n for i in range(N):\n if S[i] == E[i] == 1:\n ans = \"POSSIBLE\"\n break\n print(ans)\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "n, m = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(m)]\n\n# n, m = 3, 2\n# a = [[1, 2], [2, 3]]\n\npot_starts = []\npot_ends = []\n\nfor i in a:\n if i[0] == 1:\n pot_starts.append(i[1])\n elif i[1] == n:\n pot_ends.append(i[0])\n\nif set(pot_starts).intersection(set(pot_ends)):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "def main():\n n, m = map(int, input().split())\n ab_lst = []\n for i in range(m):\n ab_lst.append(list(map(int, input().split())))\n\n flag = False\n lst = []\n for i in range(m):\n a = ab_lst[i][0]\n b = ab_lst[i][1]\n\n if a == 1:\n lst.append(b)\n st = set(lst)\n\n for i in range(m):\n a = ab_lst[i][0]\n b = ab_lst[i][1]\n\n if b == n:\n if a in st:\n flag = True\n break\n\n if flag:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n\n\ndef __starting_point():\n main()\n__starting_point()", "N,M = map(int,input().split())\n\nki = [list() for i in range(N)]\nfor _ in range(M):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n ki[a].append(b)\n\nK = [-1] * N\ndef dfs(now,time):\n K[now] = time\n for i in ki[now]:\n time += 1\n dfs(i,time)\n time -= 1\n\ndfs(0,0)\nprint('POSSIBLE' if K[N-1] == 2 else 'IMPOSSIBLE')", "N,M = map(int,input().split())\nI = set()\nn = set()\nfor i in range(M):\n a,b = map(int,input().split())\n if a == 1:\n I.add(b)\n if b == 1:\n I.add(a)\n if a == N:\n n.add(b)\n if b == N:\n n.add(a)\nif I & n == set():\n print(\"IMPOSSIBLE\")\nelse:\n print(\"POSSIBLE\")", "n,m = map(int,input().split())\nX = [list(map(int,input().split())) for i in range(m)]\na_list = []\nb_list = []\nfor i in range(m):\n if X[i][0] == 1:\n a_list.append(X[i][1])\n elif X[i][1] == n:\n b_list.append(X[i][0])\nc_set = set(a_list) & set(b_list)\nif len(c_set) ==0:\n print(\"IMPOSSIBLE\")\nelse:\n print(\"POSSIBLE\")", "n,m = map(int, input().split())\n\nre = [[] for i in range(n+1)]\nfor i in range(m):\n a,b = map(int, input().split())\n re[a].append(b)\n re[b].append(a)\n \nreach = [0]*(n+1)\nreach[1] = 1\nfor i in re[1]:\n if reach[i] == 0:\n for j in re[i]:\n reach[j] = 1\n\nif reach[n] == 1:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "import typing\nfrom typing import Deque, Set, Dict\n\nclass Island:\n def __init__(self, id: int) -> None:\n self.id: int = id\n self.connection: List['Island'] = []\n self.rank: int = 0\n \n def addConnection(self, other: 'Island') -> None:\n self.connection.append(other)\n other.connection.append(self)\n\n def setRank(self, other: 'Island') -> None:\n self.rank = other.rank +1\n\nclass Islands(Dict[int, Island]):\n def __init__(self, num: int):\n for id in range(1, num+1):\n self[id] = Island(id)\n\ndef bfs(root: Island, max_depth: int) -> None:\n reserved: Deque[Island] = Deque([root])\n seen: Set[int] = {root.id}\n while len(reserved) != 0:\n current: Island = reserved.popleft()\n if current.rank > max_depth:\n break\n for connected in current.connection:\n if connected.id in seen:\n continue\n connected.setRank(current)\n seen.add(connected.id)\n reserved.append(connected)\n\ndef main() -> None:\n with open(0) as f:\n N, M = map(int, f.readline().split())\n ab = [map(int, line.split()) for line in f.readlines()]\n #\u8af8\u5cf6\u751f\u6210\n islands: Islands = Islands(N)\n #\u8af8\u5cf6\u9593\u5b9a\u671f\u4fbf\u751f\u6210\n for a, b in ab:\n islands[a].addConnection(islands[b])\n #bfs\n bfs(islands[1], 2)\n #\u51fa\u529b\n print('POSSIBLE' if islands[N].rank in (1, 2) else 'IMPOSSIBLE')\n\n\ndef __starting_point():\n main()\n__starting_point()", "import typing\nfrom typing import Deque, Set, Dict\n\nclass Island:\n def __init__(self, id: int) -> None:\n self.id: int = id\n self.connection: List['Island'] = []\n self.parent: 'Island' = None\n self.rank: int = 0\n \n def addConnection(self, other: 'Island') -> None:\n self.connection.append(other)\n other.connection.append(self)\n\n def setAsRoot(self):\n self.parent = self\n \n def setParent(self, other: 'Island') -> None:\n self.parent = other\n self.rank = other.rank +1\n\nclass Islands(Dict[int, Island]):\n def __init__(self, num: int):\n for id in range(1, num+1):\n self[id] = Island(id)\n\ndef bfs(root: Island, max_depth: int) -> None:\n root.setAsRoot()\n reserved: Deque[Island] = Deque([root])\n seen: Set[int] = {root.id}\n while len(reserved) != 0:\n current: Island = reserved.popleft()\n if current.rank > max_depth:\n break\n for connected in current.connection:\n if connected.id in seen:\n continue\n connected.setParent(current)\n seen.add(connected.id)\n reserved.append(connected)\n\ndef main() -> None:\n with open(0) as f:\n N, M = map(int, f.readline().split())\n ab = [map(int, line.split()) for line in f.readlines()]\n #\u8af8\u5cf6\u751f\u6210\n islands: Islands = Islands(N)\n #\u8af8\u5cf6\u9593\u5b9a\u671f\u4fbf\u751f\u6210\n for a, b in ab:\n islands[a].addConnection(islands[b])\n #bfs\n bfs(islands[1], 2)\n #\u51fa\u529b\n print('POSSIBLE' if islands[N].rank in (1, 2) else 'IMPOSSIBLE')\n\n\ndef __starting_point():\n main()\n__starting_point()", "n, m = map(int, input().split())\nab = [list(map(int, input().split())) for i in range(m)]\nl = [[] for i in range(n)]\nab.sort()\nfor i in range(m):\n x = ab[i]\n l[x[0]-1].append(x[1]-1)\n l[x[1]-1].append(x[0]-1)\nfor i in l[0]:\n if n-1 in l[i]:\n print(\"POSSIBLE\")\n return\nprint(\"IMPOSSIBLE\")", "N,M=map(int,input().strip().split())\ndp=[0 for _ in range(N)]\nfind=False\nfor _ in range(M):\n a,b=map(int,input().strip().split())\n if a==1:\n dp[b-1]+=1\n elif a==N:\n dp[b-1]+=1\n if b==1:\n dp[a-1]+=1\n elif b==N:\n dp[a-1]+=1\n if dp[a-1]==2 or dp[b-1]==2:\n find=True\n break\n\nprint(\"POSSIBLE\" if find==True else \"IMPOSSIBLE\")", "N, M = map(int, input().split())\n\nA = set()\nB = set()\n\nfor _ in range(M):\n a, b = map(int, input().split())\n if a == 1:\n A.add(b)\n if b == N:\n B.add(a)\n\nif len(A&B):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "from collections import deque\nn, m = map(int, input().split())\nE = [[] for _ in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n E[a-1].append(b-1)\n E[b-1].append(a-1)\ndis = [200000 for i in range(n)]\ndis[0] = 0\nQ = deque([0])\nwhile Q:\n now = deque.popleft(Q)\n for i in E[now]:\n if dis[i] == 200000:\n dis[i] = dis[now]+1\n deque.append(Q, i)\nprint(\"POSSIBLE\" if dis[-1] == 2 else \"IMPOSSIBLE\")", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 02:05:32 2020\n\n@author: liang\n\"\"\"\n\nN, M = map(int, input().split())\nfirst = list()\nsecond = set()\n\nfor i in range(M):\n a, b = map(int, input().split())\n if a == 1:\n first.append(b)\n if b == N:\n second.add(a)\n \nfor a in first:\n if a in second:\n print(\"POSSIBLE\")\n break\nelse:\n print(\"IMPOSSIBLE\")", "n, m = map(int, input().split())\nn -= 1\nx = [[] for _ in range(200000)]\nfor _ in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n x[a].append(b)\n\ncnt = 0\nfor i in x[0]:\n if n in x[i]:\n print(\"POSSIBLE\")\n return\nprint(\"IMPOSSIBLE\")", "from collections import defaultdict\nN, M = [int(x) for x in input().split()]\ndict = defaultdict(bool) # int/bool/list....\nfor i in range(M):\n a, b = [int(x) for x in input().split()]\n dict[(a, b)] = True\n\nfor j in range(1, N + 1):\n if dict[(1, j)] and dict[(j, N)]:\n print('POSSIBLE')\n break\nelse:\n print('IMPOSSIBLE')", "n, m = list(map(int, input().split()))\ns1 = {}\nsn = []\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n if a == 1:\n s1[b] = 1\n elif b == n:\n sn.append(a)\n\nres = False\nfor s in sn:\n if s in s1:\n res = True\n break\n\nprint(\"POSSIBLE\" if res else \"IMPOSSIBLE\")", "n,m=map(int,input().split())\nd=[[] for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1 or b==1 or a==n or b==n:\n d[a-1].append(b)\n d[b-1].append(a)\nfor i in d[n-1]:\n if 1 in d[i-1]:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "from collections import deque\n\nINF=10**20\n\nN,M=map(int,input().split())\nG=[[] for _ in range(N+1)]\nfor i in range(M):\n a,b=map(int,input().split())\n G[a].append(b)\n G[b].append(a)\n\ndef bfs(s):\n seen = [0 for i in range(N+1)]\n d = [0 for i in range(N+1)]\n todo = deque()\n seen[s]=1\n todo.append(s)\n while 1:\n if len(todo)==0:break\n a = todo.popleft()\n if d[a] >= 2:continue\n for b in G[a]:\n if seen[b] == 0:\n seen[b] = 1\n todo.append(b)\n d[b] += d[a] + 1\n return d\n\nd = bfs(1)\nif d[N] != 0 and d[N] <= 2:print('POSSIBLE')\nelse:print('IMPOSSIBLE')", "n,m = list(map(int,input().split()))\nab = [list(map(int,input().split())) for i in range(m)]\n\nren = []\n\nfor i in range(m) :\n if ab[i][0] == 1 :\n ren.append(ab[i][1])\n elif ab[i][1] == n :\n ren.append(ab[i][0])\n\nren.sort()\nif ren[0] == 1 and ren[-1] == n :\n print(\"POSSIBLE\")\nelse :\n for i in range(len(ren)-1) :\n if ren[i] == ren[i+1] :\n print(\"POSSIBLE\")\n break\n else :\n print(\"IMPOSSIBLE\")\n", "N,M=list(map(int,input().split()))\nA=[[] for _ in range(N+1)]\nfor _ in range(M):\n a,b=list(map(int,input().split()))\n A[a].append(b)\n\nans=False\nfor i in A[1]:\n if i==N:\n ans=True\n break\n for j in A[i]:\n if j==N:\n ans=True\n break\nprint((\"POSSIBLE\" if ans else \"IMPOSSIBLE\" ))\n", "n,m=map(int,input().split())\ndata=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1:\n data[b-1]+=1\n if data[b-1]==2:\n print('POSSIBLE')\n return\n if b==n:\n data[a-1]+=1\n if data[a-1]==2:\n print('POSSIBLE')\n return\n\nprint('IMPOSSIBLE')", "from _collections import deque\nn,m=list(map(int,input().split()))\nedg=[[] for i in range(n+1)]\nfor i in range(m):\n a,b=list(map(int,input().split()))\n edg[a].append(b)\n edg[b].append(a)\ndep=[-1]*(n+1)\ndep[1]=0\ndata=deque([1])\nwhile len(data)>0:\n p=data.popleft()\n for i in edg[p]:\n if dep[i]==-1:\n dep[i]=dep[p]+1\n data.append(i)\nprint((\"POSSIBLE\" if dep[n]==2 else \"IMPOSSIBLE\"))\n\n", "n,m=[int(i) for i in input().split()]\n\nhyou=[]\n\nfor i in range(m):\n hyou.append([int(i) for i in input().split()])\n\n\nnext_island=set()\npre_island=set()\nfor go in hyou:\n one,two=go\n newone=min(one,two)\n newtwo=max(one,two)\n\n if newone==1:\n next_island.add(newtwo)\n if newtwo==n:\n pre_island.add(newone)\n\nans=next_island&pre_island\n\nif len(ans)==0:\n print(\"IMPOSSIBLE\")\nelse:\n print(\"POSSIBLE\")\n", "# -*- coding: utf-8 -*-\n\n\ndef main():\n import sys\n input = sys.stdin.readline\n\n n, m = list(map(int, input().split()))\n first = list()\n second = list()\n\n for i in range(m):\n ai, bi = list(map(int, input().split()))\n\n if ai == 1:\n first.append(bi)\n\n if bi == n:\n second.append(ai)\n\n ans = set(first) & set(second)\n\n if len(ans) > 0:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n,m=map(int,input().split())\nx=[0]*n\ns=0\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1:\n if x[b-1]==0:\n x[b-1]=1\n elif x[b-1]==-1:\n s+=1\n elif b==n:\n if x[a-1]==0:\n x[a-1]=-1\n elif x[a-1]==1:\n s+=1\nif s>0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "N,M = map(int,input().split())\nAB = [tuple(map(int,input().split())) for i in range(M)]\n\ns1 = set()\nsn = set()\nfor a,b in AB:\n if a==1:\n s1.add(b)\n if b==N:\n sn.add(a)\n\nprint('POSSIBLE' if s1&sn else 'IMPOSSIBLE')", "n,m = list(map(int,input().split()))\ne = [list() for _ in range(n)]\nfor i in range(m):\n a,b = list(map(int,input().split()))\n e[a-1].append(b-1)\n e[b-1].append(a-1)\n\nvisited = [float(\"inf\")]*n\nvisited[0]=0\nfrom collections import deque\nqueue = deque()\nqueue.append([0,0])\n\nwhile queue:\n v,d = queue.popleft()\n for k in e[v]:\n if visited[k]==float(\"inf\"):\n visited[k]=d+1\n queue.append([k,d+1])\n #print(visited)\nif visited[n-1]<=2:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n\n", "N,M = map(int,input().split())\nab = [list(map(int,input().split())) for _ in range(M)]\n\ndic = {}\nfor (a, b) in ab:\n if a in dic.keys():\n dic[a].append(b)\n else:\n dic[a] = [b]\n \ncheck = False\nfor i in dic[1]:\n if i in dic.keys():\n for j in dic[i]:\n if j == N:\n check = True\n\nprint(\"POSSIBLE\" if check else \"IMPOSSIBLE\") ", "n, m = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(m)]\n\n# n, m = 3, 2\n# a = [[1, 2], [2, 3]]\n\npot_starts = []\npot_ends = []\n\nfor i in a:\n if i[0] == 1:\n pot_starts.append(i[1])\n elif i[1] == n:\n pot_ends.append(i[0])\n\nif set(pot_starts).intersection(pot_ends):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "L=list()\nR=list()\nN,M=map(int,input().split())\nfor i in range(M):\n a,b=map(int,input().split())\n if a==1:\n L.append(b)\n elif b==1:\n L.append(a)\n if a==N:\n R.append(b)\n elif b==N:\n R.append(a)\nL=set(L)\nR=set(R)\nif len(L&R)==0:\n print(\"IMPOSSIBLE\")\nelse:\n print(\"POSSIBLE\")", "import sys\nreadline = sys.stdin.readline\n\nN,M = map(int,readline().split())\nG = [[] for i in range(N)]\n\nfor i in range(M):\n a,b = map(int,readline().split())\n G[a - 1].append(b - 1)\n G[b - 1].append(a - 1)\n \nfor child in G[0]:\n for gchild in G[child]:\n if gchild == N - 1:\n print(\"POSSIBLE\")\n return\nprint(\"IMPOSSIBLE\") ", "n, m = list(map(int, input().split()))\na = [0] * m\nb = [0] * m\nfor i in range(m):\n a[i], b[i] = list(map(int, input().split()))\n'''\ncheck = 0\n\n\nfor i in range(m):\n if a[i] == 1:\n check = b[i]\n for j in range(m):\n if a[j] == check and b[j] == n:\n print(\"POSSIBLE\")\n return\n\nprint(\"IMPOSSIBLE\")\n\n'''\nstart = []\nleave = []\nfor i in range(m):\n if a[i] == 1:\n start.append(b[i])\n elif b[i] == n:\n leave.append(a[i])\n\nif set(start) & set(leave):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "n, m = list(map(int, input().split()))\nroot_map = dict()\nroot_map[1] = set()\nroot_map[n] = set()\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n if a == 1 or a == n:\n root_map[a].add(b)\n if b == 1 or b == n:\n root_map[b].add(a)\n\nfor i in root_map[1]:\n if i in root_map[n]:\n print(\"POSSIBLE\")\n break\nelse:\n print(\"IMPOSSIBLE\")\n", "N,M = map(int,input().split())\nN_List = []\nO_List = []\n\nfor i in range(M):\n a,b = map(int,input().split())\n if a == 1:\n N_List.append(b)\n if b == 1:\n N_List.append(a)\n if a == N:\n O_List.append(b)\n if b == N:\n O_List.append(a)\n\nprint((\"IMPOSSIBLE\",\"POSSIBLE\")[len(set(N_List) & set(O_List)) > 0])", "n,m = map(int,input().split())\ns=[False]*n\nt=[False]*n\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1:\n s[b-1]=True\n if b==n:\n t[a-1]=True\nfor i in range(n):\n if s[i]==True and t[i]==True:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "import collections\nn, m = list(map(int, input().split()))\nvisited = [False]*n\nships = [set() for i in range(n)]\nfor i in range(m):\n a, b = list(map(int, input().split()))\n ships[a-1].add(b-1)\n ships[b-1].add(a-1)\n\nfor i in range(1,n-1):\n if 0 in ships[i] and n-1 in ships[i]:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')\n", "n,m=map(int,input().split())\nans1=[]\nans2=[]\nfor _ in range(m):\n a,b=map(int,input().split())\n if a==1:\n ans1.append(b)\n if b==n:\n ans2.append(a)\n \nans=set(ans1)&set(ans2)\nif len(ans)>0:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "n,m=map(int,input().split())\ndata=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n if a==1:\n data[b-1]+=1\n if data[b-1]==2:\n print('POSSIBLE')\n return\n if b==n:\n data[a-1]+=1\n if data[a-1]==2:\n print('POSSIBLE')\n return\nprint('IMPOSSIBLE')", "#!/usr/bin/env python3\n\ndef main():\n n, m = list(map(int, input().split()))\n ab = [list(map(int, input().split())) for i in range(m)]\n ans = \"IMPOSSIBLE\"\n list_1 = []\n list_n = []\n for i in range(m):\n if ab[i][0] == 1:\n list_1.append(ab[i][1])\n elif ab[i][1] == n:\n list_n.append(ab[i][0])\n if len(set(list_1) & set(list_n)) > 0:\n ans = \"POSSIBLE\"\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys\n\nn,m=list(map(int,input().split()))\nl=[[] for i in range(n)]\n\nfor i in range(m):\n a,b=list(map(int,input().split()))\n l[a-1].append(b)\n# print(l)\n\n\nfor i in l[0]:\n for j in l[i-1]:\n if j==n:\n print(\"POSSIBLE\")\n return\n\nprint(\"IMPOSSIBLE\")\n\n", "n,m = map(int, input().split())\nb1 = []\nb2 = []\nfor i in range(m):\n a,b = map(int, input().split())\n if a == 1:\n b1.append(b)\n if b == n:\n b2.append(a)\nif len(b1) + len(b2) == len(list(set(b1+b2))):\n print('IMPOSSIBLE')\nelse:\n print('POSSIBLE')", "n,m = list(map(int,input().split()))\ngraph= dict()\nfor i in range(m):\n a,b = list(map(int,input().split()))\n if(graph.get(a,-1)==-1):\n graph[a] = [b]\n else:\n graph[a].append(b)\n if (graph.get(b, -1) == -1):\n graph[b] = [a]\n else:\n graph[b].append(a)\n\nq=[]\nq.append((1,0))\nvisited = dict()\nvisited[1] = 1\nans = \"IMPOSSIBLE\"\nwhile(len(q) != 0):\n front,d = q[0]\n q.pop(0)\n if(d>2):\n break\n if(front == n):\n ans = \"POSSIBLE\"\n break\n lst = graph.get(front,0)\n if(lst == 0):\n continue\n else:\n for i in lst:\n if(visited.get(i,-1)==-1):\n q.append((i,d+1))\nprint(ans)\n\n\n\n\n", "n,m = map(int,input().split())\nstart = [0]*200001\ngoal = [0]*200001\n\nfor i in range(m):\n a,b = map(int,input().split())\n if a == 1:\n if goal[b] == 1:\n print(\"POSSIBLE\")\n return\n start[b] = 1\n a\n elif b == n:\n if start[a] == 1:\n print(\"POSSIBLE\")\n return\n goal[a] = 1\nprint(\"IMPOSSIBLE\")"] | {"inputs": ["3 2\n1 2\n2 3\n", "4 3\n1 2\n2 3\n3 4\n", "100000 1\n1 99999\n", "5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n"], "outputs": ["POSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "POSSIBLE\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 44,518 | |
9becff11b5ca3621829bdf4e43b02348 | UNKNOWN | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
-----Constraints-----
- Each character in s is a lowercase English letter.
- 1β€|s|β€10^5
-----Input-----
The input is given from Standard Input in the following format:
s
-----Output-----
Print the string obtained by concatenating all the characters in the odd-numbered positions.
-----Sample Input-----
atcoder
-----Sample Output-----
acdr
Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr. | ["s = input()\ni = 0\nanswer = str()\nfor j in s:\n if i % 2 == 0:\n answer += j\n i += 1\nprint(answer)", "S = input()\n\nprint(S[0:len(S):2])", "s = input()\nfor i in range(0, len(s), 2):\n print(s[i], end='')\nprint()\n", "s = input()\nprint(s[0::2])", "s = input()\n# \u6587\u5b57\u5217[::2]\u3067\u5148\u982d\u304b\u3089\u898b\u3066\u5947\u6570\u500b\u76ee\u306e\u6587\u5b57\u306e\u307f\u53d6\u5f97\u3067\u304d\u308b\nprint(s[::2])", "a = list(input())\na_135 = a[0::2]\nmojiretu = ''.join(a_135)\nprint(mojiretu)", "s = input()\nprint(s[::2])", "s = str(input())\n\nfor i in range(len(s)):\n if i % 2 == 0:\n print(s[i], end = '') #end\u306e\u5165\u308c\u65b9\u304c\u307e\u3060\u3088\u304f\u308f\u304b\u3089\u3093", "s = input()\n\nprint(s[::2])", "class Odd:\n def __init__(self,s:str):\n self.s=s\n\n def odd_str(self):\n m=[]\n l=int(len(self.s))\n for i in range(0,l,2):\n m.append(self.s[i])\n print(''.join(m))\n\nodd1=Odd(input())\nodd1.odd_str()", "S = list(input())\n\nnew_list = \"\"\n\nfor i in range(len(S)):\n if i % 2 == 0:\n new_list += S[i]\n\nprint(new_list)", "S = input()\n \nprint(S[0:len(S):2])", "s = input()\n\nN = len(s)\nresult = []\n\nfor i in range(0, N):\n if i == 0 or i % 2 == 0:\n result.append(s[i])\n\ns = ''\nN = len(result)\n\nfor i in range(0, N):\n s += result[i]\n\nprint(s)\n", "s = input()\nprint(s[::2])", "s = input()\nprint(s[::2])", "s = input()\n\nN = len(s)\nresult = []\n\nfor i in range(0, N):\n if i == 0 or i % 2 == 0:\n result.append(s[i])\n\ns = ''\nN = len(result)\n\nfor i in range(0, N):\n s += result[i]\n\nprint(s)", "s = input()\nprint(s[::2])", "S = str(input())\nprint(S[0::2])", "print(input()[::2])", "# abc072B\n# https://atcoder.jp/contests/abc072/tasks/abc072_b\n\n# \u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217 s\n# \u524d\u304b\u3089\u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u3092\u629c\u304d\u51fa\u3057\u6587\u5b57\u5217\u3092\u51fa\u529b\n# \u5148\u982d\u306e\u6587\u5b57\u3092\uff11\u6587\u5b57\u76ee\u3068\u3059\u308b\n\n\n# \u5165\u529b\ns = str(input())\n\n# \u51e6\u7406\n# \u5947\u6570\u756a\u76ee\u6587\u5b57\u306e\u629c\u304d\u51fa\u3057\nprint((s[::2]))\n", "s = input()\nprint(s[0::2])", "\nS = str(input())\n\nprint((S[::2]))\n\n", "s = input()\na = ''\nfor i in range(0, len(s), 2):\n a = a + s[i]\nprint(a)", "s = input()\n\nans = [i for index, i in enumerate(s, start = 1) if index % 2 != 0]\nprint(\"\".join(ans))", "\n\nN = list(input())\nans = []\nfor i in range(len(N)):\n if i % 2 == 0:\n ans.append(N[i])\nprint((\"\".join(ans)))\n", "s=input()\nb=\"\"\nfor a in range(len(s)):\n if a%2==0:\n b=b+s[a]\nprint(b)\n\n", "# \u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217 s\u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\n# \u524d\u304b\u3089\u6570\u3048\u3066\u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u629c\u304d\u51fa\u3057\u3066\u4f5c\u3063\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n# \u305f\u3060\u3057\u3001\u6587\u5b57\u5217\u306e\u5148\u982d\u306e\u6587\u5b57\u30921\u6587\u5b57\u76ee\u3068\u3057\u307e\u3059\u3002\n\n# s\uff08\u6587\u5b57\u5217\uff09\uff1a\u6a19\u6e96\u5165\u529b\ns = str(input())\nprint(s[::2])", "s = input()\n\nprint(s[::2])", "s = input() # \u5165\u529b\u6587\u5b57\u5217\u3092s\u306b\u683c\u7d0d\nletters = '' # \u51fa\u529b\u7528\u5909\u6570\u3092\u7528\u610f\n\nfor i, letter in enumerate(s): # s\u30921\u6587\u5b57\u305a\u3064\u3001i\uff08\u4f55\u6587\u5b57\u76ee\u304b\uff09\u3068letter\uff081\u6587\u5b57\uff09\u306b\u5165\u308c\u308b\n if i % 2 == 0: # \u4f55\u6587\u5b57\u76ee\u304b\u3000\u306e\u5947\u6570\u3068\u5076\u6570\u3092\u5224\u5b9a\uff1b2\u3067\u5272\u3063\u3066\u4f59\u308a\u304c\u3042\u308c\u3070\u5947\u6570\u3060\u304c\u3001i\u306f0\u304b\u3089\u59cb\u307e\u308b\u306e\u3067\u5076\u6570\u306e\u3068\u304d\u306b\n letters += letter # letters\u306b\u5165\u308c\u3066\u3044\u304f\n\nprint(letters)", "s = input()\nres = \"\"\nfor i in range(len(s)):\n if i % 2 == 0:\n res += s[i]\nprint(res)", "print((input()[::2]))\n#[::x]...\u6587\u5b57\u5217\u306ex\u306e\u500d\u6570\u306e\u6587\u5b57\u3092\u6392\u9664\n", "s = input()\nli = []\nfor i in range(len(s)):\n if i % 2 == 0:\n li.append(s[i])\nprint((''.join(li)))\n", "import math\na = input()\nx = \"\"\nfor i in range(math.ceil(len(a)/2)):\n x += a[i*2]\nprint(x)", "s=input()\nodd_num=list()\n \nfor i in range(len(s)):\n if i % 2 == 0:\n odd_num.append(s[i])\n \nanswer=\"\".join(odd_num)\n \nprint(answer)", "s = str(input())\nprint(s[::2])", "s = list(input())\n\nprint(''.join(s[0::2]))", "s = str(input())\n\n# \u524d\u304b\u3089\u6570\u3048\u3066\u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u629c\u304d\u51fa\u3057\u3066\u4f5c\u3063\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u305b\u3088\u3002\n\nprint(s[::2])", "s = input()\n\nN = len(s)\nresult = []\n\nfor i in range(0, N):\n if i == 0 or i % 2 == 0:\n result.append(s[i])\n\ns = ''\nN = len(result)\n\nfor i in range(0, N):\n s += result[i]\n\nprint(s)", "S = input()\nS1 = '0' + S\nprint(S1[1::2])", "print(input()[::2])", "s = input()\neven = []\n\ndef listtostring(some):\n str1 = \"\"\n\n for ele in some:\n str1 += ele\n\n print(str1)\n\nfor i in range(len(s)):\n moji = s[i]\n if i % 2 == 0:\n even.append(moji)\n\nlisttostring(even)", "s=input()\n# \u6587\u5b57\u5217[0::2]\u3067\u5148\u982d\u304b\u3089\u5947\u6570\u756a\u76ee\u3001[1::2]\u3067\u5076\u6570\u756a\u76ee\u306e\u6587\u5b57\u3092\u53d6\u5f97\u3067\u304d\u308b\u3089\u3057\u3044\nprint(s[0::2])", "s = input()\n\n# \u6587\u5b57\u5217[::2]\u306f\u3001\u5148\u982d\u304b\u3089\u5947\u6570\u6587\u5b57\u76ee\u306e\u307f\u53d6\u5f97\u3067\u304d\u308b\u3002\nprint(s[::2])", "s = list(input())\nprint(''.join(s[0::2]))", "# -*- coding: utf-8 -*-\n\nS = list(input())\nS.insert(0,'0')\n\nfor i in range(1,len(S),2):\n print(S[i],end=\"\")\n\nprint()\n\n\n\n\n\n\n", "S = list(input())\nN = len(S)\nans = []\nfor i in range(N):\n if i % 2 == 0:\n ans.append(S[i])\nans = ''.join(ans)\nprint(ans)", "words = str(input())\nprint(words[0::2])", "s = str(input())\nans = ''\n\nfor i in range(len(s)):\n if i % 2 == 0:\n ans = ans + s[i]\n\nprint(ans)", "# ac_072_b\n# \u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217S\n# \u524d\u304b\u3089\u6570\u3048\u3066\u5947\u6570\u6587\u5b57\u5217\u76ee\u3060\u3051\u629c\u304d\u51fa\u3057\u3066\u4f5c\u3063\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u3002\n# \u6587\u5b57\u5217\u306e\u5148\u982d\u306e\u6587\u5b57\u3092\uff11\u6587\u5b57\u76ee\u3068\u3059\u308b\u3002\n\ns = input()\n\n# [0::2]\uff10\u756a\u76ee\u306f\u3058\u3081\u30662\u3064\u523b\u307f\u306e\u610f\u5473[0,1,2,3,4,5]\u306e\u5834\u5408[0,2,4,]=\u5947\u6570\u756a\u76ee\u306b\u306a\u308b\u3002\n# [1::2]\uff11\u756a\u76ee\u3081\u304b\u3089\u306f\u3058\u3081\u3066\uff12\u3064\u523b\u307f[0,1,2,3,4,5]\u306e\u5834\u5408[1,3,5]=\u5076\u6570\u756a\u76ee\u306b\u306a\u308b\u3002\n# \u5947\u6570\u756a\u76ee\u306e\u307f\u62bd\u51fa\u3057\u305f\u3044\u5834\u5408\u3002\nprint((s[0::2]))\n", "s = input()\nprint(s[::2])", "s = input()\n\nprint(s[::2])", "str = input()\nprint(str[::2])", "S = str(input())\n\nprint(S[::2])", "result = \"\"\nfor i, c in enumerate(list(input())):\n if i % 2 == 0:\n result += c\n\nprint(result)\n", "s = input()\nx = ''\nfor i in range(0, len(s)):\n if i % 2 == 0:\n x = x + s[i]\nprint(x)", "s = input()\n\nn = (len(s) + 1) // 2\n\nans = ''\n\nfor i in range(n):\n ans += s[2 * i]\n\nprint(ans)", "print(input()[::2])", "s = input()\na = ''\nfor i in range(0, len(s), 2):\n a = a + s[i]\nprint(a)", "# B - OddString\n\n# s\ns = input()\nj = 0\nm = ''\nfor i in s:\n j += 1\n if j % 2 == 1:\n m += i\n\nprint(m)\n\n", "s = str(input())\nS = s[0::2]\nprint(S)", "s = input()\nans = ''\nfor i in range(len(s)):\n if i % 2 == 0:\n ans += s[i]\n \nprint(ans)", "s = input()\nprint(\"\".join([s[i] for i in range(len(s)) if i%2==0]))", "s = list(input())\nl = int(len(s))\n\nm = []\nfor i in range(0, l, 2): \n m.append(s[i])\nprint((''.join(m)))\n", "s=input()\n\nprint((\"\".join([c for index, c in enumerate(s) if index%2==0])))\n", "#072b\n#1.\u5024\u3092\u53d7\u3051\u53d6\u308b\ns = str(input())\n\n#2.\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\nfor i in range(len(s)):\n if i % 2 == 0:\n print(s[i], end = '')", "'''\n\u554f\u984c\uff1a\n \u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217 s \u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002\n \u524d\u304b\u3089\u6570\u3048\u3066\u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u629c\u304d\u51fa\u3057\u3066\u4f5c\u3063\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n \u305f\u3060\u3057\u3001\u6587\u5b57\u5217\u306e\u5148\u982d\u306e\u6587\u5b57\u30921\u6587\u5b57\u76ee\u3068\u3057\u307e\u3059\u3002\n'''\n\n'''\n\u5236\u7d04\uff1a\n s \u306e\u5404\u6587\u5b57\u306f\u82f1\u5c0f\u6587\u5b57\n 1 \u2266 |s| \u2266 100000\n'''\n\n# \u6a19\u6e96\u5165\u529b\u304b\u3089 s \u3092\u53d6\u5f97\u3059\u308b\ns = str(input())\n\ni = 1\nresult = \"\"\nfor i in range(len(s) + 1):\n if i % 2 == 0:\n pass\n else:\n result += s[i - 1]\n\nprint(result)\n", "s = input()\nprint((s[0::2]))\n# s[\u59cb\u307e\u308a\u306e\u4f4d\u7f6e: \u7d42\u308f\u308a\u306e\u4f4d\u7f6e: \u30b9\u30e9\u30a4\u30b9\u306e\u5897\u5206]\n", "s = input()\n\nprint(\"\".join([c for index, c in enumerate(s) if index % 2 == 0]))", "s = str(input())\n \nfor i in range(len(s)):\n if i % 2 == 0:\n print(s[i], end = '')", "s = input()\n\nprint(s[0::2])", "s = input()\nprint(s[::2])", "s = input()\nans = ''\nfor i in range(0, len(s), 2):\n ans += s[i]\nprint(ans)", "s = str(input())\n\n\n\nprint(s[::2])", "s = input()\nprint(s[::2])", "s = input()\nif len(s)%2 == 0:\n f = len(s)//2\nelse:\n f = len(s)//2+1\nfor i in range(f):\n print(s[2*i],end=\"\")", "a = input().split()[0]\nb = ''\n\nfor i in range(len(a)):\n if(i % 2 == 0):\n b += a[i]\n\nprint(b)", "print(str(input())[::2])", "s = input()\ni = 0\nanswer = str()\nfor j in s:\n if i % 2 == 0:\n answer += j\n i += 1\nprint(answer)\n", "S = input()\nans = ''\nfor i, s in enumerate(S):\n if i % 2 == 0:\n ans += s\nprint(ans)\n", "s = str(input())\ndef answer(s: str) -> str:\n ans = ''\n for i in range(len(s)):\n if i % 2 == 0:\n ans += s[i]\n return ans\n\n\nprint(answer(s))", "print(input()[::2])", "\"\"\"\n\u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217 s \u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002\n\u524d\u304b\u3089\u6570\u3048\u3066\u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u629c\u304d\u51fa\u3057\u3066\u4f5c\u3063\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\u305f\u3060\u3057\u3001\u6587\u5b57\u5217\u306e\u5148\u982d\u306e\u6587\u5b57\u30921\u6587\u5b57\u76ee\u3068\u3057\u307e\u3059\u3002\n\"\"\"\n\nstr = input()\n\nprint((str[::2]))\n", "s = input()\ns.split()\nodd = []\n\nfor i in range(len(s)):\n if i % 2 == 0:\n odd.append(s[i])\nanswer = ''.join(odd)\n\nprint(answer)", "s = str(input())\n\nprint(s[::2])", "s=input()\n\nprint(s[::2])", "s = str(input())\nk = 0\nodd = \"\"\n\nfor k in range(len(s)):\n if k % 2 == 0:\n odd += s[k]\n\nprint(odd)", "s = input()\n# print(s)\nn: int = 0\nodds = \"\"\n\n\nfor i in s:\n if n % 2 == 0:\n odd = s[n]\n odds += odd\n elif n == 0:\n odd = s[n]\n odds += odd\n else:\n pass\n n += 1\n # n\u3092\u5947\u6570\u306b\u3059\u308b\nprint(odds)", "s = input()\n# \u30ea\u30b9\u30c8\uff53\u30921\u3064\u304a\u304d\u306b\u30b9\u30e9\u30a4\u30b9\nprint(s[0::2])", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\n#\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7cfb\n# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);\n# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\ns = input()\nprint((s[::2]))\n", "s = input('')\n# \u5947\u6570\u6587\u5b57\u76ee\u3060\u3051\u629c\u304d\u51fa\u3059\nprint(s[::2])", "s = input()\nfor i in range(0, len(s), 2):\n print(s[i], end=\"\")", "S = input()\ncount = 1\nstr_odd = ''\n\nfor i in S:\n if count % 2 == 1:\n str_odd += i\n count += 1\n\nprint(str_odd)\n", "s = str(input())\nprint(s[::2])", "s = input()\nans = ''\nfor i in range(0, len(s), 2):\n ans += s[i]\n\nprint(ans)", "s = input()\nprint(s[::2])", "s = input()\nres = \"\"\nfor i in range(len(s)):\n if i % 2 == 0:\n res += s[i]\nprint(res)", "# B - OddString\n\n# \u82f1\u5c0f\u6587\u5b57\u304b\u3089\u306a\u308b\u6587\u5b57\u5217s\u306e\u3001\u5947\u6570\u6587\u5b57\u76ee\u3092\u629c\u304d\u51fa\u3057\u305f\u6587\u5b57\u5217\u3092\u51fa\u529b\u3059\u308b\n# \u5148\u982d\u306e\u6587\u5b57\u30921\u6587\u5b57\u76ee\u3068\u3059\u308b\n\ns = input()\n\nprint((s[0:len(s)+1:2]))\n", "print(input()[::2])", "a=input()\nfor i in range(0,len(a),2):\n print(a[i],end=\"\")", "s = input()\n\nprint(s[0::2])"] | {"inputs": ["atcoder\n", "aaaa\n", "z\n", "fukuokayamaguchi\n"], "outputs": ["acdr\n", "aa\n", "z\n", "fkoaaauh\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 14,178 | |
2c09c14ce6685309af6326bcb7452be5 | UNKNOWN | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
- The last character in A and the initial character in B are the same.
- The last character in B and the initial character in C are the same.
If both are true, print YES. Otherwise, print NO.
-----Constraints-----
- A, B and C are all composed of lowercase English letters (a - z).
- 1 β€ |A|, |B|, |C| β€ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.
-----Input-----
Input is given from Standard Input in the following format:
A B C
-----Output-----
Print YES or NO.
-----Sample Input-----
rng gorilla apple
-----Sample Output-----
YES
They form a word chain. | ["s1,s2,s3 = input().split()\nprint(\"YES\") if s1[-1]==s2[0] and s2[-1]==s3[0] else print(\"NO\")", "a,b,c = input().split()\n\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print('YES')\nelse:\n print('NO') ", "def iroha():\n a, b, c = input().split()\n \n s = a[len(a)-1]\n sshead = b[0]\n sstail = b[len(b)-1]\n sss = c[0]\n\n if s == sshead and sstail == sss:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\n\n\n\ndef __starting_point():\n iroha()\n\n\n__starting_point()", "A, B, C = map(str, input().split())\nif A[-1] == B[0] and B[-1] == C[0]:\n result = 'YES'\nelse:\n result = 'NO'\nprint(result)", "# A - Shiritori\n\n\ndef f(x):\n f_list = []\n for i in x:\n f_list.append(i)\n return f_list\n\n\n# \u6a19\u6e96\u5165\u529b a b c\na, b, c = list(map(str, input().split(maxsplit=3)))\n\nword_list_a = f(a)\nword_list_b = f(b)\nword_list_c = f(c)\n\nif word_list_a.pop() == word_list_b[0] and word_list_b.pop() == word_list_c[0]:\n print('YES')\nelse:\n print('NO')\n", "A, B, C = input().split()\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c=map(str,input().split())\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A, B, C = input().split()\n\nprint(\"YES\" if A[-1] == B[0] and B[-1] == C[0] else \"NO\")", "'''\nabc060 A - Shiritori\nhttps://atcoder.jp/contests/abc060/tasks/abc060_a\n'''\n\ns = list(input().split())\nif s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:\n ans = 'YES'\nelse:\n ans = 'NO'\nprint(ans)\n", "a,b,c = map(str,input().split())\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A,B,C = input().split()\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c = input().split()\n\nA = list(a)\nB = list(b)\nC = list(c)\n\nif A[len(A) -1 ] == B[0] and B[len(B)-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A,B,C = map(str,input().split())\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "A,B,C = input().split()\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "A, B, C = input().split()\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c = input().split()\nif a [-1] == b[0] and b[-1] == c [0]:\n print('YES')\nelse:\n print('NO')", "s=input().split()\nprint(\"YES\" if all(s[i][-1]==s[i+1][0] for i in range(len(s)-1)) else \"NO\")", "a,b,c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "'''\n\u554f\u984c\uff1a\n \u6587\u5b57\u5217 A, B, C\u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002\n \u3053\u308c\u304c\u3057\u308a\u3068\u308a\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u5224\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n \u3064\u307e\u308a\u3001\n A \u306e\u6700\u5f8c\u306e\u6587\u5b57\u3068 B \u306e\u6700\u521d\u306e\u6587\u5b57\u304c\u540c\u3058\n B \u306e\u6700\u5f8c\u306e\u6587\u5b57\u3068 C \u306e\u6700\u521d\u306e\u6587\u5b57\u304c\u540c\u3058\n \u3053\u306e 2\u3064\u304c\u6b63\u3057\u3044\u304b\u5224\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n \u4e21\u65b9\u3068\u3082\u6b63\u3057\u3044\u306a\u3089\u3070 YES\u3001\u305d\u3046\u3067\u306a\u3044\u306a\u3089\u3070 NO \u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n'''\n\n'''\n\u5236\u7d04\uff1a\n A, B, C \u306f\u5168\u3066\u82f1\u5c0f\u6587\u5b57(a ~ z)\u304b\u3089\u306a\u308b\u3002\n 1 \u2266 |A|, |B|, |C| \u2266 10\n \u306a\u304a\u3001\n |A|, |B|, |C| \u306f\u6587\u5b57\u5217A, B, C\u306e\u9577\u3055\u3092\u8868\u3057\u307e\u3059\u3002\n'''\n\n# \u6a19\u6e96\u5165\u529b\u304b\u3089 A, B, C \u3092\u53d6\u5f97\u3059\u308b\na, b, c = list(map(str, input().split()))\n\nresult = 'ret'\n\nif ( a[-1] == b[0] ) and (b[-1] == c[0]) :\n result = 'YES'\nelse:\n result = 'NO'\n\nprint(result)\n", "# A - Shiritori\n# https://atcoder.jp/contests/abc060/tasks/abc060_a\n\na, b, c = list(map(str, input().split()))\n\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')\n", "A, B, C = list(map(str,input().split()))\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')\n", "A, B, C = input().split()\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:print('YES')\nelse:print('NO')", "a,b,c=map(str,input().split())\n\nif a[len(a)-1]==b[0] and b[len(b)-1]==c[0]:\n ans=\"YES\"\nelse:\n ans=\"NO\"\nprint(ans)", "A,B,C = list(map(str,input().split()))\n\nif A[-1] == B[0] and B[-1] == C[0]:\n result = \"YES\"\nelse:\n result = \"NO\"\n\nprint(result)\n", "A, B, C = input().split()\n\nprint(\"YES\" if A[-1] == B[0] and B[-1] == C[0] else \"NO\")", "A, B, C = input().split()\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "A, B, C = map(str, list(input().split())) # \u6587\u5b57\u5217\u3092\u4e00\u6587\u5b57\u305a\u3064\u306e\u30ea\u30b9\u30c8\u5316\u3057\u8907\u6570\u306e\u30ea\u30b9\u30c8\u306b\u5165\u308c\u308b\n\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c = input().split()\nprint(\"YES\" if a[-1]==b[0] and b[-1]==c[0] else \"NO\")", "\ndef resolve():\n a, b, c = input().split()\n print(('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO'))\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "s = [x for x in input().split()]\nif s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A, B, C = list(input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c = input().split()\n\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "\nA,B,C = map(str,input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\n\nelse:\n print('NO')", "A,B,C = input().split()\nprint(['NO','YES'][A[-1:]==B[0] and B[-1:]==C[0]])", "a, b, c = map(str, input().split())\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "import sys, math\nfrom itertools import combinations as c, product as p\nfrom collections import deque\nsys.setrecursionlimit(10**9)\nINF = float('inf')\nMOD = 10**9 + 7\n#MOD = 998244353\n\n\ndef si(): return input()\ndef ii(): return int(input())\ndef fi(): return float(input())\ndef lstr(): return input().split()\ndef lint(): return list(map(int, input().split()))\ndef lintdec(): return list(map(lambda x:int(x) - 1, input().split()))\ndef lnstr(n): return [input() for _ in range(n)]\ndef lnint(n): return [int(input()) for _ in range(n)]\ndef lint_list(n): return [lint() for _ in range(n)]\n\n\n\n############################################################\nA, B, C = lstr()\nprint('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "#60\nA,B,C=input().split()\nif A[-1]==B[0] and B[-1]==C[0]:\n print('YES')\nelse:\n print('NO')\n", "a, b, c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "A,B,C=map(str,input().split())\nif A[-1]==B[0] and B[-1]==C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a, b, c = input().split()\nprint(('YES', 'NO')[a[-1] + c[0] != b[0] + b[-1]])", "a, b, c = input().split()\nprint(\"YES\" if a[-1] == b[0] and b[-1] == c[0] else \"NO\")", "a, b, c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "A, B, C = map(str, input().split())\n\nA_num = len(A)\nB_num = len(B)\nif A[A_num - 1] == B[0] and B[B_num - 1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a, b, c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A,B,C = map(str, input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print('YES')\nelse:\n print('NO')", "A, B, C = open(0).read().split()\nprint('YES' if (A[len(A)-1] == B[0]) and (B[len(B)-1] == C[0]) else 'NO')", "A, B, C=input().split(\" \")\n\nif A[len(A)-1]==B[0] and B[len(B)-1]==C[0]:\n print('YES')\nelse:\n print('NO')", "A, B, C = map(str, input(). split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "A, B, C = map(str, input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c=input().split()\nprint(\"YES\" if a[-1]==b[0]and b[-1]==c[0] else \"NO\")", "a, b, c = input().split()\n\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c = input().split()\nlen_a = len(a)\nlen_b = len(b)\n\nif(a[len_a-1] == b[0] and b[len_b-1] == c[0]):\n print(\"YES\")\nelse:\n print(\"NO\")", "a, b, c = input().split()\nprint('YES' if a[-1]==b[0] and b[-1]==c[0] else 'NO')", "A,B,C = input().split()\nprint(\"YES\" if A[-1] == B[0] and B[-1] == C[0] else \"NO\")", "A, B, C = map(str, input(). split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print( \"YES\" )\nelse:\n print( \"NO\" )", "A, B, C = input().split()\n\ndef answer(A: int, B: int, C: int) -> str:\n if A[-1] == B[0] and B[-1] == C[0]:\n return 'YES'\n else:\n return 'NO'\n\nprint((answer(A, B, C)))\n", "a,b,c=map(str,input().split())\n\nprint('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO')", "a, b, c = map(str, input().split())\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c = input().split()\n\nif (a[-1] == b[0]) and (b[-1] == c[0]):\n print('YES')\nelse:\n print('NO')\n", "s = (input().split())\nt = len(s)\ncnt = 0\nfor i in range(t):\n if i != t - 1:\n if (s[i][-1]) == s[i + 1][0]:\n cnt += 1\n else:\n break\n\nif cnt == t - 1:print(\"YES\")\nelse:print(\"NO\")", "A, B, C = input().split()\nif A[len(A)-1:len(A)] == B[0:1] and B[len(B)-1:len(B)] == C[0:1]:\n print('YES')\nelse:\n print('NO')\n", "a,b,c = input().split()\n# \u3057\u308a\u3068\u308a\u304c\u6210\u308a\u7acb\u3063\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "# 060_a\nA, B, C = input().split()\n\nif (1<=len(A) and len(A)<=10 and A.islower()) and (1<=len(B) and len(B)<=10 and B.islower())\\\n and (1<=len(C) and len(C)<=10 and C.islower()):\n if (A[len(A) - 1] == B[0]) and (B[len(B) - 1] == C[0]):\n print('YES')\n else:\n print('NO')\n", "A,B,C = list(map(str,input().split()))\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')\n\n", "A, B, C = map(str, input().split())\n\n# \u6587\u5b57\u5217 A,B,C\u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002\u3053\u308c\u304c\u3057\u308a\u3068\u308a\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u5224\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n# \u6b63\u3057\u3044\u306a\u3089\u3070 YES\u3001\u305d\u3046\u3067\u306a\u3044\u306a\u3089\u3070 NO \u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "# \u6570\u5024\u3092\u53d6\u5f97\nword_list = input().split()\nw_cnt = len(word_list)\n\n# \u8a9e\u982d\u8a9e\u5c3e\u306e\u62bd\u51fa\ns_list = []\ne_list = []\nfor cnt in range(0,w_cnt,1):\n s_list.append(word_list[cnt][0])\n e_list.append(word_list[cnt][-1])\n\n# \u6210\u7acb\u3057\u3066\u308b\u304b\u691c\u67fb\u5f8c\u7d50\u679c\u3092\u51fa\u529b\njudge = \"YES\"\nfor cnt in range(1,w_cnt,1):\n if s_list[cnt] != e_list[cnt-1]:\n judge = \"NO\"\nprint(judge)", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a, b, c = map(str, input().split())\n\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "def atc_060a(input_value: str) -> str:\n A, B, C = list(map(str, input_value.split(\" \")))\n if A[-1] == B[0] and B[-1] == C[0]:\n return \"YES\"\n else:\n return \"NO\"\n\ninput_value = input()\nprint((atc_060a(input_value)))\n", "a,b,c = input().split()\nif a[len(a) -1] == b[0] and b[len(b) -1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print('YES')\nelse:\n print('NO')", "a, b, c = input().split()\n\nif a[-1]==b[0] and b[-1]==c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "A,B,C=input().split()\nif A[-1]==B[0] and B[-1]==C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "def atc_060a(input_value: str) -> str:\n A, B, C = map(str, input_value.split(\" \"))\n if A[-1] == B[0] and B[-1] == C[0]:\n return \"YES\"\n else:\n return \"NO\"\n\ninput_value = input()\nprint(atc_060a(input_value))", "a, b, c = list(map(str, input().split()))\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse:\n print('NO')\n", "a,b,c = input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A, B, C = map(str, input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "# A \u306e\u672b\u3068B \u306e\u982d\u6587\u5b57\u3001B \u306e\u672b\u3068C \u306e\u982d\u6587\u5b57\u304c\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\n\nA, B, C = list(map(str, input().split()))\n\ninitial_1 = A[-1]\nend_1 = B[0]\ninitial_2 = B[-1]\nend_2 = C[0]\n\nif initial_1 == end_1 and initial_2 == end_2:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "A, B, C = map(str,input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A, B, C = list(map(str, input().split()))\nif A[-1] == B[0] and B[-1] == C[0]:\n print('YES')\nelse:\n print('NO')", "#ABC060A\na,b,c = input().split()\nprint(\"YES\" if (a[-1] == b[0]) and (b[-1] == c[0]) else \"NO\")", "#\u7b54\u3048\u306f\u3042\u3063\u3066\u308b\u3051\u3069WA\nA, B, C = input().split()\n\nif A[-1]==B[0] and B[-1]==C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A,B,C=map(str,input().split())\nif A[-1]==B[0] and B[-1]==C[0] :\n print(\"YES\")\nelse :\n print(\"NO\")", "a,b,c = input().split()\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "A,B,C=list(map(str,input().split()))\n\nif A[-1]==B[0] and B[-1]==C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "A, B, C = input().split()\nprint('YES' if B.startswith(A[-1]) and C.startswith(B[-1]) else 'NO')", "A, B, C = map(str, input().split())\n\nif A[-1] == B[0] and B[-1] == C[0]:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b,c = input().split()\nprint(\"YES\" if a[-1] == b[0] and b[-1] == c[0] else \"NO\")", "S = input().split()\nprint('YES' if S[0][-1] == S[1][0] and S[1][-1] == S[2][0] else 'NO')", "a, b, c = list(map(str, input().split()))\n\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print('YES')\nelse:\n print('NO')\n\n\n", "a=input().split(\" \")\nprint(\"YES\") if a[0][-1]==a[1][0] and a[1][-1]==a[2][0] else print(\"NO\")", "a,b,c = input().split()\nif a[-1] == b[0] and b[-1] == c[0]:\n print('YES')\nelse :\n print('NO')"] | {"inputs": ["rng gorilla apple\n", "yakiniku unagi sushi\n", "a a a\n", "aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 15,782 | |
3af764e92f123c3e7569a2db4aac9d5e | UNKNOWN | You are given two positive integers A and B. Compare the magnitudes of these numbers.
-----Constraints-----
- 1 β€ A, B β€ 10^{100}
- Neither A nor B begins with a 0.
-----Input-----
Input is given from Standard Input in the following format:
A
B
-----Output-----
Print GREATER if A>B, LESS if A<B and EQUAL if A=B.
-----Sample Input-----
36
24
-----Sample Output-----
GREATER
Since 36>24, print GREATER. | ["a = int(input())\nb = int(input())\nif a < b:\n print(\"LESS\")\nelif a > b:\n print(\"GREATER\")\nelse:\n print(\"EQUAL\")", "a=int(input())\nb=int(input())\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\n\nif b < a:\n ans = 'GREATER'\nelif a < b:\n ans = 'LESS'\nelse:\n ans ='EQUAL'\n\nprint(ans)", "A = int(input())\nB = int(input())\n\nif A > B:\n print(\"GREATER\")\n\nif A < B:\n print(\"LESS\")\n\nif A == B:\n print(\"EQUAL\")", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a = int(input())\nb = int(input())\nif a > b: print('GREATER')\nif a < b: print('LESS')\nif a == b: print('EQUAL')\n", "a=input()\nb=input()\nif len(a)==len(b):\n if a==b:\n print(\"EQUAL\")\n elif a<b:\n print(\"LESS\")\n else:\n print(\"GREATER\")\nelif len(a)<len(b):\n print(\"LESS\")\nelse:\n print(\"GREATER\")", "A = int(input())\nB = int(input())\nif A == B:\n print(\"EQUAL\")\nif A > B:\n print(\"GREATER\")\nif A < B:\n print(\"LESS\")\n", "#n = int(input())\n#a, b = map(int,input().split())\n#l = list(map(int,input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\na = str(input())\nb = str(input())\nif len(a) < len(b):\n ans = 'LESS'\nelif len(a) > len(b):\n ans = 'GREATER'\nelse:\n n = len(a)\n ans = 'EQUAL'\n for i in range(n):\n if a[i] < b[i]:\n ans = 'LESS'\n break\n elif a[i] > b[i]:\n ans = 'GREATER'\n break\nprint(ans)\n", "a,b=[int(input()) for i in range(2)]\nprint(\"GREATER\" if a>b else \"LESS\" if b>a else \"EQUAL\")", "a=int(input())\nb=int(input())\n\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelif a==b:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\n\nif A == B:\n print(\"EQUAL\")\nelif A > B:\n print(\"GREATER\")\nelse:\n print(\"LESS\")", "a,b=int(input()),int(input());print(['ELQEUSASL'[a<b::2],'GREATER'][a>b])", "a = int(input())\nb = int(input())\n\nif a > b:\n print('GREATER')\nelif a < b:\n print('LESS')\nelse:\n print('EQUAL')", "a=int(input())\nb=int(input())\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "# coding: utf-8\nimport math\n\nnum1 = int(input())\nnum2 = int(input())\nif num1 == num2:\n print(\"EQUAL\")\nelif num1 > num2:\n print(\"GREATER\")\nelif num1 < num2:\n print(\"LESS\")\n", "A=input()\nB=input()\n\nif len(A)>len(B):\n print(\"GREATER\")\nelif len(A)<len(B):\n print(\"LESS\")\nelse:\n if A>B:\n print(\"GREATER\")\n elif A<B:\n print(\"LESS\")\n else:\n print(\"EQUAL\")\n", "a=int(input())\nb=int(input())\n\nif a<b:\n print(\"LESS\")\nelif a>b:\n print(\"GREATER\")\nelse:\n print(\"EQUAL\")", "A = input()\nB = input()\n\nif (A > B and len(A) ==len(B)) or (len(A) > len(B)):\n print(\"GREATER\")\nelif (A < B and len(A) ==len(B)) or (len(A) < len(B)):\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\n\nif A > B:\n print(\"GREATER\")\nelif A < B:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\nif A - B > 0:\n print('GREATER')\nelif A - B == 0:\n print('EQUAL')\nelse:\n print('LESS')", "a = int(input())\nb = int(input())\nif a > b:\n print('GREATER')\nelif a < b:\n print('LESS')\nelse:\n print('EQUAL')", "a,b=int(input()),int(input())\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "a = input()\nb = input()\n\nlen_a = len(a)\nlen_b = len(b)\n\nif len_a > len_b:\n print('GREATER')\nelif len_a < len_b:\n print('LESS')\nelse:\n if a > b:\n print('GREATER')\n elif a < b:\n print('LESS')\n else:\n print('EQUAL')", "a = int(input())\nb = int(input())\n\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")\n", "#ABC059B\na = int(input())\nb = int(input())\nprint(\"GREATER\" if a>b else \"LESS\" if a<b else \"EQUAL\")", "a = int(input())\nb = int(input())\nprint(('GREATER' if a > b else 'LESS' if a < b else 'EQUAL'))\n", "a = input()\nb = input()\nif len(a) > len(b):\n print(\"GREATER\")\nelif len(a) < len(b):\n print(\"LESS\")\nelse:\n for i in range(len(a)):\n if a[i] > b[i]:\n print(\"GREATER\")\n break\n elif a[i] < b[i]:\n print(\"LESS\")\n break\n else:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\nif A > B:\n print(\"GREATER\")\nelif A < B:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a = input()\nb = input()\nif len(a) == len(b):\n if a == b:\n print(\"EQUAL\")\n else:\n print(\"GREATER\" if a > b else \"LESS\")\nelse:\n print(\"GREATER\" if len(a) > len(b) else \"LESS\")", "a = int(input())\nb = int(input())\nif a > b :\n print('GREATER')\nelif a < b :\n print('LESS')\nelse :\n print('EQUAL')", "#59B\nA=int(input())\nB=int(input())\nif A>B:\n print('GREATER')\nelif A<B:\n print('LESS')\nelse:\n print('EQUAL')", "A = int(input())\nB = int(input())\ndiff = A - B\n\nif diff > 0:\n print(\"GREATER\")\nelif diff < 0:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")\n", "a = input()\nb = input()\nl = max(len(a), len(b))\n\nfor i,j in zip(a.zfill(l), b.zfill(l)):\n if int(i) > int(j):\n print(\"GREATER\")\n break\n elif int(i) < int(j):\n print(\"LESS\")\n break\nelse:\n print(\"EQUAL\")\n", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nif a<b:\n print(\"LESS\")\nif a==b:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\n\nprint(\"GREATER\" if A > B else \"LESS\" if A < B else \"EQUAL\")", "import sys, math\nfrom itertools import combinations as c, product as p\nfrom collections import deque\nsys.setrecursionlimit(10**9)\nINF = float('inf')\nMOD = 10**9 + 7\n#MOD = 998244353\n\n\ndef si(): return input()\ndef ii(): return int(input())\ndef fi(): return float(input())\ndef lstr(): return input().split()\ndef lint(): return list(map(int, input().split()))\ndef lintdec(): return list(map(lambda x:int(x) - 1, input().split()))\ndef lnstr(n): return [input() for _ in range(n)]\ndef lnint(n): return [int(input()) for _ in range(n)]\ndef lint_list(n): return [lint() for _ in range(n)]\n\n\n\n############################################################\nA = ii()\nB = ii()\n\nprint('GREATER' if A > B else 'LESS' if A < B else 'EQUAL')", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n a = int(input())\n b = int(input())\n\n if a == b:\n print(\"EQUAL\")\n elif a > b:\n print(\"GREATER\")\n else:\n print(\"LESS\")\n\ndef __starting_point():\n main()\n__starting_point()", "A = int(input())\nB = int(input())\nprint('GREATER' if A > B else 'EQUAL' if A == B else 'LESS')", "a, b = [int(input()) for i in range(2)]\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")\n", "a = int(input())\nb = int(input())\n\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\n\nif A > B:\n print('GREATER')\nelif A < B:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\nif a<b:\n print(\"LESS\")\nelif a==b:\n print(\"EQUAL\")\nelse:\n print(\"GREATER\")", "a = int(input())\nb = int(input())\n\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelif a == b:\n print(\"EQUAL\")", "a,b=int(input()),int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\n\nif A > B:\n print(\"GREATER\")\nelif A < B:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a = int(input())\nb = int(input())\n\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")\n", "a = int(input());\nb = int(input());\nif a>b: \n print(\"GREATER\")\nelif a == b:\n print(\"EQUAL\");\nelse:\n print(\"LESS\")", "a=int(input())\nb=int(input())\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\nprint(('GREATER' if a > b else 'LESS' if a < b else 'EQUAL'))\n\n", "a=int(input())\nb=int(input())\nimport math\nif math.sqrt(a)==math.sqrt(b):\n print(\"EQUAL\")\nelif math.sqrt(a)>math.sqrt(b):\n print(\"GREATER\")\nelif math.sqrt(a)<math.sqrt(b):\n print(\"LESS\")", "A = int(input())\nB = int(input())\nif A > B:\n print(\"GREATER\")\nelif A < B:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")\n", "a=int(input())\nb=int(input())\nprint(\"GREATER\" if a>b else \"LESS\" if a<b else \"EQUAL\")", "a = int(input())\nb = int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a = int(input())\nb = int(input())\nif a > b:\n print('GREATER')\nelif a < b:\n print('LESS')\nelse:\n print('EQUAL')", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a=int(input())\nb=int(input())\nimport math\nif math.sqrt(a)==math.sqrt(b):\n print(\"EQUAL\")\nelif math.sqrt(a)>math.sqrt(b):\n print(\"GREATER\")\nelif math.sqrt(a)<math.sqrt(b):\n print(\"LESS\")", "A=int(input())\nB=int(input())\nif A>B :\n print(\"GREATER\")\nelif A==B :\n print(\"EQUAL\")\nelse :\n print(\"LESS\")", "a = int(input())\nb = int(input())\n\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a=int(input())\nb=int(input())\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "A = int(input())\nB = int(input())\nif A > B:\n print('GREATER')\nelif A < B:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\nif a > b:\n print(\"GREATER\")\nelif b > a:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "#\n# abc059 b\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"36\n24\"\"\"\n output = \"\"\"GREATER\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"850\n3777\"\"\"\n output = \"\"\"LESS\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"9720246\n22516266\"\"\"\n output = \"\"\"LESS\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"123456789012345678901234567890\n234567890123456789012345678901\"\"\"\n output = \"\"\"LESS\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n A = int(input())\n B = int(input())\n\n if A > B:\n print(\"GREATER\")\n elif A < B:\n print(\"LESS\")\n else:\n print(\"EQUAL\")\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "A = int(input())\nB = int(input())\nif A > B:\n print('GREATER')\nelif A < B:\n print('LESS')\nelse:\n print('EQUAL')", "def main():\n a = int(input())\n b = int(input())\n\n if a > b:\n print('GREATER')\n if a < b:\n print('LESS')\n if a == b:\n print('EQUAL')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "a = int(input())\nb = int(input())\nprint(\"GREATER\" if a > b else \"EQUAL\" if a == b else \"LESS\")", "A = input()\nB = input()\n\nA = int(A)\nB = int(B)\n\nif A > B :\n print(\"GREATER\")\n \nelif A == B :\n print(\"EQUAL\")\n \nelse :\n print(\"LESS\")", "a = int(input())\nb = int(input())\nif a<b:\n print(\"LESS\")\nelif a >b:\n print(\"GREATER\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\nif A > B:\n print(\"GREATER\")\nelif A < B:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A = int(input())\nB = int(input())\nif A > B:\n print('GREATER')\nelif A < B:\n print('LESS')\nelse:\n print('EQUAL')", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a==b:\n print(\"EQUAL\")\nelse:\n print(\"LESS\")", "a=int(input())\nb=int(input())\n\nif a==b:print(\"EQUAL\")\nelif a>b:print(\"GREATER\")\nelse:print(\"LESS\")", "A = int(input())\nB = int(input())\n\nif A > B:\n print('GREATER')\nelif A == B:\n print('EQUAL')\nelse:\n print('LESS')", "a = int(input())\nb = int(input())\nif a == b:\n print('EQUAL')\nelif a > b:\n print('GREATER')\nelse:\n print('LESS')", "a = int(input())\nb = int(input())\nif a > b:\n print(\"GREATER\")\nelif a < b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n a = int(input())\n b = int(input())\n\n if a > b :\n print(\"GREATER\")\n elif a < b :\n print(\"LESS\")\n elif a == b :\n print(\"EQUAL\")\n\ndef __starting_point():\n main()\n__starting_point()", "a=list(map(int, input().split()))\nb=list(map(int, input().split()))\nif len(a) > len(b):\n print('GREATER')\n return\nelif len(a) < len(b):\n print('LESS')\n return\nelse:\n for i in range(len(a)):\n if a[i] > b[i]:\n print('GREATER')\n return\n elif a[i] < b[i]:\n print('LESS')\n return\nprint('EQUAL')", "A = int(input())\nB = int(input())\n\nif A == B:\n print('EQUAL')\nelif A // B > 0:\n print('GREATER')\nelse:\n print('LESS')", "def answer(a: str, b: str) -> str:\n if a == b:\n return 'EQUAL'\n\n if a < b or len(a) < len(b):\n return 'LESS'\n\n if a > b or len(a) > len(b):\n return 'GREATER'\n\n\ndef main():\n a = input()\n b = input()\n print(answer(a, b))\n\n\ndef __starting_point():\n main()\n__starting_point()", "A = int(input())\nB = int(input())\nif A > B:\n print('GREATER')\nif A < B:\n print('LESS')\nif A == B:\n print('EQUAL')", "a = int(input())\nb = int(input())\n\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\nprint(\"EQUAL\" if a == b else \"GREATER\" if a > b else \"LESS\")", "a = int(input())\nb = int(input())\n\nif a == b:\n print('EQUAL')\nelif a < b:\n print('LESS')\nelse:\n print('GREATER')", "a,b = [int(input()) for _ in range(2)]\nif a == b:\n print(\"EQUAL\")\nelif a > b:\n print(\"GREATER\")\nelse:\n print(\"LESS\")", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a==b:\n print(\"EQUAL\")\nelse:\n print(\"LESS\")", "import sys\nimport copy\nimport math\nimport itertools\nimport numpy as np\nA = int(input())\nB = int(input())\nif A>B:\n print(\"GREATER\")\nelif A<B:\n print(\"LESS\")\nelif A==B:\n print(\"EQUAL\")", "a,b = [int(input()) for i in range(2)]\nprint(\"GREATER\" if a>b\n else \"LESS\" if a<b\n else \"EQUAL\")", "a = int(input())\nb = int(input())\nif a > b:\n print(\"GREATER\");\nelif a == b:\n print(\"EQUAL\");\nelse:\n print(\"LESS\");", "A = float(input())\nB = float(input())\n\nif A > B:\n print('GREATER')\nelif A < B:\n print('LESS')\nelse:\n print('EQUAL')\n", "a = int(input())\nb = int(input())\n\nif a > b:\n print('GREATER')\nelif a < b:\n print('LESS')\nelse:\n print('EQUAL')\n", "a=int(input())\nb=int(input())\nif(a==b):\n print(\"EQUAL\")\nelif(a>b):\n print(\"GREATER\")\nelse:\n print(\"LESS\")", "a = int(input())\nb = int(input())\nif a > b:\n print('GREATER')\nelif a < b:\n print('LESS')\nelse:\n print('EQUAL')", "a,b = [int(input()) for i in range(2)]\n\nif a>b:\n print(\"GREATER\")\n\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "def answer(a: int, b: int) -> str:\n if a == b:\n return 'EQUAL'\n\n if a < b:\n return 'LESS'\n\n if a > b:\n return 'GREATER'\n\n\ndef main():\n a = int(input())\n b = int(input())\n print(answer(a, b))\n\n\ndef __starting_point():\n main()\n__starting_point()", "A=int(input())\nB=int(input())\nif A>B:\n print(\"GREATER\")\nelif A==B:\n print(\"EQUAL\")\nelse:\n print(\"LESS\")", "a=int(input())\nb=int(input())\nif a>b:\n print(\"GREATER\")\nelif a<b:\n print(\"LESS\")\nelse:\n print(\"EQUAL\")", "A, B = int(input()), int(input())\nif A > B:\n print('greater'.upper())\nif A < B:\n print('less'.upper())\nif A == B:\n print('equal'.upper())"] | {"inputs": ["36\n24\n", "850\n3777\n", "9720246\n22516266\n", "123456789012345678901234567890\n234567890123456789012345678901\n"], "outputs": ["GREATER\n", "LESS\n", "LESS\n", "LESS\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 16,997 | |
bc7691bac60a94812a18f04d3882fce5 | UNKNOWN | Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.
Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.
Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)
At most how much can he earn on balance?
Note that the same string may be written on multiple cards.
-----Constraints-----
- N and M are integers.
- 1 \leq N, M \leq 100
- s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.
-----Input-----
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M
-----Output-----
If Takahashi can earn at most X yen on balance, print X.
-----Sample Input-----
3
apple
orange
apple
1
grape
-----Sample Output-----
2
He can earn 2 yen by announcing apple. | ["def resolve():\n n = int(input())\n blue_cards = list()\n for i in range(n):\n card = input()\n blue_cards.append(card)\n blue_cards = sorted(blue_cards)\n m = int(input())\n red_cards = list()\n for i in range(m):\n card = input()\n red_cards.append(card)\n red_cards = sorted(red_cards)\n former = \"\"\n cards_points = []\n for card in blue_cards:\n point = 0\n if former == card:\n continue\n else:\n p = blue_cards.count(card)\n m = red_cards.count(card)\n point = p - m\n cards_points.append(point)\n former = card\n cards_points = sorted(cards_points)\n if cards_points[-1] < 0:\n print(0)\n else:\n print(cards_points[-1])\nresolve()", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\n\nans = 0\ncnt = 0\nfor i in set(s):\n cnt = s.count(i) - t.count(i)\n ans = max(ans, cnt)\nprint(ans)", "n = int(input())\na = []\nfor i in range(n):\n a.append([input(),0])\nm = int(input())\nb = []\nfor i in range(m):\n b.append([input(),0])\n\nres = 0\nfor i in range(n):\n c = 0\n if a[i][1] == 0:\n a[i][1] = 1\n for j in range(i,n):\n if a[i][0] == a[j][0]:\n c += 1\n a[j][1] = 1\n for j in range(m):\n if a[i][0] == b[j][0]:\n c -= 1\n res = max(res,c)\nprint(res)", "n = int(input())\ns = [input() for s in range(n)]\nm = int(input())\nt = [input() for i in range(m)]\nplus = []\nminus = []\ntotal = []\n\nfor i in set(s):\n plus.append(s.count(i))\n minus.append(t.count(i))\n\nfor j in range(len(plus)):\n total.append(plus[j]-minus[j])\n \nprint(max(0,max(total)))", "n = int(input())\nlist_s = [input() for i in range(0, n)]\nm = int(input())\nlist_t = [input() for i in range(0, m)]\ndict_blue = {}\ndict_red = {}\nlist_ans = []\nfor i in range(0, n):\n if list_s[i] in dict_blue: pass\n else: dict_blue[list_s[i]] = list_s.count(list_s[i])\nfor i in range(0, m):\n if list_t[i] in dict_red: pass\n else: dict_red[list_t[i]] = list_t.count(list_t[i])\nfor key, value in dict_blue.items():\n if key in dict_red.keys():\n list_ans.append(value - dict_red[key])\n else:\n list_ans.append(value)\nif max(list_ans) > 0: print(max(list_ans))\nelse: print(0)", "n = int(input())\nblue = []\nfor i in range(n):\n blue.append(input())\nm = int(input())\nred = []\nfor i in range(m):\n red.append(input())\nscores = []\nfor i in range(len(blue)):\n score = blue.count(blue[i]) - red.count(blue[i])\n scores.append(score)\n\nif max(scores) < 0:\n print(0)\nelse:\n print(max(scores))", "n = int(input())\nsl = list(input() for _ in range(n))\nm = int(input())\ntl = list(input() for _ in range(m))\n\nsl_s = list(set(sl))\ntl_s = list(set(tl))\n\nans = 0\nfor s in sl_s:\n ans = max(ans, sl.count(s) - tl.count(s))\n\nprint(ans)", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\n#\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7cfb\n# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);\n# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nn = I()\ns = Counter([input() for _ in range(n)])\nm = I()\nt = Counter([input() for _ in range(m)])\nans = 0\nfor k,v in list(s.items()):\n ans = max(ans, max(0, v-t[k]))\nprint(ans)\n", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\nans = 0\nl = list(set(s))\nfor i in range(len(l)):\n ans = max(ans,s.count(l[i])-t.count(l[i]))\nprint(ans) ", "N = int(input())\ns = []\nfor i in range(N):\n s.append(input())\ns.append('')\nM = int(input())\nt = []\nfor j in range(M):\n t.append(input())\n\nans = 0\nfor i in range(N + 1):\n target = s[i]\n cnt = 0\n for j in range(N):\n if target == s[j]:\n cnt += 1\n for k in range(M):\n if target == t[k]:\n cnt -= 1\n ans = max(ans, cnt)\nprint(ans)\n", "from collections import Counter\nN = int(input())\ns = [input() for i in range(N)]\nM = int(input())\nt = [input() for i in range(M)]\n\nS = Counter(s)\nT = Counter(t)\n\nfor key, value in list(S.items()):\n if key in list(T.keys()):\n S[key] -= T[key]\n\nif max(S.values()) > 0:\n print((max(S.values())))\nelse:\n print((0))\n\n", "n = int(input())\nblues = [input() for _ in range(n)]\nm = int(input())\nreds = [input() for _ in range(m)]\n\nmax_price = 0\n\nfor blue in blues:\n plus = len(list([x for x in blues if x == blue]))\n minus = len(list([x for x in reds if x == blue]))\n price = plus - minus\n if price > max_price:\n max_price = price\n\nprint(max_price)\n", "N = int(input())\ndic = {}\nfor i in range(N):\n word = input()\n if word in dic:\n dic[word] +=1\n else:\n dic[word] = 1\nM = int(input())\nfor i in range(M):\n word = input()\n if word in dic:\n dic[word] -= 1\n else:\n dic[word] = -1\n\nans = 0#-float('inf')\nfor i in dic:\n ans = max(ans, dic[i])\nprint(ans)", "n = int(input())\ns = [input().split() for _ in range(n)]\nm = int(input())\nt = [input().split() for _ in range(m)]\nans = -100\nfor i in s:\n ans = max(ans,s.count(i) - t.count(i))\nif ans < 0:\n ans = 0\nprint(ans)", "n = int(input())\ns = []\nfor i in range(n):\n s.append(input())\nm = int(input())\nt = []\nfor i in range(m):\n t.append(input())\n\nwords = set(s + t)\nmax_val = 0\nfor word in words:\n ans = s.count(word)\n ans -= t.count(word)\n if ans > max_val:\n max_val = ans\nprint(max_val) ", "n = int(input())\ns = [input() for i in range(n)]\nm = int(input())\nt = [input() for i in range(m)]\nc = 0\nfor i in set(s):\n d = s.count(i)-t.count(i)\n if d > c:\n c = d\nprint(c)", "bag = {}\nN = int(input())\nfor _ in range(N):\n s = input()\n if s in bag:\n bag[s] += 1\n else:\n bag[s] = 1\nM = int(input())\nfor _ in range(M):\n s = input()\n if s in bag:\n bag[s] -= 1\n\nd_swap = {v: k for k, v in list(bag.items())}\nif max(d_swap) < 0:\n print((0))\nelse:\n print((max(d_swap)))\n", "b=[]\nr=[]\nc=[]\nn=int(input())\ncnt=0\nfor i in range(n):\n s=input()\n b.append(s)\nm=int(input())\nfor j in range(m):\n t=input()\n r.append(t)\nfor i in b:\n cnt += b.count(i)-r.count(i)\n c.append(cnt)\n cnt=0\nprint(max(max(c),0))", "n = int(input())\nblue = list()\nfor i in range(n):\n blue.append(input())\nm = int(input())\nred = list()\nfor j in range(m):\n red.append(input())\nans = 0\nfor p in range(n):\n cnt = 0\n for q in range(n):\n if blue[p] == blue[q]:\n cnt += 1\n for r in range(m):\n if blue[p] == red[r]:\n cnt -= 1\n ans = max(ans, cnt)\nprint(ans)", "n = int(input())\ns = []\nt = []\nans = 0\nfor i in range(n):\n s.append(input())\nm = int(input())\nfor i in range(m):\n t.append(input())\nl = set(s)\nfor i in l:\n ans = max(ans,s.count(i) - t.count(i))\nprint(ans)\n\n\n", "from collections import defaultdict\nd1 = defaultdict(int)\nd2 = defaultdict(int)\nn = int(input())\nfor i in range(n):\n d1[input()] += 1\nm = int(input())\nfor i in range(m):\n d2[input()] += 1\n\nans = 0\nfor k, v in list(d1.items()):\n ans = max(ans, v - d2[k])\nprint(ans)\n", "N = int(input())\ns = [input() for i in range(N)]\nM = int(input())\nt = [input() for i in range(M)]\n\ns_dic = {}\nt_dic = {}\n\nfor i in s:\n if i in s_dic.keys():\n s_dic[i] += 1\n else:\n s_dic[i] = 1\n \nfor i in t:\n if i in t_dic.keys():\n t_dic[i] += 1\n else:\n t_dic[i] = 1\n \nall_list = []\n\nfor i in s_dic.keys():\n if i in t_dic.keys():\n all_list.append(s_dic[i] - t_dic[i])\n else:\n all_list.append(s_dic[i])\n \nfor i in t_dic.keys():\n if i in s_dic.keys():\n all_list.append(s_dic[i] - t_dic[i])\n else:\n all_list.append(-t_dic[i])\n \nprint(max(max(all_list), 0))", "N=int(input())\ns=[input() for i in range(N)]\nM=int(input())\nt=[input() for i in range(M)]\n\ndef ans091(N:int, s:list, M:int, t:list):\n test_count=0\n own=list(set(s))\n for i in range(len(own)):\n if test_count<=s.count(own[i])-t.count(own[i]):\n test_count=s.count(own[i])-t.count(own[i])\n if test_count>0:\n return test_count\n else:\n return 0\nprint(ans091(N,s,M,t))", "n = int(input())\nblue_cards = []\nfor i in range(n):\n blue_cards.append(input())\n\nm = int(input())\nred_cards = []\nfor i in range(m):\n red_cards.append(input())\n\nscores = []\nfor i in range(len(blue_cards)):\n score = blue_cards.count(blue_cards[i]) - red_cards.count(blue_cards[i])\n scores.append(score)\n\nif max(scores) < 0:\n print((0))\nelse:\n print((max(scores)))\n", "#B - Two Colors Card Game\nN = int(input())\ns = [input() for _ in range(N)]\nM = int(input())\nt = [input() for _ in range(M)]\ns_set = list(set(s))\n\nmaxim = 0\nfor i in s_set:\n count = 0\n for j in s:\n if i == j:\n count += 1\n for k in t:\n if i == k:\n count -= 1\n if maxim<count:\n maxim = count\nprint(maxim)", "N = int(input())\nS = [input() for _ in range(N)]\nM = int(input())\nT = [input() for _ in range(M)]\n\nfrom collections import Counter\ncounter = Counter(S)\ncounter.subtract(T)\nprint(max(0, max(counter.values())))", "n = int(input())\ns = []\nfor _ in range(n):\n s.append(str(input()))\nm = int(input())\nt = []\nfor _ in range(m):\n t.append(str(input()))\na = []\nfor i in s:\n if i not in a:\n a.append(i)\nfor i in t:\n if i not in a:\n a.append(i)\nb = []\nfor i in a:\n x = s.count(i)\n y = t.count(i)\n b.append(x - y)\nprint(max(0, max(b)))", "words={\"\":0}\nN=int(input())\nfor i in range(N):\n word=input()\n words[word]=words.get(word,0)+1\nM=int(input())\nfor i in range(M):\n word=input()\n words[word]=words.get(word,0)-1\nprint(max(words.values()))", "from collections import Counter\nfrom sys import stdin\ndef input():\n return stdin.readline().strip()\n\nn = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\n\ns = Counter(s)\nt = Counter(t)\n\nans = 0\nfor key, num in s.items():\n if key in t:\n if ans < num - t[key]:\n ans = num - t[key]\n else:\n if ans < num:\n ans = num\n\nprint(ans)", "from collections import Counter\n# ABC091\nN = int(input())\nS = Counter([input() for _ in range(N)])\nM = int(input())\nT = Counter([input() for _ in range(M)])\n\nans = 0\n\nfor word, count in S.items():\n temp = count - T[word]\n ans = max(ans, temp)\nprint(ans)", "#!/usr/bin/env python3\n\ndef main():\n blue = [input() for i in range(int(input()))]\n red = [input() for i in range(int(input()))]\n l = list(set(blue))\n print((max(0, max(blue.count(l[i]) - red.count(l[i]) for i in range(len(l))))))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\ns = [\"\"]*n\nfor i in range(n):\n s[i] = input()\nimport collections\ns = collections.Counter(s)\nm = int(input())\nfor j in range(m):\n t = input()\n if t in s:\n s[t] -= 1\nprint(max(0, s.most_common()[0][1]))", "n = int(input())\ns = [input().split() for i in range(n)]\nm = int(input())\nt = [input().split() for i in range(m)]\nans = 0\nfor i in range(n):\n temp = s.count(s[i]) - t.count(s[i])\n ans = max(ans,temp)\nprint(ans)", "from collections import defaultdict\n\n\ncnt = defaultdict(int)\ncnt[0] = 0\nN = int(input())\nfor _ in range(N):\n cnt[input()] += 1\nM = int(input())\nfor _ in range(M):\n cnt[input()] -= 1\nprint((max(v for v in list(cnt.values()))))\n", "N = int(input())\nNs = []\nfor i in range(N):\n Ns.append(input())\n \nM = int(input())\nMs = []\nfor i in range(M):\n Ms.append(input())\n \nWs = list(set(Ns + Ms))\n\nAs = []\nfor i in Ws:\n ans = 0\n for j in Ns:\n if i == j:\n ans += 1\n for j in Ms:\n if i == j:\n ans -= 1\n As.append(ans)\n \nprint((max(max(As), 0)))\n", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\nli = []\nfor i in range(n):\n li += [s.count(s[i])-t.count(s[i])]\nprint(max(max(li),0))", "N=int(input())\ns=dict()\nfor _ in range(N):\n S=input()\n if S not in s:\n s[S]=0\n s[S]+=1\nM=int(input())\nfor _ in range(M):\n t=input()\n if t in s:\n s[t]-=1\nprint((max(max(0,x) for x in list(s.values()))))\n", "N = int(input())\nblue = [input() for _ in range(N)] \nM = int(input())\nred = [input() for _ in range(M)] \n\nset_blue = set(blue) \nscores = []\nfor s in set_blue:\n score = blue.count(s) - red.count(s)\n scores.append(score)\n \nms = max(scores)\nif ms>=0:\n print(ms)\nelse:\n print(0)", "#!/usr/bin/env python3\nfrom collections import Counter\n\nn = int(input())\ns = [str(input()) for i in range(n)]\nm = int(input())\nt = [str(input()) for i in range(m)]\n\ns = Counter(s)\n\nt = Counter(t)\n\nans = 0\nfor i in list(s.keys()):\n if i in t:\n ans_tmp = s[i] - t[i]\n else:\n ans_tmp = s[i]\n ans = max(ans, ans_tmp)\nprint(ans)\n", "# -*- coding: utf-8 -*-\n\nred_cards = []\nblue_cards = []\nN = int(input())\nfor i in range(N):\n blue_cards.append(input())\nM = int(input())\nfor i in range(M):\n red_cards.append(input())\n\n\nall_words = set(blue_cards + red_cards)\n\nans = 0\nfor i,w in enumerate(all_words):\n cnt_b = cnt_r = 0\n for b in blue_cards:\n if b == w:\n cnt_b += 1\n for r in red_cards:\n if r == w:\n cnt_r+= 1\n\n diff = cnt_b - cnt_r\n if diff > ans:\n ans = diff\n\nprint(ans)", "N = int(input())\ns = []\nfor i in range(N):\n s.append(input())\nM = int(input())\nt = []\nfor i in range(M):\n t.append(input())\n\ndef point(x):\n result = 0\n result += s.count(x)\n result -= t.count(x)\n return result\n\nans = 0\n\nfor word in set(s):\n if ans < point(word):\n ans = point(word)\n\nprint(ans)", "N = int(input())\nn = 0\nblue = []\nwhile n<N:\n blue.append(input())\n n += 1\n\nM = int(input())\nm = 0\nred = []\nwhile m<M:\n red.append(input())\n m += 1\n \nset_blue = set(blue) \nscores = []\nfor s in set_blue:\n score = blue.count(s) - red.count(s)\n scores.append(score)\n \nms = max(scores)\nif ms>=0:\n print(ms)\nelse:\n print(0)", "n = int(input())\nblue = [input() for i in range(n)]\nm = int(input())\nred = [input() for i in range(m)]\n\nans = 0\nfor i in range(n):\n tmp = blue.count(blue[i]) - red.count(blue[i])\n ans = max(ans, tmp)\nprint(ans)", "n=int(input())\ns=[input() for i in range(n)]\nm=int(input())\nt=[input() for i in range(m)]\n\nans=[]\nfor i in s:\n cnt=0\n for j in range(n):\n if i==s[j]:\n cnt+=1\n for k in range(m):\n if i==t[k]:\n cnt-=1\n ans.append(cnt)\n\nif max(ans)<0:\n print('0')\nelse:\n print(max(ans))", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\ns_set = list(set(s))\nwin = max(s.count(s_set[i]) - t.count(s_set[i]) for i in range(len(s_set)))\nprint(max(0,win))", "n = int(input())\nsl = list(input() for _ in range(n))\nm = int(input())\ntl = list(input() for _ in range(m))\n\ncnt = 0\nfor s in sl:\n cnt = max(cnt, sl.count(s) - tl.count(s))\n\nprint(cnt)\n\n", "from collections import Counter\nN = int(input())\nblue = [input() for _ in range(N)]\nM = int(input())\nred = [input() for _ in range(M)]\nCb = Counter(blue)\nCr = Counter(red)\nans = 0\nfor b in Cb.most_common():\n x = b[0]\n y = b[1]\n if Cr.get(x):\n ans = max(ans, y - Cr[x])\n else:\n ans = max(ans, y)\nprint(ans)", "n = int(input())\nstr_dict = dict()\nfor i in range(n):\n s = input()\n if s not in str_dict:\n str_dict[s] = 1\n else:\n str_dict[s] += 1\n\nm = int(input())\nfor i in range(m):\n t = input()\n if t not in str_dict:\n str_dict[t] = -1\n else:\n str_dict[t] -= 1\n\nres = max(0, sorted(list(str_dict.values()))[-1])\nprint(res)\n", "n = int(input())\na = {}\nfor i in range(n):\n s = str(input())\n if s in a.keys():\n a[s] = a[s] + 1\n else:\n a[s] = 1\n \nm = int(input())\nfor i in range(m):\n t = str(input())\n if t in a.keys():\n a[t] = a[t] - 1\n else:\n a[t] = -1\nif max(a.values()) >= 0:\n print(max(a.values()))\nelif max(a.values()) < 0:\n print(0)", "import collections\n\nN = int(input())\nS = [input() for i in range(N)]\ncS = collections.Counter(S)\nlS = list(cS.items())\nM = int(input())\nT = [input() for i in range(M)]\ncT = collections.Counter(T)\nlist1 = []\nans = 0\n\nfor i in range(len(lS)):\n \n if lS[i][0] in cT:\n x = lS[i][1] - cT[lS[i][0]]\n \n else:\n x = lS[i][1]\n \n if x > 0:\n list1.append(x)\n \nif list1 == []:\n print(0)\nelse:\n print(max(list1))", "import sys, collections\nlines = [s.rstrip(\"\\n\") for s in sys.stdin.readlines()]\nn, = [int(num) for num in lines.pop(0).split(\" \")]\nblue_list = lines[:n]\nlines = lines[n:]\nm, = [int(num) for num in lines.pop(0).split(\" \")]\nred_list = lines\nblue = collections.Counter(blue_list)\nred = collections.Counter(red_list)\nc = blue - red\nlis = list(c.values())\nif len(lis):\n ans = max(lis)\nelse:\n ans = 0\nprint(ans)\n", "N = int(input())\ns = {}\nfor i in range(N):\n x = input()\n if x in s:\n s[x] += 1\n else:\n s[x] = 1\nM = int(input())\nt = {}\nfor i in range(M):\n x = input()\n if x in t:\n t[x] += 1\n else:\n t[x] = 1\n\nb = list(s.keys())\nr = list(t.keys())\nsubs = []\n\nfor i in range(len(b)):\n if b[i] in r:\n subs.append(s[b[i]]-t[b[i]])\n else:\n subs.append(s[b[i]])\nprint((max(0,max(subs))))\n", "n=int(input())\ns=[input() for i in range(n)]\nm=int(input())\nt=[input() for i in range(m)]\n\nprint((max(0,max(s.count(i)-t.count(i) for i in set(s)))))\n \n\n\n\n", "blue = []\nred = []\nans = 0\nn = int(input())\nfor i in range(n):\n blue.append(input())\nm = int(input())\nfor j in range(m):\n red.append(input())\nword = set(blue)\nfor k in word:\n c = blue.count(k) - red.count(k)\n ans = max(ans,c)\nprint(ans)", "from collections import Counter\nn = int(input())\ns = Counter([input() for _ in range(n)])\nm = int(input())\nt = Counter([input() for _ in range(m)])\n\nfor x,y in s.items():\n s[x] = s[x]-t[x]\nprint(max(max(list(s.values())), 0))", "from collections import defaultdict\nd = defaultdict(int)\nfor _ in range(int(input())):\n d[input()] += 1\nfor _ in range(int(input())):\n d[input()] -= 1\nprint(max(0, max(d.values())))", "from collections import Counter\n\nn = int(input())\ns = [None] * n\nfor i in range(n):\n s[i] = input().rstrip()\n\nm = int(input())\nt = [None] * m\nfor i in range(m):\n t[i] = input().rstrip()\n\nctr = Counter(s) - Counter(t)\nif ctr:\n print(ctr.most_common(1)[0][1])\nelse:\n print(0)", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\na = 0\nfor x in set(s):\n a = max(s.count(x) - t.count(x), a)\nprint(a)", "N=int(input())\ns=[input() for i in range(N)]\nM=int(input())\nt=[input() for i in range(M)]\na_list=list(set(s))\ntest_count=0\nfor i in range(len(a_list)):\n x=a_list[i]\n if test_count<=s.count(x)-t.count(x):\n test_count=s.count(x)-t.count(x)\nprint(test_count)", "N = int(input())\nn_list = []\nfor i in range(N):\n n_list.append(input())\nM = int(input())\nm_list = []\nfor i in range(M):\n m_list.append(input())\nadd_dic = {}\nfor n in n_list:\n add = add_dic.get(n, 0)\n add_dic[n] = add + 1\ndiff_dic = {}\nfor m in m_list:\n diff = diff_dic.get(m, 0)\n diff_dic[m] = diff + 1\n\nmax_ = 0\nfor key, add in add_dic.items():\n total = add - diff_dic.get(key, 0)\n if total > max_:\n max_ = total\n\nprint(max_)", "n = int(input())\ns = list(input() for i in range(n))\nm = int(input())\nt = list(input() for i in range(m))\nr = list(set(s+t))\nans = 0\nfor i in r:\n a = s.count(i)\n b = t.count(i)\n ans = max(ans,a-b)\nprint(ans)", "from collections import Counter\nimport math\nimport statistics\nimport itertools\na=int(input())\n# b=input()\n# c=[]\n# for i in a:\n# c.append(int(i))\n# A,B,C= map(int,input().split())\n# f = list(map(int,input().split()))\ng = [input() for _ in range(a)]\n# h = []\n# for i in range(a):\n# h.append(list(map(int,input().split())))\n# a = [[0] for _ in range(H)]#nizigen\n\nb = int(input())\ng2 = [input() for _ in range(b)]\n\ng.sort()\ng2.sort()\n\ncount=1\nans={}\nans2={}\n\nfor i in range(len(g)-1):\n if g[i+1]==g[i]:\n count+=1\n else:\n ans[g[i]]=count\n count=1\n\nans[g[-1]]=count\ncount=1\nfor i in range(len(g2)-1):\n if g2[i+1]==g2[i]:\n count+=1\n else:\n if g2[i] in list(ans.keys()):\n ans[g2[i]]-=count\n count=1\n else:\n ans[g2[i]]=-count\n\nif g2[-1] in list(ans.keys()):\n ans[g2[-1]]-=count\n count=1\nelse:\n ans[g2[-1]]=-count\n\nif max(ans.values())>0:\n print((max(ans.values())))\nelse:\n print((0))\n", "n=int(input())\nS=[input() for i in range(n)]\nm=int(input())\nT=[input() for i in range(m)]\nans=0\nfor s in set(S):\n ans = max(ans,S.count(s)-T.count(s))\nprint(ans)", "n=int(input())\ns=[input() for _ in range(n)]\nm=int(input())\nt=[input() for _ in range(m)]\n\nans=0\nfor i in set(s):\n ans=max(s.count(i)-t.count(i),ans)\nprint(ans)", "N = int(input())\ns = [input() for i in range(N)]\nM = int(input())\nt = [input() for i in range(M)]\n\nst_dict = {}\n\nfor i in range(N):\n if s[i] not in st_dict.keys():\n st_dict[s[i]] = 1\n else:\n st_dict[s[i]] += 1\nfor i in range(M):\n if t[i] not in st_dict.keys():\n st_dict[t[i]] = -1\n else:\n st_dict[t[i]] -= 1\n\nif max(st_dict.values()) < 0:\n print(0)\nelse:\n print(max(st_dict.values()))", "n = int(input())\ns_l = [ str(input()) for _ in range(n) ]\n\nm = int(input())\nt_l = [ str(input()) for _ in range(m) ]\nd = {}\nfor s in s_l:\n if s not in d:\n d[s] = 1\n else:\n d[s] += 1\nfor t in t_l:\n if t not in d:\n d[t] = -1\n else:\n d[t] -= 1\nans = 0\nfor k, v in d.items():\n ans = max(v, ans)\nprint(ans)", "N = int(input())\nss = [input() for i in range(N)]\nM = int(input())\nts = [input() for i in range(M)]\n\nssset = set(ss)\ncnt = 0\nfor x in ssset:\n\tcnt = max(cnt, ss.count(x) - ts.count(x))\nprint(cnt)\n", "N = int(input())\nS = [input() for _ in range(N)]\nM = int(input())\nT = [input() for _ in range(M)]\nGet = {}\nfor s in S:\n if s in Get:\n Get[s] += 1\n else:\n Get[s] = 1\nfor t in T:\n if t in Get:\n Get[t] += -1\n else:\n Get[t] = -1\nans = max(Get.values())\nprint(ans if ans > 0 else 0)", "from collections import Counter\nN = int(input())\nS = [''.join(sorted(input())) for _ in range(N)]\nM = int(input())\nT = [''.join(sorted(input())) for _ in range(M)]\n\ns = Counter(S)\nt = Counter(T)\n\nans = 0\nfor k, v in list(s.items()):\n tmp = v\n tmp -= t[k]\n ans = max(ans, tmp)\nprint(ans)\n", "n=int(input())\ns=[]\nt=[]\nfor i in range(n):\n s.append(input())\nm=int(input())\nfor i in range(m):\n t.append(input())\n\nm=0\nfor i in range(n):\n x=s.count(s[i])-t.count(s[i])\n m=max(m,x)\n\nprint(m)", "import collections\n\nN = int(input())\nS = [input() for i in range(N)]\nM = int(input())\nT = [input() for i in range(M)]\n\nmaxi = 0\n\nfor i in range(len(S)):\n if S.count(S[i]) - T.count(S[i]) > maxi:\n maxi = S.count(S[i]) - T.count(S[i])\n\nprint(maxi)", "N = int(input())\nS = []\nfor i in range(N):\n s = input()\n S.append(s)\n\nM = int(input())\nT = []\nfor i in range(M):\n t = input()\n T.append(t)\n\nans = -1\nx = 0\nfor i in S:\n x = S.count(i) - T.count(i)\n ans = max(ans, x)\n\nif ans < 0:\n ans = 0\n\nprint(ans)\n", "Blue=[]\nRed=[]\n\nn=int(input())\nfor i in range(n):\n s=input()\n Blue.append(s)\n \nm=int(input())\nfor i in range(m):\n t=input()\n Red.append(t)\n\nans=0\nfor a in Blue:\n plus = Blue.count(a)\n minus = Red.count(a)\n point = plus - minus\n ans = max(ans, point)\nprint(ans)", "n=int(input())\nans=0\ncount=0\ns={}\nt={}\nfor i in range(n):\n a=input()\n if a not in s:\n s[a]=1\n else:\n s[a]+=1\nm=int(input())\nfor i in range(m):\n a=input()\n if a not in t:\n t[a]=1\n else:\n t[a]+=1\n \nS=list(s.keys())\nT=list(t.keys())\nfor i in range(len(S)):\n if S[i] in T:\n count=s[S[i]]-t[S[i]]\n else: count=s[S[i]]\n ans=max(ans,count)\n \nprint(ans)", "from collections import Counter\n\nn = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\n\nc = Counter(s).most_common()\nd = Counter(t)\n\np = -1000\n\nfor k, v in c:\n p = max(p, v - d[k])\n\nprint(max(p, 0))", "N = int(input())\nblue = {}\nfor _ in range(N):\n s = input()\n if s in blue.keys():\n blue[s] += 1\n else:\n blue[s] = 1\n\nM = int(input())\nred = {}\nfor _ in range(M):\n t = input()\n if t in red.keys():\n red[t] += 1\n else:\n red[t] = 1\n \ncnt = 0\nfor i in blue.keys():\n if i in red.keys():\n cnt = max(cnt, blue[i] - red[i])\n else:\n cnt = max(cnt, blue[i])\n \nprint(cnt)", "N = int(input())\ns = []\nfor i in range(N):\n s.append(input())\n\nM = int(input())\nt = []\nfor i in range(M):\n t.append(input())\n\nmoney_list = []\nfor i in range(N):\n money = s.count(s[i]) - t.count(s[i])\n money_list.append(money)\n\nans = max(money_list)\nif ans < 0:\n print(\"0\")\nelse:\n print(ans)", "n = int(input())\ns=[]\nfor i in range(n):\n s.append(input())\nfrom collections import Counter\ncs = Counter(s)\nm = int(input())\nfor i in range(m):\n t = input()\n if cs[t]:\n cs[t] -= 1\nprint(cs.most_common(1)[0][1], flush=True)\n\n", "#!/usr/bin/env python3\n\n\ndef main():\n N = int(input())\n s = [input() for _ in range(N)]\n M = int(input())\n t = [input() for _ in range(M)]\n y = 0\n for ss in set(s):\n yy = s.count(ss) - t.count(ss)\n if y < yy:\n y = yy\n print(y)\n\n\nmain()\n", "from typing import List\n\n\ndef answer(n: int, s: List[str], m: int, t: List[str]) -> int:\n result = 0\n for i in s:\n result = max(result, s.count(i) - t.count(i))\n\n return result\n\n\ndef main():\n n = int(input())\n s = [input() for _ in range(n)]\n m = int(input())\n t = [input() for _ in range(m)]\n print((answer(n, s, m, t)))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\nans = 0\nsc = list(set(s.copy()))\nfrom collections import Counter\nsn = Counter(s)\ntn = Counter(t)\nfor i in range(len(sc)):\n ans = max(sn[sc[i]]-tn[sc[i]],ans)\nprint(ans)", "n = int(input())\ns = [input() for _ in range(n)]\nm = int(input())\nt = [input() for _ in range(m)]\n\nans = 0\nfor i in s:\n ans = max(ans,s.count(i)-t.count(i))\n\nprint(ans)", "n = [input() for _ in range(int(input()))]\nm = [input() for _ in range(int(input()))]\n\nl = list(set(n))\n\nprint(max(0,max(n.count(l[i]) - m.count(l[i]) for i in range(len(l)))))", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n n = int(input())\n word_dict={}\n for i in range(n):\n s = input().rstrip()\n if s not in word_dict:\n word_dict[s]=1\n else:\n word_dict[s]+=1\n m = int(input())\n for j in range(m):\n t= input().rstrip()\n if t in word_dict:\n word_dict[t]-=1\n else:\n word_dict[t]=-1\n\n if max(word_dict.values()) < 0:\n print(0)\n else:\n print(max(word_dict.values()))\n\ndef __starting_point():\n main()\n__starting_point()", "from collections import Counter\n\n\ndef main():\n n = int(input())\n blue = Counter(input() for _ in range(n))\n m = int(input())\n red = Counter(input() for _ in range(m))\n ans = 0\n\n for name, amount in blue.items():\n if name in red.keys():\n temp = amount - red[name]\n else:\n temp = amount\n ans = max(ans, temp)\n print(ans)\n\n\nmain()", "N = int(input())\nS = list(input() for x in range(N))\nM = int(input())\nT = list(input() for y in range(M))\n\ncount = []\n\nfor n in range(N):\n count.append(S.count(S[n]) - T.count(S[n]))\n\nmax_count = max(count)\nif max_count < 0:\n print(0)\nelse:\n print(max_count)", "s, t = [], []\nfor i in range(int(input())):\n\ts.append(input())\nfor i in range(int(input())):\n\tt.append(input())\n\nprofit = 0\nfor i in s:\n\ttemp = s.count(i) - t.count(i)\n\tif profit < temp:\n\t\tprofit = temp\n\nprint(profit)\n", "from collections import defaultdict\nn = int(input())\ns = defaultdict(int)\nt = defaultdict(int)\n\nfor i in range(n):\n x = input()\n s[x] += 1\n\nm = int(input())\nfor i in range(m):\n x = input()\n t[x] += 1\n\nans = 0\nfor x, v in list(s.items()):\n now = v - t[x]\n ans = max(ans, now)\n\nprint(ans)\n", "s=[input() for _ in range(int(input()))]\nt=[input() for _ in range(int(input()))]\n \nres=0\nfor i in set(s):\n res=max(s.count(i)-t.count(i),res)\nprint(res)", "n = int(input())\na = [input() for i in range(n)]\nm = int(input())\nb = [input() for i in range(m)]\ns = a + b\nt = []\nfor i in s:\n t.append(a.count(i) - b.count(i))\n \nprint((0 if max(t) <= 0 else max(t)))\n", "N = int(input())\nBlue = [input() for _ in range(N)]\nM = int(input())\nRed = [input() for _ in range(M)]\nWord = Blue + Red\nWord = list(set(Word))\nans = 0\nfor i in range(len(Word)):\n cnt = 0\n cnt += Blue.count(Word[i])\n cnt -= Red.count(Word[i])\n ans = max(ans,cnt)\nprint(ans)", "N = int(input())\nS = [input() for i in range(N)]\nM = int(input())\nT = [input() for i in range(M)]\n\nanswer = 0\nfor i in S:\n answer = max(answer, S.count(i) - T.count(i))\nprint(answer)", "from collections import defaultdict\n\ncnt = defaultdict(int)\ncnt[\"a\" * 11] = 0\nfor _ in range(int(input())):\n cnt[input()] += 1\nfor _ in range(int(input())):\n cnt[input()] -= 1\nans = max(cnt.values())\nprint(ans)\n", "n=int(input())\nS=[]\nT=[]\ndata=set()\nfor i in range(n):\n s=input()\n S.append(s)\n data.add(s)\nm=int(input())\nfor i in range(m):\n t=input()\n T.append(t)\n data.add(t)\nans=0\nfor i in data:\n ans=max(ans,S.count(i)-T.count(i))\nprint(ans)", "from collections import defaultdict\n\nBlue, Red = defaultdict(int), defaultdict(int)\n\nN = int(input())\nfor _ in range(N):\n Blue[input()] += 1\n\nM = int(input())\nfor _ in range(M):\n Red[input()] += 1\n\nans = 0\nfor word, cnt in list(Blue.items()):\n temp = cnt - Red[word]\n ans = max(ans, temp)\n\nprint(ans)\n", "n = int(input())\ns = [input() for i in range(n)]\nm = int(input())\nt = [input() for i in range(m)]\n\nk = set(s)\ntot = 0\nfor i in k:\n tot = max(s.count(i) - t.count(i),tot)\n \nprint(tot)\n"] | {"inputs": ["3\napple\norange\napple\n1\ngrape\n", "3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n", "1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n", "6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n"], "outputs": ["2\n", "1\n", "0\n", "1\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 32,270 | |
a4f711e7be1fb90857de9372876c175e | UNKNOWN | On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.
You are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.
-----Constraints-----
- b is one of the letters A, C, G and T.
-----Input-----
Input is given from Standard Input in the following format:
b
-----Output-----
Print the letter representing the base that bonds with the base b.
-----Sample Input-----
A
-----Sample Output-----
T
| ["d = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}\nprint((d[input()]))\n", "b = input()\n\nif b == 'A':\n print('T')\n\nelif b == 'T':\n print('A')\n\nelif b == 'C':\n print('G')\n\nelif b == 'G':\n print('C')", "b = input()\nb = b.replace('A', 'a')\nb = b.replace('T', 'b')\nb = b.replace('C', 'c')\nb = b.replace('G', 'd')\nb = b.replace('a', 'T')\nb = b.replace('b', 'A')\nb = b.replace('c', 'G')\nb = b.replace('d', 'C')\n\nprint(b)", "def f(c):\n if c == \"A\":\n return \"T\"\n elif c == \"T\":\n return \"A\"\n elif c == \"C\":\n return \"G\"\n else:\n return \"C\"\n\nprint(f(input()))", "# A and T , C and G\n\nb = input()\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"C\":\n print(\"G\")\nelif b == \"G\":\n print(\"C\")\n \n# \u5927\u6587\u5b57\u3067\u5165\u529b\u306a\u3089\u3053\u308c\u3067\u3088\u3044\u3051\u3069\u3001\u5c0f\u6587\u5b57\u3060\u3063\u305f\u3089\u3069\u3046\u3059\u308b\u306e\u304b\u306a\u3042\n", "b = input ()\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"G\":\n print(\"C\")\nelif b == \"C\":\n print(\"G\")\nelse:\n print(\"error\")", "s=input()\nif s==\"A\":\n print(\"T\")\nelif s==\"T\":\n print(\"A\")\nelif s==\"G\":\n print(\"C\")\nelif s==\"C\":\n print(\"G\")", "b = input()\nif b == \"A\":\n b = \"T\"\nelif b == \"T\":\n b = \"A\"\nelif b == \"C\":\n b = \"G\"\nelif b == \"G\":\n b = \"C\"\nprint(b)", "c = input()\n\nd = 'AGTC'\n\nfor i in range(0,4):\n\tif d[i] == c:\n\t\tprint(d[(i+2)%4])", "b=input()\n\nif b=='A' :\n print('T')\nelif b=='G':\n print('C')\nelif b=='T':\n print('A')\nelif b=='C':\n print('G')", "b = input()\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'G':\n print('C')\nelse:\n print('G')", "\nn=str(input())\nif n=='A':\n print('T')\nelif n=='T':\n print('A')\nelif n=='G':\n print('C')\nelse:\n print('G')", "b = input()\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\") \nelif b == \"C\":\n print(\"G\") \nelse:\n print(\"C\") ", "print(\"ATCG\"[\"TAGC\".index(input())])", "b = input()\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'G':\n print('C')\nelse:\n print('G')", "moji = str(input())\ncorrect = [\"A\",\"C\",\"G\",\"T\"]\nind = correct.index(moji) + 1\nprint(correct[ind*-1])", "a = ['A','C','G','T']\nb = ['T','G','C','A']\nasn = ''\ns = str(input())\nfor i in range(4):\n if s == a[i]:\n print((b[i]))\n", "s = input()\n\nif s == \"A\":\n print(\"T\")\nelif s == \"T\":\n print(\"A\")\nelif s == \"C\":\n print(\"G\")\nelse:\n print(\"C\")", "n=input()\nc=[\"A\",\"T\",\"G\",\"C\"]\na=[\"T\",\"A\",\"C\",\"G\"]\nfor i in range(4):\n if n==c[i]:\n print(a[i])\n break", "b = input()\nif b == \"A\":\n print(\"T\")\nelif b == \"C\":\n print(\"G\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"G\":\n print(\"C\")\nelse:\n print(\"error\")", "b = input()\nif b == \"A\":\n print(\"T\")\nelif b == \"C\" :\n print(\"G\")\nelif b == \"G\":\n print(\"C\")\nelif b == \"T\":\n print(\"A\")\n", "b = input()\ndh = {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'C'}\n\nprint(dh[b])", "b = input()\n\nL = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}\nprint(L[b])", "b=input()\nif b==\"A\":\n print(\"T\")\nelif b==\"T\":\n print(\"A\")\nelif b==\"C\":\n print(\"G\")\nelse:\n print(\"C\")", "table = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'}\nprint(table[input().rstrip()])", "b = input ()\n\nif b == \"A\":\n print (\"T\")\n\nelif b == \"C\":\n print (\"G\")\n\nelif b == \"T\":\n print (\"A\")\n\nelif b == \"G\":\n print (\"C\")", "print({\"A\":\"T\",\"T\":\"A\",\"C\":\"G\",\"G\":\"C\"}[input()])", "M = {'A':'T', 'T': 'A', 'C':'G', 'G':'C'}\nprint(M[input()])", "b=input()\nif b==\"A\":\n print(\"T\")\nelif b==\"T\":\n print(\"A\")\nelif b==\"C\":\n print(\"G\")\nelse:\n print(\"C\")", "d = {\"A\":\"T\", \"T\":\"A\", \"G\":\"C\", \"C\":\"G\"}\nprint((d[input()]))\n", "s1 = 'ACGT'\ns2 = 'TGCA'\n\nb = input()\n\nfor i in range(4):\n if(s1[i]==b):\n print(s2[i])\n break", "b = input()\n\ns0 = ['A', 'T', 'C', 'G']\ns1 = ['T', 'A', 'G', 'C']\n\nfor i, s in enumerate(s0):\n if s == b:\n print((s1[i]))\n break\n", "x = input()\n\nif x == 'A':\n print('T')\nelif x == 'C':\n print('G')\nelif x == 'G':\n print('C')\nelse:\n print('A')", "b = input()\n\nprint('A') if b == 'T' else print('T') if b == 'A' else print('C') if b == 'G' else print('G')", "b = input()\ndic = {\n 'A':'T',\n 'T':'A',\n 'C':'G',\n 'G':'C'\n}\n \nprint((dic[b]))\n", "# \u5165\u529b\nb = input()\n\n# \u51e6\u7406&\u51fa\u529b\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\n\nif b == 'C':\n print('G')\nelif b == 'G':\n print('C')", "b=input()\n\nif b==\"A\":\n ans=\"T\"\n\nelif b==\"T\":\n ans=\"A\"\n \nelif b==\"C\":\n ans=\"G\"\n \nelse:\n ans=\"C\"\n \nprint(ans)", "# ABC122\n# A Double Helix\n# AT CG\nb = input()\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"C\":\n print(\"G\")\nelse:\n print(\"C\")\n", "l = ['A','C','G','T']\nprint(l[3-l.index(input())])", "b = input()\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelse:\n print('C')", "# A - Double Helix\n\nb = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'G':\n print('C')\nelif b == 'C':\n print('G')", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelse:\n print('C')\n", "b = input()\n\nif b == 'A':\n ans = 'T'\nelif b == 'C':\n ans = 'G'\nelif b == 'G':\n ans = 'C'\nelif b == 'T':\n ans = 'A'\n\nprint(ans)", "b = str(input())\n\nbasis = ['A', 'C', 'G', 'T']\nlabel = basis.index(b)\nprint(basis[3-label])", "b = input()\nif(b == 'A' or b == 'T'):\n if(b == 'A'):\n print(\"T\")\n else:\n print(\"A\")\nelse:\n if(b == 'C'):\n print('G')\n else:\n print('C')\n", "b = input()\nif b ==\"A\":\n print(\"T\")\nelif b ==\"T\":\n print(\"A\")\nelif b ==\"C\":\n print(\"G\")\nelif b ==\"G\":\n print(\"C\")", "b = input()\n\nif b == 'A':\n print(\"T\")\n\nelif b == 'T':\n print(\"A\")\n\nelif b == 'C':\n print(\"G\")\n\nelif b == 'G':\n print(\"C\")\n", "b = input()\n\nif b =='A':\n print('T')\n\nelif b == 'T':\n print('A')\n\nelif b == 'C':\n print('G')\n\nelif b == 'G':\n print('C')\n", "print(input().replace(\"A\",\"a\").replace(\"T\",\"A\").replace(\"a\",\"T\").replace(\"G\",\"g\").replace(\"C\",\"G\").replace(\"g\",\"C\"))", "b = input()\na = {'A':'T', 'T':'A', 'C':'G', 'G':'C'}\nprint(a[b])", "b=input()\nif b==\"A\":\n print(\"T\")\nelif b==\"T\":\n print(\"A\")\nelif b==\"C\":\n print(\"G\")\nelse:\n print(\"C\")", "S = input()\nif S=='G':\n print('C')\nelif S=='C':\n print('G')\nelif S=='A':\n print('T')\nelse:\n print('A')", "b = input()\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"C\":\n print(\"G\")\nelif b == \"G\":\n print(\"C\")", "a = input()\nif a == 'A':\n print('T')\nelif a == 'T':\n print('A')\nelif a == 'C':\n print('G')\nelse:\n print('C')\n", "b=input()\nprint(\"A\" if b==\"T\" else \"T\" if b==\"A\" else \"G\" if b==\"C\" else \"C\")", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'G':\n print('C')\nelif b == 'C':\n print('G')", "d = {'A':'T', 'T':'A', 'C':'G', 'G':'C'}\nprint((d[input()]))\n\n", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'C':\n print('G')\nelif b == 'G':\n print('C')\nelse:\n print('A')", "a = input()\nprint(\"A\" if a ==\"T\" else \"T\" if a ==\"A\" else \"G\" if a ==\"C\" else \"C\")", "# 4\u7a2e\u985e\u306e\u5869\u57fa A,C,G,T \u304c\u5b58\u5728\u3057\u3001 A \u3068 T \u3001 C \u3068 G \u304c\u305d\u308c\u305e\u308c\u5bfe\n# A,C,T,G \u3044\u305a\u308c\u304b\u306e\u6587\u5b57 b \u304c\u5165\u529b\u3055\u308c\u308b\n# \u5869\u57fa b \u3068\u5bfe\u306b\u306a\u308b\u5869\u57fa\u3092\u3042\u3089\u308f\u3059\u6587\u5b57\u3092\u51fa\u529b\n\nb = input()\n\nif b == 'A':\n print('T')\nelif b == 'C':\n print('G')\nelif b == 'G':\n print('C')\nelse:\n print('A')", "p = {'A':'T', 'T':'A', 'G':'C', 'C':'G'}\nprint(p[input()])", "b = input()\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelif b == 'G':\n print('C')", "s = input()\nif s == 'A':\n print('T')\nelif s == 'T':\n print('A')\nelif s == 'C':\n print('G')\nelif s == 'G':\n print('C')\n", "char = input()\n\nanswer = ''\nif char == 'A':\n answer = 'T'\nelif char == 'C':\n answer = 'G'\nelif char == 'G':\n answer = 'C'\nelse:\n answer = 'A'\n\nprint(answer)", "c = input()\n\nif c == 'A':\n\tprint('T')\nelif c == 'T':\n\tprint('A')\nelif c == 'C':\n\tprint('G')\nelse:\n\tprint('C')", "b=input()\n\nif b==\"A\":\n\tprint(\"T\")\nelif b==\"T\":\n\tprint(\"A\")\nelif b==\"C\":\n\tprint(\"G\")\nelse:\n\tprint(\"C\")", "b = str(input())\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelse:\n print('C')", "#N, K=map(int,input().split())\nb = str(input())\n\ndef main():\n if b == \"A\":\n print(\"T\")\n elif b == \"T\":\n print(\"A\")\n elif b == \"C\":\n print(\"G\")\n elif b == \"G\":\n print(\"C\")\n\ndef __starting_point():\n main()\n__starting_point()", "b = input()\n\nif b == \"A\":\n print(\"T\")\nif b == \"T\":\n print(\"A\")\nif b == \"C\":\n print(\"G\")\nif b == \"G\":\n print(\"C\")", "b=input()\nif b=='A':\n print('T')\nif b=='T':\n print('A')\nif b=='C':\n print('G')\nif b=='G':\n print('C')", "def main():\n b = input()\n if b == \"A\": print(\"T\")\n elif b == \"T\": print(\"A\")\n elif b == \"C\": print(\"G\")\n else: print(\"C\")\n\nmain()", "s = input()\n\nif s == 'A':\n print('T')\nelif s == 'T':\n print('A')\nelif s == 'G':\n print('C')\nelif s == 'C':\n print('G')", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\n\nelif b == ('G'):\n print('C')\n", "b = input()\nif b == \"A\":\n print(\"T\")\nelif b == \"C\":\n print(\"G\")\nelif b == \"G\":\n print(\"C\")\nelse:\n print(\"A\")\n", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelse:\n print('C')", "b=input()\nif b==\"A\":\n print(\"T\")\nif b==\"T\":\n print(\"A\")\nif b==\"C\":\n print(\"G\")\nif b==\"G\":\n print(\"C\")\n", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'C':\n print('G')\nelif b == 'G':\n print('C')\n", "a = input()\nif a == \"A\":\n print(\"T\")\nelif a == \"T\":\n print(\"A\")\nelif a == \"G\":\n print(\"C\")\nelse:\n print(\"G\")", "# author: Taichicchi\n# created: 09.09.2020 23:20:32\n\nimport sys\n\nb = input()\n\nd = {\n \"A\" : \"T\",\n \"T\" : \"A\",\n \"G\" : \"C\",\n \"C\" : \"G\",\n}\n\nprint(d[b])", "b = input()\n\nif b == \"A\":\n print(\"T\")\nif b == \"C\":\n print(\"G\")\nif b == \"T\":\n print(\"A\")\nif b == \"G\":\n print(\"C\")\n", "# A,Double Helix\n# AtCoder \u661f\u306b\u306f\u56db\u7a2e\u985e\u306e\u5869\u57fa A, C, G, T \u304c\u5b58\u5728\u3057\u3001A \u3068 T\u3001C \u3068 G \u304c\u305d\u308c\u305e\u308c\u5bfe\u306b\u306a\u308a\u307e\u3059\u3002\n# \u6587\u5b57 b\u304c\u5165\u529b\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f A, C, G, T \u306e\u3044\u305a\u308c\u304b\u3067\u3059\u3002\u5869\u57fab\u3068\u5bfe\u306b\u306a\u308b\u5869\u57fa\u3092\u8868\u3059\u6587\u5b57\u3092\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u304f\u3060\u3055\u3044\u3002\n\n# b\u306f\u6587\u5b57 A, C, G, T \u306e\u3044\u305a\u308c\u304b\u3067\u3042\u308b\u3002\n\nb = input()\n\n# \u5869\u57fab\u3068\u5bfe\u306b\u306a\u308b\u5869\u57fa\u3092\u8868\u3059\u6587\u5b57\u3092\u51fa\u529b\u305b\u3088\u3002\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"C\":\n print(\"G\")\nelif b == \"G\":\n print(\"C\")", "b = input()\nif b == \"A\":\n print(\"T\")\nif b == \"T\":\n print(\"A\")\nif b == \"C\":\n print(\"G\")\nif b == \"G\":\n print(\"C\")\n\n", "print('TCG A'[ord(input())%5])", "b = input()\nif b == 'A': print('T')\nelif b == 'T': print('A')\nelif b == 'C': print('G')\nelse: print('C')", "DNA_b = input()\n\nif DNA_b == 'A':\n print('T')\nelif DNA_b == 'T':\n print('A')\nelif DNA_b == \"C\":\n print('G')\nelif DNA_b == \"G\":\n print('C')", "a = input()\nif a == \"A\":\n print(\"T\")\nif a == \"T\":\n print(\"A\")\nif a == \"G\":\n print(\"C\")\nif a == \"C\":\n print(\"G\")", "b = str(input())\n\nif b == 'A':\n print('T')\nif b == 'T':\n print('A')\n\nif b == 'C':\n print('G')\nif b == 'G':\n print('C')", "b = input()\nif b == \"A\" :\n print(\"T\")\nelif b == \"T\" :\n print(\"A\")\nelif b == \"G\" :\n print(\"C\")\nelif b == \"C\" :\n print(\"G\")", "AT = ['A', 'T']\nCG = ['C', 'G']\nb = input()\n\nif b in AT:\n AT.remove(b)\n print((*AT))\nelse:\n CG.remove(b)\n print((*CG))\n", "b = input()\n\nif b == 'A' or b == 'T':\n print('AT'.replace(b,''))\nelse:\n print('CG'.replace(b,''))", "b = input()\n\nif b == \"A\":\n print(\"T\")\n\nelif b == \"T\":\n print(\"A\")\n\nelif b == \"C\":\n print(\"G\")\n\nelif b == \"G\":\n print(\"C\")", "b = input()\n\ndict = {\n 'A':'T',\n 'T':'A',\n 'C':'G',\n 'G':'C'\n}\n\nprint(dict[b])", "b = input()\n\nif b == \"A\":\n print(\"T\")\nelif b == \"T\":\n print(\"A\")\nelif b == \"G\":\n print(\"C\")\nelse:\n print(\"G\")", "#122A\n\n#1.\u5165\u529b\u3092\u3061\u3083\u3093\u3068\u53d7\u3051\u53d6\u308b\u3053\u3068\nb=input()\n#2.\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\nif b=='A' :\n print('T')\nelif b=='G':\n print('C')\nelif b=='T':\n print('A')\nelif b=='C':\n print('G')", "s = input()\n\nif s == 'A':\n print('T')\nelif s == 'T':\n print('A')\nelif s == 'C':\n print('G')\nelse:\n print('C')", "a = input()\n\nif a==\"A\":\n print(\"T\")\n\nelif a == \"C\":\n print(\"G\")\n\nelif a ==\"G\":\n print(\"C\")\n\nelse:\n print(\"A\")", "d = dict()\nd[\"A\"] = \"T\"\nd[\"T\"] = \"A\"\nd[\"C\"] = \"G\"\nd[\"G\"] = \"C\"\nS = input()\nprint(d[S])", "b = input()\nif b==\"A\":\n print(\"T\")\nelif b==\"T\":\n print(\"A\")\nelif b==\"C\":\n print(\"G\")\nelse:\n print(\"C\") ", "a=input()\nif a=='A':print('T')\nelif a=='T':print('A')\nelif a=='C':print('G')\nelse:print('C')", "b = input()\n\nif b == 'A':\n print('T')\nelif b == 'T':\n print('A')\nelif b == 'G':\n print('C')\nelse:\n print('G')"] | {"inputs": ["A\n", "G\n", "C\n", "T\n"], "outputs": ["T\n", "C\n", "G\n", "A\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 15,009 | |
507afa7ba2e061135530c4a0de9f6f85 | UNKNOWN | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1).
You will travel to the bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies.
You will collect all the candies you visit during the travel.
The top-left and bottom-right squares also contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to travel?
-----Constraints-----
- 1 \leq N \leq 100
- 1 \leq A_{i, j} \leq 100 (1 \leq i \leq 2, 1 \leq j \leq N)
-----Input-----
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
-----Output-----
Print the maximum number of candies that can be collected.
-----Sample Input-----
5
3 2 2 4 1
1 2 2 2 1
-----Sample Output-----
14
The number of collected candies will be maximized when you:
- move right three times, then move down once, then move right once. | ["def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n = int(input())\n a_1 = Input()\n a_2 = Input()\n ans = 0\n for i in range(n):\n ans = max(ans, sum(a_1[:i+1])+sum(a_2[i:n]))\n print(ans)\n\nmain()", "N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\n\nans = 0\n\nfor i in range(1,N+1):\n ans = max(sum(A[:i])+sum(B[i-1:]),ans)\nprint(ans)", "N = int(input())\narr = []\nfor _ in range(2):\n arr.append(list(map(int,input().split())))\n\nans = 0\nfor i in range(0,N):\n x = sum(arr[0][:i+1]) + sum(arr[1][i:])\n ans = max(ans,x)\nprint(ans)", "import math\nimport sys\nimport os\nfrom operator import mul\nimport numpy as np\n\nsys.setrecursionlimit(10**7)\n\ndef _S(): return sys.stdin.readline().rstrip()\ndef I(): return int(_S())\ndef LS(): return list(_S().split())\ndef LI(): return list(map(int,LS()))\n\nif os.getenv(\"LOCAL\"):\n inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'\n sys.stdin = open(inputFile, \"r\")\nINF = float(\"inf\")\n\n\nN = I()\nA1 = LI()\nA2 = LI()\n\nif N == 1:\n print(A1[0]+A2[0])\n return\n\nans = 0\nfor i in range(N):\n ans = max(ans, sum(A1[:i])+sum(A2[i-1:]))\n\n\n# A1n = np.zeros(N,dtype='int')\n# A1n = np.array(A1)\n# A2n = np.zeros(N,dtype='int')\n# A2n = np.array(A2)\n\n# A1_cum = np.zeros(N,dtype='int')\n# A2_cum = np.zeros(N,dtype='int')\n# A1_cum[1:] = A1n[1:].cumsum()\n# A2_cum[1:] = A2n[:-1].cumsum()\n# # print(A1_cum)\n# # print(A2_cum)\n\n# # \u4e0b\u306b\u964d\u308a\u308b\u6700\u521d\u306e\u4f4d\u7f6e\n# start = N - 2\n# for i in range(N-1):\n# if A1_cum[N-1] - A1_cum[i] < A2_cum[N-1] - A2_cum[i]:\n# start = i\n# break\n\n# ans = A1n[0] + A2n[-1] + A1_cum[start] + (A2_cum[-1] - A2_cum[start])\n\n# # ans = sum(A1) + sum(A2) - min(A1[-1],A2[0]+A2[1])\n\nprint(ans)", "n = int(input())\na = [list(map(int,input().split())) for _ in range(2)]\ncnt = 0\nans = 0\nif n != 1:\n for i in range(1,n):\n cnt = sum(a[0][0:i]) + sum(a[1][i-1:n])\n ans = max(ans,cnt)\n cnt = 0\nelse:\n ans = a[0][0]+a[1][0]\nprint(ans)", "n = int(input())\na = [list(map(int,input().split())) for _ in range(2)]\ns = 0\nfor i in range(n):\n s += a[0][i]\n a[0][i] = s\na[1][0] += a[0][0]\nfor i in range(1, n):\n a[1][i] += max(a[0][i], a[1][i - 1])\nprint(a[1][-1])", "N = int(input())\n\nA = [[] for _ in range(2)]\nfor i in range(2):\n A[i] = list(map(int,input().split()))\n\nAmeMax = 0\nfor n in range(1, N+1):\n preAme = sum(A[0][:n]) + sum(A[1][n-1:])\n if AmeMax < preAme:\n AmeMax = preAme\n\nprint(AmeMax)\n\n", "N = int(input())\nA1 = list(map(int,input().split()))\nA2 = list(map(int,input().split()))\nC = []\n\nS = sum(A2) + A1[0]\n\nfor i in range(1,N):\n C.append(S)\n S += A1[i]-A2[i-1]\n \nif N != 1:\n print(max(C))\nelse:\n print(A1[0]+A2[0])", "import numpy as np\n\nN = int(input())\n\nA1 = list(map(int, input().split()))\nA2 = list(map(int, input().split()))\n\nA1_sum = [np.sum(A1[:N-i]) for i in range(N)]\nA2_sum = [np.sum(A2[N-1-i:]) for i in range(N)]\n\nA_sum = [A1_sum[i]+A2_sum[i] for i in range(N)]\nprint(np.max(A_sum))", "N = int(input())\na1 = list(map(int,input().split()))\na2 = list(map(int,input().split()))\n\nmaxim = 0\nfor i in range(N):\n count = 0\n count += sum(a1[:i+1]) + sum(a2[i:])\n if count > maxim:\n maxim = count\nprint(maxim)", "def main():\n n = int(input())\n a_lst1 = list(map(int, input().split()))\n a_lst2 = list(map(int, input().split()))\n candies_lst = []\n\n tmp = 1\n while tmp <= n:\n a1_tmp = a_lst1[:tmp]\n a2_tmp = a_lst2[tmp-1:]\n a1 = sum(a1_tmp)\n a2 = sum(a2_tmp)\n\n tmp += 1\n candies = a1 + a2\n candies_lst.append(candies)\n\n maximum = max(candies_lst)\n print(maximum)\n\n\ndef __starting_point():\n main()\n__starting_point()", "n = int(input())\naa = [\n list(map(int, input().split()))\n for _ in range(2)\n]\n\nif n == 1:\n print(aa[0][0] + aa[1][0])\n return\n\nfor i in range(1, n):\n aa[1][-i - 1] += aa[1][-i]\nfor i in range(1, n):\n aa[0][-i - 1] += max(aa[1][-i - 1], aa[0][-i])\nprint(aa[0][0])", "n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\ntmp = []\ncnd = 0\nfor i in range(n):\n cnd = sum(a[:i+1]) + sum(b[i:])\n tmp.append(cnd)\n cnd = 0\nprint(max(tmp))", "n = int(input())\nl = [list(map(int, input().split())) for _ in range(2)]\n\nr1 = [sum(l[0][:i+1])for i in range(n)]\nr2 = [sum(l[1][i:])for i in range(n)]\n\nmax_cnt = 0\nfor i in range(n):\n cnt = r1[i] + r2[i]\n max_cnt = max(max_cnt, cnt)\nprint(max_cnt)", "N = int(input())\n\nA = [list(map(int,input().split())) for i in range(2)]\nB = [[0 for i in range(N)] for j in range(2)]\n\nB[0][0] = A[0][0]\nfor i in range(2):\n for j in range(N):\n for x, y in [[0, -1], [-1, 0]]:\n id = i+x\n jd = j+y\n if id < 0 or id >= 2 or jd < 0 or jd >= N: continue\n c = B[id][jd]+A[i][j]\n if c > B[i][j]:\n B[i][j] = c\n \n\n\nprint(B[1][N-1])", "n = int(input())\nL = [list(map(int,input().split())), list(map(int,input().split()))]\nans = 0\n\nfor i in range(n):\n cnt = 0\n for j in range(n):\n if j < i: \n cnt += L[0][j]\n elif j == i:\n cnt += L[0][j] + L[1][j]\n else:\n cnt += L[1][j]\n ans = max(ans,cnt)\n\nprint(ans)", "N = int(input())\nimport numpy as np\nA = np.array([[int(x) for x in input().split()],[int(x) for x in input().split()]], dtype='int64')\nA = A.cumsum(axis=1)\nAns = [A[0,i]+A[1,N-1]-A[1,i-1] if i > 0 else A[0,i]+A[1,N-1] for i in range(N)]\nprint(max(Ans))", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon Sep 21 21:50:38 2020\n\n@author: liang\n\"\"\"\n\nN = int(input())\nA = [int(x) for x in input().split()]\nB = [int(x) for x in input().split()]\n\ntmp = sum(A) + B[N-1]\nans = tmp\nfor i in reversed(range(1,N)):\n tmp -= A[i]\n tmp += B[i-1]\n if ans < tmp:\n ans = tmp\nprint(ans)", "n=int(input())\na = list(map(int, input().split()))\nb= list(map(int, input().split()))\nans=0\nfor i in range(n):\n if ans<(sum(a[:i+1])+sum(b[i:])):\n ans=(sum(a[:i+1])+sum(b[i:]))\nprint(ans)", "import numpy as np\nN = int(input())\na = []\na.append(list(map(int, input().split())))\na.append(list(map(int, input().split())))\ndp = np.zeros((2,N), dtype=int)\nfor j in range(N):\n if j == 0:\n dp[0][j] = a[0][j]\n dp[1][j] = a[0][j] + a[1][j]\n else:\n dp[0][j] = dp[0][j-1] + a[0][j]\n dp[1][j] = max(dp[1][j-1] + a[1][j], dp[0][j] + a[1][j])\nprint((max(dp[1][-1],dp[0][-1])))\n", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nmax=0\nfor i in range(n):\n tmp=sum(a[:i+1])\n tmp+=sum(b[i:])\n if max<tmp:\n max=tmp\n\nprint(max)", "import itertools\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nmaxi = 0\n\nfor i in range(N):\n if sum(A[0:i+1]) + sum(B[i:N]) > maxi:\n maxi = sum(A[0:i+1]) + sum(B[i:N])\n\nprint(maxi)\n", "N=int(input())\na=list(map(int,input().strip().split()))\nb=list(map(int,input().strip().split()))\n\n#\u7d2f\u7a4d\u548c\nA=[]\nB=[]\nsuma=0\nsumb=0\nfor n in range(N):\n suma+=a[n]\n A.append(suma)\nfor n in reversed(range(N)):\n sumb+=b[n]\n B.append(sumb)\n\nMAX=0\nfor n in range(N):\n MAX=max(MAX,A[n]+B[N-n-1])\nprint(MAX)", "n=int(input())\n\na=[[int(i) for i in input().split()] for j in range(2)]\n\nsentou=[]\nusiro=[]\n\nfor i in range(n):\n if i==0:\n sentou.append(a[0][0])\n usiro.append(a[1][-1])\n else:\n sentou.append(a[0][i]+sentou[-1])\n usiro.append(a[1][-i-1]+usiro[-1])\n\nusiro=usiro[::-1]\nans=[]\nfor i in range(n):\n ans.append(sentou[i]+usiro[i])\nprint(max(ans))", "n = int(input())\na1 = list(map(int, input().split()))\na2 = list(map(int, input().split()))\n\nres = 0\ntmp1 = 0\nfor i in range(n):\n tmp1 += a1[i]\n tmp2 = 0\n for j in range(i, n):\n tmp2 += a2[j]\n res = max(res, tmp1+tmp2)\n\nprint(res)\n", "n = int(input())\nal = list(list(map(int, input().split())) for _ in range(2))\n\nans = 0\nfor i in range(n):\n # print(al[0][:i+1], al[1][i:])\n ans = max(ans, sum(al[0][:i+1]) + sum(al[1][i:]))\n\nprint(ans)", "from numpy import cumsum\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nsa = cumsum(a)\nsb = cumsum(b)\nans = 0\nfor i in range(n):\n ans = max(ans, sa[i] + sb[n-1] - sb[i] + b[i])\n\nprint(ans)\n", "n = int(input())\nl = list(map(int, input().split()))\nm = list(map(int, input().split()))\na = 0\nb = 0\n\nfor j in range(n):\n b = sum(l[0:j+1]) + sum(m[j:n+1])\n if a < b:\n a = b\n else:\n pass\n \nprint(a)\n", "N = int(input())\nList = []\nfor i in range (2):\n List.append(list(map(int, input().split())))\nsumList1 = [0]*N\nsumList2 = [0]*N\nfor i in range(N):\n if i == 0:\n sumList1[i] = List[0][i]\n sumList2[N-1-i] = List[1][N-1-i]\n else:\n sumList1[i] = List[0][i]+sumList1[i-1]\n sumList2[N-1-i] = List[1][N-1-i]+sumList2[N-i]\nres = 0\nfor i in range(N):\n res = max(sumList1[i]+sumList2[i],res)\nprint(res)", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, A: \"List[List[int]]\"):\n from itertools import accumulate\n B = [list(accumulate([0]+a)) for a in A]\n return max(B[0][i+1] + B[1][N] - B[1][i] for i in range(N))\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n A = [[int(next(tokens)) for _ in range(N)] for _ in range(2)] # type: \"List[List[int]]\"\n print((solve(N, A)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef __starting_point():\n #test()\n main()\n\n__starting_point()", "N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nans = 0\nfor i in range(N):\n ans = max(ans, sum(A[:i+1]) + sum(B[i:]))\nprint(ans)\n", "# -*- coding: utf-8 -*-\n\nN = int(input())\nA = [list(map(int, input().split())) for _ in range(2)]\n\nans = 0\nfor k in range(N):\n res = 0\n for x in range(N):\n if x < k:\n res += A[0][x]\n elif x==k:\n res += A[0][x]+A[1][x]\n else:\n res += A[1][x]\n\n ans = max(ans,res)\n\nprint(ans)", "N = int(input())\nA = list(map(int,input().split())) ##\u4e0a\u6bb5\nB = list(map(int,input().split())) ##\u4e0b\u6bb5\n\ndp = [[] for i in range(N)]\ndp[0] = A[0] + B[0]\nUpSum = A[0]\nfor i in range(1,N):\n UpSum += A[i] \n dp[i] = max(dp[i-1],UpSum) + B[i]\nprint(dp[-1])", "\n\nN = int(input())\n\nupper = list(map(int,input().split()))\ndown = list(map(int,input().split()))\n\nscores = []\nfor i in range(N):\n score = 0\n flag = 0\n for j in range(N):\n if i == j and flag == 0:\n score += upper[j]\n score += down[j]\n flag = 1\n elif flag == 0:\n score += upper[j]\n elif flag == 1:\n score += down[j]\n scores.append(score)\n\nprint(max(scores))", "n = int(input())\n\nlis = []\nfor _ in range(2):\n lis.append(list(map(lambda x: int(x), input().split(\" \"))))\nmax = 0\nfor i in range(n):\n su = sum(lis[0][:i + 1])\n su += sum(lis[1][i:])\n if su >= max:\n max = su\n\nprint(max)", "N = int(input())\nA1 = list(map(int,input().split()))\nA2 = list(map(int,input().split()))\n\ns = []\n\nfor i in range(N):\n a = sum(A1[0:i+1])+sum(A2[i:])\n s.append(a)\n\nprint((max(s)))\n", "N = int(input())\nA1= list(map(int,input().split()))\nA2= list(map(int,input().split()))\nsum2 = sum(A2)\nans = A1[0]+sum2\nvalue = A1[0]+sum2\nfor i in range(1,N):\n value = value + A1[i] - A2[i-1]\n ans = max(ans,value)\nprint(ans)", "N = int(input())\nS1,S2 = [list(map(int,input().split())) for i in range(2)]\nS = 0\nfor i in range(N):\n S = max(S,sum(S1[:i+1])+sum(S2[i:]))\nprint(S)", "n = int(input())\narr = [list(map(int,input().split())) for _ in range(2)]\nans = 0\nfor i in range(n):\n ans = max(ans, sum(arr[0][:i+1] + arr[1][i:]))\nelse:\n print(ans)", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=0\nfor i in range(n):\n c=max(sum(a[:i+1])+sum(b[i:]),c)\nprint(c)", "N = int(input())\nA1 = list(map(int,input().split()))\nA2 = list(map(int,input().split()))\nans = 0\nfor i in range(N):\n cnt = sum(A1[:i+1]) + sum(A2[i:])\n ans = max(ans,cnt)\nprint(ans)", "n=int(input())\na=[[],[]]\na[0]=list(map(int,input().split()))\na[1]=list(map(int,input().split()))\nans=0\nfor i in range(n):\n x,sum=0,0\n for j in range(n+1):\n if i==j-1:x=1\n sum+=a[x][j-x]\n ans=max(sum,ans)\nprint(ans)", "N=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\n\nnax=0\n\nfor i in range(N):\n nax=max(nax,sum(A[:i+1])+sum(B[i:]))\nprint(nax)", "n = int(input())\na = [list(map(int,input().split())),list(map(int,input().split()))]\name = 0\name_l = []\nfor i in range(n): #\u91cd\u8907\u3059\u308b\u5217\u306e\u9078\u629e\n for j in range(n): #\u5404\u5217\u8db3\u3057\u3066\u304f\n if i > j:\n ame += a[0][j]\n elif i == j:\n ame += a[0][j]+a[1][j]\n else:\n ame += a[1][j]\n if j == n-1:\n ame_l.append(ame)\n ame = 0\nprint(max(ame_l))", "n = int(input())\nl = [list(map(int, input().split())) for _ in range(2)]\n\nr1 = []\ntmp1 = 0\nfor i in range(n):\n rui1 = l[0][i] + tmp1\n r1.append(rui1)\n tmp1 = rui1\n\nr2 = [0] * n\ntmp2 = 0\nfor i in reversed(range(n)):\n rui2 = l[1][i] + tmp2\n r2[i] = rui2\n tmp2 = rui2\n\nmax_cnt = 0\nfor i in range(n):\n cnt = r1[i] + r2[i]\n max_cnt = max(max_cnt, cnt)\nprint(max_cnt)", "N=int(input())\nA=[list(map(int,input().split())) for _ in range(2)]\nsum1=[0]\nsum2=[0]\nfor i in range(N):\n sum1.append(sum1[-1]+A[0][i])\n sum2.append(sum2[-1]+A[1][i])\n\nprint((max(sum1[i]+sum2[N]-sum2[i-1] for i in range(1,N+1))))\n", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\ndp=[[0 for i in range(n)] for j in range(2)]\ndp[0][0]=a[0]\nfor i in range(1,n):\n dp[0][i]=a[i]+dp[0][i-1]\ndp[1][0]=dp[0][0]+b[0]\nfor i in range(1,n):\n dp[1][i]=max(dp[0][i],dp[1][i-1])+b[i]\nprint((dp[1][n-1]))\n\n", "N = int(input())\nA = list(map(int,input().split())) \nB = list(map(int,input().split()))[::-1]\n#print(A)\n#print(B)\n\n\nl = []\n\nfor i in range(N):\n l.append(sum(A[:N-i])+sum(B[:i+1]))\n \n#print(l)\nprint((max(l)))\n\n\n", "n=int(input())\na=[list(map(int,input().split())) for i in range(2)]\nans=0\nif n==1:\n print(sum(a[0])+sum(a[1]))\n return\nfor i in range(n):\n ans=max(ans,sum(a[0][0:i])+sum(a[1][i-1:n]))\nprint(ans)", "n = int(input())\na = [list(map(int,input().split())) for _ in range(2)]\nprint(max(sum(a[0][:i+1] + a[1][i:]) for i in range(n)))", "N=int(input())\nA=[]\nfor _ in range(2):\n A.append(list(map(int,input().split())))\nans=0\nfor i in range(N):\n tmp=0\n tmp+=sum(A[0][:i+1])\n tmp+=sum(A[1][i:])\n if tmp>ans:\n ans=tmp\nprint(ans)", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n = int(input())\n a_1 = Input()\n a_2 = Input()\n\n a_1_sum = [0] * n\n a_2_sum = [0] * n\n a_1_sum[0] = a_1[0]\n\n for i in range(1, n):\n a_1_sum[i] = a_1_sum[i-1] + a_1[i]\n for i in range(n):\n a_2_sum[i] = sum(a_2) - sum(a_2[:i])\n\n ans = 0\n for a1, a2 in zip(a_1_sum, a_2_sum):\n ans = max(ans, a1+a2)\n print(ans)\n\n\nmain()", "N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\n\nC = [0] * N \nC[0] = A[0] + sum(B)\nfor i in range(1,N):\n C[i] = C[i-1]+A[i]-B[i-1]\nprint((max(C)))\n", "n = int(input())\nup = list(map(int,input().split()))\ndw = list(map(int,input().split()))\nans = up[0]+sum(dw)\ntmp = up[0]+sum(dw)\nfor i in range(1,n):\n tmp = tmp+up[i]-dw[i-1]\n ans = max(tmp,ans)\nprint(ans)", "N = int(input())\nA1 = list(map(int, input().split()))\nA2 = list(map(int, input().split()))\n\na1 = [0]\na2 = [0]\n\nfor i in range(N):\n if i == 0:\n a1.append(A1[i])\n a2.append(A2[i])\n else:\n a1.append(a1[-1] + A1[i])\n a2.append(a2[-1] + A2[i])\n \nans = 0\n\nfor i in range(N):\n if a1[i+1] + a2[-1] - a2[i] > ans:\n ans = a1[i+1] + a2[-1] - a2[i]\n \nprint(ans)", "n = int(input())\na1 = list(map(int,input().split()))\na2 = list(map(int,input().split()))\nans = 0\nfor i in range(n):\n ans = max(ans,sum(a1[0:i+1])+sum(a2[i:n]))\nprint(ans)\n\n\n\n", "n=int(input())\na = [list(map(int,input().split())) for _ in range(2)]\n\namemax=0\nfor i in range(n):\n ame=sum(a[0][:i+1])+sum(a[1][i:])\n amemax = max(ame,amemax)\n \nprint(amemax)", "n = int(input())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nres = 0\nfor i in range(n):\n c = 0\n for j in range(n):\n if j < i:\n c += a[j]\n elif j == i:\n c += a[j]\n c += b[j]\n else:\n c += b[j]\n res = max(res,c)\nprint(res)", "N = int(input())\nA1 = input().split(' ')\nA2 = input().split(' ')\nA1 = [int(A1[i]) for i in range(N)]\nA2 = [int(A2[i]) for i in range(N)]\nSaidai = 0\nfor i in range(N):\n Atai = 0\n for j in range(i+1):\n Atai += A1[j]\n for h in range(i, N):\n Atai += A2[h]\n if Atai > Saidai:\n Saidai = Atai\nprint(Saidai)", "n = int(input())\na1 = list(map(int, input().split()))\na2 = list(map(int, input().split()))\n\nfor i in range(1, n):\n a1[i] += a1[i - 1]\n\nfor i in range(n - 2, -1, -1):\n a2[i] += a2[i + 1]\n\nres = 0\nfor i in range(n):\n tmp = a1[i] + a2[i]\n res = max(tmp, res)\n\nprint(res)\n", "n = int(input())\na1 = list(map(int, input().split()))\na2 = list(map(int, input().split()))\nans = sum(a1)+a2[-1]\nmemo = ans\na1.reverse()\na2.reverse()\nfor i in range(n-1):\n memo -=a1[i]-a2[i+1]\n if memo > ans:\n ans = memo\nprint(ans)\n", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int, input().split()))\nans = 0\nfor i in range(n):\n ans = max(ans,sum(a[:i+1])+sum(b[i:n]))\nprint(ans)", "n = int(input())\na_l1 = list(map(int, input().split()))\na_l2 = list(map(int, input().split()))\nc = 0\nm_a_l1 = []\nfor i in a_l1:\n c += i\n m_a_l1.append(c)\nc = 0\nm_a_l2 = [0] * n\nfor i,j in enumerate(reversed(a_l2)):\n c += j\n m_a_l2[-1-i] = c\n\nans = 0\nfor i,j in zip(m_a_l1, m_a_l2):\n ans = max(i+j, ans)\nprint(ans)", "N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nC=[]\nfor i in range(N):\n C.append(sum(A[0:i+1])+sum(B[i:]))\nprint(max(C))", "N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\n\nans = 0\nx = 0\nC = []\nD = []\nif N == 1:\n print((A[0] + B[0]))\n return\nfor i in range(N):\n C = A[0:i]\n D = B[i - 1:N]\n x = sum(C) + sum(D)\n ans = max(ans, x)\n\nprint(ans)\n", "N = int(input())\nA1 = list(map(int, input().split()))\nA2 = list(map(int, input().split()))\nans = 0\nfor i in range(N):\n t = 0\n for j in range(0, min(N, i + 1)):\n t += A1[j]\n for k in range(i, N):\n t += A2[k]\n ans = max(t, ans)\nprint(ans)\n", "n = int(input())\na = [list(map(int,input().split())) for _ in range(2)]\name = []\nfor i in range(n):\n ame.append(sum(a[0][:i+1])+sum(a[1][i:]))\nprint(max(ame))", "N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nans = 0\nfor i in range(N):\n ans = max(ans, sum(A[:i+1])+sum(B[i:]))\nprint(ans)", "n = int(input())\na = [list(map(int, input().split())) for _ in range(2)]\n\nans = 0\nfor i in range(n):\n t = sum(a[0][:i+1]) + sum(a[1][i:])\n if ans < t: ans = t\nprint(ans)", "N = int(input())\nA_top = list(map(int,input().split()))\nA_down = list(map(int,input().split()))\ncnt_max = 0\n\nfor i in range(N):\n count = sum(A_top[:i+1]) + sum(A_down[i:])\n if count > cnt_max:\n cnt_max = count\n \nprint(cnt_max)\n", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n maps=[]\n n = int(input())\n maps=[list(map(int,input().split())) for _ in range(2)]\n dp=[]\n for i in range(n):\n total=sum(maps[0][:i+1])+sum(maps[1][i:])\n dp.append(total)\n print(max(dp))\n\ndef __starting_point():\n main()\n__starting_point()", "n=int(input())\nA1=list(map(int,input().split()))\nA2=list(map(int,input().split()))\nans=0\nfor i in range(n):\n ans=max(ans,sum(A1[:i+1])+sum(A2[i:]))\nprint(ans)", "\nN = int(input())\nAU = list(map(int, input().split()))\nAD = list(map(int, input().split()))\n\nAUS = [AU[0]]\nADS = [AD[-1]]\n\nfor i in range(1, N):\n AUS.append(AUS[-1] + AU[i])\n ADS.append(ADS[-1] + AD[-1-i])\n\nADS.reverse()\n\nans = 0\nfor i in range(N):\n temp = AUS[i]+ADS[i]\n ans = max(ans, temp)\n\nprint(ans)", "N = int(input())\nA = list([0]*N for _ in range(2))\nfor i in range(2):\n A[i] = list(map(int, input().split()))\n\nresult = []\n\nfor i in range(N):\n tmp = 0\n tmp += sum(A[0][0:i+1])\n tmp += sum(A[1][i:N])\n result.append(tmp)\n\nprint(max(result))", "n = int(input())\na = [list(map(int,input().split())) for _ in range(2)]\nprint(max((sum(a[0][:i+1] + a[1][i:])) for i in range(n)))", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nmax=0\nfor i in range(n):\n tmp=sum(a[:i+1])\n tmp+=sum(b[i:])\n if max<tmp:\n max=tmp\nprint(max)", "N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\n\name_A = [0] * N\name_B = [0] * N\n\nfor i in range(N):\n if i == 0:\n ame_A[i] += A[i]\n continue\n ame_A[i] += ame_A[i-1] + A[i]\n\nfor i in range(N-1,-1,-1):\n if i == N - 1:\n ame_B[i] += B[i]\n continue\n ame_B[i] += ame_B[i+1] + B[i]\n \nans = 0\nfor j in range(N):\n cnt = ame_A[j] + ame_B[j]\n ans = max(ans, cnt)\n \nprint(ans)", "N = int(input())\nA1 = list(map(int,input().split()))\nA2 = list(map(int,input().split()))\n\ns = []\n\nfor i in range(N):\n a = sum(A1[0:i+1])+sum(A2[i:])\n s.append(a)\n\nprint(max(s))", "#!/usr/bin/env python3\nn = int(input())\na = [list(map(int, input().split())) for i in range(2)]\n\ndp = [[0]*(n+1) for _ in range(3)]\n\nfor i in range(1, 3):\n for j in range(1, n+1):\n now = a[i-1][j-1]\n dp[i][j] = max(dp[i-1][j], dp[i][j-1])+now\n\n# print(dp)\nprint((dp[-1][-1]))\n", "n = int(input())\na = [list(map(int, input().split())) for _ in range(2)]\n\nm = 0\n\nfor i in range(n):\n l = sum(a[0][:i+1]) + sum(a[1][i:])\n m = max(m, l)\n\nprint(m)\n", "N = int(input())\nA1 = list(map(int, input().split()))\nA2 = list(map(int, input().split()))\nans = 0\n\nfor i in range(N):\n x = sum(A1[:i+1])+sum(A2[i:])\n if x > ans:\n ans = x\nprint(ans)\n", "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n maps=[]\n n = int(input())\n maps=[list(map(int,input().split())) for _ in range(2)]\n dp=[]\n for i in range(n):\n total=sum(maps[0][:i+1])+sum(maps[1][i:])\n dp.append(total)\n print(max(dp))\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nlist1 = []\name = A[0]\nfor i in range(N-1):\n list1.append(sum(A[:i+1])+sum(B[i:]))\n \nif list1 == []:\n print(A[0]+B[0])\nelse:\n print(max(list1))", "N = int(input())\nA = [list(map(int, input().split())) for _ in range(2)]\n\n# \u9ad8\u3005N\u901a\u308a\n# A[0][0] + (A[1][0] + ... + A[1][N-1])\n# (A[0][0] + A[0][1]) + (A[1][1] + ... + A[1][N-1])\n# (A[0][0] + A[0][1] + A[0][2]) + (A[1][2] + ... + A[1][N-1])\n# (A[0][0] + ...+ A[0][N-1]) + A[1][N-1]\n\n# N=100 => O(N^2)\u3067\u9593\u306b\u5408\u3046\nans = 0\nfor i in range(N):\n ans = max(ans, sum(A[0][:i+1]) + sum(A[1][i:]))\n \nprint(ans)", "def main():\n N = int(input())\n A1 = list(map(int, input().split()))\n A2 = list(map(int, input().split()))\n ans = 0; cnt = 0\n for i in range(N):\n cnt += sum(A1[:i]) + A1[i]\n cnt += sum(A2[i:])\n ans = max(ans, cnt)\n cnt = 0\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "N=int(input())\n\nA1=list(map(int,input().split()))\nA2=list(map(int,input().split()))\nans=0\nfor i in range(N):\n temp=sum(A1[:i+1])+sum(A2[i:])\n if temp>ans:\n ans=temp\n\nprint(ans)\n", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n n = ini()\n a1 = inl()\n a2 = inl()\n b1, b2 = a1[0], a1[0] + a2[0]\n for i in range(1, n):\n b2 = max(b2 + a2[i], b1 + a1[i] + a2[i])\n b1 = b1 + a1[i]\n return b2\n\n\nprint(solve())\n", "n = int(input())\na1 = [ int(x) for x in input().split() ]\na2 = [ int(x) for x in input().split() ]\n\ncandy_max = 0\n\nfor i in range(n+1):\n candies = sum(a1[0:i+1]) + sum(a2[i:n])\n if candy_max < candies:\n candy_max = candies\n\nprint(candy_max)\n", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nans=0\nfor i in range(n):\n z=0\n for j in range(i+1):\n z+=a[j]\n for j in range(i,n):\n z+=b[j]\n ans=max(ans,z)\nprint(ans)\n", "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nacount=0\nbcount=0\nans=0\n\nfor i in range(n):\n bcount=0\n acount+=a[i]\n for j in range(i,n):\n bcount+=b[j]\n if ans<acount+bcount:\n ans=acount+bcount\nprint(ans)", "n = int(input())\n\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nans = []\nfor i in range(n):\n ans.append(sum(a[0:i+1]) + sum(b[i:n]))\n\n\nprint(max(ans))", "import sys\n\ninput = sys.stdin.readline\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nans = 0\nfor i in range(N):\n tmp = sum(A[:i+1]) + sum(B[i:])\n ans = max(ans, tmp)\nprint(ans)", "\ndef main():\n with open(0) as f:\n N = int(f.readline())\n A = list(map(int, f.readline().split()))\n B = list(map(int, f.readline().split()))\n\n ans = max([sum(A[:i+1]+B[i:]) for i in range(N)])\n print(ans)\n\nmain()", "# coding: utf-8\n\n\ndef main():\n N = int(input())\n A = [list(map(int, input().split())) for _ in range(2)]\n\n for i in range(1, N):\n A[0][i] += A[0][i - 1]\n A[1][N - i - 1] += A[1][N - i]\n\n ans = max([A[0][i] + A[1][i] for i in range(N)])\n\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\ndp = [[0 for i in range(n)] for i in range(2)]\na1 = list(map(int, input().split()))\na2 = list(map(int, input().split()))\n\ndp[0][0] = a1[0]\nfor i in range(1, n):\n dp[0][i] = dp[0][i - 1] + a1[i]\ndp[1][0] = dp[0][0] + a2[0]\n\nfor i in range(1, n):\n dp[1][i] = max(dp[0][i] + a2[i], dp[1][i - 1] + a2[i])\n\nprint((dp[1][-1]))\n", "N = int(input())\n\nr1 = [int(s) for s in input().split()]\nr2 = [int(s) for s in input().split()]\n\nsum_max = 0\nfor e in range(N):\n right = r1[:e+1]\n left = r2[e:]\n if sum_max < sum(right) + sum(left):\n sum_max = sum(right) + sum(left)\n\nprint(sum_max)\n", "N = int(input())\nA = [[],[]]\nA[0] = list(map(int, input().split()))\nA[1] = list(map(int, input().split()))\nresult = 0\nfor i in range(N+1):\n result = max(sum(A[0][:i]) + sum(A[1][i-1:]), result)\nprint(result)", "n = int(input())\nA1 = list(map(int, input().split()))\nA2 = list(map(int, input().split()))\nmax_p = -1\n\nfor i in range(n):\n point = sum(A1[:i+1]) + sum(A2[i:])\n max_p = max(max_p, point)\nprint(max_p)", "n=int(input())\nx=list(map(int,input().split()))\ny=list(map(int,input().split()))\nans=0\nfor i in range(n):\n ans=max(ans,sum(x[:i+1])+sum(y[i:]))\nprint(ans)", "N=int(input())\nA=[0,0]\nA[0]=list(map(int,input().split()))\nA[1]=list(map(int,input().split()))\ncount=[0]*N\nfor i in range(N) :\n count[i]+=sum(A[0][:i+1])+sum(A[1][i:])\nprint(max(count))"] | {"inputs": ["5\n3 2 2 4 1\n1 2 2 2 1\n", "4\n1 1 1 1\n1 1 1 1\n", "7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n", "1\n2\n3\n"], "outputs": ["14\n", "5\n", "29\n", "5\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 28,687 | |
4911d853491cda47cba0ae9b24119d06 | UNKNOWN | There are N boxes arranged in a row.
Initially, the i-th box from the left contains a_i candies.
Snuke can perform the following operation any number of times:
- Choose a box containing at least one candy, and eat one of the candies in the chosen box.
His objective is as follows:
- Any two neighboring boxes contain at most x candies in total.
Find the minimum number of operations required to achieve the objective.
-----Constraints-----
- 2 β€ N β€ 10^5
- 0 β€ a_i β€ 10^9
- 0 β€ x β€ 10^9
-----Input-----
The input is given from Standard Input in the following format:
N x
a_1 a_2 ... a_N
-----Output-----
Print the minimum number of operations required to achieve the objective.
-----Sample Input-----
3 3
2 2 2
-----Sample Output-----
1
Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2). | ["N, x = [int(n) for n in input().split(\" \")]\nA = [int(a) for a in input().split(\" \")]\n\ncnt = 0\nif A[0] > x:\n cnt += A[0] - x\n A[0] = x\n\nfor i in range(1, len(A)):\n if A[i] + A[i - 1] > x:\n cnt += A[i] + A[i - 1] - x\n A[i] = x - A[i - 1]\n\nprint(cnt)", "N,X=map(int,input().split())\n*A,=map(int,input().split())\n\nB=[0]*N\nfor i in range(N):\n B[i] = A[i] if A[i]<=X else X\n\ncnt=sum(A)-sum(B) \nfor i in range(N-1):\n if X < B[i]+B[i+1]:\n d=B[i]+B[i+1]-X\n B[i+1]-=d\n cnt+=d\nprint(cnt)", "#coding: utf-8\n\nN, X = (int(x) for x in input().split())\nA = [int(x) for x in input().split()]\n\nret = 0\nfor i in range(N-1):\n if A[i] + A[i+1] > X:\n tmp = A[i] + A[i+1] - X\n ret += tmp\n A[i+1] -= min(A[i+1], tmp)\n\n\nprint(ret)\n\n", "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n N, x = LI()\n a = LI()\n\n # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\n s = [a[i] + a[i+1] for i in range(N - 1)]\n # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\u3092x\u4ee5\u4e0b\u306b\u3057\u305f\u3082\u306e\n s_after = [min(i, x) for i in s]\n\n # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\u3092x\u4ee5\u4e0b\u306b\u3057\u305f\u3082\u306e\u304b\u3089\u5143\u306e\u6570\u5217\u3092\u5fa9\u5143\n a_after = [0] * N\n a_after[0] = min(a[0], s_after[0])\n for i in range(N - 1):\n a_after[i+1] = min(s_after[i] - a_after[i], a[i+1])\n\n ans = sum(a) - sum(a_after)\n print(ans)\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "N,X=(int(T) for T in input().split())\nA=list(map(int,input().split()))\nans=0\nfor i in range(0,N-1):\n if A[i]+A[i+1]>X:\n s=A[i]+A[i+1]-X\n ans=s+ans\n A[i]=A[i]-max(0,A[i]-A[i+1])\n A[i+1]=max(0,A[i+1]-s)\nprint(ans)\n", "import sys\n\nN, X = map(int, input().split())\nA = list(map(int, sys.stdin.readline().rsplit()))\nB = A[::]\n\nfor i in range(N - 1):\n a = A[i] + A[i + 1]\n if a > X:\n if A[i + 1] >= a - X:\n A[i + 1] -= a - X\n else:\n A[i] -= a - X - A[i + 1]\n A[i + 1] = 0\n\nres = 0\nfor i in range(N):\n res += B[i] - A[i]\n\nprint(res)", "N,X = (int(T) for T in input().split())\nA = [int(T) for T in input().split()]\nEat = 0\nfor AN in range(0,N-1):\n if A[AN]+A[AN+1]>X:\n Need = A[AN]+A[AN+1]-X\n if A[AN+1]>=Need:\n A[AN+1] -= Need\n else:\n A[AN] -= Need-A[AN+1]\n A[AN+1] = 0\n Eat += Need\nprint(Eat)", "def candy():\n boxNum, x = [int(i) for i in input().split()]\n ain = input()\n alist = ain.split(' ')\n\n s = 0\n \n for i in range(0, boxNum-1):\n if int(alist[i+1]) + int(alist[i]) > x:\n s = s + (int(alist[i+1]) + int(alist[i]) - x)\n alist[i+1] = x - int(alist[i])\n if int(alist[i+1]) < 0:\n alist[i] = int(alist[i]) + int(alist[i+1])\n alist[i+1] = 0\n \n print(s)\n \ncandy()", "n, x = map(int, input().split())\na = list(map(int, input().split()))\ncount = 0\nfor i in range(n-1):\n if a[i] + a[i+1] > x:\n y = a[i] + a[i+1] - x\n count += y\n a[i+1] = max(0, a[i+1]-y)\nprint(count)", "N, x = map(int,input().split())\na = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(N-1):\n if a[i] + a[i+1] > x:\n temp = a[i] + a[i+1] - x \n if a[i+1] - temp >= 0:\n ans += temp\n a[i+1] -= temp\n else:\n ans += temp\n a[i+1] = 0\n a[i] -= temp - a[i+1]\n \nprint(ans)", "n, x = list(map(int, input().split()))\na = [int(y) for y in input().split()]\nans = 0\nfor i in range(1, n):\n d = a[i-1] + a[i]\n if d <= x: continue\n a[i] -= min(a[i], d - x)\n a[i-1] -= max(d - x - a[i], 0)\n ans += d - x\nprint(ans)\n", "N,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n tmp=a[i-1]+a[i]\n if tmp>x:\n ans+=tmp-x\n if a[i]>=tmp-x:\n a[i]-=tmp-x\n else:\n a[i]=0\nprint(ans)", "n, x = map(int, input().split())\narr = list(map(int, input().split()))\nsum_arr = sum(arr)\narr[0] = min(x, arr[0])\n\n\nfor i in range(n-1):\n diff = arr[i] + arr[i+1]\n if diff > x:\n arr[i+1] -= diff - x\n\nprint(sum_arr - sum(arr))", "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nfor i, a in enumerate(A):\n if i == 0:\n ans += min(a, x)\n now_x = x - min(a, x)\n continue\n \n ans += min(a, now_x)\n now_x = x - min(a, now_x)\n\nans2 = 0\nfor i, a in enumerate(A[::-1]):\n if i == 0:\n ans2 += min(a, x)\n now_x = x - min(a, x)\n continue\n \n ans2 += min(a, now_x)\n now_x = x - min(a, now_x)\n\nprint(sum(A) - max(ans, ans2))", "N,X=map(int,input().split())\n*A,=map(int,input().split())\n\nB=[a if a<=X else X for a in A]\nc=sum(A)-sum(B)\nfor i in range(N-1):\n t=B[i]+B[i+1]\n if X < t:\n d=t-X\n B[i+1]-=d\n c+=d\nprint(c)", "N,x=map(int,input().split())\na=list(map(int,input().split()))\n \nans=0\nfor i in range(1,N):\n tmp=a[i-1]+a[i]\n if tmp>x:\n ans+=tmp-x\n if a[i]>=tmp-x:\n a[i]-=tmp-x\n else:\n a[i]=0\n else:\n continue\nprint(ans)", "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\nans = 0\nfor i in range(N-1):\n n = a[i]+a[i+1]\n if n > x:\n ans += n-x\n if n-x > a[i+1]:\n a[i], a[i+1] = a[i]-(n-x-a[i+1]), 0\n else:\n a[i+1] -= (n-x)\nprint(ans)", "N,x = map(int,input().split())\nls = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n if ls[i]+ls[i+1] <= x:\n continue\n else:\n eat = - x + ls[i] + ls[i+1]\n ls[i+1] -= eat\n if ls[i+1] < 0:\n ls[i+1] = 0\n ans += eat\nprint(ans)", "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\ny = min(a[0], x)\nans = a[0]-y\nfor i in range(1, N):\n z = a[i]\n w = max(y+z-x, 0)\n y = z-w\n ans += w\n\nprint(ans)", "n, x = list(map(int, input().split()))\nA = tuple(map(int, input().split()))\npre = max(0, A[0] - x)\nans = pre\n\nfor i in range(n - 1):\n a = A[i]\n b = A[i + 1]\n a -= pre\n tmp = 0\n if b > x:\n tmp += b - x\n b = x\n\n if a + b > x:\n tmp += a + b - x\n ans += tmp\n pre = tmp\nprint(ans)\n", "N, x = map(int, input().split())\nvalues = map(int, input().split())\ncount = 0\nv1 = next(values)\nfor v2 in values:\n surplus = max(v1 + v2 - x, 0)\n count += surplus\n v1 = max(0, v2 - surplus)\nprint(count)", "N,x=map(int,input().split())\na=list(map(int,input().split()))\n\nans=0\nfor i in range(1,N):\n tmp=a[i-1]+a[i]\n if tmp>x:\n ans+=tmp-x\n if a[i]>=tmp-x:\n a[i]-=tmp-x\n else:\n a[i]=0\n else:\n continue\nprint(ans)", "N, x = map(int, input().split())\na = list(map(int, input().split()))\nresult = 0\nif a[0] > x:\n result += a[0] - x\n a[0] = x\nfor i in range(N-1):\n if a[i] + a[i+1] > x:\n result += a[i] + a[i+1] - x\n a[i+1] = x - a[i]\nprint(result)", "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nsum_val = A[0] + A[1]\nif A[0] + A[1] > x:\n if A[1] >= sum_val - x:\n ans += sum_val - x\n A[1] -= sum_val - x\n else:\n ans += A[1] + (A[0] - x)\n A[0] -= (x - A[1])\n A[1] = 0\n# print(A)\n# print(ans)\n\nfor i in range(1, N - 1):\n sum_val = A[i] + A[i + 1]\n if sum_val <= x:\n continue\n ans += sum_val - x\n A[i + 1] -= sum_val - x\n# print(A)\nprint(ans)", "n, x = map(int, input().split())\na = list(map(int, input().split()))\nk = 0\ncnt = 0\n\nif a[1] + a[0] > x and x >= a[0] :\n k = x - a[0]\n cnt += a[1] + a[0] - x\n\nelif a[1] + a[0] > x and x < a[0] :\n k = 0\n cnt += a[1] + a[0] - x\n\nelse :\n k = a[1]\n\nfor i in range(1, n - 1) :\n if k + a[i + 1] <= x :\n k = a[i + 1] \n\n elif x >= k :\n cnt += k + a[i + 1] - x\n k = x - k\n\n else :\n cnt += k + a[i + 1] - x\n k = 0\n \n\nprint(cnt)", "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ncnt = max(0, a[0] - x)\na[0] -= cnt\nfor i in range(1, n):\n cnt_now = max(0, a[i-1] + a[i] - x)\n a[i] -= cnt_now\n cnt += cnt_now\n\nprint(cnt)\n", "n,x = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(n-1):\n if a[i] <= x:\n if a[i]+a[i+1] <= x: continue\n else:\n ans += (a[i]+a[i+1])-x\n a[i+1] -= (a[i]+a[i+1])-x\n else:\n ans += a[i]-x + a[i+1]\n a[i], a[i+1] = x, 0\nif a[-1] > x: ans += a[-1]-x\nprint(ans)", "N,x = map(int,input().split())\na = list(map(int,input().split()))\ncnt = 0\nfor i in range(N-1):\n if(a[i] > x):\n cnt += a[i] - x\n a[i] = x\n \n if(a[i] + a[i+1] > x):\n cnt += a[i] + a[i+1] - x\n a[i+1] = x - a[i]\n \nprint(cnt)", "N, x = [int(x) for x in input().split()]\na = list([int(x) for x in input().split()])\n\ncount = 0\nfor i in range(N):\n if a[i] > x:\n count += a[i] - x\n a[i] -= a[i] - x\n\n if i - 1 >= 0:\n if a[i] + a[i-1] > x:\n count += (a[i] + a[i-1]) - x\n a[i] -= (a[i] + a[i-1]) - x\n\nprint(count)\n", "N, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nans = 0\nkeep = a[0]\nfor i in range(1, N):\n if (keep + a[i]) > x:\n ans = ans + (keep + a[i] - x)\n keep = max(x - keep, 0)\n else:\n keep = a[i]\n\n\nprint(ans)\n", "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = []\nfor i in range(1, n):\n b.append(a[i] + a[i - 1])\nb.append(0)\n\nres = 0\nfor i in range(n - 1):\n dif = max(b[i] - x, 0)\n minus = min(dif, a[i + 1])\n b[i + 1] -= minus\n b[i] -= dif\n res += dif\n\nprint(res)\n", "n,x=[int(i) for i in input().split()]\na=[int(i) for i in input().split()]\n\nadd_a=[]\nfor i in range(n-1):\n add_a.append(max(a[i]+a[i+1]-x,0))\n\nans=0\nfor i in range(n-1):\n ans+=min(add_a[i],a[i+1])\n if i!=n-2:\n add_a[i+1]=max(0,add_a[i+1]-min(add_a[i],a[i+1]))\n add_a[i]-=min(add_a[i],a[i+1])\nans+=add_a[0]\n\nprint(ans)", "def boxes():\n N, x = input().split()\n N, x = int(N), int(x)\n arr = [int(a) for a in input().split()]\n\n total = 0\n for i in range(1, N):\n a, b = arr[i-1], arr[i]\n extra = a + b - x\n if extra > 0:\n total += extra\n if b >= extra:\n arr[i] -= extra\n else:\n arr[i] = 0\n print(total)\nboxes()", "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\nr1 = sum(a)\nflow = 0\n\nfor i in range(1, N):\n t = (a[i] + a[i - 1]) - x\n if flow != 0:\n a[i-1] -= flow\n t -= flow\n flow = 0\n\n if t > 0:\n if t > a[i]:\n t -= a[i]\n a[i - 1] -= t\n t = a[i]\n\n flow = t\n\na[-1] -= flow\n\nr2 = sum(a)\n\nprint(r1 - r2)", "n, x = map(int, input().split())\nA = list(map(int, input().split()))\n\nans = 0\nfor i in range(n - 1):\n if A[i] + A[i + 1] > x:\n ans += A[i] + A[i + 1] - x\n A[i + 1] = max(x - A[i], 0)\nprint(ans)", "N,x = map(int,input().split())\na = list(map(int, input().split()))\nans=0\nwa=a[0]+a[1]\nif wa>x:\n ans=wa-x\n if a[1]<ans:\n a[1]=0\n else:\n a[1]-=ans\nfor i in range(1,N-1):\n wa=a[i]+a[i+1]\n if wa>x:\n ans+=wa-x\n a[i+1]-=(wa-x)\nprint(ans)", "def solve():\n ans = 0\n N, x = map(int, input().split())\n A = list(map(int, input().split()))\n if A[0]>x:\n ans += A[0]-x\n A[0] = x\n for i in range(1,N):\n if A[i]+A[i-1]>x:\n ans += A[i]+A[i-1]-x\n A[i] = x-A[i-1]\n return ans\nprint(solve())", "n, x = map(int, input().split())\na = [int(_) for _ in input().split()]\nans = max(0, a[0]-x)\na[0] -= ans\nfor i in range(n-1):\n if a[i] + a[i+1] > x:\n val = a[i] + a[i+1] - x\n a[i+1] -= val\n ans += val\nprint(ans)", "N, M = map(int, input().split())\nL = list(map(int, input().split()))\n\ncount = 0\n\nif L[0] > M:\n\tcount+= (L[0]-M)\n\tL[0]-= (L[0]-M)\n\nfor i in range (1, N):\n\tif L[i]+L[i-1] > M:\n\t\tcount+= (L[i]+L[i-1])-M\n\t\tL[i]-= (L[i]+L[i-1])-M\n \nprint(count)", "from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf\nfrom itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement\nfrom collections import deque,defaultdict,Counter\nfrom bisect import bisect_left,bisect_right\nfrom operator import itemgetter\nfrom heapq import heapify,heappop,heappush\nfrom queue import Queue,LifoQueue,PriorityQueue\nfrom copy import deepcopy\nfrom time import time\nimport string\nimport sys\nsys.setrecursionlimit(10 ** 7)\ndef input() : return sys.stdin.readline().strip()\ndef INT() : return int(input())\ndef MAP() : return map(int,input().split())\ndef LIST() : return list(MAP())\n\nn, x = MAP()\na = LIST()\nans = 0\nfor i in range(n-1):\n if a[i] + a[i+1] > x:\n ans += a[i] + a[i+1] - x\n a[i+1] = max(0, x - a[i])\nprint(ans)", "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nif a[0]>x:\n ans+=a[0]-x\n a[0]=x\nfor i in range(n-1):\n if a[i]+a[i+1]>x:\n ans+=(a[i+1]-(x-a[i]))\n a[i+1]=(x-a[i])\nprint(ans)", "n, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\ncnt = [0] * (n - 1)\nans1 = 0\nfor i in range(n - 1):\n cnt[i] = A[i] + A[i + 1]\n cnt[i] -= x\n cnt[i] = max(cnt[i], 0)\ntemp_cnt = cnt[::]\n# print(cnt)\nfor i in range(n - 1):\n if temp_cnt[i] == 0:\n continue\n if i < n - 2:\n ans1 += temp_cnt[i]\n temp_cnt[i + 1] -= min(A[i + 1], temp_cnt[i])\n temp_cnt[i] = 0\n temp_cnt[i + 1] = max(temp_cnt[i + 1], 0)\n # print(ans1)\nans1 += temp_cnt[-1]\n\n\nprint(ans1)\n", "N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nans = 0\nfor i, j in zip(range(N - 1), range(1, N)):\n Asum = A[i] + A[j]\n if Asum <= K:\n continue\n eat = Asum - K\n d = min(eat, A[j])\n A[j] -= d\n eat -= d\n ans += d\n d = min(eat, A[i])\n A[i] -= d\n ans += d\n\nprint(ans)", "n,m = map(int, input().split(\" \"))\na = list(map(int, input().split(\" \")))\ncount = 0\nfor i in range(1, n-1):\n suma = a[i-1]+a[i]\n if suma > m:\n count += suma - m\n if a[i] > suma-m:\n a[i]-= suma - m\n else:\n a[i-1] -= suma-m-a[i]\n a[i] = 0\n #print(i, count, a)\nelse:\n if a[-1]+a[-2] > m:\n count += a[-2] + a[-1]-m\n a[-1] -= a[-2] + a[-1]-m\n#print(a, count)\nif n <= 2:\n if count + sum(a)-m >= 0:\n print(count + sum(a)-m)\n else:\n print(0)\nelse:\n print(count)", "N, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\nans = 0\nif A[0] > x:\n ans += A[0] - x\n A[0] = x\n\nfor i in range(1, N):\n if A[i]+A[i-1] > x:\n ans += A[i]+A[i-1]-x\n A[i] -= A[i]+A[i-1]-x\n\nprint(ans)\n", "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=[0]*n\nif a[0]>x:\n ans[0]=x\nelse:\n ans[0]=a[0]\nfor i in range(1,n):\n ans[i]=min(a[i],x-ans[i-1])\nprint(sum(a)-sum(ans)) ", "n,x = list(map(int,input().split()))\na = list(map(int,input().split()))\nif x==0:\n print((sum(a)))\nelse:\n eat = 0\n for i in range(n-1):\n tmp = 0\n if a[i]+a[i+1]>x:\n tmp = a[i]+a[i+1]-x\n eat += tmp\n if tmp>a[i+1]:\n tmp -= a[i+1]\n a[i+1] = 0\n a[i] -= tmp\n else:\n a[i+1] -= tmp\n print(eat)\n #print(a)\n", "n, x = [int(s) for s in input().split()]\na_list = [int(s) for s in input().split()]\nans = 0\ntemp = a_list[0] - x\nif temp > 0:\n ans += temp\n a_list[0] -= temp\nfor i in range(1, n):\n temp = a_list[i] + a_list[i - 1] - x\n if temp > 0:\n ans += temp\n a_list[i] -= temp\nprint(ans)", "\ndef resolve():\n N, X = map(int, input().split())\n A = list(map(int, input().split()))\n\n ans = 0\n for i in range(1, N):\n diff = max((A[i - 1] + A[i]) - X, 0)\n ans += diff\n A[i] = max(A[i] - diff, 0)\n\n print(ans)\n\n\ndef __starting_point():\n resolve()\n__starting_point()", "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\n\nans=0\nfor i in range(n-1):\n pre=a[i]\n post=a[i+1]\n many=pre+post-x\n if many>0:\n ans += many\n if many<=post:\n a[i+1]-=many\n else:\n a[i]-=many-post\n a[i+1]=0\n\nprint(ans)", "n, x, *a = map(int, open(c:=0).read().split())\nfor i in range(n - 1):\n s = max(a[i] + a[i + 1] - x, 0)\n a[i + 1] -= s\n if a[i + 1] < 0:\n a[i] += a[i + 1]\n a[i + 1] = 0\n c += s\nprint(c)", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[8]:\n\n\nN,x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\n\n# In[9]:\n\n\nans = 0\nif a[0] > x:\n ans += a[0]-x\n a[0] = x\nfor i in range(N-1):\n if a[i]+a[i+1] > x:\n cnt = a[i]+a[i+1]-x\n ans += cnt\n a[i+1] -= cnt\nprint(ans)\n\n\n# In[ ]:\n\n\n\n\n", "N, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nif x == 0:\n print((sum(A)))\n return\n\ncount = 0\nfor i in range(N - 1):\n d = A[i] + A[i + 1] - x\n if d <= 0:\n continue\n if A[i + 1] >= d:\n A[i + 1] -= d\n count += d\n else:\n count += d\n A[i] = d - A[i + 1]\n A[i + 1] = 0\n\n\nprint(count)\n", "n, x = list(map(int, input().split()))\na = [int(i) for i in input().split()]\nop = 0\nfor i in range(1, n):\n s = a[i-1] + a[i]\n if s > x:\n op += s - x\n if a[i] < s - x:\n a[i] = 0\n else:\n a[i] -= s - x\nprint(op)\n", "def candy():\n n = []\n n = input().split()\n N = int(n[0])\n x = int(n[1])\n alist = [int(i) for i in input().split()]\n\n s = 0\n for i in range(0, N - 1):\n c = int(alist[i])\n d = int(alist[i + 1])\n if int( alist[i] + alist[i + 1] ) > x:\n if int( alist[i] ) >= x:\n alist[i] = x\n alist[i + 1] = 0\n else :\n alist[i + 1] = int(x - alist[i] )\n s += c - int(alist[i]) + d - int(alist[i + 1])\n \"\"\"\n if int(alist[i]) > x:\n s = s + int(alist[i+1])\n alist[i+1] = 0\n\n if int(alist[i+1]) + int(alist[i]) > x:\n s = s + (int(alist[i+1]) + int(alist[i]) - x)\n alist[i+1] = x - int(alist[i])\n \"\"\"\n print(s)\ncandy()", "#\n# abc048 c\n#\n\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"3 3\n2 2 2\"\"\"\n output = \"\"\"1\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"6 1\n1 6 1 2 0 4\"\"\"\n output = \"\"\"11\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"5 9\n3 1 4 1 5\"\"\"\n output = \"\"\"0\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"2 0\n5 5\"\"\"\n output = \"\"\"10\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n N, x = list(map(int, input().split()))\n a = list(map(int, input().split()))\n\n ans = 0\n for i in range(N):\n if a[i] > x:\n ans += (a[i] - x)\n a[i] = x\n\n for i in range(1, N):\n if a[i-1] + a[i] > x:\n ans += (a[i] + a[i-1] - x)\n a[i] = x - a[i-1]\n\n print(ans)\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "f=lambda:map(int,input().split())\nN,X=f()\n*A,=f()\n\nB=[a if a<=X else X for a in A]\nc=sum(A)-sum(B)\nfor i in range(N-1):\n t=B[i]+B[i+1]\n if X < t:\n d=t-X\n B[i+1]-=d\n c+=d\nprint(c)", "n ,k = map(int, input().split())\na = list(map(int, input().split()))\n\nresult = 0\n\nif a[0] > k:\n result = a[0] -k\n a[0] = k\n\nfor i in range(n-1):\n if a[i] + a[i+1] > k:\n result += a[i] + a[i+1] - k #a[i] + a[i+1] -x = k\n a[i+1] = -a[i] + k\n\nprint(result)", "N,X = map(int,input().split())\nA = list(map(int,input().split()))\nwa = []\nans = 0\n\nif A[0] > X:\n ans += A[0]-X\n A[0] = X\n\nfor i in range(N-1):\n wa.append(A[i]+A[i+1])\n\nfor j in range(N-2):\n if wa[j] > X:\n ans += wa[j]-X\n wa[j+1] -= wa[j]-X\n\nif wa[N-2] > X:\n ans += wa[N-2]-X\n\nprint(ans)", "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nsyaku = 0\nfor i in range(n-1):\n if a[i]+a[i+1]>=x:\n sa=a[i]+a[i+1]-x\n ans+=sa\n if sa<=a[i+1]:\n a[i+1]-=sa\n else:\n a[i]=sa-a[i+1]\n a[i+1]=0\n\nif n!=2 and a[n-2]+a[n-1]>=x:\n sa=a[i]+a[i+1]-x\n ans+=sa\n if sa<=a[n-1]:\n a[n-1]-=sa\n else:\n a[n-2]=sa-a[n-1]\n a[n-1]=0\nprint(ans)", "N, x = list(map(int, input().split()))\nnums = list(map(int, input().split()))\n# print(nums)\nans = 0\nfor i in range(1, N):\n if nums[i - 1] + nums[i] > x:\n diff = nums[i - 1] + nums[i] - x\n if diff > nums[i]:\n nums[i - 1] -= (diff - nums[i])\n nums[i] = 0\n else:\n nums[i] -= diff\n ans += diff\n# print(nums)\nprint(ans)\n", "def main():\n N, x = list(map(int, input().split()))\n A = list(map(int, input().split()))\n Acount = sum(A)\n if A[0] > x:\n A[0] = x\n for i in range(N-1):\n tmp = A[i] + A[i+1]\n if tmp > x:\n A[i+1] -= tmp - x\n ans = Acount - sum(A)\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nif a[0]>x:\n ans+=a[0]-x\n a[0]=x\nfor i in range(n-1):\n if a[i]+a[i+1]>x:\n if a[i+1]>(x-a[i]):\n ans+=(a[i+1]-(x-a[i]))\n a[i+1]=(x-a[i])\nif a[-2]+a[i-1]>x:\n if a[-1]>(x-a[-2]):\n ans+=(a[-1]-(x-a[-2]))\n a[-1]=(x-a[-2])\nprint(ans)\n \n", "N, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nSum = 0\nif a[0] - x > 0:\n Sum += a[0] - x\n a[0] = x\nif a[N - 1] - x > 0:\n Sum += a[N - 1] - x\n a[N - 1] = x\nfor i in range(1, N):\n d = max(a[i] + a[i - 1] - x, 0)\n a[i] -= d\n Sum += d\n\nprint(Sum)\n\n", "N,x = map(int, input().split())\na = list(map(int, input().split()))\ncnt = 0\nfor i in range(1,N):\n if a[i-1] > x:\n b = a[i-1] - x\n cnt += b\n a[i-1] -= b\n if a[i-1]+a[i] > x:\n b = a[i-1] + a[i] - x\n cnt += b\n a[i] -= b\nprint(cnt)", "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nfor i in range(N-1):\n n = max(0, A[i] + A[i+1] - x)\n ans += n\n A[i+1] = max(0, A[i+1]-n)\n\nprint(ans)", "import sys\n\ninput = sys.stdin.readline\n\nn, x= map(int, input().split())\n\na_list = list(map(int, input().split()))\n\ncount = 0\nif a_list[0] > x:\n count += a_list[0] - x\n a_list[0] -= a_list[0] - x\nfor i in range(len(a_list)):\n if i+1 == len(a_list):\n break\n if a_list[i] + a_list[i+1] > x:\n count += a_list[i] + a_list[i+1] - x\n a_list[i+1] -= a_list[i] + a_list[i+1] - x\n \n\nprint(count)", "N,X = map(int, input().split())\n\nA = list(map(int, input().split()))\ncnt = 0\n\nfor i in range(N-1):\n temp = 0\n if A[i]+A[i+1] <= X:\n continue\n else:\n temp = A[i]+A[i+1]-X\n if A[i+1] < temp:\n A[i+1] = 0\n cnt += A[i+1]\n temp -= A[i+1]\n else:\n A[i+1] -= temp\n cnt += temp\n temp -= A[i+1]\n\n if A[i]+A[i+1] > X:\n A[i] -= temp\n cnt += temp\n\nprint(cnt)", "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,n):\n num=x\n num2=a[i-1]+a[i]-x\n if num2>0:\n ans+=num2\n a[i]=max(a[i]-num2,0)\nprint(ans)\n", "N,X = (int(T) for T in input().split())\nA = [int(T) for T in input().split()]\nEat = 0\nfor AT in range(0,N-1):\n if A[AT]+A[AT+1]>X:\n Need = A[AT]+A[AT+1]-X\n Eat += Need\n A[AT] -= max(0,Need-A[AT+1])\n A[AT+1] = max(0,A[AT+1]-Need)\nprint(Eat)", "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n tmp=a[i-1]+a[i]\n if tmp>x:\n ans+=tmp-x\n if a[i]>=tmp-x:\n a[i]-=tmp-x\n else:\n a[i]=0\nprint(ans)\n", "N, x, *A = list(map(int, open(0).read().split()))\nans = 0\nfor i in range(1, N):\n required = (A[i] + A[i - 1]) - x\n if required <= 0:\n continue\n elif required <= A[i]:\n A[i] -= required\n else:\n A[i] = 0\n rem = required - A[i]\n A[i - 1] -= rem\n ans += required\n\nprint(ans)\n", "n, x = map(int, input().split())\na = list(map(int, input().split()))\nans = sum(a)\na = [i if i <= x else x for i in a]\nfor i in range(n-1):\n if a[i]+a[i+1] > x:\n a[i+1] = x-a[i]\nprint(ans-sum(a))", "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in range(n):\n if a[i] > x:\n cnt += a[i] - x\n a[i] = x\n\nfor i in range(n-1):\n dif = a[i] + a[i+1] - x\n\n if dif > 0:\n a[i+1] -= dif\n cnt += dif\n\nprint(cnt)", "N, x = list(map(int, input().split()))\nA = [0] + [int(x) for x in input().split()]\nans = 0\nfor i in range(1,N+1):\n if A[i-1] + A[i] > x:\n ans += A[i-1] + A[i] - x\n A[i] = x - A[i-1]\nprint(ans)\n", "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\nans = 0\nfor i in range(n-1):\n num = a[i]+a[i+1]-x\n if num > 0:\n a[i+1] = max(a[i+1]-num, 0)\n ans += num\nprint(ans)\n", "n,x = list(map(int,input().split()))\nnarr = list(map(int,input().split()))\nc=0\nfor i in range(1,n):\n total = narr[i]+narr[i-1]\n if(total <= x):\n continue\n else:\n c += (total - x)\n narr[i] = max(0,narr[i]-(total-x))\nprint(c)\n", "f=lambda:map(int,input().split())\nN,X=f()\n*A,=f()\nA=[0]+A\n\nc=0\nfor i in range(N):\n c+=max(0,A[i]+A[i+1]-X)\n A[i+1]=min(A[i+1],X-A[i])\nprint(c)", "n, x = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(1, n):\n if a[i] + a[i-1] > x:\n ans += min(a[i], a[i] + a[i-1] - x)\n a[i] = max(0, x - a[i-1])\n if a[i] + a[i-1] > x:\n ans += a[i-1] - x\n a[i-1] = x\nprint(ans)", "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\ns=0\nfor i in range(1,n):\n b=a[i-1]+a[i]-x\n if b>0:\n s+=b\n a[i]=max(a[i]-b,0)\nprint(s)\n", "n,x = map(int, input().split())\na= list(map(int, input().split()))\n \ncnt = 0\n \nif a[0] > x:\n\tcnt+= (a[0]-x)\n\ta[0]-= (a[0]-x)\n \nfor i in range (n-1):\n\tif a[i]+a[i+1] > x:\n\t\tcnt+= (a[i]+a[i+1])-x\n\t\ta[i+1]-= (a[i]+a[i+1])-x\n \nprint(cnt)", "import collections\n\nn,x = map(int,input().split())\na = list(map(int,input().split()))\n\nans = 0\nq = collections.deque()\nif a[0] <= x:\n q.append(a[0])\nelse:\n ans += a[0]- x\n q.append(x)\n\nfor i in range(1,n):\n tmp = q[-1] + a[i] \n if tmp <= x:\n q.append(a[i])\n else:\n ans += tmp-x\n q.append(x-q[-1])\n q.popleft()\n\n\nprint(ans)", "n,x=map(int,input().split())\na=list(map(int,input().split()))\ns=[0]*(n-1)\nans=0\nif a[0]>x:\n ans+=a[0]-x\n a[0]=x\nfor i in range(n-1):\n s[i]=a[i]+a[i+1]\nfor i in range(n-2):\n if s[i]>x:\n t=s[i]-x\n s[i+1]-=t\n s[i]=x\n ans+=t\nif s[n-2]>x:\n ans+=s[n-2]-x\nprint(ans)", "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(N-1):\n if a[i]+a[i+1]>x:\n diff=a[i]+a[i+1]-x\n ans+=diff\n a[i+1]-=min(diff,a[i+1])\nprint(ans)\n", "N, K = map(int,input().split())\na = list(map(int,input().split()))\nif a[0] > K:\n ans = a[0]-K\n a[0] = K\nelse:\n ans = 0\nfor i in range(1, N):\n if a[i-1]+a[i] > K:\n ans += a[i] - (K-a[i-1])\n a[i] = K-a[i-1]\nprint(ans)", "n,x = map(int, input().split())\na = list(map(int, input().split()))\n\nt = 0\nans = 0\nfor i in a:\n s = max(0, t+i-x) # \u4e00\u3064\u524d\u306e\u5024\u306e\u5dee\u5206\u3092\u542b\u3081\u3066\u3001x\u3068\u306e\u5dee\u5206\u3092\u53d6\u5f97\u3057\u3001\u6bd4\u8f03\n t = i - s\n ans += s\nprint(ans)", "n, x = list(map(int, input().split()))\nal = list(map(int, input().split()))\n\ncnt = 0\nfor i in range(n-1):\n if al[i] + al[i+1] > x:\n if al[i+1] > (al[i] + al[i+1]) - x:\n cnt += al[i] + al[i+1] - x\n al[i+1] -= (al[i] + al[i+1] - x)\n else:\n cnt += al[i+1] + al[i] - x\n al[i+1] = 0\n al[i] = x\n\nprint(cnt)\n# print(al)\n", "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nif A[0] > x:\n ans += A[0] - x\n A[0] = x\n \nfor i in range(1, N):\n if A[i]+A[i-1] > x:\n ans += A[i]+A[i-1]-x\n A[i] -= A[i]+A[i-1]-x\n \nprint(ans)", "import sys\n\ninput = sys.stdin.readline\n\n\ndef main():\n N, x = list(map(int, input().split()))\n A = list(map(int, input().split()))\n\n ans = 0\n for i in range(N - 1):\n if A[i] + A[i + 1] <= x:\n continue\n if A[i] >= x:\n ans += (A[i] - x) + A[i + 1]\n A[i] = x\n A[i + 1] = 0\n else:\n ans += (A[i] + A[i + 1] - x)\n A[i + 1] = x - A[i]\n\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n, x = map(int, input().split())\na = list(map(int, input().split()))\nk = 0\ncnt = 0\n\nif a[1] + a[0] > x and x >= a[0] :\n k = x - a[0]\n cnt += a[1] + a[0] - x\n\nelif a[1] + a[0] > x and x < a[0] :\n k = 0\n cnt += a[1] + a[0] - x\n\nelse :\n k = a[1]\n\nfor i in range(1, n - 1) :\n if k + a[i + 1] <= x :\n k = a[i + 1] \n\n elif x >= k :\n cnt += k + a[i + 1] - x\n k = x - k\n\n else :\n cnt += k + a[i + 1] - x\n k = 0\n \n\nprint(cnt)", "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n tmp=a[i-1]+a[i]\n if tmp>x:\n ans+=tmp-x\n if a[i]>=tmp-x:\n a[i]-=tmp-x\n else:\n a[i]=0\nprint(ans)\n", "import sys\nimport numpy as np\ndef input(): return sys.stdin.readline().rstrip()\ndef ii(): return int(input())\ndef mi(): return map(int, input().split())\ndef li(): return list(mi())\n\n\ndef main():\n n, x = mi()\n a = li()\n cnt = 0\n for i in range(1,n):\n if a[i-1]+a[i]>x:\n cnt += a[i-1]+a[i]-x\n a[i] = max(0, x-a[i-1])\n print(cnt)\n \ndef __starting_point():\n main()\n__starting_point()", "#coding: utf-8\n\nN, X = (int(x) for x in input().split())\nA = [int(x) for x in input().split()]\n\ndiffs = []\nfor i in range(N-1):\n diffs.append(A[i]+A[i+1] - X)\n\nret = 0\nfor i in range(N-1):\n tmp = min(diffs[i], A[i+1])\n ret += tmp\n diffs[i] -= tmp\n if i+1 < len(diffs):\n diffs[i+1] -= min(tmp, diffs[i+1]) \n ret += diffs[i]\n\nprint((max(0, ret)))\n\n", "n,x=map(int,input().split())\nl=list(map(int,input().split()))\nc=0\nt=l[0]\nfor a in l[1:]:\n d=t+a-x\n if d>0:\n if a<d:\n a=0\n else:\n a-=d\n c+=d\n t=a\nprint(c)", "import math\nN, x = list(map(int, input().split()))\nL = [int(x) for x in input().split()]\nans = 0\nfor i in range(1,N):\n if L[i-1] + L[i] > x:\n if L[i-1] > x:\n ans += L[i-1] - x\n ans += L[i]\n L[i] = 0\n else:\n ans += L[i] + L[i-1] - x\n L[i] = x - L[i-1]\nprint(ans)\n", "n,x = map(int,input().split())\nl = list(map(int,input().split()))\ncount = 0\nfor i in range(n-1):\n if l[i]>x:\n count += (l[i]-x)\n l[i] -= (l[i]-x)\n if l[i]+l[i+1]>x:\n count += (l[i]+l[i+1]-x)\n l[i+1] -= (l[i]+l[i+1]-x)\nprint(count)", "def solve():\n ans = 0\n N, x = map(int, input().split())\n A = [0]+list(map(int, input().split()))\n for i in range(1,N+1):\n if A[i]+A[i-1]>x:\n ans += A[i]+A[i-1]-x\n A[i] = x - A[i-1]\n return ans\nprint(solve())", "N,x = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n if a[i] + a[i+1] > x:\n y = a[i] + a[i+1] - x\n ans += y\n a[i+1] = max(0,a[i+1]-y)\nprint(ans)", "n,x = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nif a[0] > x:\n b = a[0] - x\n ans = b\n a[0] -= b\nfor i in range(1,n):\n if a[i-1] + a[i] > x:\n b = a[i-1] + a[i] - x\n ans += b\n a[i] -= b\nprint(ans)"] | {"inputs": ["3 3\n2 2 2\n", "6 1\n1 6 1 2 0 4\n", "5 9\n3 1 4 1 5\n", "2 0\n5 5\n"], "outputs": ["1\n", "11\n", "0\n", "10\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 34,195 | |
665b02be62f11d31838de5321fddb5a0 | UNKNOWN | We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.
According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.
Determine if he is correct.
-----Constraints-----
- c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).
-----Input-----
Input is given from Standard Input in the following format:
c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}
-----Output-----
If Takahashi's statement is correct, print Yes; otherwise, print No.
-----Sample Input-----
1 0 1
2 1 2
1 0 1
-----Sample Output-----
Yes
Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1. | ["#!/usr/bin/env python3\n\nc = [list(map(int, input().split())) for i in range(3)]\n\n\na1 = 0\nb1, b2, b3 = c[0][0], c[0][1], c[0][2]\na2 = c[1][0]-b1\na3 = c[2][0]-b1\n\ncheck = []\ncheck.append(c[1][1] == a2+b2)\ncheck.append(c[2][1] == a3+b2)\ncheck.append(c[1][2] == a2+b3)\ncheck.append(c[2][2] == a3+b3)\n\nif sum(check) == 4:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "c11, c12, c13 = map(int, input().split())\nc21, c22, c23 = map(int, input().split())\nc31, c32, c33 = map(int, input().split())\n\nif c21-c11==c22-c12==c23-c13 and c31-c21==c32-c22==c33-c23 and c12-c11==c22-c21==c32-c31 and c13-c12==c23-c22==c33-c32:\n print(\"Yes\")\nelse:\n print(\"No\")", "import numpy as np\nC = np.array([[int(x) for x in input().split()] for _ in range(3)])\nans = 'Yes'\nfor i in range(2):\n if not(C[0,i+1]-C[0,i] == C[1,i+1]-C[1,i] == C[2,i+1]-C[2,i]):\n ans = 'No'\n if not(C[i+1,0]-C[i,0] == C[i+1,1]-C[i,1] == C[i+1,2]-C[i,2]):\n ans = 'No'\nprint(ans)\n", "A1 = 0\nB1, B2, B3 = map(int, input().split())\nC1, C2, C3 = map(int, input().split())\nD1, D2, D3 = map(int, input().split())\nflag = 0\nif not( C2-B2 == C1-B1 and C3-B3 == C1-B1 and C2-B2 == C3-B3):\n flag = 1\nif not( D2-B2 == D1-B1 and D3-B3 == D1-B1 and D2-B2 == D3-B3):\n flag = 1\nprint(\"Yes\" if flag == 0 else \"No\")", "C=[list(map(int,input().split())) for i in range(3)]\nBs=[C[0][i] for i in range(3)]\nAs=[0,C[1][0]-Bs[0],C[2][0]-Bs[0]]\nif all(As[i]+Bs[j]==C[i][j] for i in range(3) for j in range(3)):\n print(\"Yes\")\nelse:\n print(\"No\")", "c = []\nfor i in range(3):\n c.append(list(map(int, input().split())))\n\nans = True\nfor i in range(2):\n tmp = c[0][i + 1] - c[0][i]\n for j in range(2):\n if c[j + 1][i + 1] - c[j + 1][i] != tmp:\n ans = False\n break\n\nfor i in range(2):\n tmp = c[i + 1][0] - c[i][0]\n for j in range(2):\n if c[i + 1][j + 1] - c[i][j + 1] != tmp:\n ans = False\n break\n\nif ans:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "with open(0) as f:\n C = [list(map(int, line.split())) for line in f.readlines()]\nb = [(C[i][1]-C[i][0], C[i][2]-C[i][1]) for i in range(3)]\na = [(C[1][j]-C[0][j], C[2][j]-C[1][j]) for j in range(3)]\nprint('Yes' if a[0]==a[1]==a[2] and b[0]==b[1]==b[2] else 'No')", "a,b,c = map(int,input().split())\nd,e,f = map(int,input().split())\ng,h,i = map(int,input().split())\n\nif a+e+i == b+f+g == c+d+h == a+f+h == c+e+g == b+d+i:\n print(\"Yes\")\nelse:\n print(\"No\")", "c = [list(map(int, input().split())) for _ in range(3)]\nA1 = c[1][0] - c[0][0]\nA2 = c[2][0] - c[1][0]\nB1 = c[0][1] - c[0][0]\nB2 = c[0][2] - c[0][1]\nif c[1][1] == A1 + B1 + c[0][0] and c[1][2] == A1 + B1 + B2 + c[0][0] and c[2][1] == A1 + A2 + B1 + c[0][0] and c[2][2] == A1 + A2 + B1 + B2 + c[0][0]:\n print(\"Yes\")\nelse:\n print(\"No\")", "c = [list(map(int, input().split())) for _ in range(3)]\n\nif sum([sum(i) for i in c]) % 3 != 0:\n print(\"No\")\nelse:\n a0 = 0\n b0, b1, b2 = c[0][0], c[0][1], c[0][2]\n a1, a2 = c[1][0] - b0, c[2][0] - b0\n if c[1][1] == a1 + b1 and c[1][2] == a1 + b2 and c[2][1] == a2 + b1 and c[2][2] == a2 + b2:\n print(\"Yes\")\n else:\n print(\"No\")\n", "def LIHW(h):\n return [list(map(int, input().split())) for _ in range(h)]\n \n \nmasu = LIHW(3)\nans = \"Yes\"\nfor i in range(2):\n if masu[i+1][1]-masu[i+1][0] != masu[0][1]-masu[0][0]:\n ans = \"No\"\n if masu[i+1][2]-masu[i+1][1] != masu[0][2]-masu[0][1]:\n ans = \"No\"\nfor i in range(2):\n if masu[1][i+1]-masu[0][i+1] != masu[1][0]-masu[0][0]:\n ans = \"No\"\n if masu[2][i+1]-masu[1][i+1] != masu[2][0]-masu[1][0]:\n ans = \"No\"\nprint(ans)", "c=[]\nfor _ in range(3):\n c.append(list(map(int,input().split())))\n\ns=0\nfor i in range (3):\n for j in range(3):\n if i==j:\n s+=c[i][j]*2\n else:s-=c[i][j]\n\nif s==0:print(\"Yes\")\nelse:print(\"No\")\n", "c=[list(map(int,input().split())) for i in range(3)]\nif (c[0][0]+c[1][1]+c[2][2])*2==c[0][1]+c[0][2]+c[1][0]+c[1][2]+c[2][0]+c[2][1]:\n print('Yes')\nelse:\n print('No')\n", "r1 = list(map(int, input().split()))\nr2 = list(map(int, input().split()))\nr3 = list(map(int, input().split()))\na = [0]*3\nb = [0]*3\nfor i in range(101):\n a[0] = i\n for j in range(3):\n b[j] = r1[j]-a[0]\n \n a[1] = r2[0] - b[0]\n a[2] = r3[0] - b[0]\n\n flag = False\n for j in range(3):\n if r1[j]==a[0]+b[j] and r2[j]==a[1]+b[j] and r3[j] == a[2]+b[j]:\n flag = True\n else:\n flag = False\n break\n if flag:\n break\n \nprint(\"Yes\") if flag else print(\"No\")", "x=list(map(int, input().split()))\ny=list(map(int, input().split()))\nz=list(map(int, input().split()))\nif x[1]-x[0] != y[1]-y[0] or y[1]-y[0] != z[1]-z[0] or x[2]-x[0] != y[2]-y[0] or y[0]-x[0] !=y[1]-x[1] or z[1]-x[1] !=z[2]-x[2] or z[0]-x[0] !=z[1]-x[1] or z[1]-x[1] !=z[2]-x[2] :\n print('No')\nelse:\n print('Yes')", "def is_valid(m, a, b):\n for i in range(3):\n for j in range(3):\n if (m[i][j] != a[i] + b[j]):\n return 0\n return 1\n\n\nm = []\nfor a0 in range(3):\n m.append(list(map(int, input().split())))\n\nfor a0 in range(101):\n b0 = m[0][0] - a0\n b1 = m[0][1] - a0\n b2 = m[0][2] - a0\n a1 = m[1][0] - b0\n a2 = m[2][0] - b0\n if (is_valid(m, [a0, a1, a2], [b0, b1, b2])):\n print(\"Yes\")\n return\nprint(\"No\")\n", "List=[list(map(int,input().split())) for i in range(3)]\nnewlist=[]\nnew = [x-y for (x,y) in zip(List[0],List[1])]\nnew2 = [x-y for (x,y) in zip(List[2],List[1])]\nif new[0]==new[1] and new[1]==new[2]:\n pass\nelse:\n print('No')\n return\nif new2[0]==new2[1] and new2[1]==new2[2]:\n pass\nelse:\n print('No')\n return\n \nif List[0][0]-List[0][1]==List[1][0]-List[1][1] and List[2][0]-List[2][1]==List[1][0]-List[1][1]:\n pass\nelse:\n print('No')\n return\nif List[0][0]-List[0][2]==List[1][0]-List[1][2] and List[2][0]-List[2][2]==List[1][0]-List[1][2]:\n pass\nelse:\n print('No')\n return\nprint('Yes')", "a,b,c = map(int,input().split())\nd,e,f = map(int,input().split())\ng,h,i = map(int,input().split())\n \nif a+e+i == b+f+g == c+d+h:\n print(\"Yes\")\nelse:\n print(\"No\")", "# -*- coding: utf-8 -*-\nimport numpy as np\n\n# worst order: 101^6 => 10^8\n\nc = []\nc.append(list(map(int, input().split())))\nc.append(list(map(int, input().split())))\nc.append(list(map(int, input().split())))\n\narr_c = np.array(c)\na_max = np.amax(arr_c, axis=1)\nb_max = np.amax(arr_c, axis=0)\n\na = []\nb = []\nfor i in range(3):\n if len(list(range(0, a_max[i]+1, 1)))==0:\n a.append([0])\n else:\n a.append(list(range(0, a_max[i]+1, 1)))\n \n if len(list(range(0, b_max[i]+1, 1)))==0:\n b.append([0])\n else:\n b.append(list(range(0, b_max[i]+1, 1)))\n\nans = 'No'\ncnt = 0\nfor a0 in a[0]:\n for b0 in b[0]:\n if c[0][0] != a0 + b0:\n continue\n for a1 in a[1]:\n if c[1][0] != a1 + b0:\n continue\n for b1 in b[1]:\n if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:\n continue \n for a2 in a[2]:\n if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:\n continue\n for b2 in b[2]:\n if c[0][2] != a0 + b2 or c[1][2] != a1 + b2 or c[2][2] != a2 + b2:\n continue\n\n print(\"Yes\")\n return\n\nprint(ans)", "c = [list(map(int, input().split())) for _ in range(3)]\n\nfor i in range(1, 3):\n d = c[i][0] - c[0][0]\n e = c[0][i] - c[0][0]\n for j in range(1, 3):\n if d != c[i][j] - c[0][j]:\n print(\"No\")\n return\n if e != c[j][i] - c[j][0]:\n print(\"No\")\n return\nprint(\"Yes\")", "c11 ,c12, c13 = map(int,input().split())\nc21 ,c22, c23 = map(int,input().split())\nc31 ,c32, c33 = map(int,input().split())\n\nif c11 - c12 == c21 -c22 == c31-c32 and c12 - c13 == c22 -c23 == c32-c33 and c11 - c21 == c12 -c22 == c13-c23 and c21 - c31 == c22 -c32 == c23-c33 :\n print('Yes')\nelse :\n print('No')", "clst=list(map(int,input().split()))\ndif=[x-clst[0] for x in clst]\nclst=list(map(int,input().split()))\nif not [clst[0]+x for x in dif]==clst : print(\"No\");return\nclst=list(map(int,input().split()))\nif not [clst[0]+x for x in dif]==clst : print(\"No\");return\nprint(\"Yes\")", "a=[list(map(int,input().split())) for _ in range(3)]\nb=list(zip(*a))\nc=a[0]\nd=b[0]\nf=True\n\ndx1=c[1]-c[0]\ndx2=c[2]-c[1]\ndy1=d[1]-d[0]\ndy2=d[2]-d[1]\n\nfor i in range(3):\n c=a[i]\n d=b[i]\n if dx1==c[1]-c[0] and dx2==c[2]-c[1] and dy1==d[1]-d[0] and dy2==d[2]-d[1]:\n f=True\n else:\n f=False\n break\nif f:\n print('Yes')\nelse:\n print('No')", "c11,c12,c13=list(map(int, input().split()))\nc21,c22,c23=list(map(int, input().split()))\nc31,c32,c33=list(map(int, input().split()))\n\nans=\"No\"\nfor a1 in range(c11+1):\n \n b1=c11-a1\n b2=c12-a1\n b3=c13-a1\n a2=c21-b1\n a3=c31-b1\n\n if c22==a2+b2 and c23==a2+b3 and c32==a3+b2 and c33==a3+b3:\n ans=\"Yes\"\n break\n\nprint(ans)\n", "c=[list(map(int,input().split())) for _ in range(3)]\nfor i in range(2):\n if not (c[i+1][0]-c[i][0]==c[i+1][1]-c[i][1] and c[i+1][1]-c[i][1]==c[i+1][2]-c[i][2]):\n print(\"No\")\n break\n if not (c[0][i+1]-c[0][i]==c[1][i+1]-c[1][i] and c[1][i+1]-c[1][i]==c[2][i+1]-c[2][i]):\n print(\"No\")\n break\nelse:\n print(\"Yes\")\n", "C = [list(map(int, input().split())) for _ in range(3)]\nx = [0, 0, 0]\ny = [0, 0, 0]\n\nfor i in range(3):\n y[i] = C[0][i]\nfor i in range(3):\n x[i] = C[i][0] - y[0]\nfor i in range(3):\n for j in range(3):\n if C[i][j] != x[i] + y[j]:\n print('No')\n return\nprint('Yes')", "c = [list(map(int, input().split())) for _ in range(3)]\n\na = [0, 0, 0]\nb = [0, 0, 0]\n\ndef check(c, a, b):\n for i in range(3):\n for j in range(3):\n if a[i] + b[j] != c[i][j]:\n return False\n return True\n\nfor i in range(101):\n b[0] = i\n a[0] = c[0][0] - b[0]\n a[1] = c[1][0] - b[0]\n a[2] = c[2][0] - b[0]\n b[1] = c[0][1] - a[0]\n b[2] = c[0][2] - a[0]\n\n if check(c, a, b):\n print(\"Yes\")\n return\n\nprint(\"No\")\n", "# -*- coding: utf-8 -*-\nimport numpy as np\n\n# worst order: 101^6 => 10^8\n\ndef check(a, b, c):\n flag = True\n for i in range(3):\n for j in range(3):\n if c[i][j]!=a[i]+b[j]:\n flag = False\n return flag\n\n return flag\n\nc = []\nc.append(list(map(int, input().split())))\nc.append(list(map(int, input().split())))\nc.append(list(map(int, input().split())))\n\narr_c = np.array(c)\na_max = np.amax(arr_c, axis=1)\nb_max = np.amax(arr_c, axis=0)\n\na = []\nb = []\nfor i in range(3):\n if len(list(range(0, a_max[i]+1, 1)))==0:\n a.append([0])\n else:\n a.append(list(range(0, a_max[i]+1, 1)))\n \n if len(list(range(0, b_max[i]+1, 1)))==0:\n b.append([0])\n else:\n b.append(list(range(0, b_max[i]+1, 1)))\n\nans = 'No'\ncnt = 0\nfor a0 in a[0]:\n for b0 in b[0]:\n if c[0][0] != a0 + b0:\n continue\n for a1 in a[1]:\n if c[1][0] != a1 + b0:\n continue\n for b1 in b[1]:\n if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:\n continue \n for a2 in a[2]:\n if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:\n continue\n for b2 in b[2]:\n if c[0][2] != a0 + b2 or c[1][2] != a1 + b2 or c[2][2] != a2 + b2:\n continue\n\n print(\"Yes\")\n return\n\nprint(ans)", "# -*- coding: utf-8 -*-\n\nc = [list(map(int, input().split())) for _ in range(3)]\n\na = [0] * 3\nb = [0] * 3\n\nfor j in range(3):\n b[j] = c[0][j] - a[0]\n\nfor i in range(1,3,1):\n a[i] = c[i][0] - b[0]\n\nfor i in range(3):\n for j in range(3):\n if c[i][j] != a[i] + b[j]:\n print(\"No\")\n return\n\nprint(\"Yes\")\n", "c = [0] * 3\nfor i in range(3):\n c[i] = list(map(int, input().split()))\n\nif c[2][1] - c[2][0] == c[0][1] - c[0][0] and c[0][2] - c[1][2] == c[0][0] - c[1][0] and c[1][2] - c[2][2] == c[1][0] - c[2][0] and c[0][2] - c[2][2] == c[0][0] - c[2][0] and c[1][1] - c[0][1] == c[1][0] - c[0][0]:\n print(\"Yes\")\nelse:\n print(\"No\")", "c = [list(map(int,input().split())) for _ in range(3)]\na = [0]*3\nb = [0]*3\nok = True\n\nb = c[0]\n\na[1] = c[1][0]-b[0]\na[2] = c[2][0]-b[0]\n\nfor i in range(3):\n for j in range(3):\n if c[i][j]!=a[i]+b[j]:\n ok = False\n \nif ok:\n print('Yes')\nelse:\n print('No')\n", "c = [list(map(int, input().split())) for _ in range(3)]\nans = \"Yes\"\nfor i in range(1,3):\n if c[i][0]-c[0][0] != c[i][1]-c[0][1] or c[i][1]-c[0][1] != c[i][2]-c[0][2]:\n ans = \"No\"\nprint(ans)", "ans = 'Yes'\nc = []\nfor _ in range(3):\n c.append(list(map(int, input().split())))\nadiff = []\nbdiff = []\nfor i in range(2):\n adiff.append(c[i+1][0] - c[i][0])\n bdiff.append(c[0][i+1] - c[0][i])\nfor i in range(1, 3):\n for j in range(1, 3):\n if adiff[i-1] != c[i][j] - c[i-1][j] or bdiff[j-1] != c[i][j] - c[i][j-1]:\n ans = 'No'\n break\nprint(ans)\n", "a,b,c=[list(map(int,input().split())) for i in range(3)]\nprint(\"Yes\" if (a[0]-a[1],a[1]-a[2],a[0]-a[1])==(b[0]-b[1],b[1]-b[2],b[0]-b[1])==(c[0]-c[1],c[1]-c[2],c[0]-c[1]) else \"No\")", "c = [list(map(int,input().split())) for i in range(3)]\nx = [0] * 3\ny = [0] * 3\nfor i in range(3):\n y[i] = c[0][i] - x[0]\nfor i in range(3):\n x[i] = c[i][0] - y[0]\n\nflag = True\nfor i in range(3):\n for j in range(3):\n if x[i] + y[j] != c[i][j]:\n flag = False\nif flag:\n print(\"Yes\")\nelse:\n print(\"No\")", "c = [list(map(int, input().split())) for _ in range(3)]\nfor i in [1, 2]:\n d1 = c[0][0] - c[i][0]\n d2 = c[0][1] - c[i][1]\n d3 = c[0][2] - c[i][2]\n d4 = c[0][0] - c[0][i]\n d5 = c[1][0] - c[1][i]\n d6 = c[2][0] - c[2][i]\n if d1 != d2 or d1 != d3 or d4 != d5 or d4 != d6:\n print(\"No\")\n return\nprint(\"Yes\")", "arr = []\n\nfor _ in range(3):\n arr += list(map(int, input().split()))\n\na = [0] * 3\nb = [0] * 3\na[0] = 0\nb[0] = arr[0]\nb[1] = arr[1]\nb[2] = arr[2]\na[1] = arr[4] - b[1]\na[2] = arr[8] - b[2]\n\ntmp = [a[i] + b[j] for i in range(3) for j in range(3)]\n\nprint('Yes' if arr == tmp else 'No')", "field=[]\nresult=\"Yes\"\nfor i in range(3):\n field.append(list(map(int,input().split())))\nfor i in range(3):\n for j in range(3):\n if not (field[i][j]>=0 and field[i][j]<=100*2):\n result=\"No\"\n if j ==0:\n pos_i0=field[i][j]\n field[i][j]-=pos_i0\nfor j in range(3):\n if not (field[0][j]==field[1][j] and field[0][j]==field[2][j]):\n result=\"No\"\nprint(result)", "def main():\n c1 = list(map(int, input().split()))\n c2 = list(map(int, input().split()))\n c3 = list(map(int, input().split()))\n for i in range(0, 101):\n for j in range(0, 101):\n for k in range(0, 101):\n flag = True\n b = []\n for l in range(3):\n b.append(c3[l] - k)\n for l in range(3):\n if j+b[l] != c2[l]:\n flag = False\n break\n for l in range(3):\n if i+b[l] != c1[l]:\n flag = False\n break\n if flag:\n print('Yes')\n return\n\n print('No')\n\ndef __starting_point():\n main()\n\n__starting_point()", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Tue Sep 22 04:07:05 2020\n\n@author: liang\n\"\"\"\n\nC = [[int (x) for x in input().split()] for _ in range(3)]\nA = [0]*3\nB = [0]*3\n\nans = False\nfor a1 in range(C[0][0]+1):\n tmp = True\n b1 = C[0][0] - a1\n b2 = C[0][1] - a1\n b3 = C[0][2] - a1\n a2 = C[1][0] - b1\n a3 = C[2][0] - b1\n if C[1][1] != a2+b2:\n tmp = False\n if C[1][2] != a2+b3:\n tmp = False\n if C[2][1] != a3+b2:\n tmp = False\n if C[2][2] != a3+b3:\n tmp = False\n if tmp == True:\n ans = True\nif ans:\n print(\"Yes\")\nelse:\n print(\"No\")", "# coding: utf-8\n\n\ndef main():\n ans = 'No'\n c = [list(map(int, input().split())) for _ in range(3)]\n for i in range(101):\n for j in range(101):\n for k in range(101):\n flgs = [False, False, False]\n if c[0][0] - i == c[1][0] - j and c[0][0] - i == c[2][0] - k: flgs[0] = True\n if c[0][1] - i == c[1][1] - j and c[0][1] - i == c[2][1] - k: flgs[1] = True\n if c[0][2] - i == c[1][2] - j and c[0][2] - i == c[2][2] - k: flgs[2] = True\n if (all(flgs)): ans = 'Yes'\n\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "from sys import stdin, stdout # only need for big input\n\n\ndef solve():\n c1 = list(map(int, input().split()))\n c2 = list(map(int, input().split()))\n c3 = list(map(int, input().split()))\n b = c1\n a2 = [c2[i] - b[i] for i in range(3)]\n a3 = [c3[i] - b[i] for i in range(3)]\n if max(a2) == min(a2) and max(a3) == min(a3):\n print(\"Yes\")\n else:\n print(\"No\")\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n__starting_point()", "c = [list(map(int,input().split())) for _ in range(3)]\n\ncheck = False\nfor i in range(101):\n for j in range(101):\n for k in range(101):\n o = c[0][0] - i\n p = c[1][1] - j\n q = c[2][2] - k\n \n if o < 0 or p < 0 or q < 0:\n continue\n \n ls = [[i+o,i+p,i+q],[j+o,j+p,j+q],[k+o,k+p,k+q]]\n if ls == c:\n check = True\n break\n \nprint(\"Yes\" if check else \"No\")", "def main():\n c=[list(map(int,input().split())) for _ in [0,0,0]]\n for j in [2,1,0]:\n if c[j][0]-c[j-1][0]==c[j][1]-c[j-1][1]==c[j][2]-c[j-1][2]:\n continue\n if c[0][j]-c[0][j-1]==c[1][j]-c[1][j-1]==c[2][j]-c[2][j-1]:\n continue\n print(\"No\")\n return\n print(\"Yes\")\n return\nmain()", "List = []\nfor i in range (3):\n List.append(list(map(int, input().split())))\na = 0\nb = 0\nc = 0\nflg = True\nfor i in range(2):\n a = List[0][i+1] - List[0][i]\n b = List[1][i+1] - List[1][i]\n c = List[2][i+1] - List[2][i]\n if a != b or b != c or c != a:\n flg = False\n a = List[i+1][0] - List[i][0]\n b = List[i+1][1] - List[i][1]\n c = List[i+1][2] - List[i][2]\n if a != b or b != c or c != a:\n flg = False\nif flg:\n print(\"Yes\")\nelse:\n print(\"No\")", "A=[list(map(int,input().split())) for i in range(3)]\nif A[0][0]+A[1][1]==A[0][1]+A[1][0] and A[1][1]+A[2][2]==A[1][2]+A[2][1] and A[0][0]+A[2][2]==A[0][2]+A[2][0] :\n print(\"Yes\")\nelse:\n print(\"No\")", "c = []\nfor _ in range(3):\n c.append(list(map(int, input().split())))\nif c[0][1]-c[0][0] == c[1][1]-c[1][0] and c[2][1]-c[2][0] == c[1][1]-c[1][0] and c[0][2]-c[0][1] == c[1][2]-c[1][1] and c[2][2]-c[2][1] == c[1][2]-c[1][1]:\n print(\"Yes\")\nelse:\n print(\"No\")", "L = [list(map(int, input().split())) for _ in range(3)]\nT = sum([sum(i) for i in L])\nprint('Yes' if L[0][0] + L[1][1] + L[2][2] == (T / 3) else 'No')", "c=[list(map(int,input().split())) for _ in range(3)]\n\nans = \"Yes\"\n\nfor i in range(2):\n if c[i+1][1]-c[i+1][0] != c[0][1]-c[0][0]:\n ans = \"No\"\n if c[i+1][2]-c[i+1][1] != c[0][2]-c[0][1]:\n ans = \"No\"\nfor j in range(2):\n if c[1][i+1]-c[0][i+1] != c[1][0]-c[0][0]:\n ans = \"No\"\n if c[2][i+1]-c[1][i+1] != c[2][0]-c[1][0]:\n ans = \"No\"\n\nprint(ans)", "c = [list(map(int, input().split())) for _ in range(3)]\n# a2 + b1 = c21\n# a2 + b2 = c22\n# a2 + b3 = c23\nb1, b2, b3 = c[0][0], c[0][1], c[0][2]\n\nif c[1][0] - b1 == c[1][1] - b2 == c[1][2] - b3 and c[2][0] - b1 == c[2][1] - b2 == c[2][2] - b3:\n print('Yes')\nelse:\n print('No')\n", "c1 = list(map(int, input().split()))\nc2 = list(map(int, input().split()))\nc3 = list(map(int, input().split()))\nc = [c1,c2,c3]\nfor a1 in range(100):\n b1 = c1[0] - a1\n b2 = c1[1] - a1\n b3 = c1[2] - a1\n a21 = c2[0] - b1\n a22 = c2[1] - b2\n a23 = c2[2] - b3\n a31 = c3[0] - b1\n a32 = c3[1] - b2\n a33 = c3[2] - b3\n# print('a1',a1)\n# print('a2',a21,a22,a23)\n# print('a3',a31,a32,a33)\n# print('b',b1,b2,b3)\n if (a21 == a22 == a23) and (a31 == a32 == a33):\n print('Yes')\n break\n elif a1 == 99:\n print('No')\n break\n else:\n continue", "c=[list(map(int,input().split())) for _ in range(3)]\n\nans = \"Yes\"\nfor i in range(2):\n # print(\"i =\",i)\n if c[0][i] - c[0][i+1] != c[1][i] - c[1][i+1]:\n # print(\"check1\")\n # print(c[0][i], \"-\", c[0][i+1], \"!=\", c[1][i], \"-\", c[1][i+1])\n ans = \"No\"\n elif c[1][i] - c[1][i+1] != c[2][i] - c[2][i+1]:\n # print(\"check2\")\n # print(c[1][i], \"-\", c[1][i+1], \"!=\", c[2][i], \"-\", c[2][i+1])\n ans = \"No\"\n elif c[i][0] - c[i+1][0] != c[i][1] - c[i+1][1]:\n # print(\"check3\")\n # print(c[i][0], \"-\", c[i+1][0], \"!=\", c[i+1][1], \"-\", c[i+1][1])\n ans = \"No\"\n elif c[i][1] - c[i+1][1] != c[i][2] - c[i+1][2]:\n # print(\"check4\")\n # print(c[i][1], \"-\", c[i+1][1], \"!=\", c[i+1][2], \"-\", c[i+1][2])\n ans = \"No\"\nprint(ans)", "l = []\nfor i in range(3):\n c1,c2,c3 = map(int, input().split())\n l.append([c1,c2,c3])\n\n# assign a1 as 0\nb1 = l[0][0]\nb2 = l[1][0]\nb3 = l[2][0]\n\nflag = 0\nfor i in range(3):\n if not (l[0][1]-b1 == l[1][1]-b2 == l[2][1]-b3):\n flag = 1\n if not (l[0][2]-b1 == l[1][2]-b2 == l[2][2]-b3):\n flag = 1\nif flag == 1:\n print('No' , flush=True)\nelse:\n print('Yes' , flush=True)\n\n# TLE\n# l = []\n# for i in range(3):\n# c1,c2,c3 = map(int, input().split())\n# l.append([c1,c2,c3])\n\n# def check_sum(i,j):\n# for r in range(3):\n# if r == i:\n# continue;\n# for c in range(3):\n# if c == j:\n# continue;\n# sum_a = l[i][j] + l[r][c]\n# sum_b = l[r][j] + l[i][c]\n# if sum_a == sum_b:\n# return 1\n# else:\n# return -1\n# break;\n\n# for i in range(3):\n# for j in range(3):\n# flag = check_sum(i, j)\n# if flag == -1:\n# break;\n\n# if flag == 1:\n# print('Yes' , flush=True)\n# else:\n# print('No' , flush=True)\n", "c1 = list(map(int, input().split()))\nc2 = list(map(int, input().split()))\nc3 = list(map(int, input().split()))\n\nf = 0\nfor a1 in range(min(c1)+1):\n b1 = c1[0]-a1\n b2 = c1[1]-a1\n b3 = c1[2]-a1\n\n a2_1 = c2[0]-b1\n a2_2 = c2[1]-b2\n a2_3 = c2[2]-b3\n if not (a2_1==a2_2 and a2_2==a2_3):\n continue\n\n a3_1 = c3[0]-b1\n a3_2 = c3[1]-b2\n a3_3 = c3[2]-b3\n if not (a3_1==a3_2 and a3_2==a3_3):\n continue\n\n print(\"Yes\")\n f=1\n break\n\nif not f:\n print(\"No\")", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom fractions import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\n#\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7cfb\n# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);\n# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nC = [readInts() for _ in range(3)]\nA = [0] * 3\nB = [0] * 3\nA[0] = 0\nfor i in range(3):\n B[i] = C[0][i]\nfor j in range(3):\n A[j] = C[j][0] - B[0]\nfor i in range(3):\n for j in range(3):\n if A[i] + B[j] == C[i][j]:\n pass\n else:\n print('No')\n return\nprint('Yes')\n", "c_1_1, c_1_2, c_1_3 = map(int, input().split())\nc_2_1, c_2_2, c_2_3 = map(int, input().split())\nc_3_1, c_3_2, c_3_3 = map(int, input().split())\n\nans = \"No\"\nfor a_1 in range(101):\n b_1 = c_1_1 - a_1\n b_2 = c_1_2 - a_1\n b_3 = c_1_3 - a_1\n for a_2 in range(101):\n if c_2_1 != a_2 + b_1:\n continue\n if c_2_2 != a_2 + b_2:\n continue\n if c_2_3 != a_2 + b_3:\n continue\n for a_3 in range(101):\n if c_3_1 != a_3 + b_1:\n continue\n if c_3_2 != a_3 + b_2:\n continue\n if c_3_3 != a_3 + b_3:\n continue\n ans = \"Yes\"\n break\n if ans == \"Yes\":\n break\n if ans == \"Yes\":\n break\n\nprint(ans)", "c=[[] for _ in range(3)]\nfor i in range(3):\n c[i] = list(map(int, input().split()))\n\ndiff0 = [x - y for x, y in zip(c[0], c[1])]\ndiff1 = [x - y for x, y in zip(c[0], c[2])]\n \nif diff0[0] == diff0[1] and diff0[0] == diff0[2] and diff1[0] == diff1[1] and diff1[0] == diff1[2]:\n print('Yes')\nelse:\n print('No')\n\n\n\n", "#18 C - Takahashi's Information\nc = [list(map(int,input().split())) for _ in range(3)]\n\ncnt = 0\nif (c[0][0] - c[1][0]) == (c[0][1] - c[1][1]) == (c[0][2] - c[1][2]):\n cnt += 1\nif (c[1][0] - c[2][0]) == (c[1][1] - c[2][1]) == (c[1][2] - c[2][2]):\n cnt += 1\nif (c[2][0] - c[0][0]) == (c[2][1] - c[0][1]) == (c[2][2] - c[0][2]):\n cnt += 1\nif cnt == 3:\n print('Yes')\nelse:\n print('No')", "import sys\n\ninput = sys.stdin.readline\n\n#N\n#t1 x1 y1t1 x1 y1\n#t2 x2 y2t2 x2 y2\n#\u22ee\u22ee\n#tN xN yNtN xN yN\nN = 3\nx = [0 for i in range(N)]\ny = [0 for i in range(N)]\nc =[[0 for i in range(N)] for i in range(N)]\n\nfor i in range(N):\n c1, c2, c3 = map(int, input().split())\n c[i][0] = c1\n c[i][1] = c2\n c[i][2] = c3\n\n\nx[0] = 0\nfor i in range(N):\n y[i] = c[0][i] - x[0]\nx[1] = c[1][0] - y[0]\nx[2] = c[2][0] - y[0]\n\nflag = True\nfor i in range(N):\n for j in range(N):\n numx = x[i]\n numy = y[j]\n if not numx + numy == c[i][j]:\n flag = False\nif flag:\n print(\"Yes\")\nelse:\n print(\"No\")", "c=[list(map(int,input().split())) for _ in range(3)]\na=[0,0,0]\nb=[0,0,0]\n\nfor i in range(3):\n b[i] = c[0][i] - a[0]\n\nfor i in range(1,3):\n a[i] = c[i][0] - b[0]\n\nfor i in range(3):\n for j in range(3):\n if c[i][j] != a[i]+b[j]:\n print(\"No\")\n return\nprint(\"Yes\")", "#18\nimport sys\nc = [list(map(int,input().split())) for i in range(3)]\n\nif not(c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1]):\n print(\"No\")\n return\nif not(c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]):\n print(\"No\")\n return\nif not(c[0][1] - c[0][2] == c[1][1] - c[1][2] == c[2][1] - c[2][2]):\n print(\"No\")\n return\nif not(c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]):\n print(\"No\")\n return\nif not(c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]):\n print(\"No\")\n return\nif not(c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]):\n print(\"No\")\n return\nprint(\"Yes\")\n \n\n", "totalArray=[]\nanswer ='No'\nYoko=False\ntate=False\nfor i in range(3):\n array=input().split(' ')\n for j in range(len(array)):\n totalArray.append(int(array[j]))\nif (totalArray[1]-totalArray[0]) == (totalArray[4]-totalArray[3]) == (totalArray[7]-totalArray[6]) and (totalArray[2]-totalArray[1]) == (totalArray[5]-totalArray[4]) == (totalArray[8]-totalArray[7]):\n Yoko=True\nif (totalArray[3]-totalArray[0]) == (totalArray[4]-totalArray[1]) == (totalArray[5]-totalArray[2]) and (totalArray[6]-totalArray[3]) == (totalArray[7]-totalArray[4]) == (totalArray[8]-totalArray[5]):\n tate=True\nif Yoko==True and tate==True:\n print('Yes')\nelse:\n print('No')", "C = [list(map(int, input().split())) for _ in range(3)]\nif not (C[0][0] - C[0][1] == C[1][0] - C[1][1] == C[2][0] - C[2][1]):\n print(\"No\")\n return\nif not (C[0][0] - C[0][2] == C[1][0] - C[1][2] == C[2][0] - C[2][2]):\n print(\"No\")\n return\nif not (C[0][2] - C[0][1] == C[1][2] - C[1][1] == C[2][2] - C[2][1]):\n print(\"No\")\n return\n\nprint(\"Yes\")\n", "c = [\n list(map(int, input().split()))\n for _ in range(3)\n]\n\nf = True\nfor j in range(2):\n x = c[j][0] - c[j + 1][0]\n y = c[0][j] - c[0][j + 1]\n for i in range(3):\n if c[j][i] - c[j + 1][i] != x:\n f = False\n if c[i][j] - c[i][j + 1] != y:\n f = False\nprint(['No', 'Yes'][int(f)])", "L = [list(map(int,input().split())) for _ in range(3)]\nans = 'Yes'\n\nif L[0][0] + L[1][1] != L[0][1] + L[1][0]: ans = 'No'\nif L[0][1] + L[1][2] != L[0][2] + L[1][1]: ans = 'No'\nif L[1][0] + L[2][1] != L[1][1] + L[2][0]: ans = 'No'\nif L[1][1] + L[2][2] != L[1][2] + L[2][1]: ans = 'No'\n\nprint(ans)", "a = []\na.append(list(map(int, input().split())))\na.append(list(map(int, input().split())))\na.append(list(map(int, input().split())))\n\nif not((a[0][2]-a[0][1]) == (a[1][2]-a[1][1]) == (a[2][2]-a[2][1])):\n print(\"No\")\n return\n\nif not((a[0][1]-a[0][0]) == (a[1][1]-a[1][0]) == (a[2][1]-a[2][0])):\n print(\"No\")\n return\n\nif not((a[0][0]-a[1][0]) == (a[0][1]-a[1][1]) == (a[0][2]-a[1][2])):\n print(\"No\")\n return\n\nif not((a[2][0]-a[1][0])== (a[2][1]-a[1][1])== (a[2][2]-a[1][2])):\n print(\"No\")\n return\nprint(\"Yes\")\n", "c = [[int(x) for x in input().split()] for _ in range(3)]\n\nans = False\nfor a1 in range(101):\n for a2 in range(101):\n for a3 in range(101):\n ok = True\n b1 = c[0][0] - a1\n b2 = c[0][1] - a1\n b3 = c[0][2] - a1\n if c[1][0] != a2 + b1 or \\\n c[1][1] != a2 + b2 or \\\n c[1][2] != a2 + b3 or \\\n c[2][0] != a3 + b1 or \\\n c[2][1] != a3 + b2 or \\\n c[2][2] != a3 + b3:\n ok = False\n if ok:\n ans = True\n\nif ans:\n print(\"Yes\")\nelse:\n print(\"No\") \n\n\n\n", "c = []\nfor i in range(3):\n c.append(list(map(int, input().split())))\nflag = True\nfor i in range(2):\n if flag==True and c[i][1]-c[i][0]==c[i+1][1]-c[i+1][0] and c[i][2]-c[i][1]==c[i+1][2]-c[i+1][1] and c[1][i]-c[0][i]==c[1][i+1]-c[0][i+1] and c[2][i]-c[1][i]==c[2][i+1]-c[1][i+1]:\n flag = True\n else:\n flag = False\nif flag==True:\n print('Yes')\nelse:\n print('No')\n", "import numpy as np\n\nl = [list(map(int,input().split())) for i in range(3)]\nl_2 =np.array(l).T \n\ndef square(l):\n flag = 1\n for i in range(2):\n for j in range(2):\n if l[j][i] - l[j+1][i] != l[j][i+1] - l[j+1][i+1]:\n flag = 0\n return flag\nif square(l) * square(l_2) == 1:\n print(\"Yes\")\nelse:\n print(\"No\")\n \n\n\n\n\n\n\n\n", "# Problem: https://atcoder.jp/contests/abc088/tasks/abc088_c\n# Python 3rd Try\n\nimport sys\n# from collections import defaultdict\n# import heapq,copy\nimport pprint as pp\n# from collections import deque\ndef II(): return int(sys.stdin.readline())\ndef MI(): return list(map(int, sys.stdin.readline().split()))\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\n\n\n# Const\nMAXSIZE = ( 1 << 31 ) -1\nMINSIZE = -( 1 << 31) + 1\nyes = \"Yes\"\nno = \"No\"\n\ndef solver(line00,line01,line02,\n line10,line11,line12,\n line20,line21,line22):\n\n result = no\n a0 = 0\n b0 = line00\n b1 = line01 - a0\n b2 = line02 - a0\n a1 = line10 -line00\n a2 = line20 - line00\n if (( a1 + b1 ) == line11) and (( a1 + b2 ) == line12\n ) and (( a2 + b1 ) == line21) and (( a2 + b2 ) == line22):\n result = yes\n return result\n\n\ndef __starting_point():\n line00 , line01, line02 = MI()\n line10 , line11, line12 = MI()\n line20 , line21, line22 = MI()\n print((\"{}\".format(solver(line00, line01, line02,\n line10, line11, line12,\n line20, line21, line22))))\n\n__starting_point()", "#!/usr/bin/env python3\nimport sys\n\nYES = \"Yes\" # type: str\nNO = \"No\" # type: str\n\n\ndef solve(c: \"List[List[int]]\"):\n from itertools import product\n for a1, b1 in product(list(range(101)), repeat=2):\n a2 = c[1][0] - b1\n a3 = c[2][0] - b1\n b2 = c[0][1] - a1\n b3 = c[0][2] - a1\n if a2 < 0 or a3 < 0 or b2 < 0 or b3 < 0:\n continue\n a = [a1, a2, a3]\n b = [b1, b2, b3]\n if all((a[i]+b[j])==c[i][j] for i, j in product(list(range(3)), repeat=2)):\n return YES\n return NO\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n c = [[int(next(tokens)) for _ in range(3)] for _ in range(3)] # type: \"List[List[int]]\"\n print((solve(c)))\n\ndef test():\n import doctest\n doctest.testmod()\n\ndef __starting_point():\n #test()\n main()\n\n__starting_point()", "c = [list(map(int,input().split())) for _ in range(3)]\n\nok = True\n\nlis = [[0,1],[1,2],[2,0]]\n\nd = [[c[l[0]][i]-c[l[1]][i] for i in range(3)]for l in lis]\ne = [[c[i][l[0]]-c[i][l[1]] for i in range(3)]for l in lis]\n\nfor i in range(3):\n if d[i].count(d[i][0])!=3:\n ok = False\n if e[i].count(e[i][0])!=3:\n ok = False\n \nif ok:\n print('Yes')\nelse:\n print('No')\n", "c = [list(map(int, input().split())) for _ in range(3)]\n\ndiff0 = [x - y for x, y in zip(c[0], c[1])]\ndiff1 = [x - y for x, y in zip(c[0], c[2])]\n\nif diff0[0] == diff0[1] and diff0[0] == diff0[2] and diff1[0] == diff1[1] and diff1[0] == diff1[2]:\n print('Yes')\nelse:\n print('No')", "c = []\nfor i in range(3):\n c.append([int(x) for x in input().split()])\nres = \"No\"\nfor i in range(101):\n for j in range(101):\n for k in range(101):\n if c[0][0] - i == c[1][0] - j == c[2][0] - k:\n if c[0][1] - i == c[1][1] - j == c[2][1] - k:\n if c[0][2] - i == c[1][2] - j == c[2][2] - k:\n res = \"Yes\"\nprint(res)", "grid = [[-1] * 4 for i in range(4)]\nfor i in range(1,4):\n grid[i][1],grid[i][2],grid[i][3] = list(map(int,input().split()))\n grid[i][0] = min(grid[i][1],grid[i][2],grid[i][3])\n#print('----------')\n#for i in range(4):\n# print(grid[i])\n\nisOK = False\nfor i in range(grid[1][0]+1):\n grid[0][0] = i\n grid[0][1] = grid[1][1]-i\n grid[0][2] = grid[1][2]-i\n grid[0][3] = grid[1][3]-i\n# print('----------')\n# for j in range(4):\n# print(grid[j])\n if grid[2][1]-grid[0][1] == grid[2][2]-grid[0][2] and grid[2][2]-grid[0][2] == grid[2][3]-grid[0][3]:\n if grid[3][1]-grid[0][1] == grid[3][2]-grid[0][2] and grid[3][2]-grid[0][2] == grid[3][3]-grid[0][3]:\n isOK = True\n break\nif isOK:\n print('Yes')\nelse:\n print('No')\n", "c=[list(map(int,input().split())) for i in range(3)]\nif (c[0][0]+c[1][1]+c[2][2])*2==c[0][1]+c[0][2]+c[1][0]+c[1][2]+c[2][0]+c[2][1]:\n print('Yes')\nelse:\n print('No')", "def main():\n grid = [list(map(int, input().split())) for i in range(3)]\n all = sum(sum(grid, []))\n a = [0] * 3\n b = [0] * 3\n for i1 in range(0, grid[0][0] + 1):\n a[0] = i1\n b[0] = grid[0][0] - i1\n for j2 in range(0, grid[1][1] + 1):\n a[1] = j2\n b[1] = grid[1][1] - j2\n for k3 in range(0, grid[2][2] + 1):\n a[2] = k3\n b[2] = grid[2][2] - k3\n if (sum(a) * 3) + (sum(b) * 3) == all:\n print(\"Yes\")\n return\n print('No')\n\n\n\n\n\ndef __starting_point():\n main()\n__starting_point()", "c=[]\nfor i in range(3):\n c.append([int(i) for i in input().split()])\n\na1,a2,a3=[0,c[1][1]-c[0][1],c[2][1]-c[0][1]]\nb1,b2,b3=[c[0][0],c[0][1],c[0][2]]\n\nans=[[a1+b1,a1+b2,a1+b3],[a2+b1,a2+b2,a2+b3],[a3+b1,a3+b2,a3+b3]]\n\nif ans==c:\n print(\"Yes\")\nelse:\n print(\"No\")\n\n", "\nc = [list(map(int,input().split())) for i in range(3)]\n\nfor i in range(0,2):\n if not c[0][0+i]-c[0][1+i] \\\n == c[1][0+i]-c[1][1+i] \\\n == c[2][0+i]-c[2][1+i]:\n print('No')\n break\n\n if not c[0+i][0]-c[1+i][0] \\\n == c[0+i][1]-c[1+i][1] \\\n == c[0+i][2]-c[1+i][2]:\n print('No')\n break\nelse:\n print('Yes')\n", "def main():\n c_lst = [list(map(int, input().split())) for _ in range(3)]\n c1 = c_lst[0][0] + c_lst[1][1] + c_lst[2][2]\n c2 = c_lst[1][0] + c_lst[2][1] + c_lst[0][2]\n c3 = c_lst[2][0] + c_lst[0][1] + c_lst[1][2]\n \n if c1 == c2 and c2 == c3:\n print('Yes')\n else:\n print('No')\n \n\ndef __starting_point():\n main()\n__starting_point()", "C = []\nfor _ in range(3):\n c = list(map(int, input().split()))\n C.append(c)\n \na = [0, C[1][1]-C[0][1], C[2][1]-C[0][1]]\nb = [C[0][0], C[0][1], C[0][2]]\n\nans = [[a[0]+b[0], a[0]+b[1], a[0]+b[2]], [a[1]+b[0], a[1]+b[1], a[1]+b[2]], [a[2]+b[0], a[2]+b[1], a[2]+b[2]]]\n\nif ans == C:\n print(\"Yes\")\nelse:\n print(\"No\")", "c = [list(map(int,input().split())) for _ in range(3)]\nif (c[2][0]-c[1][0])==(c[2][1]-c[1][1])==(c[2][2]-c[1][2]) and (c[1][0]-c[0][0])==(c[1][1]-c[0][1])==(c[1][2]-c[0][2]) and (c[2][2]-c[2][1])==(c[1][2]-c[1][1])==(c[0][2]-c[0][1]) and (c[2][1]-c[2][0])==(c[1][1]-c[1][0])==(c[0][1]-c[0][0]):\n print(\"Yes\")\nelse:\n print(\"No\")", "def LIHW(h):\n return [list(map(int, input().split())) for _ in range(h)]\n\n\nmasu = LIHW(3)\nans = \"Yes\"\nfor i in range(2):\n if masu[i+1][1]-masu[i+1][0] != masu[0][1]-masu[0][0]:\n ans = \"No\"\n if masu[i+1][2]-masu[i+1][1] != masu[0][2]-masu[0][1]:\n ans = \"No\"\nfor i in range(2):\n if masu[1][i+1]-masu[0][i+1] != masu[1][0]-masu[0][0]:\n ans = \"No\"\n if masu[2][i+1]-masu[1][i+1] != masu[2][0]-masu[1][0]:\n ans = \"No\"\nprint(ans)\n", "import numpy as np\n\nM = np.array(list(map(int,open(0).read().split()))).reshape(3,3)\n\nhSum = M.sum(axis=0)\nvSum = M.sum(axis=1)\n\nf=True\nfor i in range(3):\n if (hSum[i]-hSum[(i+1)%3])%3!=0:\n f = False\n\nfor i in range(3):\n if (vSum[i]-vSum[(i+1)%3])%3!=0:\n f = False\n \nprint(\"Yes\" if f else \"No\")", "cc = [list(map(int, input().split())) for i in range(3)]\ntc = [x for c in cc for x in c]\n\nif sum(tc) % 3 != 0:\n print('No')\nelse:\n cnt = 0\n for i in range(3):\n cnt += cc[i][i]\n if cnt == sum(tc)//3:\n print('Yes')\n else:\n print('No')", "c = [list(map(int, input().split())) for _ in range(3)]\n\nflag = True\n\nfor i in range(1, 3):\n if not(c[i][0] - c[0][0] == c[i][1] - c[0][1] == c[i][2] - c[0][2]):\n flag = False\n if not(c[0][i] - c[0][0] == c[1][i] - c[1][0] == c[2][i] - c[2][0]):\n flag = False\n\nif flag:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "c = [list(map(int,input().split())) for i in range(3)]\nans = \"Yes\"\nfor i in range(3):\n for j in range(3):\n if c[i][j]==c[i-1][j]+c[i][j-1]-c[i-1][j-1]:\n continue\n ans = \"No\"\nprint(ans)", "\nc = [list(map(int, input().split())) for i in range(3)]\n\nflag = False\nfor a0 in range(-100, 200):\n b0 = c[0][0] - a0\n a1 = c[1][0] - b0\n a2 = c[2][0] - b0\n b1 = c[0][1] - a0\n b2 = c[0][2] - a0\n if (a1 + b1 == c[1][1]\n and a2 + b1 == c[2][1]\n and a1 + b2 == c[1][2]\n and a2 + b2 == c[2][2]):\n flag = True\n\nif flag:\n print(\"Yes\")\nelse:\n print(\"No\")", "import itertools\ndef main():\n grid = [list(map(int, input().split())) for i in range(3)]\n all = sum(sum(grid, []))\n a = [0] * 3\n b = [0] * 3\n for i, j, k in itertools.product(list(range(grid[0][0] + 1)), list(range(grid[1][1] + 1)), list(range(grid[2][2] + 1))):\n a = [i, j, k]\n b = [grid[idx][idx] - v for idx, v in enumerate(a)]\n if (sum(a) * 3) + (sum(b) * 3) == all:\n print(\"Yes\")\n return\n print('No')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "c = [[0]*3]*3\n\nfor i in range(3):\n c[i] = [int(x) for x in input().split()]\n\nans = False\n\nif c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1] and\\\n c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]:\n ans = True\n\nif ans == True:\n print('Yes')\nelse: # ans == False:\n print('No')", "xy = [list(map(int, input().split())) for i in range(3)]\nresult = sum(map(sum, xy))\nif result % 3 != 0:\n print(\"No\")\n return\nif result != (xy[0][0]+xy[1][1]+xy[2][2]) * 3:\n print(\"No\")\n return\nif result != (xy[0][2]+xy[1][1]+xy[2][0]) * 3:\n print(\"No\")\n return\nelse:\n print(\"Yes\")", "a=[]\nfor i in range(3):\n a.append(list(map(int,input().split())))\nif ((a[1][0]-a[0][0]==a[1][1]-a[0][1]==a[1][2]-a[0][2]) and\n (a[2][0]-a[0][0]==a[2][1]-a[0][1]==a[2][2]-a[0][2])):\n print('Yes')\nelse:\n print('No')", "c1 = list(map(int,input().split()))\nc2 = list(map(int,input().split()))\nc3 = list(map(int,input().split()))\n\nsw = 1\nb1 = min(c1)\na = [c1[0]-b1, c1[1]-b1, c1[2]-b1]\n\nif not(c2[0]-a[0] == c2[1]-a[1] == c2[2]-a[2]):\n sw = 0\nif not(c3[0]-a[0] == c3[1]-a[1] == c3[2]-a[2]):\n sw = 0\n \nprint(([\"No\",\"Yes\"][sw]))\n", "c1 = list(map(int,input().split()))\nc2 = list(map(int,input().split()))\nc3 = list(map(int,input().split()))\n\na1_a2 = c1[0] - c2[0]\na2_a3 = c2[0] - c3[0]\nb1_b2 = c1[0] - c1[1]\nb2_b3 = c1[1] - c1[2]\n\ncnt = 0\nif a1_a2 == c1[1]-c2[1] == c1[2]-c2[2]:\n cnt += 1\nif a2_a3 == c2[1]-c3[1] == c2[2]-c3[2]:\n cnt += 1\nif b1_b2 == c2[0]-c2[1] == c3[0]-c3[1]:\n cnt += 1\nif b2_b3 == c2[1]-c2[2] == c3[1]-c3[2]:\n cnt += 1\n\nif cnt == 4:\n print(\"Yes\")\nelse:\n print(\"No\")", "N = 3\nc = [list(map(int, input().split())) for _ in range(N)]\nds = [sum(c[j][(i + j) % 3] for j in range(N)) for i in range(N)]\nif ds[0] == ds[1] == ds[2]:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "ls = []\nfor i in range(3):\n ls.append(list(map(int,input().split())))\nans = 'Yes'\nif ls[1][1]-ls[1][0] != ls[0][1]-ls[0][0]:\n ans = 'No'\nif ls[2][1]-ls[2][0] != ls[0][1]-ls[0][0]:\n ans = 'No' \nif ls[1][2]-ls[1][0] != ls[0][2]-ls[0][0]:\n ans = 'No'\nif ls[2][2]-ls[2][0] != ls[0][2]-ls[0][0]:\n ans = 'No'\nprint(ans)", "c = [list(map(int,input().split())) for _ in range(3)]\nif c[0][0]+c[1][1]+c[2][2]\\\n==c[0][2]+c[1][1]+c[2][0]\\\n==c[0][0]+c[1][2]+c[2][1]\\\n==c[0][1]+c[1][0]+c[2][2]:\n print('Yes')\nelse:\n print('No')\n\n\n", "C1 = list(map(int,input().split()))\nC2 = list(map(int,input().split()))\nC3 = list(map(int,input().split()))\n\nif C1[0]-C1[1]==C2[0]-C2[1]==C3[0]-C3[1] and C1[1]-C1[2]==C2[1]-C2[2]==C3[1]-C3[2] and C1[0]-C2[0]==C1[1]-C2[1]==C1[2]-C2[2] and C2[0]-C3[0]==C2[1]-C3[1]==C2[2]-C3[2]: \n print(\"Yes\")\nelse:\n print(\"No\")"] | {"inputs": ["1 0 1\n2 1 2\n1 0 1\n", "2 2 2\n2 1 2\n2 2 2\n", "0 8 8\n0 8 8\n0 8 8\n", "1 8 6\n2 9 7\n0 7 7\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 44,353 | |
95f9e2e6c556ca1d21f7826f7b84bd64 | UNKNOWN | AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is held at a time.
The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.
Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.
-----Constraints-----
- S is ABC or ARC.
-----Input-----
Input is given from Standard Input in the following format:
S
-----Output-----
Print the string representing the type of the contest held this week.
-----Sample Input-----
ABC
-----Sample Output-----
ARC
They held an ABC last week, so they will hold an ARC this week. | ["s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "S=input()\nif S==\"ARC\":\n print(\"ABC\")\nelse:\n print(\"ARC\")\n", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "S=input()\nif S[1]=='B':\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s=input()\nif s=='ABC':\n print('ARC')\nelse:\n print('ABC')", "s = input()\n\nif s == \"ABC\" :\n print(\"ARC\")\n\nelif s == \"ARC\" :\n print(\"ABC\")", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\nif(S == \"ABC\"):print(\"ARC\")\nelse:print(\"ABC\") ", "s = input()\n\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "x = input()\nif x[1] == 'B':\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s=input()\nif s==\"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "# coding: utf-8\n# Your code here!\nS = input()\n\nif S == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "a = input()\n\nif a == \"S\" :\n print(\"\u4eca\u9031\u958b\u50ac\u3055\u308c\u308b\u30b3\u30f3\u30c6\u30b9\u30c8\u3092\u8868\u3059\u6587\u5b57\u5217\u3092\u51fa\u529b\u305b\u3088\u3002\")\nelif a == \"ABC\":\n print(\"ARC\")\nelse :\n print(\"ABC\")", "S = input()\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "s=input()\nif s==\"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\n\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\nif S[1] == \"R\":\n print(\"ABC\")\nelse:\n print(\"ARC\")", "S = input()\nif(S == \"ABC\"):\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s=input()\n\nif s==\"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "print(\"ABC\" if input()==\"ARC\" else \"ARC\")", "s = input()\nprint(\"ABC\" if s == \"ARC\" else \"ARC\")", "s = str(input())\nif s==\"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = str(input())\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "s = input()\nprint(\"ABC\" if s == \"ARC\" else \"ARC\")", "print(f\"A{'RB'['R'in input()]}C\")", "print(\"ARC\" if input()[1]==\"B\" else \"ABC\")", "a=input()\nif a==\"ABC\":\n \tprint(\"ARC\")\nelse:\n print(\"ABC\")", "import sys\nfrom collections import deque, defaultdict, Counter\nfrom itertools import accumulate, product, permutations, combinations\nfrom operator import itemgetter\nfrom bisect import bisect_left, bisect_right\nfrom heapq import heappop, heappush\nfrom math import ceil, floor, sqrt, gcd, inf\nfrom copy import deepcopy\nimport numpy as np\nimport scipy as sp\n\nINF = inf\nMOD = 1000000007\n\ns = input()\n\ntmp = 0\nres = \"ABC\"\n\nif s == \"ABC\":\n res = \"ARC\"\n\nprint(res)\n", "#!/usr/bin/env python3\ns = input()\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n", "S=input()\n\nif S=='ABC':\n print('ARC')\nelse:\n print('ABC')\n", "print(input().translate(str.maketrans({\"R\":\"B\",\"B\":\"R\"})))", "S = input()\nif S == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s=input();print(\"ABC\"if s==\"ARC\"else\"ARC\")", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport sys # {{{\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\n# }}}\n\n# pre-defined{{{\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\nALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)] # can also use string module\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 DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\nfrom inspect import currentframe\n# }}}\n\ndef solve():\n s = input()\n if s == \"ABC\":\n print(\"ARC\")\n else:\n print(\"ABC\")\n\n return 0\n\ndef __starting_point():# {{{\n solve()\n\n# vim: set foldmethod=marker: }}}\n\n__starting_point()", "print('ARC' if input()!='ARC' else 'ABC')", "#!/usr/bin/env python3\ns = input()\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n", "s=input()\n\nif s.find('B')==1:\n print('ARC')\nelse:\n print('ABC')", "S = input()\nprint('ABC' if S == 'ARC' else 'ARC')", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport sys # {{{\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\n# }}}\n\n# pre-defined{{{\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\nALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)] # can also use string module\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 DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\nfrom inspect import currentframe\n# }}}\n\ndef solve():\n s = input()\n if s == \"ABC\":\n print(\"ARC\")\n else:\n print(\"ABC\")\n\n return 0\n\ndef __starting_point():# {{{\n solve()\n\n# vim: set foldmethod=marker: }}}\n\n__starting_point()", "S=input()\nif S == \"ABC\":print(\"ARC\")\nelse : print(\"ABC\")", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "S = input()\n\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "a = input()\nif a =='ABC':\n print('ARC')\nelse:\n print('ABC')", "S = input()\n\nprint('ABC') if S == 'ARC' else print('ARC')\n", "S = input()\nprint('ARC' if S == 'ABC' else 'ABC')", "S = input()\n\nif S == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n\n", "s = input()\nif s == 'ARC':\n print('ABC')\nelse:\n print('ARC')", "s = input()\nif s == 'ARC':\n print('ABC')\nelse:\n print('ARC')", "word = input()\nif word == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\nif S == 'ABC':\n print('ARC')\n return\nelse:\n print('ABC')\n return", "n = input()\n\nif n == 'ABC':\n print('ARC')\n\nif n == 'ARC':\n print('ABC')\n", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "S = input();print('ARC') if S=='ABC' else print('ABC')", "S=input()\nif S==\"ABC\":\n print(\"ARC\")\nelse:print(\"ABC\")", "s = input()\n\nif s == \"ARC\":\n print(\"ABC\")\nelse:\n print(\"ARC\")", "def inN():\n return int(input())\ndef inL():\n return list(map(int,input().split()))\ndef inNL(n):\n return [list(map(int,input().split())) for i in range(n)]\nmod = pow(10,9)+7\n#import numpy\ns = input()\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\n\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "s = input()\nif(s == 'ABC'):\n print('ARC')\nelse:\n print(\"ABC\") \n", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "print(\"A%sC\"%'BR'[input()<\"AR\"])", "S = input()\n\nprint((*({\"ABC\", \"ARC\"} - {S})))\n", "S=input()\nif S=='ABC':\n print('ARC')\nelse:\n print('ABC')", "s=input()\n\nif s.find('B')==1:\n print('ARC')\nelse:\n print('ABC')", "s = input()\n\nif s == 'ARC':\n print('ABC')\nelse:\n print('ARC')\n", "S = input()\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\n\nif S == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = str(input())\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "print({\"ABC\":\"ARC\",\"ARC\":\"ABC\"}[input()])", "s = input()\n\nif (s==\"ABC\"):\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\nif s == 'ABC':\n print('ARC')\nelif s == 'ARC':\n print('ABC')", "def main() -> None:\n s = input()\n\n print(('ARC' if s == 'ABC' else 'ABC'))\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "s = list(input())\n\nif s[1] == 'B':\n print('ARC')\nelse:\n print('ABC')", "s = input()\n\nif s == 'ABC':\n print('ARC')\n \nelse :\n print('ABC')", "s = input()\nprint(\"ABC\" if s == \"ARC\" else \"ARC\")", "S = input()\nprint(\"ARC\") if S==\"ABC\" else print(\"ABC\")", "S=input()\nif S=='ABC':\n print('ARC')\nelse:\n print('ABC')\n", "print(['ARC','ABC'][input()[1]=='R'])", "S = input()\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC') ", "#ABC166\nS = input()\n#----------\u4ee5\u4e0a\u5165\u529b----------\nif S == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "print(('ABC' if input()[1] == 'R' else 'ARC'))\n", "S = input()\n\nif S == \"ABC\":\n print(\"ARC\")\n\nelse:\n print(\"ABC\")\n", "s=input()\nprint('ARC') if s=='ABC' else print('ABC')", "def __starting_point():\n\n s = input()\n if s == \"ARC\":\n print(\"ABC\")\n else:\n print(\"ARC\")\n\n__starting_point()", "s = input()\nif s == 'ABC' :\n print('ARC')\nelse :\n print('ABC')", "s=input()\nif s==\"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s = input()\n\nif s[1] == \"B\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S=input()\nif S=='ABC':\n print('ARC')\nelse:\n print('ABC')", "string = input()\n\nif string == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "s=input()\n\nif s.find('B')==1:\n print('ARC')\nelse:\n print('ABC')", "print(*({\"ABC\",\"ARC\"}-{input()}))", "print('ARC' if (input()=='ABC') else 'ABC')", "S = input()\nif S[1] == \"B\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\nif S == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")", "S = input()\n\nprint('ABC') if S == 'ARC' else print('ARC')"] | {"inputs": ["ABC\n", "ARC\n", "ARC\n", "ARC\n"], "outputs": ["ARC\n", "ABC\n", "ABC\n", "ABC\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,090 | |
a2627a8682e57ae07153b77d129aa7c4 | UNKNOWN | You are given nonnegative integers a and b (a β€ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?
-----Constraints-----
- 0 β€ a β€ b β€ 10^{18}
- 1 β€ x β€ 10^{18}
-----Input-----
The input is given from Standard Input in the following format:
a b x
-----Output-----
Print the number of the integers between a and b, inclusive, that are divisible by x.
-----Sample Input-----
4 8 2
-----Sample Output-----
3
There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8. | ["a,b,x=list(map(int,input().split()))\nprint((b//x-(a-1)//x))\n", "a, b, x = map(int, input().split())\n\ndef divided_num(n):\n return n//x + 1\n\nprint(divided_num(b)-divided_num(a)+(1 if a%x==0 else 0))", "a, b, x = map(int, input().split())\n\nans = b // x - (a - 1) // x\nprint(ans)", "def generator(x, a): # x\u306e\u500d\u6570\u3067a\u3088\u308a\u5927\u304d\u3044\u3082\u306e\u306e\u3046\u3061\u306e\u6700\u5c0f\u5024\n if x >= a:\n y = x\n else:\n tmp = a // x + 1\n if a % x == 0:\n tmp -= 1\n y = x * tmp\n\n return y\n\n\ndef main():\n a, b, x = map(int, input().split())\n minimum = generator(x, a)\n\n if minimum > b:\n count = 0\n else:\n count = (b - minimum) // x + 1\n\n if a == 0:\n count += 1\n\n print(count)\n\n\ndef __starting_point():\n main()\n__starting_point()", "a, b, x = list(map(int, input().split()))\nprint((b // x - (a - 1) // x))\n", "a, b, x = map(int, input().split())\nA = a + ((x - (a % x)) % x)\nB = b - (b % x)\nprint((B - A) // x + 1 if B >= A else 0)", "a, b, x = map(int, input().split(' '))\nanswer = b//x - (a-1)//x\nprint(answer)", "a, b, x = map(int, input().split())\n\nif a % x == 0:\n print(b // x - a // x + 1)\nelse:\n print(b // x - a // x)", "a, b, x = map(int, input().split())\n\nc = b - a + a % x\nif a % x != 0:\n print(c // x)\nelse:\n print(c // x + 1)", "a, b, c = map(int,input().split())\nif a % c == 0:\n print((b // c) - (a // c) + 1)\nelse:\n print((b // c) - (a // c))", "def __starting_point():\n # n = int(input())\n a, b, x = list(map(int, input().split()))\n c = b//x - a//x\n if a%x == 0:\n c = c+1\n print(c)\n\n__starting_point()", "def main():\n a,b,x = list(map(int,input().split()))\n print((b//x-(a-1)//x))\n\ndef __starting_point():\n main()\n\n__starting_point()", "a,b,x = map(int, input().split())\nprint(b//x - (a-1)//x)", "a, b, x = [int(x) for x in input().split()]\n\n\nb_num = b // x\na_num = (a - 1) // x if a - 1 >= 0 else -1\nprint((b_num - a_num))\n", "# ABC048\na, b, x = list(map(int, input().split()))\n\nprint((b//x - a//x + (a % x == 0)))\n", "# -*- coding: utf-8 -*-\n\na,b,x = map(int, input().split())\n\nans = (b // x) - ((a-1) // x) \nif ans < 0:\n ans = 0\n\nprint(ans)", "a, b, x = map(int, input().split())\nif a != 0:\n print((b // x) - (a - 1) // x)\nelse:\n print(b // x + 1)", "a,b,x = map(int, input().split())\nans = b//x - (a-1)//x\nprint(ans)", "import sys\ninput = sys.stdin.readline\nenum = enumerate\ninf = 1001001001\n\nimport collections\nimport random\n\ndef linput(ty=int, cvt=list):\n\treturn cvt(list(map(ty,input().split())))\n\ndef vinput(rep=1, ty=int, cvt=list):\n\treturn cvt(ty(input().rstrip()) for _ in \"*\"*rep)\n\ndef gcd(a: int, b: int):\n\twhile b: a, b = b, a%b\n\treturn a\n\ndef lcm(a: int, b: int):\n\treturn a * b // gcd(a, b)\n\ndef dist(x1,y1,x2,y2):\n\treturn abs(x1-x2)+abs(y1-y2)\n\n#vD = [chr(ord(\"a\")+i) for i in range(26)]\n\ndef ran():\n\tvRan = [random.randint(1, 10),\n\t random.randint(0, 10),\n\t random.randint(1, 100)]\n\treturn vRan\n\ndef bye(res):\n\tsT = \"No Yes\".split()\n\tprint((sT[res]))\n\t#return\n\ndef sol_n(a,b,c):\n\tres = 0\n\tcnt = 0\n\twhile cnt<c:\n\t\tres += 1\n\t\tcnt += a\n\t\tif res%7==0:\n\t\t\tcnt += b\n\treturn res\n\n\ndef sol(a,b,c):\n\t#a,b,c = linput()\n\t### 3 6 9 12 15\n\t### 1 2 3 4 5\n\t\n\tres = 0\n\tL = -(-a//c)\n\tR = (b//c)\n\tres = R-L+1\n\t\n\treturn res\n\ndef deb():\n\t#vI = linput()\n\tvI = ran()\n\t#print(vI)\n\tI = sol_n(*vI)\n\tJ = sol(*vI)\n\tif 1:#I!=J:\n\t\tprint((vI, I, J))\n\ndef main():\n\tvI = linput()\n\tprint((sol(*vI)))\n\ndef __starting_point():\n\t#for _ in \"*\"*1000:\n\t#\tdeb()\n\tmain()\n\n__starting_point()", "a,b,x = list(map(int, input().split()))\n\n#\u6700\u5c0f\u5024\nif(a%x != 0):\n min_div = a + x - (a % x)\n\nelse:\n min_div = a\n\n#\u6700\u5927\u5024\nif(b%x != 0):\n max_div = b - (b % x)\n\nelse:\n max_div = b\n\nprint((int(max((max_div - min_div + x) // x, 0))))\n", "a,b,x=map(int,input().split())\nprint(b//x-(a+x-1)//x+1)", "a,b,x = map(int, input().split())\nprint(b//x - (a+x-1)//x + 1)", "a,b,x = map(int,input().split())\nprint((b//x)-(a-1)//x)", "import math;\nfrom decimal import *;\n\na,b,x = map(Decimal, input().split())\n\nprint(max(0, (b//x) - math.ceil(a/x) + 1))", "def answer(a: int, b: int, x: int) -> int:\n return b // x - (a - 1) // x\n\n\ndef main():\n a, b, x = map(int, input().split())\n print(answer(a, b, x))\n\n\ndef __starting_point():\n main()\n__starting_point()", "a, b, x = list(map(int, input().split()))\nprint((b // x - (a + x - 1) // x + 1))\n", "a, b, c = map(int, input().split())\nif a == 0:\n print(b // c+1)\n return\nprint(b // c - (a-1) // c)", "a,b,x = map(int,input().split())\n\nif a % x == 0:\n print((b//x)-(a//x)+1)\nelse:\n print((b//x)-(a//x))", "a,b,x = map(int,input().split())\nprint((b//x)-((a-1)//x))", "a, b, x = map(int,input().split())\n\nif a == 0:\n ans = b // x + 1\nelse:\n ans = b // x - (a-1) // x\nprint(ans)", "a,b,x = map(int,input().split())\nst = -(-a//x)\ned = b//x\nprint(ed-st+1)", "a, b, x = list(map(int, input().split()))\nres = b // x - (a + x - 1) // x + 1\nprint(res)\n", "a, b, x = list(map(int, input().split()))\n\na_x = a // x\nb_x = b // x\nif a % x == 0:\n print((b_x - a_x + 1))\nelse:\n print((b_x - a_x))\n", "def LI():\n return list(map(int, input().split()))\n\n\na, b, x = LI()\nans = b//x-(a-1)//x\nprint(ans)\n", "a, b, x = map(int, input().split())\nprint(b//x-(a-1)//x)", "a,b,x = map(int,input().split())\nif a != 0:\n print(b // x - (a - 1) // x)\nelse:\n print(b // x + 1)", "a, b, x = map(int, input().split())\n\nans = b//x -(a-1) //x\nprint(ans)", "a, b, x = list(map(int, input().split()))\n\nans = (b-a)//x\n\nif (x-a % x) % x+(b % x) < x:\n ans += 1\n\nprint(ans)\n", "a, b, x = map(int, input().split())\nprint(b//x - (a-1)//x)", "a, b, c = map(int, input().split())\nprint(b // c - (a - 1) // c)", "a, b, x = map(int, input().split())\ncount = 0\nstart = 0\nfor i in range(x, 10**18+x+1, x):\n if a<=i:\n start = count\n break\n count += 1\nif a==0:\n start = -1\nprint(b//x - start)", "a, b, x = list(map(int, input().split()))\nif a % x == 0:\n print(((b // x) - (a // x) + 1))\nelse:\n print(((b // x) - (a // x)))\n", "a, b, x = map(int, input().split())\nans = b//x - a//x + (a%x==0)\nprint(ans)", "import math\na,b,x = map(int, input().split())\n\na_c = a//x if a%x == 0 else a//x + 1\nb_f = b//x\nprint(b_f-a_c+1)", "a,b,x = map(int,input().split())\n\ndef get(n):\n if n<0:\n return 0\n else:\n return n//x + 1\nprint(get(b)-get(a-1))", "a, b, x = tuple([int(x) for x in input().split(\" \")])\nif a % x == 0:\n print((b // x - a // x + 1))\nelse:\n print((b // x - a // x))\n", "a, b, x = list(map(int, input().split()))\n\nbb = b // x\naa = (a - 1) // x\n\nprint((bb - aa))\n", "a, b, x = map(int, input().split())\nprint(b // x - (a - 1) // x)", "a, b, x = list(map(int, input().split()))\n\nans = b//x -(a-1) //x\nprint(ans)\n", "a,b,x = map(int,input().split())\nprint(b//x+(-a//x)+1)", "a,b,k = [int(x) for x in input().split()]\nres = b // k\nres -= (a-1) // k\nprint(res)", "a, b, x = list(map(int, input().split()))\n\nif a % x == 0:\n print(b // x - a // x + 1)\nelse:\n\tprint(b // x - a // x)", "a, b, x = map(int, input().split())\nprint(b//x - (a-1)//x)", "lst = input().split()\n\na = int(lst[0])\nb = int(lst[1])\nx = int(lst[2])\n\nif a % x != 0:\n a = x * ((a // x) + 1)\n\nif b % x != 0:\n b = x * (b // x)\n\nprint(((b - a) // x) + 1)", "a,b,x = map(int,input().split())\n\nprint((b//x)-((a-1)//x))", "a,b,x=list(map(int,input().split()))\nans = 0\nif a % x == 0:\n ans += 1\nb //= x\na //= x\nans += b - a\nprint(ans)\n", "a,b,x = list(map(int,input().split()))\n\nif a%x == 0 :\n print((b//x - a//x + 1))\nelif a%x is not 0 :\n print((b//x - a//x))\n\n\n\n", "a,b,x=map(int,input().split())\nbb=b//x\naa=a//x\nans=bb-aa\nif a%x==0:\n ans+=1\nprint(ans)", "import sys\nimport math\nimport itertools\nimport collections\nimport heapq\nimport re\nimport numpy as np\nfrom functools import reduce\n\nrr = lambda: sys.stdin.readline().rstrip()\nrs = lambda: sys.stdin.readline().split()\nri = lambda: int(sys.stdin.readline())\nrm = lambda: list(map(int, sys.stdin.readline().split()))\nrl = lambda: list(map(int, sys.stdin.readline().split()))\ninf = float('inf')\nmod = 10**9 + 7\n\n\na, b, x = rm()\nprint((b//x - (a-1)//x))\n\n\n\n\n\n", "a,b,x=map(int,input().split())\nprint((b//x)-((a-1)//x))", "import sys\nimport re\nimport queue\nimport collections\nimport math\nfrom decimal import *\nfrom copy import deepcopy\nfrom collections import Counter, deque\nfrom heapq import heapify, heappop, heappush\nfrom itertools import accumulate, product, combinations, combinations_with_replacement\nfrom bisect import bisect, bisect_left, bisect_right\nfrom functools import reduce\nfrom typing import Callable\nfrom decimal import Decimal, getcontext\n# input = sys.stdin.readline\ndef i_input(): return int(input())\ndef i_map(): return map(int, input().split())\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\ndef lcm(a, b): return a * b // gcd(a, b)\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\nnum_list = []\nstr_list = []\n\ndef main():\n\ta,b,x = i_map()\n\n\tc = math.ceil((Decimal(a)/Decimal(x)))\n\td = math.floor(Decimal(b)/Decimal(x))\n\tprint(d-c+1)\n\ndef __starting_point():\n\tmain()\n__starting_point()", "a,b,x = map(int,input().split())\nprint(b//x - (a-1)//x)", "a,b,x=map(int,input().split())\ndef cntr(n,x):\n if n>=0:\n return n//x+1\n else:\n return 0\nprint(cntr(b,x)-cntr(a-1,x) if a!=0 else cntr(b,x)-cntr(-1,x))", "a,b,x = map(int, input().split())\n\na_div=0\nb_div = b//x\nif a!=0:\n a_div = (a-1)//x\n count = b_div-a_div\nelse:\n count = b_div-a_div+1\nprint(count)", "a, b, x = map(int, input().split())\nif a != 0:\n print(b // x - (a - 1) // x)\nelse:\n print(b // x + 1)", "import math\nimport sys\nimport os\nfrom operator import mul\n\nsys.setrecursionlimit(10**7)\n\ndef _S(): return sys.stdin.readline().rstrip()\ndef I(): return int(_S())\ndef LS(): return list(_S().split())\ndef LI(): return list(map(int,LS()))\n\nif os.getenv(\"LOCAL\"):\n inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'\n sys.stdin = open(inputFile, \"r\")\nINF = float(\"inf\")\n\na,b,x = LI()\n\nans = 0\nif a > 0:\n a -= 1\nelse:\n ans += 1\nans += b//x - a//x\n\nprint(ans)", "a, b, x = list(map(int, input().split()))\n\nprint(b // x - (a - 1) // x)", "a,b,x = map(int,input().split())\n\ncnt = b // x - (a - 1) // x\n\nprint(cnt)", "a,b,x=map(int,input().split())\nb=b//x\na=(a+x-1)//x\nprint(b-a+1)", "a,b,x = map(int,input().split())\nprint(b//x-(a-1)//x)", "a,b,x=map(int,input().split())\nprint(b//x-(a-1)//x)", "a,b,x = map(int,input().split())\n\ncnt = 0\nif a % x == 0:\n cnt += 1\n\n#if b % x == 0:\n# cnt += 1\n \ncnt += (b//x - a//x)\n\nprint(cnt)", "import re\nimport copy\n\ndef accept_input():\n a,b,x = list(map(int,input().split()))\n return a,b,x\n\na,b,x = accept_input()\nprint((b // x - (a - 1) // x))\n\"\"\"\nif a%x == 0 and a != b:\n print(b//x - a//x +1)\nelif a%x == 0 and a == b:\n print(0)\nelse:\n print(b//x - a//x)\n\"\"\" \n", "a, b, x = map(int, input().split())\nans = b//x - a//x\nif a%x == 0:\n print(ans+1)\nelse:\n print(ans)", "a,b,x = list(map(int,input().split()))\n\nprint((b//x-(a-1)//x))\n", "a,b,x=map(int,input().split())\n\nres1=(a-1)//x\nres2=b//x\nans=res2-res1\nprint(ans)", "a, b, x = map(int, input().split())\nprint(b // x - (a - 1) // x)", "a, b, x = list(map(int, input().split()))\nprint((b // x - (a - 1) // x))\n", "a,b,x = map(int,input().split())\nans = (b//x+1) - (a//x+1)\nif a % x == 0:\n ans += 1\n\nprint(ans)", "import math\nimport collections\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\na,b,x = mi()\n\nif a%x != 0:\n A = x*(a//x + 1)\nelse:\n A = a\nB = b - b%x\nprint((B-A)//x+1)", "import math\nfrom math import gcd,pi,sqrt\nINF = float(\"inf\")\n\nimport sys\nsys.setrecursionlimit(10**6)\nimport itertools\nfrom collections import Counter,deque\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\n\nimport string\n\ndef main():\n a,b,x = i_map()\n print((b//x - (a-1)//x))\n\ndef __starting_point():\n main()\n\n__starting_point()", "a, b, x = [int(x) for x in input().split()]\nprint((b//x)-((a-1)//x))", "a, b ,x = map(int, input().split())\nans = 0\nn_a = a//x\nn_b = b//x\nif a%x == 0:\n ans+=1\nans += n_b - n_a\nprint(ans)", "import sys\ninput=sys.stdin.read\na,b,x=map(int,input().split())\nprint((b//x)-(a//x) if a%x!=0 else (b//x)-(a//x)+1)", "a,b,x = map(int, input().split())\n\nans = b//x - (a-1)//x\n\nprint(ans)", "import sys, math\nfrom itertools import combinations as c, product as p\nfrom collections import deque\nsys.setrecursionlimit(10**9)\n\n\ndef si(): return input()\ndef ii(): return int(input())\ndef fi(): return float(input())\ndef lstr(): return input().split()\ndef lint(): return list(map(int, input().split()))\ndef lint_dec(): return list([int(x) - 1 for x in input().split()])\ndef lnstr(n): return [input() for _ in range(n)]\ndef lnint(n): return [int(input()) for _ in range(n)]\ndef lint_list(n): return [lint() for _ in range(n)]\n\n\n\n############################################################\na, b, x = lint()\nprint((b // x - (a - 1) // x))\n", "import sys\n\ninput = sys.stdin.readline\n\na,b,x= map(int, input().split())\n\na_count = (a-1) // x\n\n\nb_count = b // x\nprint(b_count - a_count)", "a, b, x = map(int, input().split())\n\nl = a//x + 1\nif a % x == 0:\n l -= 1\n\nr = b//x\n\nprint((r - l) + 1)", "a, b, x = map(int, input().split())\n\nar = a % x\nn = b - a + 1\nif ar != 0:\n n -= x - ar\n\nans = n // x\nif n % x >= 1:\n ans += 1\n\nprint(ans)", "a,b,x=map(int,input().split())\nans=b//x - (a-1)//x\nprint(ans)", "a,b,x = list(map(int, input().split()))\n\nif a == 0:\n mi = -1\nelif a > 1:\n mi = (a - 1) // x\nelse:\n mi = 0\nma = b // x if b != 0 else 0\n\nprint((ma-mi))\n", "a, b, x = list(map(int, input().split()))\n\nbd = b // x\nad = (a-1) // x\nprint((bd - ad))\n", "a,b,x=list(map(int,input().split()))\nprint((b//x-(a-1)//x))\n", "a,b,x = map(int,input().split())\nif a%x == 0:\n min = a//x - 1\nelse:\n min = a//x\nmax = b//x\nprint(max-min)", "a, b, x = list(map(int, input().split()))\n\ndef f(n, d):\n if n == -1:\n return 0\n return n // d + 1\n\nprint((f(b, x) - f(a - 1, x)))\n\n#b\u3092\u5272\u3063\u305f\u3068\u304d\u306e\u500b\u6570\u304b\u3089a\u3092\u5272\u3063\u305f\u3068\u304d\u306e\u500b\u6570\u3092\u5f15\u304f\n", "def __starting_point():\n a, b, x = map(int, input().split())\n l = b // x\n r = (a-1) // x\n print(l - r)\n__starting_point()", "a, b, x = map(int, input().split())\n\nprint(b // x - (a - 1) // x)", "# cook your dish here\n\nli=list(map(int,input().split()))\nif li[0]-1<0:\n print((li[1]//li[2])+1)\nelse:\n print((li[1]//li[2])-(li[0]-1)//li[2])", "a,b,x=map(int,input().split())\nbb=b//x\naa=a//x\nans=bb-aa\nif a%x==0:\n ans+=1\nprint(ans)", "a,b,x=map(int,input().split())\naa=(a-1)//x\nbb=b//x\nprint(bb-aa)"] | {"inputs": ["4 8 2\n", "0 5 1\n", "9 9 2\n", "1 1000000000000000000 3\n"], "outputs": ["3\n", "6\n", "0\n", "333333333333333333\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 16,324 | |
a902fe8e3e854f64d68875fca6fbe205 | UNKNOWN | In some other world, today is December D-th.
Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.
-----Constraints-----
- 22 \leq D \leq 25
- D is an integer.
-----Input-----
Input is given from Standard Input in the following format:
D
-----Output-----
Print the specified string (case-sensitive).
-----Sample Input-----
25
-----Sample Output-----
Christmas
| ["d=int(input())\nprint('Christmas'+' Eve'*(25-d))", "D = int (input ())\nx = 25 - D\nprint ('Christmas', 'Eve '*x)", "D = int(input())\n\nif D == 25: print('Christmas') \nelif D == 24: print('Christmas Eve')\nelif D == 23: print('Christmas Eve Eve')\nelse: print('Christmas Eve Eve Eve')", "a = int(input())\n\nif a == 25:\n print(\"Christmas\")\nelif a == 24:\n print(\"Christmas Eve\")\nelif a == 23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "# ABC115\n# A Christmas Eve Eve Eve\nD = int(input())\nif D == 25:\n print(\"Christmas\")\nelif D == 24:\n print(\"Christmas Eve\")\nelif D ==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")\n", "d = int(input())\n\nl1 = [22,23,24,25]\n\ndic = { 22:'Christmas Eve Eve Eve',\n 23:'Christmas Eve Eve',\n 24:'Christmas Eve',\n 25:'Christmas'}\n\nfor i in range(4):\n if(l1[i]==d):\n print(dic[l1[i]])", "# import numpy as np\n# import math\n\n# from scipy.special import perm : perm(n, r, exact=True)\n# from scipy.special import comb : comb(n, r, exact=True)\n\n# import itertools\n# for v in itertools.combinations(L, n):M.append(list(v))\n\n# from numba import njit\n# @njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)\n\n\n\"\"\" Definitions \"\"\"\n\ndef lcm(a, b):\n return a*b//math.gcd(a, b)\n\nMOD = 10**9+7\n\n# ============================================================\n\nD = int(input())\n\nL = ['Christmas Eve', 'Christmas', 'Christmas Eve Eve Eve', 'Christmas Eve Eve']\n\nprint((L[D%4]))\n\n", "D = int(input())\n\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "D = int(input())\nprint('Christmas'+' Eve'*(25 - D))", "print('Christmas' + ' Eve' * (25 - int(input())))", "D = int(input())\nprint('Christmas' + \" Eve\"*(25-D))", "n = int(input())\nprint(\"Christmas\" + \" Eve \" * (25 - n))", "\nD=int(input())\nif D==25:\n print('Christmas')\nelif D==24:\n print('Christmas Eve')\nelif D==23:\n print('Christmas Eve Eve')\nelif D==22:\n print('Christmas Eve Eve Eve')", "D = int(input())\n\nans = \"Christmas\"\nans += \" Eve\" * (25 - D)\n\nprint(ans)", "D=int(input())\nprint(\"Christmas\"+\" Eve\"*(25-D))", "D = int(input())\n\nprint('Christmas' + ' Eve' * (25 - D))", "d = int(input())\nif d == 25:\n print(\"Christmas\")\nelif d == 24:\n print(\"Christmas Eve\")\nelif d == 23:\n print(\"Christmas Eve Eve\")\nelif d == 22:\n print(\"Christmas Eve Eve Eve\")\n", "D=int(input())\nif D==25:\n print(\"Christmas\")\nelif D==24:\n print(\"Christmas Eve\")\nelif D==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "d = int(input())\nx = [\"Christmas Eve Eve Eve\"] + [\"Christmas Eve Eve\"] + [\"Christmas Eve\"] + [\"Christmas\"]\nprint(x[d-22])", "d = int(input())\ndic = {25: \"Christmas\", 24: \"Christmas Eve\", 23: \"Christmas Eve Eve\", 22: \"Christmas Eve Eve Eve\"}\nprint(dic[d])", "d=int(input())\nif d==25:\n print(\"Christmas\")\nelif d==24:\n print(\"Christmas Eve\")\nelif d==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "D = int(input())\n\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "a = int(input())\n\nif a == 25:\n print('Christmas')\nif a == 24:\n print('Christmas Eve')\nif a == 23:\n print('Christmas Eve Eve')\nif a == 22:\n print('Christmas Eve Eve Eve')\n", "D = int(input())\n\nif D == 25:\n print(\"Christmas\")\nelif D == 24:\n print(\"Christmas Eve\")\nelif D == 23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "D = int(input())\n\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "d=input()\nif d=='25':\n print('Christmas')\nif d=='24':\n print('Christmas Eve')\nif d=='23':\n print('Christmas Eve Eve')\nif d=='22':\n print('Christmas Eve Eve Eve')", "print((\"Christmas\"+\" Eve\"*(25-int(input()))))\n", "d=int(input())\nprint('Christmas'+' Eve'*(25-d))", "#ABC115A\nd = int(input())\nprint(\"Christmas\" + \" Eve\"*(25-d))", "D=int(input())\nif D==25:\n print(\"Christmas\")\nelif D==24:\n print(\"Christmas Eve\")\nelif D==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")\n", "d = int(input())\nif(d==25):\n print(\"Christmas\")\nelif(d==24):\n print(\"Christmas Eve\")\nelif(d==23):\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "d=int(input())\nd=25-d\nprint('Christmas',end=' ')\n\nfor i in range(0,d):\n print('Eve',end=' ')\n", "d = int(input())\nif d == 25:\n print('Christmas')\nelif d == 24:\n print('Christmas Eve')\nelif d == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "print(\"Christmas \"+str(25%int(input())*\"Eve \"))", "a = int(input())\nans = 'Christmas' + ' Eve' * (25-a)\nprint(ans)\n", "d=int(input())\nprint(\"Christmas\"+\" Eve\"*(25-d))", "a=input()\na=int(a)\nif a==25:\n print(\"Christmas\")\nif a==24:\n print(\"Christmas Eve\")\nif a==23:\n print(\"Christmas Eve Eve\")\nif a==22:\n print(\"Christmas Eve Eve Eve\")", "d = int(input())\ns = \"Christmas\"\ne = \" Eve\"\nprint(s+e*(25-d))", "D = int(input())\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelif D == 22:\n print('Christmas Eve Eve Eve')", "christmas_day = 25\nd = int(input())\nprint(\"Christmas\", \" Eve\" * (christmas_day - d))", "s=\"Christmas\"\nd=int(input())\nt=25-d\nprint(s+\" Eve\"*t)", "n=input()\nif n==\"25\":\n print(\"Christmas\") \nelif n==\"24\":\n print(\"Christmas Eve\") \nelif n==\"23\": \n print(\"Christmas Eve Eve\") \nelif n==\"22\": \n print(\"Christmas Eve Eve Eve\") ", "d = int(input())\n\nif d == 25:\n print('Christmas')\nelif d == 24:\n print('Christmas Eve')\nelif d == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "D=int(input())\nif D==25:\n print(\"Christmas\")\nelif D==24:\n print(\"Christmas Eve\")\nelif D==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "a = int(input())\nif a == 25:\n print(\"Christmas\")\nelif a == 24:\n print(\"Christmas Eve\")\nelif a == 23:\n print(\"Christmas Eve Eve\")\nelif a == 22:\n print(\"Christmas Eve Eve Eve\")", "d=int(input())\nif d==25:\n print('Christmas')\nelif d==24:\n print('Christmas Eve')\nelif d==23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "dict={25:\"Christmas\",24:\"Christmas Eve\",23:\"Christmas Eve Eve\",22:\"Christmas Eve Eve Eve\"}\nprint((dict[int(input())]))\n", "d = int(input())\n\nif d == 25:\n print('Christmas')\nif d == 24:\n print('Christmas Eve')\nif d == 23:\n print('Christmas Eve Eve')\nif d == 22:\n print('Christmas Eve Eve Eve')\n", "D=int(input())\n\nans=[\"Christmas Eve Eve Eve\",\"Christmas Eve Eve\",\"Christmas Eve\",\"Christmas\"]\n\nprint(ans[D-22])", "import math\nimport collections\nfrom itertools import product\n\nii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nd = ii()\nif d == 25:\n print(\"Christmas\")\nelif d == 24:\n print(\"Christmas Eve\")\nelif d == 23:\n print(\"Christmas Eve Eve\")\nelif d == 22:\n print(\"Christmas Eve Eve Eve\")", "d = int(input())\na = 'Christmas'\nb = ' Eve'\nif d == 25:\n print(a)\nelif d == 24:\n print(a + b)\nelif d == 23:\n print(a + b * 2)\nelse:\n print(a + b * 3)", "print(\"Christmas\"+\" Eve\"*(25-int(input())))", "d = int(input())\nEve = ' Eve'\nprint('Christmas'+Eve*(25-d))", "a = int(input())\nif a == 22:\n print(\"Christmas Eve Eve Eve\")\nelif a == 23:\n print(\"Christmas Eve Eve\")\nelif a == 24:\n print(\"Christmas Eve\")\nelse:\n print(\"Christmas\")\n\n", "a = int(input())\nif a == 22:\n print('Christmas Eve Eve Eve')\nelif a == 23:\n print('Christmas Eve Eve')\nelif a == 24:\n print('Christmas Eve')\nelse:\n print('Christmas')", "d = int(input())\nif d == 25:\n print(\"Christmas\")\nelif d == 24:\n print(\"Christmas Eve\")\nelif d == 23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "d = int(input())\ns = \"Christmas\"\nfor _ in range(25-d):\n s += \" Eve\"\nprint(s)", "d = input()\nif d == \"25\":\n print(\"Christmas\")\nelif d == \"24\":\n print(\"Christmas Eve\")\nelif d == \"23\":\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "print(\"Christmas\"+\" Eve\"*(25-int(input())))", "D = int(input())\nif D==25:\n print('Christmas')\nelif D==24:\n print('Christmas Eve')\nelif D==23:\n print('Christmas Eve Eve') \nelif D==22:\n print('Christmas Eve Eve Eve')\n", "D = int(input())\nif D == 25:\n print(\"Christmas\")\nelif D == 24:\n print(\"Christmas Eve\")\nelif D == 23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "print(\"Christmas\"+\" Eve\"*(25-int(input())))", "d=int(input())\n\nif d==25:\n ans=\"Christmas\"\nelif d==24:\n ans=\"Christmas Eve\"\nelif d==23:\n ans=\"Christmas Eve Eve\"\nelse:\n ans=\"Christmas Eve Eve Eve\"\n \nprint(ans)\n", "def main():\n n = int(input())\n if n == 22: print(\"Christmas Eve Eve Eve\")\n if n == 23: print(\"Christmas Eve Eve\")\n if n == 24: print(\"Christmas Eve\")\n if n == 25: print(\"Christmas\")\n\nmain()", "d = int(input())\ne = 25 - d\nprint(\"Christmas\"+\" Eve\"*e)", "D = int(input())\nif D == 25:\n print(\"Christmas\")\nelif D == 24:\n print(\"Christmas Eve\")\nelif D == 23:\n print(\"Christmas\"+\" Eve\"*2)\nelse:\n print(\"Christmas\"+\" Eve\"*3)", "N = int(input())\nAns = \"Christmas\"\nfor i in range(25,N,-1):\n Ans += \" Eve\"\nprint(Ans)", "print('Christmas' + ' Eve' * (25 - int(input())))", "d = int(input())\nday = {25: 'Christmas', 24: 'Christmas Eve', 23: 'Christmas Eve Eve', 22: 'Christmas Eve Eve Eve'}\nprint(day[d])", "D = int(input())\na = \"Christmas \"\nb = \"Eve \"\nprint(a+b*(25-D))", "n = int(input())\n\nif n == 25:\n print(\"Christmas\")\nelif n == 24:\n print(\"Christmas Eve\")\nelif n == 23:\n print(\"Christmas Eve Eve\")\nelif n == 22:\n print(\"Christmas Eve Eve Eve\")", "d = {25: 'Christmas', 24: 'Christmas Eve', 23: 'Christmas Eve Eve', 22: 'Christmas Eve Eve Eve'}\nprint((d[int(input())]))\n", "x = int(input())\nprint(\"Christmas\"+\" Eve\"*(25-x))", "a = int(input())\nif a == 22:\n print('Christmas Eve Eve Eve')\nelif a == 23:\n print('Christmas Eve Eve')\nelif a == 24:\n print('Christmas Eve')\nelif a == 25:\n print('Christmas')", "d = int(input())\nans = 'Christmas' + ' Eve' * (25 - d)\nprint(ans)", "print(\"Christmas\"+\" Eve\"*(25-int(input())))", "d=int(input())\nif d==22:\n print(\"Christmas Eve Eve Eve\")\nelif d==23:\n print(\"Christmas Eve Eve\")\nelif d==24:\n print(\"Christmas Eve\")\nelif d==25:\n print(\"Christmas\")", "d=int(input())\nc=\"Christmas\"\ne=\"Eve\"\nif d==25:\n print(c)\nelif d==24:\n print(c,e)\nelif d==23:\n print(c,e,e)\nelif d==22:\n print(c,e,e,e)", "d = int(input())\nif d == 25:\n print('Christmas')\nelif d == 24:\n print('Christmas Eve')\nelif d == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "D = int(input())\nprint('Christmas'+' Eve'*(25-D))", "d=int(input())\nif d==25:\n print(\"Christmas\")\nelif d==24:\n print(\"Christmas Eve\")\nelif d==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "n = int(input())\n\nif n ==25:\n print(\"Christmas\")\n\nelif n ==24:\n print(\"Christmas Eve\")\n\nelif n ==23:\n print(\"Christmas Eve Eve\")\n\nelse:\n print(\"Christmas Eve Eve Eve\")", "print(('Christmas' + ' Eve'*(25-int(input()))))\n", "D=int(input())\nif D==22:\n print(\"Christmas Eve Eve Eve\")\nelif D==23:\n print(\"Christmas Eve Eve\")\nelif D==24:\n print(\"Christmas Eve\")\nelif D==25:\n print(\"Christmas\")", "d = int(input())\nif d == 25:\n print('Christmas')\nelif d == 24:\n print('Christmas Eve')\nelif d == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "S=input()\nif S=='25':\n print(\"Christmas\")\nif S=='24':\n print(\"Christmas Eve\")\nif S=='23':\n print(\"Christmas Eve Eve\")\nif S=='22':\n print(\"Christmas Eve Eve Eve\")\n", "d = int(input())\n\nif d == 25:\n print(\"Christmas\")\nelif d == 24:\n print(\"Christmas Eve\")\nelif d == 23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")", "D = int(input())\n\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelif D == 22:\n print('Christmas Eve Eve Eve')\n", "D = int(input())\nans = 'Christmas'\nfor i in range(25-D):\n ans += ' Eve'\nprint(ans)", "N = int(input())\nif N==25:print(\"Christmas\")\nelif N==24:print(\"Christmas Eve\")\nelif N==23:print(\"Christmas Eve Eve\")\nelse : print(\"Christmas Eve Eve Eve\")", "D = int(input())\n\nif D == 25:\n print('Christmas')\nelif D == 24:\n print('Christmas Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "d = int(input())\nif d == 25:\n print(\"Christmas\")\nelif d == 24:\n print(\"Christmas Eve\")\nelif d == 23:\n print(\"Christmas Eve Eve\")\nelif d == 22:\n print(\"Christmas Eve Eve Eve\")", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n D = int(readline())\n\n if D == 25:\n ans = 'Christmas'\n elif D == 24:\n ans = 'Christmas Eve'\n elif D == 23:\n ans = 'Christmas Eve Eve'\n else:\n ans = 'Christmas Eve Eve Eve'\n\n print(ans)\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "d = int(input())\nprint(\"Christmas \" + \"Eve \" * (5 - d%20))", "d = int(input())\n \nif d == 25:\n print('Christmas')\nelif d == 24:\n print('Christmas Eve')\nelif d == 23:\n print('Christmas Eve Eve')\nelse:\n print('Christmas Eve Eve Eve')", "D = input()\na = {'25':'Christmas', '24':'Christmas Eve', '23':'Christmas Eve Eve', '22':'Christmas Eve Eve Eve'}\nprint(a[D])", "day = int(input())\n\nif day == 22:\n print('Christmas Eve Eve Eve')\nelif day == 23:\n print('Christmas Eve Eve')\nelif day == 24:\n print('Christmas Eve')\nelif day == 25:\n print('Christmas')\n", "D = int(input())\n\nif D == 22:\n print('Christmas Eve Eve Eve')\nelif D == 23:\n print('Christmas Eve Eve')\nelif D == 24:\n print('Christmas Eve')\nelse:\n print('Christmas')", "D=int(input())\nprint(\"Christmas Eve Eve Eve\" if D==22 else \"Christmas Eve Eve\" if D==23 else \"Christmas Eve\" if D==24 else \"Christmas\")", "N=int(input())\nif N==25:\n print(\"Christmas\")\nelif N==24:\n print(\"Christmas Eve\")\nelif N==23:\n print(\"Christmas Eve Eve\")\nelse:\n print(\"Christmas Eve Eve Eve\")"] | {"inputs": ["25\n", "22\n", "23\n", "24\n"], "outputs": ["Christmas\n", "Christmas Eve Eve Eve\n", "Christmas Eve Eve\n", "Christmas Eve\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 15,264 | |
13a7674a29f20739ce1f7f078d123663 | UNKNOWN | Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
- 6 can be divided by 2 once: 6 -> 3.
- 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
- 3 can be divided by 2 zero times.
-----Constraints-----
- 1 β€ N β€ 100
-----Input-----
Input is given from Standard Input in the following format:
N
-----Output-----
Print the answer.
-----Sample Input-----
7
-----Sample Output-----
4
4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7. | ["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int):\n if N >= 64:\n print((64))\n elif N >= 32:\n print((32))\n elif N >= 16:\n print((16))\n elif N >= 8:\n print((8))\n elif N >= 4:\n print((4))\n elif N >= 2:\n print((2))\n else:\n print((1))\n return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n solve(N)\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nif n >= 64:\n print((64))\nelif n >= 32:\n print((32))\nelif n >= 16:\n print((16))\nelif n >= 8:\n print((8))\nelif n >= 4:\n print((4))\nelif n >= 2:\n print((2))\nelse:\n print((1))\n", "n = int(input())\nx = 0\nfor i in range(1, n+1):\n if i%64 == 0 and 64 > x:\n ans = i\n x = 64\n elif i%32 == 0 and 32 > x:\n ans = i\n x = 32\n elif i%16 == 0 and 16 > x:\n ans = i\n x = 16\n elif i%8 == 0 and 8 > x:\n ans = i\n x = 8\n elif i%4 == 0 and 4 > x:\n ans = i\n x = 4\n elif i%2 == 0 and 2 > x:\n ans = i\n x = 2\n elif i == 1:\n ans = 1\n x = 1\nprint(ans)", "n = int(input())\nres = 1\nwhile True:\n if res > n:\n break\n res *= 2\nprint((res // 2))\n", "N = int(input())\n\ndef black_magic(n):\n d = {\n 1: 1431655765,\n 2: 858993459,\n 4: 252645135,\n 8: 16711935,\n 16: 65535\n }\n n=(n&d[1])+((n>>1)&d[1])\n n=(n&d[2])+((n>>2)&d[2])\n n=(n&d[4])+((n>>4)&d[4])\n n=(n&d[8])+((n>>8)&d[8])\n n=(n&d[16])+((n>>16)&d[16])\n return n\n\nwhile black_magic(N) - 1:\n N &= N-1\nprint(N)", "s = int(input())\nt = 1\nfor i in range(1,8,1):\n if(s >= (2 ** i)):t = 2 ** i\nprint(t)", "print((2**(len(bin(int(input()))[2:])-1)))\n", "N = int(input())\n\ncnt_list = []\nfor i in range(1, N + 1):\n cnt = 0\n while i >= 1:\n if i % 2 == 0:\n cnt += 1\n i = i / 2\n else:\n break\n cnt_list.append(cnt)\nM = cnt_list.index(max(cnt_list))\nprint(M + 1)", "n = int(input())\nif n == 1:\n print(1)\nelif 2 <= n < 4:\n print(2)\nelif 4 <= n < 8:\n print(4)\nelif 8 <= n < 16:\n print(8)\nelif 16 <= n < 32:\n print(16)\nelif 32 <= n < 64:\n print(32)\nelse:\n print(64)", "N = int(input())\nnum = 1\nwhile num <= N:\n num *= 2\nprint(num // 2)", "n = int(input())\ni = 0\n\nwhile 2 ** (i +1) <= n:\n i += 1\nprint(2 ** i)", "n = int(input())\nans = 0\nanswer = 1\nfor i in range(1, n+1):\n cnt = 0\n num = i\n while num % 2 == 0:\n num //= 2\n cnt += 1\n if cnt > ans :\n answer = i\n ans = cnt \nprint(answer)", "N = int(input())\nfor i in range(100):\n x = 2 ** (100 - i)\n if x <= 64 and x <= N:\n ans = x\n break\n else:\n ans = N\nprint(ans)", "import bisect\nn = int(input())\nt = [1, 2, 4, 8, 16, 32, 64]\n\nprint(t[bisect.bisect_right(t, n)-1])", "n = int(input())\n\ni = 1\nwhile i < n:\n i = i * 2\n\nif i > n:\n print((int(i / 2)))\nelse:\n print(i)\n", "N = int(input())\nans = [1, 2, 4, 8, 16, 32, 64]\nprint(max(filter(lambda x : x<=N,ans)))", "# -*- coding:utf-8 -*-\nN = int(input())\n\nif N == 1:\n print(N)\nelse:\n for i in range(1,8):\n if 2**(i+1) > N:\n print(2**i)\n break\n else:\n i+=1", "n = int(input())\nans = 0\nfor i in range(n):\n if 2**i <= n:\n ans = max(ans, 2**i)\nprint(ans)", "N=int(input())\ntwo=[2**i for i in range(7)]\nans=max([x for i,x in enumerate(two) if x<=N])\nprint(ans)", "N = int(input())\ni = 1\nwhile i*2 <= N:\n i *= 2\nprint(i)", "n = int(input())\ncount = [0] * n\nfor i in range(1, n + 1):\n num = i\n while num % 2 == 0:\n num //= 2\n count[i - 1] += 1\nprint(count.index(max(count)) + 1)", "def cnt_div_two(n):\n res = 0\n while n % 2 == 0:\n n //= 2\n res += 1\n return res\n\n\nans = 0\nmax_cnt = -1\nfor i in range(1, int(input()) + 1):\n cdt = cnt_div_two(i)\n if cdt > max_cnt:\n ans = i\n max_cnt = cdt\nprint(ans)\n", "N = int(input())\ncount = 0\nwhile N > 1:\n N //= 2\n count += 1\nprint(2**count) ", "def resolve():\n print(2 ** (len(bin(int(input()))) - 3))\n\n\ndef __starting_point():\n resolve()\n__starting_point()", "n=int(input())\nans=1\n\nwhile(ans<=n):\n ans*=2\n\nprint(int(ans/2))", "N = int(input())\ncount = 0\nnum = 1\n\nwhile N >= num:\n count += 1\n num *= 2\n\nprint(num // 2)", "print(1<<int(input()).bit_length()-1)", "num = int(input())\nans = 1\nwhile ans <= num:\n ans = ans * 2\nprint((int(ans/2)))\n", "n = int(input())\n\na = 1\nwhile a <= n:\n a *= 2\nprint(a//2)", "n = int(input())\nmaxCnt = 0\nans = 1\n\nfor i in range(1,n+1,1):\n tmpCnt = 0\n j = i\n while j%2 == 0:\n j = j/2\n tmpCnt += 1\n if maxCnt < tmpCnt:\n maxCnt = tmpCnt\n ans = i\n\nprint(ans)", "n = int(input())\nans, cnt = 1, 0\nfor i in range(1, n+1):\n j = i\n t_cnt = 0\n if i%2 == 0:\n # print(i)\n while i%2 == 0:\n i = i//2\n t_cnt += 1\n # print(i, t_cnt)\n if t_cnt >= cnt:\n ans = j\n cnt = t_cnt\n\nprint(ans)", "n=int(input())\nfor i in range(1,n+1):\n if 2**i>n:\n print((2**(i-1)))\n return\n \n", "N=int(input())\n\nX=[]\n\n\nfor i in range(1,N+1):\n count=0\n while i%2==0:\n i//=2\n count+=1\n X.append(count)\n\nprint((X.index(max(X))+1))\n", "n = int(input())\nans = 1\nfor i in range(7):\n if 2 ** i <= n:\n ans = 2 ** i\nprint(ans)\n", "n=int(input())\nm = 0\ni = 0\nwhile 2**i <= n:\n m = max(m, 2**i)\n i += 1\nprint(m)", "N=int(input())\na=1\nwhile(N>1):\n N//=2\n a*=2\nprint(a)", "N = int(input())\nfor i in range(7):\n if 2 ** i <= N < 2 ** (i + 1):\n print(2 ** i)\n return", "#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)\u3067\u6700\u5927\u306e2\u500b\u3068\u308a\u3060\u305b\u308b\u304a a[0][0]\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product # (string,3) 3\u56de\n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n# python\u3067\u7121\u7406\u306a\u3068\u304d\u306f\u3001pypy\u3067\u3084\u308b\u3068\u6b63\u89e3\u3059\u308b\u304b\u3082\uff01\uff01\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n# \u56db\u6368\u4e94\u5165g\n#\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7cfb\n# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);\n# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nn = I()\nlis = [2**i for i in range(10)]\nidx = bisect.bisect_right(lis, n)\nprint((lis[idx-1]))\n", "N=int(input())\nlis=[0]*(N+1)\nMcnt=0\nMi=1\n\nfor i in range(1,N+1):\n lis[i]=i\n cnt=0\n while lis[i]%2==0:\n lis[i]//=2\n cnt+=1\n \n if Mcnt<cnt:\n Mcnt=cnt\n Mi=i\n \nprint(Mi)", "import math\n\nN = int(input())\n\ni = 1\nwhile i < N:\n i = i*2\n\nif i <= N:\n print(i)\nelse:\n print(math.floor(i/2))", "n = int(input())\nans = 1\n\nfor i in range(1, 7):\n if 2**i <= n:\n ans = 2**i\n\nprint(ans)", "import math\n\nn = int(input())\nans, i = 0, 1\nwhile ans <= n:\n ans = 2**i\n i += 1\n\nprint(ans//2)", "N = int(input())\n\nif N == 1:\n print((1))\nelif 1 < N < 2**2:\n print((2))\nelif 2**2 <= N < 2**3:\n print((4))\nelif 2**3 <= N < 2**4:\n print((8))\nelif 2**4 <= N < 2**5:\n print((16))\nelif 2**5 <= N < 2**6:\n print((32))\nelif 2**6 <= N:\n print((64))\n", "\nN = int(input())\nN2 = N\na = []\n\nfor i in range(N):\n count = 0\n if i != 0:\n tmp = N\n while tmp % 2 == 0:\n tmp = tmp / 2\n count += 1\n\n N = N - 1\n a.append(count)\n\nmax_value = max(a)\n\nind = a.index(max_value)\n\nif N2 == 1:\n print((1))\nelse:\n print((N2-ind+1))\n", "n = int(input())\nans = 2\nwhile n > ans:\n ans *= 2\nif n < ans: ans //= 2\nprint(ans)", "N=int(input())\ni=0\nwhile pow(2, i+1)<=N:\n i+=1\nprint(pow(2, i))", "n = int(input())\nnum = [i for i in range(1,n+1)]\njou = [2**j for j in range(0,7)]\nfor l in jou:\n if l in num:\n ans = l\n else:\n break\nprint(ans)", "from math import log2\n\nN = int(input())\n\nm = 0\na = 0\n\nfor i in range(1, N + 1):\n l = log2(i)\n if l % 1 == 0:\n m = i\n\n\nprint(m)\n", "#!/usr/bin/env python3\n\ndef main():\n n = int(input())\n i = 0\n while 2 ** i <= n:\n i += 1\n print((2 ** (i - 1)))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\nif n == 1:\n print(1)\nelse:\n for i in range(1,7):\n if 2**(7-i) <= n:\n print(2**(7-i))\n return", "n = int(input())\nif n == 1:\n print((1))\nelif 2 <= n < 4:\n print((2))\nelif 4 <= n < 8:\n print((4))\nelif 8 <= n < 16:\n print((8))\nelif 16 <= n < 32:\n print((16))\nelif 32 <= n < 64:\n print((32))\nelse:\n print((64))\n", "n = int(input())\ns = [i for i in range(1,n+1)]\ncounter = 0\nwhile(True):\n if len(s)==1:\n print((1))\n break\n if len([i for i in s if i % 2 == 0])==1:\n s = [i for i in s if i % 2 == 0]\n print((int(s[0]) * (2 ** counter)))\n break\n else:\n s = [i/2 for i in s]\n counter += 1\n", "n = int(input())\nans = 1\nx = 0\nfor i in range(1, n+1):\n counter = 0\n r = 0+i\n while r%2 == 0:\n r //= 2\n counter += 1\n if x < counter:\n ans = i\n x = counter\nprint(ans)", "n = int(input())\nfor i in range(1,10):\n if 2 ** i > n:\n print((2 ** (i - 1)))\n break\n", "N = int(input())\n\nans = 0\nres = 1\nfor i in range(2,N+1):\n j = i\n if j % 2 == 1:\n continue\n cnt = 0\n while j % 2 == 0:\n j //= 2\n cnt += 1\n if ans < cnt:\n res = i\n ans = cnt\n \nprint(res)", "N = int(input())\ncounter = 0\nwhile N >= 2:\n N //= 2\n counter +=1\nans = 2**counter\nprint(ans)", "import math\nn=int(input())\nprint(2**int(math.log(n,2)))", "n = int(input())\n\ncnt = 0\nwhile n > 0:\n n = n // 2\n if n != 0:\n cnt += 1\nprint(2 ** cnt)", "n = int(input())\nans = 1\nwhile ans*2 <= n:\n ans *= 2\nprint(ans)", "N = int(input())\nans_max = 0\nans = 1\nfor i in range(1, N + 1):\n cnt = 0\n moto_i = i\n while i % 2 == 0:\n cnt += 1\n if cnt > ans_max:\n ans = moto_i\n ans_max = max(ans_max, cnt)\n i //= 2\nprint(ans)\n", "N=int(input())\nresult=64\nwhile N>=1:\n if N >= result:\n print(result)\n break\n result=int(result/2)\nelse:\n print(result)", "print(1<<len(f'{int(input()):b}')-1)", "n = int(input())\nli = [2,4,8,16,32,64]\nimport bisect\nindex = bisect.bisect(li,n)-1\nimport sys\nif index == -1:\n print(n)\n return\nprint(li[index])", "n=int(input())\nans=0\nfor i in range(7):\n if (n>>i)&1:\n ans=(n>>i)<<i\nprint(ans)", "n = int(input())\nmax_count, answer = 0, 0\nfor i in range(1, n + 1):\n num = i\n count = 0\n while num % 2 == 0:\n num = num // 2\n count += 1\n if count > max_count:\n max_count, answer = count, i\n\nprint((max(1, answer)))\n", "n = int(input())\nc = 0\nfor i in range(1,8):\n if 2**i > n:\n print(2**(i-1))\n break", "import math\n\n\ndef answer(n: int) -> int:\n return 2 ** int(math.log(n, 2))\n\n\ndef main():\n n = int(input())\n print(answer(n))\n\n\ndef __starting_point():\n main()\n__starting_point()", "N = int(input())\n\nans = 1\nwhile ans <= N:\n ans *= 2\n\nprint(ans//2)", "n = int(input())\nans = 0\nfor i in range(n):\n if 2**i <=n:\n ans = 2**i\n else:\n break\nprint(ans)", "N = int(input())\nans = []\nfor i in range(N):\n q = i+1\n count = 0\n if q == 1:\n continue\n while True:\n if q%2 != 0:\n break\n q = q//2\n count += 1\n ans.append(count)\n\nif len(ans) > 0:\n max_count = max(ans)\n print(ans.index(max_count)+2)\nelse:\n print(1)", "def solve(n):\n res = 0\n while(n != 1):\n if n%2 == 0:\n res += 1\n n /= 2\n else:\n break\n return res\n\nn = int(input())\n\nans = 1\nans_max = 0\nfor i in range(1, n+1):\n cnt = solve(i)\n if cnt > ans_max:\n ans_max = cnt\n ans = i\nprint(ans)", "N = int(input())\nL = [64, 32, 16, 8, 4, 2]\nfor i in L:\n if i <= N:\n print(i)\n break\nelse:\n print(N)", "#!/usr/local/bin/python3\n# https://atcoder.jp/contests/abc068/tasks/abc068_b\nimport math\n\ndef fact(N):\n ans = {}\n for i in range(2, math.ceil(math.sqrt(N))+1):\n if N % i != 0:\n continue\n ex = 0\n\n while N % i == 0:\n ex += 1\n N /= i\n ans[i] = ex\n\n if N != 1:\n ans[int(N)] = 1\n return ans\n\nN = int(input())\nmax_x = 0\nmax_n = 0\n\nif N == 1:\n print((1))\n return\n\nfor i in range(N+1):\n num = fact(i)\n num = num.get(2, 0)\n if num > max_n:\n max_x = i\n max_n = num\n\nprint(max_x)\n", "# B - Break Number\ndef main():\n n = int(input())\n\n if 64 <= n <= 100:\n print(64)\n elif 32 <= n <= 63:\n print(32)\n elif 16 <= n <= 31:\n print(16)\n elif 8 <= n <= 15:\n print(8)\n elif 4 <= n <=7:\n print(4)\n elif 2 <= n <= 3:\n print(2)\n else:\n print(1)\n\nif __name__ == \"__main__\":\n main()", "N = int(input())\nresult = 0\nfor i in range(7):\n if N >= 2**i:\n result = 2**i\n else:\n None\nprint(result)\n", "N=int(input())\nans=1\nwhile 2*ans<=N:\n ans*=2\nprint(ans)\n", "N = int(input())\nans = 1\nwhile ans <= N:\n ans *= 2\n\nprint(ans//2)", "n = int(input())\na = n\nm = 0\nfor i in range(n+1):\n j = 1\n for h in range(i+1):\n if i%(2**j) != 0:\n if m < j-1:\n m = j-1\n a = i\n break\n j += 1\nprint(a)", "N = int(input())\n\ncount_max = -1\nOK = True\n\nfor i in range(N):\n count = 0\n a = N - i\n while a % 2 == 0:\n a = a // 2\n count += 1\n if count_max < count:\n count_max = count\n else:\n continue\nif 2 ** count_max == 0.5:\n print(1)\nelse:\n print(2 ** count_max)", "n = int(input())\n \nk = 0\nwhile 1:\n if 2 ** k > n:\n break\n \n ans = 2 ** k\n k += 1\n \nprint(ans)", "import sys\nsys.setrecursionlimit(250000)\n\ndef main():\n n = int(input())\n\n if n >= 64 :\n print((64))\n elif n >= 32:\n print((32))\n elif n >= 16:\n print((16))\n elif n >=8 :\n print((8))\n elif n >=4 :\n print((4))\n elif n>=2:\n print((2))\n else:\n print(n)\nmain()\n\n\n\n#\n# while True:\n# pair_str = input().split()\n# pair_int = [int(s) for s in pair_str]\n# if pair_int[0] == 0 and pair_int[1] == 0 :\n# break\n# else:\n# input_list.append(pair_int)\n\n\n# if b > c * 2 :\n # b_price = c\n #\n # input_array_list = []\n #\n # while True:\n # input_array = input().split()\n # if input_array[0] == \"0\" and input_array[1] == \"0\":\n # break\n # else:\n # input_array_list.append(input_array)\n #\n # for item in input_array_list:\n # n = int(item[0])\n # k_sum = int(item[1])\n #\n # count = 0\n # for i in range(1,n + 1- 2):\n # for j in range(i+1, n + 1 - 1):\n # for k in range (j+1, n+ 1):\n # if i + j + k == k_sum :\n # count = count + 1\n # print(count)\n\n #\n # for item in input_array_list:\n # if item[1] == \"+\":\n # print(str(int(item[0])+int(item[2])))\n # elif item[1] ==\"-\":\n # print(str(int(item[0])-int(item[2])))\n # elif item[1] == \"/\":\n # print(str(int(item[0])//int(item[2])))\n # elif item[1] == \"*\":\n # print(str(int(item[0])*int(item[2])))\n #\n\n# import sympy as sp\n\n# input_list = []\n# a,b,c = map(int, input().split())\n# divisors = sp.divisors(c)\n#\n# count = 0\n#\n# for divisor in divisors:\n# if a <= divisor and divisor <= b:\n# count = count + 1\n# print(count)\n#\n# while True:\n# pair_str = input().split()\n# pair_int = [int(s) for s in pair_str]\n# if pair_int[0] == 0 and pair_int[1] == 0 :\n# break\n# else:\n# input_list.append(pair_int)\n#\n# for pair_int in input_list:\n# if pair_int[0] <= pair_int[1]:\n# print(\"{} {}\".format(pair_int[0], pair_int[1]))\n# else:\n# print(\"{} {}\".format(pair_int[1], pair_int[0]))\n\n#for i in range(10000):\n# print(\"Hello World\")\n#a = input().split()\n#a_int = [int(s) for s in a]\n#a_sorted = sorted(a_int)\n#print(' '.join(map(str, a_sorted)))\n", "N = int(input())\ni = 0\nwhile True:\n if 2**i > N:\n print(2**(i-1))\n return\n i += 1", "import math as mt\nn=int(input())\nprint(2**int(mt.log2(n)))", "from itertools import count\nn = int(input())\nfor i in count(0):\n if n < 2**(i+1):\n print(2**i)\n break", "import math\nn = int(input())\nans = pow(2,int(math.log(n)/math.log(2)))\nprint(ans)", "N = int(input())\n\ncnt = 0\n\nwhile 2 ** cnt <= N:\n cnt+=1\n\ncnt-=1\n\nprint(2**cnt)", "n = int(input())\n\n\nclass Solution:\n def __init__(self, n):\n self.n = n\n\n @staticmethod\n def answer():\n ans = 1\n current_zero_count = 0\n for i in range(1, n + 1):\n target_zero_count = list(map(int, bin(i)[2:])).count(0)\n if n == 1:\n break\n else:\n if target_zero_count > current_zero_count:\n current_zero_count = target_zero_count\n ans = i\n print(ans)\n\n\nconditions = Solution(n)\nconditions.answer()", "n = int(input())\nans = 1\ncurrent_zero_count = 0\nfor i in range(1, n + 1):\n target_zero_count = list(map(int, bin(i)[2:])).count(0)\n if n == 1:\n break\n else:\n if target_zero_count > current_zero_count:\n current_zero_count = target_zero_count\n ans = i\nprint(ans)", "n = int(input())\n\nif n < 2:\n print(1)\nelif n < 4:\n print(2)\nelif n < 8:\n print(4)\nelif n < 16:\n print(8)\nelif n < 32:\n print(16)\nelif n < 64:\n print(32)\nelse:\n print(64)", "n = int(input())\nans = 1\nwhile ans <= n:\n ans *= 2\nprint((ans // 2))\n", "N = int(input())\n\nif 64 <= N:\n print(64)\nelif 32 <= N:\n print(32)\nelif 16 <= N:\n print(16)\nelif 8 <= N:\n print(8)\nelif 4 <= N:\n print(4)\nelif 2 <= N:\n print(2)\nelse:\n print(1)", "n = int(input())\nfor i in range(8):\n if 2**(i) > n:\n print(2**(i-1))\n break", "N = int(input())\nresult = 0\nnum = 1\nfor i in range(7):\n if N >= num:\n result = num\n else:\n None\n num *= 2\nprint(result)", "n = int(input())\nmax_count = 0\nans = 1\nfor i in range(1, n + 1):\n num = i\n count = 0\n while num % 2 == 0:\n num //= 2\n count += 1\n if count > max_count:\n ans = i\n max_count = count\nprint(ans)", "N = int(input())\nprint((max(2 ** i if 2 ** i <= N else 0 for i in range(10))))\n", "\ndef dev2(a):\n ans = 0 \n while a%2==0:\n ans+=1\n a/=2\n if a == 0 : break\n return ans\n\nn = int(input())\nans = 0 \nans_num = 0\nfor i in range(1,n+1):\n if ans < dev2(i):\n ans_num = i\n ans = dev2(i) \nprint((1 if n==1 else ans_num))\n", "N = int(input())\n\nans = 1\nprev = 0\nfor i in range(1, N + 1):\n count = 0\n tmp = i\n while i % 2 == 0 and 1 < i:\n count += 1\n i /= 2\n if prev < count:\n prev = count\n ans = tmp\n\nprint(ans)\n", "print(2 ** (len(bin(int(input()))) - 3))", "N=int(input())\ndef rec(n):\n if n%2==0: return rec(n/2)+1\n else: return 0\nm,c=0,1\nfor i in range(1,N+1):\n if m < rec(i):\n m=rec(i)\n c=i\nprint(c)", "def LI(): return list(map(int, input().split()))\ndef I(): return map(int, input().split())\nmod = 10**9 + 7\n\ndef main():\n n = int(input())\n cnt = 1\n while n >= cnt:\n ans = cnt\n cnt *= 2\n print(ans)\ndef __starting_point():\n main()\n__starting_point()"] | {"inputs": ["7\n", "32\n", "1\n", "100\n"], "outputs": ["4\n", "32\n", "1\n", "64\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 21,211 | |
6f644bd2f2f6fce4b155fc719440b2ab | UNKNOWN | Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.
Two people can directly communicate when the distance between them is at most d meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
-----Constraints-----
- 1 β€ a,b,c β€ 100
- 1 β€ d β€ 100
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
a b c d
-----Output-----
If A and C can communicate, print Yes; if they cannot, print No.
-----Sample Input-----
4 7 9 3
-----Sample Output-----
Yes
A and B can directly communicate, and also B and C can directly communicate, so we should print Yes. | ["import sys\n\n\ndef input(): return sys.stdin.readline().strip()\ndef I(): return int(input())\ndef LI(): return list(map(int, input().split()))\ndef IR(n): return [I() for i in range(n)]\ndef LIR(n): return [LI() for i in range(n)]\ndef SR(n): return [S() for i in range(n)]\ndef S(): return input()\ndef LS(): return input().split()\n\n\nINF = float('inf')\n\n\na, b, c, d = LI()\nprint(('Yes' if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d) else 'No'))\n", "a, b, c, d = list(map(int, input().split()))\na_b = max(a, b) - min(a, b) <= d\nb_c = max(b, c) - min(b, c) <= d\nc_a = max(c, a) - min(c, a) <= d\n\nif (a_b and b_c) or c_a:\n print('Yes')\nelse:\n print('No')\n", "a, b, c, d = map(int, input().split())\nprint('Yes' if any([all([abs(a-b) <= d, abs(b-c)<= d]), abs(a-c) <= d]) else 'No')", "a, b, c, d = list(map(int, input().split()))\n\nif (abs(a - b) <= d and abs(b - c) <= d) or abs(a - c) <= d:\n print('Yes')\nelse:\n print('No')\n", "a, b, c, d = map(int, input().split())\n\nif -d <= a - c <= d:\n print(\"Yes\")\nelif -d <= a - b <= d and -d <= b - c <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "\n\n\n\na,b,c,d = list(map(int, input().split()))\n\n\nif abs(c-a) <= d:\n print('Yes')\nelif abs(b-a)<=d and abs(c-b)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")\n\n\n\n\n\n\n\n", "a,b,c,d=map(int,input().split())\nif abs(c-a)<=d:\n print(\"Yes\")\nelif abs(c-b)<=d and abs(b-a)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int,input().split())\nif abs(a-c)<=d:\n print(\"Yes\")\nelif abs(a-b)<=d and abs(b-c)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int,input().split())\n\nif abs(a-c) <= d:\n print('Yes')\n\nelif abs(a-b) <= d and abs(b-c) <= d:\n print('Yes')\n\nelse:\n print('No')", "a,b,c,d = map(int, input().split())\nprint('Yes' if abs(a-b) <= d and abs(b-c) <= d or abs(a-c) <= d else 'No')", "a,b,c,d=list(map(int,input().split()))\nif abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "# A - Colorful Transceivers\n\na, b, c, d = map(int, input().split())\n\nif abs(c - a) <= d:\n print('Yes')\nelif abs(c - a) > d and abs(c - b) <= d and abs(b - a) <= d:\n print('Yes')\nelif abs(c - a) > d and abs(c - b) > d:\n print('No')\nelif abs(c - a) > d and abs(c - b) <= d and abs(b - a) > d:\n print('No')", "a, b, c, d = map(int, input().split())\n\n#a<b<c\nba =abs(b-a)\ncb =abs(c-b)\nca =abs(c-a)\n\nif ca <= d:\n print(\"Yes\")\nelif ba <= d and cb<= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n a, b, c, d = Input()\n\n if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):\n print(\"Yes\")\n else:\n print(\"No\")\n\n\nmain()", "a,b,c,d=map(int, input().split())\n\nans=\"No\"\n\nif abs(c-a)<=d:\n ans=\"Yes\"\n \nelif abs(c-b)<=d and abs(b-a)<=d:\n ans=\"Yes\"\n \nprint(ans)", "def resolve():\n a, b, c, d = map(int, input().split())\n ans = \"\"\n if abs(c-a) <= d: ans = \"Yes\"\n elif abs(c-b) <= d and abs(b-a) <= d: ans = \"Yes\"\n else: ans = \"No\"\n print(ans)\nresolve()", "a,b,c,d=map(int,input().split())\n\nif abs(a-c)<=d:\n print(\"Yes\")\nelif abs(a-b)<=d and abs(b-c)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\nif abs(a-c) > d:\n if abs(a-b) <= d and abs(b-c) <= d:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n print(\"Yes\")", "a, b, c, d = list(map(int, input().split()))\n\nif abs(a - c) <= d:\n print(\"Yes\")\nelif abs(a - b) <= d and abs(b - c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a, b, c, d = list(map(int, input().split()))\n\nprint('Yes' if (abs(a - b) <= d and abs(b - c) <= d) or abs(a - c) <= d else 'No')", "a,b,c,d=map(int,input().split())\nif abs(a-c)<=d:\n print(\"Yes\")\nelif abs(a-b)<=d and abs(b-c)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "#ABC097A\na,b,c,d = map(int,input().split())\nprint(\"Yes\" if (abs(a-b)<=d and abs(c-b)<=d) or (abs(a-c)<=d) else \"No\")", "A, B, C, D = map(int, input().split())\n\nif abs(A - C) <= D:\n print(\"Yes\")\nelif abs(A - B) <= D and abs(B - C) <= D:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int , input().split())\n\n# a\u3068c\u306e\u7d76\u5bfe\u5024\u304c\uff44\u4ee5\u4e0b\nif abs(c - a) <= d:\n print(\"Yes\")\n\nelif abs(b-a) <= d and abs(c - b)<= d:\n print(\"Yes\")\n\nelse:\n print(\"No\")", "a,b,c,d=map(int,input().split())\nif abs(a-c)<=d:\n print(\"Yes\")\nelif abs(a-b)<=d and abs(b-c)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\n\nAB = abs(b - a)\nBC = abs(c - b)\nAC = abs(c - a)\n\nif (AB <= d and BC <= d) or AC <= d:\n print('Yes')\nelse:\n print('No')", "a = list(map(int,input().split()))\nif (abs(a[1] - a[0]) <= a[3] and (abs(a[2] - a[1]) <= a[3])) or (abs(a[2] - a[0]) <= a[3]):\n print(\"Yes\")\nelse:\n print(\"No\")\n\n", "a, b, c, d = list(map(int, input().split()))\n\nif abs(c - a) <= d:\n print('Yes')\nelif abs(b - a) <= d and abs(c - b) <= d:\n print('Yes')\nelse:\n print('No')\n", "a, b, c, d = map(int,input().split())\n \nif abs(a -c) <= d:\n print(\"Yes\")\nelif abs(a - b) <= d and abs(b - c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int,input().split())\n \nif abs(a - c) <= d or abs(b - a) <= d and abs(c - b) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\nif abs(a-c) <= d:\n print('Yes')\nelif abs(a-b) <= d and abs(b-c) <= d:\n print('Yes')\nelse:\n print('No')", "a , b , c, d= map ( int, input ().split())\nif abs(a-c) <= d or abs(a-b) <= d and abs(b-c) <= d:\n print(\"Yes\")\n\nelse:\n print(\"No\")", "a, b, c, d = list(map(int, input().split()))\n\nif abs(a - c) <= d:\n print('Yes')\nelif abs(a - b) <= d and abs(b - c) <= d:\n print('Yes')\nelse:\n print('No')\n", "a,b,c,d = map(int,input().split())\n\n1 <= a,b,c,d <= 100\n\nif abs(a-b) <= d and abs(b-c) <= d or abs(a-c) <= d:\n result = (\"Yes\")\nelse:\n result = (\"No\")\n\nprint(result)", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d or abs(b - a) <= d and abs(c - b) <= d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\nct = False\nif abs(a - c) <= d: ct = True\nif abs(a - b) <= d and abs(c - b) <= d: ct = True\nif ct: print(\"Yes\")\nelse: print(\"No\")", "a,b,c,d = list(map(int, input().split()))\nif abs(c-a) <= d:\n print('Yes')\nelif abs(b-a) <= d and abs(c-b) <= d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\nif abs(a - c) <= d:\n print(\"Yes\")\nelif abs(a-b) <= d and abs(b-c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\nf = lambda x, y: abs(x - y) <= d\nprint('Yes' if (f(a, b) and f(b, c)) or f(a, c) else 'No')", "a, b, c, d = map(int, input().split())\n\nif abs(c-a) <= d:\n print('Yes')\nelif abs(b-a)<=d and abs(c-b)<=d:\n print('Yes')\nelse: print('No')", "a,b,c,d=map(int,input().split())\ns='Yes'\nif abs(a-c)>d:\n if abs(a-b)>d or abs(b-c)>d:\n s='No'\nprint(s)", "a, b, c, d = map(int, input().split())\nif abs(c - a) <= d or (abs(b - a) <= d and abs(c - b) <= d):\n print('Yes')\nelse:\n print('No')", "# A\u3055\u3093\u306f a[m] \u5730\u70b9\u3001B\u3055\u3093\u306f b[m] \u5730\u70b9\u3001C\u3055\u3093\u306f c [m] \u5730\u70b9\u306b\u3044\u307e\u3059\u3002\n# \u4e8c\u4eba\u306e\u4eba\u9593\u306f\u3001\u8ddd\u96e2\u304c d [m] \u4ee5\u5185\u306e\u3068\u304d\u76f4\u63a5\u4f1a\u8a71\u304c\u51fa\u6765\u307e\u3059\u3002\n# A\u3055\u3093\u3068C\u3055\u3093\u304c\u76f4\u63a5\u7684\u3001\u3042\u308b\u3044\u306f\u9593\u63a5\u7684\u306b\u4f1a\u8a71\u304c\u3067\u304d\u308b\u304b\u5224\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n# \u305f\u3060\u3057A\u3055\u3093\u3068C\u3055\u3093\u304c\u9593\u63a5\u7684\u306b\u4f1a\u8a71\u304c\u3067\u304d\u308b\u3068\u306f\u3001A\u3055\u3093\u3068B\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u3001\u304b\u3064B\u3055\u3093\u3068C\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u308b\u3053\u3068\u3092\u6307\u3057\u307e\u3059\u3002\n\n# a,b,c,d(\u8ddd\u96e2\uff09 \uff1a\u6a19\u6e96\u5165\u529b\na, b, c, d = map(int, input().split())\n\n\n# \u76f4\u63a5\u7684\u306b\u4f1a\u8a71\u53ef\u2193\n# A\u3055\u3093\u3068C\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u53ef\u2192 a-c(\u7d76\u5bfe\u5024\uff09 <= d\n# \u9593\u63a5\u7684\u306b\u53ef\u2193\n# A\u3055\u3093\u3068B\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u53ef\u2192 a-b(\u7d76\u5bfe\u5024\uff09 <= d\n# B\u3055\u3093\u3068C\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u53ef\u2192 b-c(\u7d76\u5bfe\u5024\uff09 <= d\n# \u8ddd\u96e2\u306f\u7d76\u5bfe\u5024\u3092\u53d6\u308b abs()\nif abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):\n print('Yes')\nelse:\n print('No')", "a,b,c,d = map(int, input().split())\n\nif (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\nif abs(a-c) <= d:\n print(\"Yes\")\nelif abs(a-b) <= d and abs(b-c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int,input().split())\nprint(\"Yes\" if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d) else \"No\")", "a, b, c, d = map(int, input().split())\nif abs(b - a) <= d and abs(c - b) <= d:\n print(\"Yes\")\nelif abs(c - a) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "# A\u3055\u3093\u306f a[m] \u5730\u70b9\u3001B\u3055\u3093\u306f b[m] \u5730\u70b9\u3001C\u3055\u3093\u306f c[m] \u5730\u70b9\n# \u4e8c\u4eba\u306e\u4eba\u9593\u306f\u3001\u8ddd\u96e2\u304c d[m] \u4ee5\u5185\u306e\u3068\u304d\u76f4\u63a5\u4f1a\u8a71\u53ef\u80fd\n# A\u30fbC\u304c\u76f4\u63a5\u7684\u306b\u4f1a\u8a71\u304c\u3067\u304d\u308b or A\u30fbB\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u3001\u304b\u3064B\u30fbC\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u308b\n# \u4f1a\u8a71\u3067\u304d\u308b\u306a\u3089 Yes \u3092, \u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u305b\u3088\u3002\n \na,b,c,d = map(int , input().split())\n# print(a)\n# print(b)\n# print(c)\n# print(d)\n \n# a\u3068c\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\nif abs(c-a) <= d:\n print('Yes')\n# a\u3068b\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\u304b\u3064b\u3068c\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\nelif abs(b-a) <= d and abs(c-b) <= d:\n print('Yes')\nelse:\n print('No') ", "a, b, c, d = map(int, input().split())\n\nif abs(c - a) <= d:\n print('Yes')\nelif abs(b - a) <= d and abs(c - b) <= d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d or abs(b - a) <= d and abs(c - b) <= d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = (int (i) for i in input().split())\n\nif abs(a - c) <= d:\n print(\"Yes\")\nelif (abs(a - b) <= d) and (abs(b - c) <= d):\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\n\nif d >= abs(a - c) or (d >= abs(a - b) and d >= abs(b - c)):\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d:\n print('Yes')\nelif (a < b and b < c) or (a > b and b > c):\n if abs(a - b) <= d and abs(b - c) <= d:\n print('Yes')\n else:\n print('No')\nelse:\n print('No')", "# A\u3055\u3093\u306f a[m] \u5730\u70b9\u3001B\u3055\u3093\u306f b[m] \u5730\u70b9\u3001C\u3055\u3093\u306f c[m] \u5730\u70b9\n# \u4e8c\u4eba\u306e\u4eba\u9593\u306f\u3001\u8ddd\u96e2\u304c d[m] \u4ee5\u5185\u306e\u3068\u304d\u76f4\u63a5\u4f1a\u8a71\u53ef\u80fd\n# A\u30fbC\u304c\u76f4\u63a5\u7684\u306b\u4f1a\u8a71\u304c\u3067\u304d\u308b or A\u30fbB\u3055\u3093\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u3001\u304b\u3064B\u30fbC\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u308b\n# \u4f1a\u8a71\u3067\u304d\u308b\u306a\u3089 Yes \u3092, \u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u305b\u3088\u3002\n\na,b,c,d = map(int , input().split())\n# print(a)\n# print(b)\n# print(c)\n# print(d)\n\n# a\u3068c\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\nif abs(c-a) <= d:\n print('Yes')\n# a\u3068b\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\u304b\u3064b\u3068c\u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304cd\u4ee5\u4e0b\nelif abs(b-a) <= d and abs(c-b) <= d:\n print('Yes')\nelse:\n print('No') ", "a,b,c,d = map(int,input().split())\n\nif (abs(b-a) <= d and abs(c-b) <= d) or (abs(a-c) <= d):\n print('Yes')\nelse:\n print('No')", "a, b, c, d= map(int,input().rstrip().split())\nif abs(a-c)<=d:\n print('Yes')\nelif abs(a-b)<=d and abs(b-c)<=d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(c-a) <= d:\n print(\"Yes\")\nelif abs(b-a) <= d and abs(c-b) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\nfrom collections import deque\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nDR = [1, -1, 0, 0]\nDC = [0, 0, 1, -1]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n \ndef main():\n a, b, c, d = LI()\n can = False\n if abs(c-a) <= d:\n can = True\n if abs(a-b) <= d and abs(b-c) <= d:\n can = True\n if can:\n print(\"Yes\")\n else:\n print(\"No\")\n\nmain()\n\n", "a, b, c, d = map(int, input().split())\n\nx = abs(a - b)\ny = abs(b - c)\nz = abs(a - c)\n\nif x <= d and y <= d:\n print(\"Yes\")\nelif z <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = list(map(int, input().split()))\n\nif abs(a - b) <= d and abs(b - c) <= d:\n print('Yes')\nelif abs(a - c) <= d:\n print('Yes')\nelse:\n print('No')\n", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d:\n print('Yes')\nelif abs(a - b) <= d and abs(b - c) <= d:\n print('Yes')\nelse:\n print('No')", "a,b,c,d = list(map(int , input().split()))\nif abs(c -a) <= d :\n print('Yes')\nelif abs(b -a) <= d and abs(c -b) <= d:\n print('Yes')\nelse:\n print('No')\n", "a, b, c, d = map(int, input().split())\nif abs(c - a) <= d or (abs(b - a) <= d and abs(c - b) <= d):\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int,input().split())\n\nif abs(a -c) <= d:\n print(\"Yes\")\nelif abs(a - b) <= d and abs(b - c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d=list(map(int,input().split()))\nif (abs(b-a)<=d and abs(c-b)<=d) or abs(a-c)<=d:print(\"Yes\")\nelse:print(\"No\")\n", "a,b,c,d=map(int,input().split())\nif abs(c-a)<=d or (abs(b-a)<=d and abs(c-b)<=d):\n print(\"Yes\")\nelse:\n print(\"No\")", "# A\u3055\u3093:a B\u3055\u3093:b C\u3055\u3093:c\n# \u8ddd\u96e2\u304cd\u4ee5\u5185\u306e\u3068\u304d\u4f1a\u8a71\u53ef\u80fd\n\na, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d:\n ans = 'Yes'\nelif (abs(a - b) <= d) and (abs(b - c) <= d):\n ans = 'Yes'\nelse:\n ans = 'No'\n\nprint(ans)", "lst = input().split()\na = int(lst[0])\nb = int(lst[1])\nc = int(lst[2])\nd = int(lst[3])\n\nif ((abs(b - a) <= d) and (abs(c - b) <= d)) or (abs(c - a) <= d):\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d or abs(b - a) <= d and abs(c - b) <= d:\n print('Yes')\nelse:\n print('No') ", "a,b,c,d=map(int,input().split())\n\nif abs(a-c)<=d:\n ans=\"Yes\"\nelif abs(a-b)<=d and abs(b-c)<=d:\n ans=\"Yes\"\nelse:\n ans=\"No\"\nprint(ans)", "a, b, c, d = map(int,input().split())\n\n# a\u3068c\u306e\u8ddd\u96e2AC\u3092\u5b9a\u7fa9\nif (a - c) >= 0:\n AC = (a-c)\nelse:\n AC = (c-a)\n\n# B\u304cA\u3068C\u306e\u9593\u306b\u5165\u308b\u5834\u5408\u306e\u307f\u3001AB\u9593\u3001BC\u9593\u3092\u5b9a\u7fa9\nif a < b < c:\n AB = (b - a)\n BC = (c - b)\nif c < b < a:\n AB = (a-b)\n BC = (b-c)\n\n# A\u3068C\u306e\u8ddd\u96e2\u304cd\u4ee5\u4e0b\u306a\u3089Yes\uff01\nif AC <= d:\n print('Yes')\n# AB\u9593\u3001BC\u9593\u3068\u3082\u306bd\u4ee5\u4e0b\u306a\u3089Yes\uff01\nelif AB <= d and BC <= d:\n print('Yes')\nelse:\n print('No')", "a,b,c,d=list(map(int,input().split()))\nif abs(a-c)<=d:\n print('Yes')\n return\nif abs(c-b)<=d and abs(b-a)<=d:\n print('Yes')\n return\nprint('No')", "a,b,c,d = map(int,input().split())\nif abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):\n print('Yes')\nelse:\n print('No')", "a,b,c,d = map(int,input().split())\nif abs(a-c) <= d:\n print(\"Yes\")\nelif abs(a-b) <= d and abs(b-c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = map(int,input().split())\n\nif abs(a-b) <= d and abs(b-c) <= d:\n print('Yes')\nelif abs(a-c) <= d:\n print('Yes')\nelse:\n print('No')", "a,b,c,d = list(map(int,input().split()))\nif abs(b - a) <= d and abs(c - b) <= d:\n print(\"Yes\")\nelif abs(c - a) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a, b, c, d = list(map(int, input().split()))\n\nab = abs(a - b)\nbc = abs(b - c)\nca = abs(c - a)\n\nif ca <= d:\n print(\"Yes\")\nelif ab <= d and bc <= d:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a, b, c, d = list(map(int,input().split()))\n\n# a\u3068c\u306e\u8ddd\u96e2\u306e\u7d76\u5bfe\u5024AC\u3092\u5b9a\u7fa9\nif (a - c) >= 0:\n AC = (a-c)\nelse:\n AC = (c-a)\n\n# B\u304cA\u3068C\u306e\u9593\u306b\u5165\u308b\u5834\u5408\u306e\u307f\u3001AB\u9593\u3001BC\u9593\u3092\u5b9a\u7fa9\nif a < b < c:\n AB = (b - a)\n BC = (c - b)\nif c < b < a:\n AB = (a-b)\n BC = (b-c)\n\n# A\u3068C\u306e\u8ddd\u96e2\u304cd\u4ee5\u4e0b\u306a\u3089Yes\uff01\nif AC <= d:\n print('Yes')\n# AB\u9593\u3001BC\u9593\u3068\u3082\u306bd\u4ee5\u4e0b\u306a\u3089Yes\uff01\nelif AB <= d and BC <= d:\n print('Yes')\nelse:\n print('No')\n", "a,b,c,d=map(int,input().split())\nif abs(c-a) <= d:\n print('Yes')\nelse:\n if abs(a-b) <= d and abs(b-c) <= d:\n print('Yes')\n else:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):\n answer = 'Yes'\nelse:\n answer = 'No'\n\nprint(answer)", "a, b, c,d = (int(x) for x in input().split())\n\nkyori1 = a - c\nkyori2 = a - b\nkyori3 = b - c\n\nif abs(kyori1) <= d or (abs(kyori2) <= d and abs(kyori3) <= d) :\n print('Yes')\nelse :\n print('No')", "a, b, c, d = map(int, input().split())\nif (abs(a - b) <= d and abs(b - c) <= d) or abs(a - c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d=map(int,input().split())\n\nif abs(a-c)<=d:\n print(\"Yes\")\nelif abs(a-b)<=d and abs(b-c)<=d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d = [int(x) for x in input().split()]\nres = \"No\"\nif abs(c - a) <= d:\n res = \"Yes\"\nif abs(a - b) <= d and abs(b - c) <= d:\n res = \"Yes\"\nprint(res)", "a,b,c,d=map(int,input().split())\n\nx=abs(b-a)\ny=abs(c-b)\nz=abs(c-a)\n\n\nif x<=d and y<=d:\n print('Yes')\n\nelif z<=d:\n print('Yes')\n\nelse:\n print('No')", "a,b,c,d = map(int, input().split())\n\nprint(\"Yes\" if abs(a-c) <= d or abs(a-b) <= d and abs(b-c) <=d else \"No\")", "a,b,c,d = map(int,input().split())\n\n1 <= a,b,c,d <= 100\n\nif abs(a-b) <= d and abs(b-c) <= d or abs(a-c) <= d:\n result = (\"Yes\")\nelse:\n result = (\"No\")\n\nprint(result)", "a,b,c,d=map(int,input().split(\" \"))\nprint([\"No\",\"Yes\"][(abs(a-b)<=d and abs(c-b)<=d) or abs(a-c)<=d])", "a, b, c, d = list(map(int, input().split()))\n\nif abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):\n print('Yes')\nelse:\n print('No')\n", "# A\u3055\u3093\u306f a[m]\u5730\u70b9\u3001B\u3055\u3093\u306f b[m]\u5730\u70b9\u3001C\u3055\u3093\u306f c[m]\u5730\u70b9\n# 2\u4eba\u306e\u4eba\u9593\u306f\u3001\u8ddd\u96e2\u304c d[m] \u4ee5\u5185\u306e\u6642\u76f4\u63a5\u4f1a\u8a71\u53ef\u80fd\n# A\u30fbC\u304c\u76f4\u63a5\u7684\u306b\u4f1a\u8a71\u3067\u304d\u308b or A\u30fbB\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u3001\u304b\u3064 B\u30fbC\u304c\u76f4\u63a5\u4f1a\u8a71\u3067\u304d\u308b\n# \u4f1a\u8a71\u3067\u304d\u308b\u306a\u3089 Yes ,\u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\n\na,b,c,d = map(int , input().split())\n# print(a)\n# print(b)\n# print(c)\n# print(d)\n\n\n# a \u3068 c \u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304c d \u4ee5\u4e0b\nif abs(c-a) <= d:\n print('Yes')\n# a \u3068 b \u306e\u5dee\u306e\u7d76\u5bfe\u5024\u304c d \u4ee5\u4e0b\u304b\u3064 b \u3068 c \u91ce\u3055\u306e\u7d76\u5bfe\u5024\u304c d \u4ee5\u4e0b\nelif abs(b-a) <= d and abs(c-b) <= d:\n print('Yes')\nelse:\n print('No')", "from sys import stdin\nnii=lambda:map(int,stdin.readline().split())\nlnii=lambda:list(map(int,stdin.readline().split()))\n\na,b,c,d=nii()\nif (abs(a-b)<=d and abs(c-b)<=d) or abs(c-a)<=d:\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int, input().split())\n\nif abs(a-b)<=d and abs(b-c)<=d:\n print('Yes')\n\nelif abs(a-c)<=d :\n print('Yes')\n\nelse:\n print('No')", "a,b,c,d=map(int,input().split())\n\nif abs(b-a)<=d and abs(c-b)<=d:\n print('Yes')\nelif abs(c-a)<=d:\n print('Yes')\nelse:\n print('No')", "a,b,c,d=map(int,input().split())\nif abs(a-c)<=d:\n print(\"Yes\")\nelif a<=b<=c or c<=b<=a:\n if abs(a-b)<=d and abs(c-b)<=d:\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n print(\"No\")", "a,b,c,n=map(int,input().split())\nif abs(c-a)<=n:\n print(\"Yes\")\nelif abs(c-b)<=n and abs(b-a)<=n:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c,d=map(int, input().split())\nif abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d):\n print('Yes')\nelse:\n print('No')", "a, b, c, d = map(int,input().split())\n \nif abs(a -c) <= d:\n print(\"Yes\")\nelif abs(a - b) <= d and abs(b - c) <= d:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c, d = map(int, input().split())\n#print(a, b, c, d)\n\ndistance_ab = abs(a - b)\ndistance_bc = abs(b - c)\ndistance_ac = abs(a - c)\n\n # a\u3068c\u304c\u9593\u63a5\u7684\u306b\u8a71\u305b\u308b\u3002\nif distance_ab <= d and distance_bc <= d:\n print('Yes')\n # a\u3068c\u304c\u76f4\u63a5\u8a71\u305b\u308b\u3002\nelif distance_ac <= d:\n print('Yes')\nelse:\n print('No')", "a,b,c,d=map(int, input().split())\nprint(\"Yes\" if abs(c-a)<=d or (abs(a-b)<=d and abs(b-c)<=d) else \"No\")"] | {"inputs": ["4 7 9 3\n", "100 10 1 2\n", "10 10 10 1\n", "1 100 2 10\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 22,835 | |
e7a08298cb9fb2307a8fb318ee8b8521 | UNKNOWN | You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.
Print the acronym formed from the uppercased initial letters of the words.
-----Constraints-----
- s_1, s_2 and s_3 are composed of lowercase English letters.
- 1 β€ |s_i| β€ 10 (1β€iβ€3)
-----Input-----
Input is given from Standard Input in the following format:
s_1 s_2 s_3
-----Output-----
Print the answer.
-----Sample Input-----
atcoder beginner contest
-----Sample Output-----
ABC
The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC. | ["def answer(s: str) -> str:\n return ''.join(s[0].upper() for s in s.split())\n\n\ndef main():\n s = input()\n print(answer(s))\n\n\ndef __starting_point():\n main()\n__starting_point()", "s1,s2,s3=map(str,input().split())\nprint((s1[0]+s2[0]+s3[0]).upper())", "def abc059a(s1: str, s2: str, s3: str) ->str:\n return s1[0].upper() + s2[0].upper() + s3[0].upper()\n\ns1, s2, s3 = list(map(str, input().split()))\nprint((abc059a(s1, s2, s3)))\n", "A,B,C = input().split()\n\ninitial = A[0] + B[0] + C[0]\ninitial = initial.upper()\nprint(initial)", "def atc_059a(input_value: str) -> str:\n S = input_value.split(\" \")\n SSS = S[0][0].upper() + S[1][0].upper() + S[2][0].upper()\n return SSS\n\ninput_value = input()\nprint((atc_059a(input_value)))\n", "a = input().split()\nprint(a[0][0].upper()+a[1][0].upper()+a[2][0].upper())", "a, b, c = map(str, input().split())\nd = a[0] + b[0] + c[0]\nprint(d.upper())", "a,b,c=input().split()\nprint((a[0]+b[0]+c[0]).upper())", "def atc_059a(input_value: str) -> str:\n S = input_value.split(\" \")\n SSS = S[0][0].upper() + S[1][0].upper() + S[2][0].upper()\n return SSS\n\ninput_value = input()\nprint((atc_059a(input_value)))\n", "S = input().split()\n\nmy_list = []\n\nfor i in range(len(S)):\n S[i] = S[i].title()\n my_list.append(S[i][0])\n\nprint(my_list[0]+my_list[1]+my_list[2])", "a, b, c = input().split()\nprint((a[0] + b[0] + c[0]).upper())", "# \u5358\u8a9e\uff13\u3064\u304c\u7a7a\u767d\u533a\u5207\u308a\u3067\u4e0e\u3048\u3089\u308c\u308b\n# \u53cd\u8a9e\u306e\u5148\u982d\u306e\u6587\u5b57\u3092\u3064\u306a\u3052\u308b\n# \u5927\u6587\u5b57\u306b\u3059\u308b\n\na,b,c = map(str, input().split())\n\nword = a[0]+b[0]+c[0]\n\nprint(word.upper())", "a,b,c=input().split(\" \")\nprint((a[0]+b[0]+c[0]).upper())", "a, b, c = input().split()\nprint((a[0]+b[0]+c[0]).upper())", "a,b,c = input().split()\n\ns = a[0]+b[0]+c[0]\nprint(s.upper())", "# 1.\u3000s1,s2,s3\u3092\u5165\u529b\u3059\u308b\ns1, s2, s3 = list(map(str,input().split()))\n\n# 2.\u3000s1,s2,s3\u306e\u5148\u982d\u6587\u5b57\u3092\u53d6\u308a\u51fa\u3057\u3066\u3001\u4e00\u3064\u306e\u30ea\u30b9\u30c8\u306b\u683c\u7d0d\u3059\u308b\ns_list = [s1[0], s2[0], s3[0]]\n\n# 3.\u30002\u3092\u7d50\u5408\u3057\u3001\u5927\u6587\u5b57\u306b\u3059\u308b\ns = \"\".join(s_list)\nss = s.upper()\n\n# 4.\u30003\u3092\u5927\u6587\u5b57\u306b\u3059\u308b\nprint(ss)\n", "s1, s2, s3 = input().split()\nans = str(chr(ord(s1[0]) - 32) + chr(ord(s2[0]) - 32) + chr(ord(s3[0]) - 32))\nprint(ans)\n", "a,b,c=input().split()\nprint((a[0]+b[0]+c[0]).upper())", "texts = list(map(str, input().split()))\n\nresult = \"\"\nfor text in texts:\n result = result + text[0].upper()\nprint(result)", "#https://atcoder.jp/contests/abc059/tasks/abc059_a\nS_list = list(input().split())\nS = [i[0] for i in S_list]\nprint(\"\".join(S).upper())", "a = input().split()\nres = \"\"\nfor i in range(len(a)):\n a[i] = a[i].upper()\n res += a[i][0]\nprint(res)", "s1,s2,s3 = input().split()\nprint((s1[0]+s2[0]+s3[0]).upper())", "s=input().split()\nprint((s[0][0]+s[1][0]+s[2][0]).upper())", "def answer(a: str, b: str, c: str) -> str:\n return (a[0]+b[0]+c[0])\n\na,b,c=input().split()\nprint(answer(a,b,c).upper())", "s1, s2, s3 = list(map(str, input().split()))\nprint(((s1[0] + s2[0] + s3[0]).upper()))\n", "a, b, c = map(str, input().split())\nprint((a[0] + b[0] + c[0]).upper())", "s = list(map(str,input().upper().split()))\nprint(s[0][0]+s[1][0]+s[2][0])", "s = input().split()\nprint(f\"{s[0][0]}{s[1][0]}{s[2][0]}\".upper())", "Tre_words = input().split()\ns1 = (Tre_words[0].title())\ns2 = (Tre_words[1].title())\ns3 = (Tre_words[2].title())\nA = list(s1)\nB = list(s2)\nC = list(s3)\n\nprint(A[0]+B[0]+C[0])", "a,b,c=map(str,input().split())\n\nprint(a[0].upper() + b[0].upper() + c[0].upper())", "s1, s2, s3 = list(map(str, input().split()))\n\ndef three_letter_acronym() -> str:\n return (s1[0] + s2[0] + s3[0])\nprint(three_letter_acronym().upper())", "s1, s2, s3 = map(str, input().split())\n\nS = s1[0] + s2[0] + s3[0]\n\nprint(S.upper())", "import sys\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef main():\n words = list(input().split())\n print((words[0][0]+words[1][0]+words[2][0]).upper())\n\ndef __starting_point():\n main()\n__starting_point()", "# 3\u3064\u30ea\u30b9\u30c8\u3092\u4f5c\u3063\u3066\u3001\u5404\u982d\u6587\u5b57\u3092\u304f\u3063\u3064\u3051\u305f\u7565\u8a9e\u3092\u30a2\u30c3\u30d1\u30fc\n\ns1, s2, s3 = list(map(list, input().split()))\n# print(s1)\n# print(s2)\n# print(s3)\n\nabbreviation = s1[0] + s2[0] + s3[0]\n# print(abbreviation)\n\nprint((abbreviation.upper()))\n", "def generate_acronym(l1: list) -> str:\n answer = \"\"\n for i, word in enumerate(l1):\n # answer.append(word[0].upper())\n answer += word[0].upper()\n\n return answer\n\n\nlists = list(map(str, input().split()))\nprint((generate_acronym(lists)))\n", "s1,s2,s3=input().split()\n\ns1=s1[0]\ns2=s2[0]\ns3=s3[0]\n\nprint(s1.upper()+s2.upper()+s3.upper())", "s = list(input().split())\n\ns1 = s[0]\ns2 = s[1]\ns3 = s[2]\n\nprint((s1[0]+s2[0]+s3[0]).upper())", "S = list(map(str, input().split()))\n\n# \u5358\u8a9e\u306e\u5148\u982d\u306e\u6587\u5b57\u3092\u3064\u306a\u3052\u3001\u5927\u6587\u5b57\u306b\u3057\u305f\u7565\u8a9e\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\n\ns1 = S[0][0].upper()\ns2 = S[1][0].upper()\ns3 = S[2][0].upper()\n\nprint(s1 + s2 + s3)", "# A - Three-letter acronym\n\n# s1 s2 s3\ns1, s2, s3 = list(map(str, input().split(maxsplit=3)))\n\nanswer = s1[0].upper() + s2[0].upper() + s3[0].upper()\n\nprint(answer)\n", "def iroha():\n a, b, c = input().split()\n\n shead = a[0].upper()\n sshead = b[0].upper()\n ssshead = c[0].upper()\n\n print((shead + sshead + ssshead))\n\ndef __starting_point():\n iroha()\n\n__starting_point()", "a,b,c=input().split()\nprint(((a[0]+b[0]+c[0]).upper()))\n", "s = [x for x in input().split()]\nprint(s[0][0].upper() + s[1][0].upper() + s[2][0].upper())", "S1,S2,S3 = map(str,input().split())\n\nstring = str.upper(S1[0] + S2[0] + S3[0])\nprint(string)", "a, b, c = input().split()\nans = a[0] + b[0] + c[0]\nA = ans.upper()\nprint(A)", "s1,s2,s3 = input().upper().split()\nprint('{}{}{}'.format(s1[0],s2[0],s3[0]))", "s1,s2,s3 = map(str,input().split())\nprint((s1[0]+s2[0]+s3[0]).upper())", "words = str(input()).upper()\nwords_list = words.split(' ')\n\nprint((words_list[0][0] + words_list[1][0] + words_list[2][0]))\n\n\n\n", "a,b,c=input().split()\nprint(a[0].upper()+b[0].upper()+c[0].upper())", "a,b,c=map(str,input().split())\na=a.upper()\nb=b.upper()\nc=c.upper()\nprint(a[0]+b[0]+c[0])", "a,b,c = list(map(str, input().split()))\n\na=a.upper()\nb=b.upper()\nc=c.upper()\n\nprint((a[0]+b[0]+c[0]))\n", "#n = int(input())\na, b, c = list(map(str, input().split()))\n#l = list(map(int,input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\n\na = a.upper()\nb = b.upper()\nc = c.upper()\nprint((a[0]+b[0]+c[0]))\n", "# \u6587\u5b57\u5217\u306e\u53d6\u5f97\nstrlist = list(map(str,input().split()))\nlnum = len(strlist)\n\n# \u5148\u982d\u6587\u5b57\u306e\u5927\u6587\u5b57\u51fa\u529b\nhead = \"\"\nfor cnt in range(0,lnum,1):\n head = head + (strlist[cnt][:1])\nprint(head.upper())", "s1, s2, s3 = input().split()\n\nprint((s1[0] + s2[0] + s3[0]).upper())", "S=list(input().split())\nfor i in range(3):\n S[i]=S[i].upper()\nprint((S[0][0]+S[1][0]+S[2][0]))\n", "a, b, c = map(str,input().split())\n\nS = a[0] + b[0] + c[0]\nprint(S.upper())", "a,b,c=map(str,input().split())\nprint(a[0].upper()+b[0].upper()+c[0].upper())", "a,b,c = input().split()\nd = a[0]+b[0]+c[0]\nprint(str.upper(d))", "s1, s2, s3 = input().split()\n\ntop = s1[0] + s2[0] + s3[0]\nprint(top.upper())", "def generate_acronym(l1: list) -> str:\n answer = \"\"\n for word in l1:\n # answer.append(word[0].upper())\n answer += word[0].upper()\n\n return answer\n\n\nlists = list(map(str, input().split()))\nprint((generate_acronym(lists)))\n", "a,b,c=map(str,input().split())\n\na=a.upper()\nb=b.upper()\nc=c.upper()\n\nprint(str(a[0])+b[0]+c[0])", "s1, s2, s3 = list(map(str, input().split()))\nprint((s1[0] + s2[0] + s3[0]).upper())", "for s in input().upper().split():\n print(s[0], end='')", "s1,s2,s3=input().split()\ns=s1[0]+s2[0]+s3[0]\nprint(s.upper())", "a, b, c = input().split()\n\nA = list(a)\nB = list(b)\nC = list(c)\n\nans = A[0] + B[0] + C[0]\nprint(ans.upper())", "s = list(input().split())\n\ns1 = s[0]\ns2 = s[1]\ns3 = s[2]\n\nprint((s1[0] + s2[0] + s3[0]).upper())", "a,b,c = input().split()\n\nn = a[0]+b[0]+c[0]\nprint((n.upper()))\n", "a,b,c=input().split()\nprint(a.upper()[0],b.upper()[0],c.upper()[0],sep=\"\")", "s1, s2, s3 = map(str, input().split())\nprint(s1[0].upper() + s2[0].upper() + s3[0].upper())", "s = input().split()\ns1 = list(s[0])\ns2 = list(s[1])\ns3 = list(s[2])\nprint(s1[0].upper()+s2[0].upper()+s3[0].upper())", "s1, s2, s3 = input().upper().split()\nprint((\"{}{}{}\".format(s1[0], s2[0], s3[0])))\n", "a,b,c = input().split()\nprint(str.upper(a[0]+b[0]+c[0]))", "a, b, c = input().split()\na = a.upper()\nb = b.upper()\nc = c.upper()\nprint(a[0]+b[0]+c[0])", "a, b, c = input().split()\n\nprint(((a[0]+b[0]+c[0]).upper()))\n", "print(''.join(s[0].upper() for s in input().split()))", "s1,s2,s3 = input().split()\ns = s1[0].upper() + s2[0].upper() + s3[0].upper()\nprint(s)", "print(''.join(s[0].upper() for s in input().split()))", "a,b,c=input().split()\nprint(a[0].upper()+b[0].upper()+c[0].upper())", "s1, s2, s3 = list(map(str, input().split()))\nprint(((s1[0]+s2[0]+s3[0]).upper()))\n", "# 3\u3064\u306e\u5358\u8a9e\u3092\u5165\u529b\u3067\u53d7\u3051\u53d6\u308b\ns1,s2,s3 = input().split()\n# \u305d\u308c\u305e\u308c\u306e\u982d\u6587\u5b57\u3092\u96c6\u3081\u3066\u5927\u6587\u5b57\nshort = str.upper(s1[0]+s2[0]+s3[0])\nprint(short)", "for a in input().upper().split():\n print(a[0],end='')", "S = list(map(str,input().split()))\na = S[0][0].upper()\nb = S[1][0].upper()\nc = S[2][0].upper()\nprint(a + b + c)", "a,b,c=map(str.upper,input().split())\nprint(a[0]+b[0]+c[0])", "'''\nabc059 A - Three-letter acronym\nhttps://atcoder.jp/contests/abc059/tasks/abc059_a\n'''\n\ns = list(input().split())\nans = ''\nfor i in s:\n ans += i[0].upper()\nprint(ans)\n", "a, b, c = input().split()\n\nprint(a[0].upper() + b[0].upper() + c[0].upper())", "n, m, l = input().split()\nprint(n[0].upper()+m[0].upper()+l[0].upper())", "s1, s2, s3 =map(str,input().split())\nans = [s1[0].upper(), s2[0].upper(), s3[0].upper() ]\nprint(''.join(ans))", "s1,s2,s3 = input().split()\nS = s1[0] + s2[0] + s3[0]\nprint(S.upper())", "# A - Three-letter acronym\n# https://atcoder.jp/contests/abc059/tasks/abc059_a\n\ns1, s2, s3 = list(map(str, input().split()))\n\nprint((s1[0].upper() + s2[0].upper() + s3[0].upper()))\n", "a, b, c = input().split()\n\ndef answer(a: str, b: str, c: str) -> str:\n return ((a[0] + b[0] + c[0]).upper())\n\nprint((answer(a, b, c)))\n", "s1, s2, s3 = input().split()\n\nS = s1[0] + s2[0] + s3[0]\nprint(S.upper())", "S1, S2, S3 = map(str,input().split())\n\nlist_join = (S1[0] + S2[0] + S3[0])\n\n\n\nprint(list_join.upper())", "S1, S2, S3 = map(str, input().split())\nprint((S1[0] + S2[0] + S3[0]).upper())", "a,b,c=list(map(str,input().split()))\ndef answer(a:str,b:str,c:str)->str:\n return (a[0]+b[0]+c[0]).upper()\nprint((answer(a,b,c)))\n", "a,b,c=input().split()\na,b,c=a.capitalize(),b.capitalize(),c.capitalize()\nprint(a[0]+b[0]+c[0])", "a, b, c = input().split()\n\nn = a[0] + b[0] + c[0]\nprint(n.upper())", "A, B, C = list(map(str, input().split()))\n\nprint(((A[0]+B[0]+C[0]).upper()))\n", "s1, s2, s3 = list(map(str, input().split()))\n\nprint((str.upper(s1[0]) + str.upper(s2[0]) + str.upper(s3[0])))\n", "s1,s2,s3 = map(str, input().split())\ns= s1[0]+s2[0]+s3[0]\n\nprint(s.upper())", "a, b, c = input().split()\nd = a[0] + b[0] + c[0]\nprint(d.upper())"] | {"inputs": ["atcoder beginner contest\n", "resident register number\n", "k nearest neighbor\n", "async layered coding\n"], "outputs": ["ABC\n", "RRN\n", "KNN\n", "ALC\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,962 | |
1f0e2e93b1c7d8651f22736ee467b3d4 | UNKNOWN | An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
-----Constraints-----
- All input values are integers.
- 1 \leq A, B \leq 500
- 1 \leq C \leq 1000
-----Input-----
Input is given from Standard Input in the following format:
A B C
-----Output-----
If Takahashi can buy the toy, print Yes; if he cannot, print No.
-----Sample Input-----
50 100 120
-----Sample Output-----
Yes
He has 50 + 100 = 150 yen, so he can buy the 120-yen toy. | ["a,b,c = map(int,input().split())\nprint(\"Yes\" if a + b >= c else \"No\")", "a, b, c = map(int, input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "A,B,C = map(int,input().split())\nprint(\"Yes\" if A+B >= C else \"No\")", "a,b,c = map(int,input().split())\nif a+b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")", "A, B, C = list(map(int, input().split()))\nif A+B>=C:\n print('Yes')\nelse:\n print('No')\n", "a=input().split()\na=[int(i) for i in a]\nif sum(a[:2]) >= a[2]:\n print(\"Yes\")\nelse:\n print(\"No\")", "#\n# abc091 a\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"50 100 120\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"500 100 1000\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"19 123 143\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"19 123 142\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n A, B, C = list(map(int, input().split()))\n\n if A+B >= C:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "A,B,C = map(int, input().split())\nif A+B >= C:\n print('Yes')\nelse:\n print('No')", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c = map(int,input().split())\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "a,b,c=map(int,input().split())\n\nif a+b>=c:\n ans=\"Yes\"\nelse:\n ans=\"No\"\nprint(ans)", "n,m,c = [int(x) for x in input().split()]\nif n + m >= c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\n\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "a, b, c = map(int, input().split())\nif a+b < c:\n print(\"No\")\nelse:\n print(\"Yes\")", "a, b, c = list(map(int, input().split()))\nif a + b >= c:\n print('Yes')\nelse:\n print('No')\n", "def LI():\n return list(map(int, input().split()))\n\n\nA, B, C = LI()\nif A+B >= C:\n ans = \"Yes\"\nelse:\n ans = \"No\"\nprint(ans)\n", "a, b, c = map(int, input().split())\n\nif a + b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")", "def main():\n A, B, C = list(map(int, input().split()))\n print(('Yes' if A + B - C >= 0 else 'No'))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "a, b, c = map(int, input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "a, b, c = map(int, input().split())\nprint(\"Yes\" if a + b >= c else \"No\")", "a, b, c = list(map(int, input().split()))\nif a + b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n A, B, C = LI()\n\n if A + B >= C:\n print('Yes')\n else:\n print('No')\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "a, b, c = map(int, input().split())\nif a+b >= c:\n print('Yes')\nelse:\n print('No')", "a,b,c = map(int,input().split())\nprint(\"Yes\" if a+b >= c else \"No\")", "a, b, c = map(int, input().split())\nprint(\"Yes\" if (a + b) >= c else \"No\")", "a,b,c = map(int, input().split())\nprint('Yes' if (a+b) >= c else 'No')", "a, b, c = map(int, input().split())\nif c <= a + b:\n print('Yes')\nelse:\n print('No')", "A, B, C = map(int, input().split())\n\nif A+B >= C:\n print(\"Yes\")\nelse:\n print(\"No\")", "#!/usr/bin/env python3\n\na, b, c = list(map(int, input().split()))\n\nif a+b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "A, B, C = map(int, input().split())\nif A + B >= C:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c = list(map(int, input().split()))\nif c <= a + b:\n print('Yes')\nelse:\n print('No')\n", "a,b,c = map(int,input().split())\nprint(\"Yes\" if a+b>=c else \"No\" )", "a,b,c=list(map(int,input().split()))\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a,b,c=input().split()\na=int(a)\nb=int(b)\nc=int(c)\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c = map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "A, B, C = map(int, input().split())\nprint(\"YNeos\"[A+B<C::2])", "a,b,c = map(int,input().split())\n\nprint('Yes' if a + b >= c else 'No')", "a, b, c = list(map(int, input().split()))\nif a + b < c:\n print(\"No\")\nelse:\n print(\"Yes\")\n", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a_coin, b_coin, price = map(int, input().split())\n\nif a_coin + b_coin >= price:\n print('Yes')\nelse:\n print('No')", "a,b,c = map(int, input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split(\" \"))\nprint([\"No\",\"Yes\"][a+b>=c])", "A, B, C = map(int, input().split())\n\nif A + B >= C:\n print('Yes')\nelse:\n print('No')", "A,B,C=map(int,input().split())\nif A+B>=C :\n print(\"Yes\")\nelse :\n print(\"No\")", "a, b, c = list(map(int, input().split()))\nif a + b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "a,b,c = map(int,input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "A, B, C = map(int, input().split())\nprint('Yes' if A+B>=C else 'No')", "from sys import stdin\nnii=lambda:map(int,stdin.readline().split())\nlnii=lambda:list(map(int,stdin.readline().split()))\n\na,b,c=nii()\nprint('Yes' if a+b>=c else 'No')", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c = map(int, input().split())\n\nprint(\"Yes\" if a + b >= c else \"No\")", "a,b,c=map(int, input().split())\nprint(\"Yes\" if a+b>=c else \"No\")", "a,b,c=map(int,input().split())\nprint([\"Yes\",\"No\"][a+b<c])", "a, b, c = map(int, input().split())\nprint(\"Yes\" if a + b >= c else \"No\")", "a, b, c = list(map(int, input().split()))\n\nif a + b >= c:\n print('Yes')\nelse:\n print('No')\n", "a,s,d=map(int, input().split())\nprint('Yes' if a+s>=d else 'No')", "def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n a, b, c = Input()\n if a + b >= c:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\nmain()", "a,b,c = map(int,input().split())\nif a+b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "A,B,C = list(map(int,input().split()))\nif (A+B)>=C:\n print('Yes')\nelse:\n print('No')", "a, b, c = map(int, input().split())\n\nif a + b < c:\n print('No')\nelse:\n print('Yes')", "A,B,C=map(int,input().split())\nif A+B>=C:\n print(\"Yes\")\nelse:\n print(\"No\")", "A,B,C=list(map(int,input().split()))\nif A+B>=C:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "A, B, C = map(int, input().split())\n\nif A + B >= C:\n print('Yes')\nelse:\n print('No')", "a, b, c = map(int, input().split())\nprint('Yes' if a + b >= c else 'No')", "a, b, c = list(map(int, input().split()))\nprint((\"No\" if a + b < c else \"Yes\"))\n", "a,b,c=map(int,input().split())\nprint(\"No\" if a + b < c else \"Yes\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "A,B,C = list(map(int,input().split()))\nif (A+B)>=C:\n print('Yes')\nelse:\n print('No')\n", "a, b, c = map(int, input().split())\nprint(\"Yes\" if c <= a + b else \"No\")", "a,b,c=map(int, input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c = map(int, input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "\na,b,c=map(int,input().split())\nif a+b >= c:\n print('Yes')\nelse:\n print('No')", "A,B,C=map(int,input().split())\n\nif A+B>=C:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b,c = map(int, input().split())\nif a+b >=c:\n print('Yes', flush=True)\nelse:\n print('No', flush=True)\n", "a, b, c = list(map(int, input().split()))\n\nif a + b >= c:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "A, B, C = map(int, input().split())\nprint('Yes' if A+B >= C else 'No')", "a, b, c = map(int, input().split())\nprint(\"No\" if a + b < c else \"Yes\")", "A,B,C=map(int,input().split())\nif C <= A+B:\n ans=\"Yes\"\nelse:\n ans=\"No\"\nprint(ans)", "a,b,c = map(int,input().split())\n\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "a, b, c = map(int, input().split())\nprint('Yes' if (a + b) >= c else 'No')", "a,b,c=map(int,input().split())\nprint(\"Yes\" if a+b>=c else \"No\") ", "a, b, c = map(int, input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "a,b,c=map(int,input().split())\n\nif a+b<c:\n print(\"No\")\nelse:\n print(\"Yes\")", "a,b,c = map(int,input().split())\n\nif a+b >= c:\n print('Yes')\n \nelse:\n print('No')", "A,B,C=map(int,input().split())\nif A+B>=C:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a,b,c=map(int,input().split())\nif a+b>=c:\n print('Yes')\nelse:\n print('No')", "a,b,c = map(int,input().split())\nif a+b>=c:\n print(\"Yes\")\nelse:\n print(\"No\")", "a, b, c = map(int, input().split())\nif a+b < c:\n print(\"No\")\nelse:\n print(\"Yes\")", "a,b,c = list(map(int,input().split()))\nprint((\"Yes\" if a+b >= c else \"No\"))\n", "A, B, C = map(int, input().split())\n\nif A + B >= C:\n print('Yes')\nelse:\n print('No')", "a,b,c=map(int,input().split())\nif a+b<c:print('No')\nelse:print('Yes')", "def resolve():\n a, b, c = map(int, input().split())\n if c <= a+b:\n print(\"Yes\")\n else:\n print(\"No\")\nresolve()", "a, b, c = map(int,input().split())\n\nif a + b < c:\n print(\"No\")\nelse:\n print(\"Yes\")", "a,b,c=map(int,input().split())\n\nprint('Yes') if a+b>=c else print('No')\n", "A,B,C=map(int,input().split())\nprint([\"Yes\",\"No\"][A+B<C])", "a,b,c=list(map(int,input().split()))\nprint(('Yes' if a+b>=c else 'No'))\n"] | {"inputs": ["50 100 120\n", "500 100 1000\n", "19 123 143\n", "19 123 142\n"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 11,292 | |
1a5baaac0def4942a7581e6eee3c0f98 | UNKNOWN | Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i.
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.
In how many ways can he make his selection?
-----Constraints-----
- 1 \leq N \leq 50
- 1 \leq A \leq 50
- 1 \leq x_i \leq 50
- N,\,A,\,x_i are integers.
-----Partial Score-----
- 200 points will be awarded for passing the test set satisfying 1 \leq N \leq 16.
-----Input-----
The input is given from Standard Input in the following format:
N A
x_1 x_2 ... x_N
-----Output-----
Print the number of ways to select cards such that the average of the written integers is exactly A.
-----Sample Input-----
4 8
7 9 8 9
-----Sample Output-----
5
- The following are the 5 ways to select cards such that the average is 8:
- Select the 3-rd card.
- Select the 1-st and 2-nd cards.
- Select the 1-st and 4-th cards.
- Select the 1-st, 2-nd and 3-rd cards.
- Select the 1-st, 3-rd and 4-th cards. | ["import sys\nimport heapq\nimport re\nfrom itertools import permutations\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, deque\nfrom fractions import gcd\nfrom math import factorial, sqrt, ceil\nfrom functools import lru_cache, reduce\nINF = 1 << 60\nMOD = 1000000007\nsys.setrecursionlimit(10 ** 7)\n\n# UnionFind\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n# \u30c0\u30a4\u30af\u30b9\u30c8\u30e9\ndef dijkstra_heap(s, edge, n):\n #\u59cb\u70b9s\u304b\u3089\u5404\u9802\u70b9\u3078\u306e\u6700\u77ed\u8ddd\u96e2\n d = [10**20] * n\n used = [True] * n #True:\u672a\u78ba\u5b9a\n d[s] = 0\n used[s] = False\n edgelist = []\n for a,b in edge[s]:\n heapq.heappush(edgelist,a*(10**6)+b)\n while len(edgelist):\n minedge = heapq.heappop(edgelist)\n #\u307e\u3060\u4f7f\u308f\u308c\u3066\u306a\u3044\u9802\u70b9\u306e\u4e2d\u304b\u3089\u6700\u5c0f\u306e\u8ddd\u96e2\u306e\u3082\u306e\u3092\u63a2\u3059\n if not used[minedge%(10**6)]:\n continue\n v = minedge%(10**6)\n d[v] = minedge//(10**6)\n used[v] = False\n for e in edge[v]:\n if used[e[1]]:\n heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])\n return d\n\n# \u7d20\u56e0\u6570\u5206\u89e3\ndef factorization(n):\n arr = []\n temp = n\n for i in range(2, int(-(-n**0.5//1))+1):\n if temp%i==0:\n cnt=0\n while temp%i==0:\n cnt+=1\n temp //= i\n arr.append([i, cnt])\n\n if temp!=1:\n arr.append([temp, 1])\n\n if arr==[]:\n arr.append([n, 1])\n\n return arr\n\n# 2\u6570\u306e\u6700\u5c0f\u516c\u500d\u6570\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\n# \u30ea\u30b9\u30c8\u306e\u8981\u7d20\u306e\u6700\u5c0f\u516c\u500d\u6570\ndef lcm_list(numbers):\n return reduce(lcm, numbers, 1)\n\n# \u30ea\u30b9\u30c8\u306e\u8981\u7d20\u306e\u6700\u5927\u516c\u7d04\u6570\ndef gcd_list(numbers):\n return reduce(gcd, numbers)\n\n# \u7d20\u6570\u5224\u5b9a\ndef is_prime(n):\n if n <= 1:\n return False\n p = 2\n while True:\n if p ** 2 > n:\n break\n if n % p == 0:\n return False\n p += 1\n return True\n\n\n# limit\u4ee5\u4e0b\u306e\u7d20\u6570\u3092\u5217\u6319\ndef eratosthenes(limit):\n A = [i for i in range(2, limit+1)]\n P = []\n\n while True:\n prime = min(A)\n \n if prime > sqrt(limit):\n break\n \n P.append(prime)\n \n i = 0\n while i < len(A):\n if A[i] % prime == 0:\n A.pop(i)\n continue\n i += 1\n \n for a in A:\n P.append(a)\n \n return P\n\n# \u540c\u3058\u3082\u306e\u3092\u542b\u3080\u9806\u5217\ndef permutation_with_duplicates(L):\n\n if L == []:\n return [[]]\n\n else:\n ret = []\n\n # set\uff08\u96c6\u5408\uff09\u578b\u3067\u91cd\u8907\u3092\u524a\u9664\u3001\u30bd\u30fc\u30c8\n S = sorted(set(L))\n\n for i in S:\n\n data = L[:]\n data.remove(i)\n\n for j in permutation_with_duplicates(data):\n ret.append([i] + j)\n\n return ret\n\n\n# \u3053\u3053\u304b\u3089\u66f8\u304d\u59cb\u3081\u308b\nn, a = map(int, input().split()) \nx = [i - a for i in map(int, input().split())]\ndp = [[0 for j in range(4901)] for i in range(n)]\ndp[0][2450] += 1\ndp[0][x[0] + 2450] += 1\nfor i in range(1, n):\n for j in range(4901):\n dp[i][j] = dp[i - 1][j]\n if 0 <= j - x[i] < 4901:\n dp[i][j] += dp[i - 1][j - x[i]]\nans = dp[n - 1][2450] - 1\nprint(ans)", "def abc044_c():\n #\u5024\u5165\u529b\n _, A = map(int, input().split())\n X = list(map(lambda x : int(x)-A,input().split()))\n #\u521d\u671f\u5024\n d = {0:1}\n for x in X:\n for k,v in list(d.items()):\n d[k + x] = d.get(k + x,0) + v #\u5dee\u5206\u306e\u5408\u8a08\n ans = d[0] - 1 #\u5dee\u5206\u5408\u8a080\u3067\u521d\u671f\u5024\u3092\u9664\u304f\n print(ans)\n\ndef __starting_point():\n abc044_c()\n__starting_point()", "ma = lambda :map(int,input().split())\nlma = lambda :list(map(int,input().split()))\ntma = lambda :tuple(map(int,input().split()))\nni = lambda:int(input())\nyn = lambda fl:print(\"Yes\") if fl else print(\"No\")\nimport collections\nimport math\nimport itertools\nimport heapq as hq\ndef ncr(n,r):\n ret = 1\n if n<r:\n return 0\n if n-r <r:\n r = n-r\n for i in range(1,r+1):\n ret*=(n-r+i)\n ret//=i\n return ret\n\nn,a = ma()\nX = lma()\nfor i in range(n):\n X[i] -= a\nco = collections.Counter(X)\nans = 0\nmx = 49*n #\u305a\u308c\u306e\u6700\u5927\u306fA=1,x=50 2*mx +1\u3053\u306e\u914d\u5217\ndp = [[0 for j in range(-mx,mx+1)] for i in range(n+1)]# dp[i][j] i\u307e\u3067\u4f7f\u3063\u3066\u5024\u3092j\u306b\u3059\u308b\u7d44\u307f\u5408\u308f\u305b\ndp[-1][0] = 1 #\u4e00\u500b\u3082\u4f7f\u308f\u306a\u3044\u7d44\u307f\u5408\u308f\u305b\nfor i in range(n):\n x = X[i]\n #print(x)\n for j in range(-mx,mx+1,1):\n dp[i][j] += dp[i-1][j] + dp[i-1][j-x] #\u9078\u3070\u306a\u3044/\u3076\n #if j==0:print(i,j,dp[i-1][j] , dp[i-1][j-x])\nprint(dp[n-1][0]-1)\n", "n, a = list(map(int, input().split()))\nx = list(map(int, input().split()))\n\ndp = [[[0] * (50 * (n + 10)) for _ in range(n + 10)] for _ in range(n + 10)]\ndp[0][0][0] = 1\n\nfor i in range(n):\n for use in range(n):\n for total in range(n * a):\n if dp[i][use][total]:\n dp[i + 1][use][total] += dp[i][use][total]\n dp[i + 1][use + 1][total + x[i]] += dp[i][use][total]\n\nans = 0\nfor i in range(1, n + 1):\n ans += dp[n][i][a * i]\n\nprint(ans)\n", "n,a,*l=map(int,open(0).read().split())\nR=2500\ndp=[[0]*R*2 for _ in range(n+1)]\ndp[0][0]=1\nfor i in range(n):\n for s in range(-R,R):\n dp[i+1][s]=dp[i][s]+dp[i][s-l[i]+a]\nprint(dp[n][0]-1)", "n, a = map(int, input().split())\nx = list(map(int, input().split()))\nx = [i - a for i in x]\ndic = {0:1}\nfor i in x:\n for j, k in list(dic.items()):\n dic[i+j] = dic.get(i+j, 0) + k\n\nprint(dic[0] - 1)", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N, A, *X = list(map(int, read().split()))\n\n X = [x - A for x in X]\n\n base = 2500\n dp = [0] * 5001\n dp[base] = 1\n for i in range(N):\n dp, dp_prev = dp[:], dp\n for j in range(5001):\n if 0 <= j - X[i] <= 5000:\n dp[j] += dp_prev[j - X[i]]\n\n print((dp[base] - 1))\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "from collections import defaultdict\nimport io\n\nnim, mike = map(int, input().split())\nkite = list(map(int, input().split()))\nfor i in range(nim):\n kite[i] -= mike\nqwe = defaultdict(int)\nqwe[0] = 1\nfor o in kite:\n for j, c in list(qwe.items()):\n qwe[j + o] += c\nprint(qwe[0]-1)", "def solve():\n N, A = list(map(int, input().split()))\n X = list(map(int, input().split()))\n \n dp = [[0] * (A * N + 1) for _ in range(N + 1)]\n dp[0][0] = 1\n for i, x in enumerate(X):\n for j in reversed(list(range(1, i + 2))):\n for a in range(x, A * N + 1):\n dp[j][a] += dp[j - 1][a - x]\n print((sum(dp[i][A * i] for i in range(1, N + 1))))\n \nsolve()\n", "n, a = list(map(int, input().split()))\nx = [int(i)-a for i in input().split()]\n\ndp = {0: 1}\n\nfor i in x:\n tmp = list(dp.items())\n for key, value in tmp:\n dp[key+i] = dp.get(key+i, 0) + value\nprint((dp[0] - 1))\n\n\n", "def abc044_c():\n ''' \u904e\u53bb\u63d0\u51fa\u3092\u53c2\u8003\u306b '''\n _, A = map(int, input().split())\n X = list(map(lambda x: int(x) - A, input().split()))\n d = {0: 1} # \u8ca0\u306e\u5024\u3092\u53d6\u308a\u5f97\u308b\u305f\u3081\u3001\u914d\u5217\u3067\u306a\u304f\u8f9e\u66f8\u3067\u6301\u3064\n for x in X:\n prev = list(d.items()) # \u524d\u306e\u30bf\u30fc\u30f3\u306e\u3076\u3093\u3092\u4fdd\u6301\u3057\u3066\u304a\u304f\n for val, cnt in prev:\n d[val + x] = d.get(val + x, 0) + cnt\n ans = d[0] - 1\n print(ans)\n\ndef __starting_point():\n abc044_c()\n__starting_point()", "n, a = list(map(int, input().split()))\nxxx = list(map(int, input().split()))\nlimit = a * n\ndp = [[0] * (limit + 1) for i in range(n + 1)]\ndp[0][0] = 1\nfor i, x in enumerate(xxx):\n if x > limit:\n continue\n for j in range(i, -1, -1):\n for k in range(limit - x, -1, -1):\n dp[j + 1][k + x] += dp[j][k]\n\nprint((sum(dp[i][i * a] for i in range(1, n + 1))))\n", "#\n# Written by NoKnowledgeGG @YlePhan\n# ('\u03c9')\n#\n#import math\n#mod = 10**9+7\n#import itertools\n#import fractions\n#import numpy as np\n#mod = 10**4 + 7\ndef kiri(n,m):\n r_ = n / m\n if (r_ - (n // m)) > 0:\n return (n//m) + 1\n else:\n return (n//m)\n\n\"\"\" n! mod m \u968e\u4e57\nmod = 1e9 + 7\nN = 10000000\nfac = [0] * N\ndef ini():\n fac[0] = 1 % mod\n for i in range(1,N):\n fac[i] = fac[i-1] * i % mod\"\"\"\n\n\"\"\"mod = 1e9+7\nN = 10000000\npw = [0] * N\ndef ini(c):\n pw[0] = 1 % mod\n for i in range(1,N):\n pw[i] = pw[i-1] * c % mod\"\"\"\n\n\"\"\"\ndef YEILD():\n yield 'one'\n yield 'two'\n yield 'three'\ngenerator = YEILD()\nprint(next(generator))\nprint(next(generator))\nprint(next(generator))\n\"\"\"\n\"\"\"def gcd_(a,b):\n if b == 0:#\u7d50\u5c40\u306fc,0\u306e\u6700\u5927\u516c\u7d04\u6570\u306fc\u306a\u306e\u306b\n return a\n return gcd_(a,a % b) # a = p * b + q\"\"\"\n\"\"\"def extgcd(a,b,x,y):\n d = a\n if b!=0:\n d = extgcd(b,a%b,y,x)\n y -= (a//b) * x\n print(x,y)\n else:\n x = 1\n y = 0\n return d\"\"\"\n\n\ndef readInts():\n return list(map(int,input().split()))\n\ndef main():\n n,a = readInts()\n \n X = readInts()\n \n X = list(map(lambda i: i-a, X))# lambda i\u306b\u3001 i - a\u3068\u3044\u3046\u6f14\u7b97\u306e\u3082\u3068 X\u304b\u3089\u5165\u308c\u308b\n # \u3053\u3053\u3067\u3001\u5e73\u5747\u304c8\u306b\u306a\u308b\u3082\u306e key = 0\u306e\u6642\u304c\u7b54\u3048\u306b\u306a\u308b\u3002\n # \u3060\u304b\u3089\u3053\u305d\u3000\u7b54\u3048\u3067 dp[0] - 1 \u3059\u308b\u306e\u306f\u3053\u306e\u305f\u3081\n \n dp = {0:1} \n \n for i in X:\n for k,v in list(dp.items()): # key,value\u3092\u305d\u308c\u305e\u308c\u62bd\u51fa\n dp[i+k] = dp.get(i+k, 0) + v\n #\n # get(\u306a\u3093\u304b) \u306a\u3093\u304b\u306b\u5165\u3063\u3066\u308b\u8f9e\u66f8\u306evalue\u304c\u8fd4\u3063\u3066\u304f\u308b\n # \u7121\u304b\u3063\u305f\u3089\u3001get(\u306a\u3093\u304b,\u3007)\u3067\u3001\u3007\u306b\u5165\u3063\u3066\u308b\u306e\u3067\u8f9e\u66f8\u304c\u66f4\u65b0\u3055\u308c\u308b\n # \n # print(dp)\n #{0: 6, 1: 6, 2: 2, -1: 2}\n # \u8ca0\u306e\u6570\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u308b\n print(dp[0]-1)\n \ndef __starting_point():\n main()\n__starting_point()", "from collections import defaultdict\nN, A = map(int, input().split())\nX = list(map(int, input().split()))\n\ndp = defaultdict(dict)\ndp[0][0] = 1 # \u30ab\u30fc\u30c90\u679a\u3067\u5408\u8a08\n\nfor x in X:\n newDP = defaultdict(dict)\n for card, memo in dp.items():\n for k, v in memo.items():\n # \u30ab\u30fc\u30c9X\u3092\u8ffd\u52a0\u3057\u306a\u3044\n if k in newDP[card]:\n newDP[card][k] += v\n else:\n newDP[card][k] = v\n # \u30ab\u30fc\u30c9X\u3092\u8ffd\u52a0\u3059\u308b\u3088\n if k + x in newDP[card + 1]:\n newDP[card + 1][k + x] += v\n else:\n newDP[card + 1][k + x] = v\n dp = newDP\n\nans = 0\nfor i in range(1, N + 1):\n if A * i in dp[i]:\n ans += dp[i][A * i]\nprint(ans)", "\nNMAX = 55\n\nN, A = list(map(int, input().split()))\nX = list(map(int, input().split()))\n\ndp = [[[0] * NMAX for s in range(3000)] for i in range(NMAX)]\n\ndp[0][0][0] = 1 # dp[i][s][k]: i\u500b\u304b\u3089k\u500b\u9078\u3076\u3068\u304d\u3001\u7dcf\u548c\u304cs\u306e\u3082\u306e\u306e\u500b\u6570\nfor i in range(N): # N-1\u6642\u70b9\u3067N\u304c\u66f4\u65b0\u3055\u308c\u308b\u306e\u3067\u3053\u3053\u307e\u3067\u3067\u5341\u5206\n for s in range(N*A+1):\n for k in range(N+1):\n if dp[i][s][k] == 0:\n continue\n dp[i+1][s][k] += dp[i][s][k]\n dp[i+1][s+X[i]][k+1] += dp[i][s][k]\n\nans = 0\nfor k in range(1, N+1):\n ans += dp[N][A*k][k]\n\nprint(ans)\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\nfrom collections import Counter, defaultdict\n\n\ndef main():\n N, A = list(map(int, input().split()))\n X = [int(x) - A for x in input().split()]\n\n result = Counter([0])\n\n for x in X:\n dct = defaultdict(int)\n for k, v in list(result.items()):\n dct[k + x] += v\n result += dct\n\n print((result[0] - 1))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N,A = (int(T) for T in input().split())\nX = [int(T) for T in input().split()]\nDP = [[[0]*(N+1) for TS in range(0,50*N+1)] for TI in range(0,N+1)]\nDP[0][0][0] = 1\nfor TI in range(0,N):\n for TS in range(0,50*N+1):\n for TK in range(0,N+1):\n if DP[TI][TS][TK]!=0:\n DP[TI+1][TS][TK] += DP[TI][TS][TK]\n DP[TI+1][TS+X[TI]][TK+1] += DP[TI][TS][TK]\nprint(sum(DP[N][A*TA][TA] for TA in range(1,N+1)))", "n, a = map(int, input().split())\nx = list(map(int, input().split()))\nfor i in range(n):\n x[i] -= a\ndp = [[0 for i in range(100 * n + 1)] for j in range(n + 1)]\ndp[0][50 * n] = 1\nfor i in range(n):\n for j in range(100 * n + 1):\n j2 = j - 50 * n\n num = x[i]\n if -50 * n <= j2 - num <= 50 * n:\n dp[i + 1][j] = dp[i][j] + dp[i][j - num]\n else:\n dp[i + 1][j] = dp[i][j]\nprint(dp[n][50 * n] - 1)", "N,A = map(int,input().split())\nX = list(map(int,input().split()))\nY = [x-A for x in X]\ndp = {0:1}\n\nfor y in Y:\n for k,v in list(dp.items()):\n dp[k+y]=dp.get(k+y,0)+v\n\nprint(dp[0]-1)", "N, A = map(int, input().split())\n\nx = list(map(int, input().split()))\n\nmaxint = 50 * N\n\ndp = [[[0] * (maxint + 1) for _ in range(N + 1)] for _ in range(N + 1)]\n\ndp[0][0][0] = 1\n\nfor xi, xe in enumerate(x, 1):\n for j in range(xi+1):\n for k in range(maxint + 1):\n dp[xi][j][k] = dp[xi - 1][j][k]\n \n if j >= 0 and k >= xe:\n dp[xi][j][k] += dp[xi - 1][j - 1][k - xe]\n \n\nres = 0\n\nfor i in range(1, N+1):\n res += dp[N][i][i * A]\n\nprint(res)", "N,A = list(map(int,input().split()))\nX = list(map(int,input().split()))\ndp = [[[0 for _ in range(50*(N+2))] for _ in range(N+2)] for _ in range(N+2)]\n\ndp[0][0][0] = 1\n#k\u307e\u3067\u307f\u305f\nfor k in range(N):\n #used\u500b\u4f7f\u3063\u305f\n for used in range(N):\n for i in range(50*N):\n #\u4f7f\u3046\u6642\n if dp[used][k][i] == 0: \n continue\n dp[used+1][k+1][i+X[k]] += dp[used][k][i]\n dp[used][k+1][i] += dp[used][k][i]\nans = 0\nfor used in range(1,N+1):\n ans += dp[used][N][used*A]\nprint(ans)\n\n\n", "n,a=map(int,input().split())\nnums=[int(i)-a for i in input().split()]\nd={0:1}\nfor i in nums:\n s = [[j, d[j]] for j in d]\n for j in s:\n if j[0] + i in d:\n d[j[0]+i] += j[1]\n else:\n d[j[0]+i] = j[1]\nprint(d[0]-1)", "n,a,*l=map(int,open(0).read().split())\nR=2500\ndp=[[0]*R*2,[0]*R*2]\ndp[0][0]=1\nt=0\nfor i in range(n):\n u=1-t\n for s in range(-R,R):\n dp[u][s]=dp[t][s]+dp[t][s-l[i]+a]\n t=u\nprint(dp[t][0]-1)", "def c_tak_and_cards():\n from collections import defaultdict\n N, A = [int(i) for i in input().split()]\n X = [int(i) for i in input().split()]\n\n average = [x - A for x in X]\n dp = defaultdict(int) # dp[s]: y \u304b\u3089 1 \u679a\u4ee5\u4e0a\u9078\u3093\u3067\u6574\u6570\u306e\u548c\u3092 s \u306b\u3059\u308b\u65b9\u6cd5\n dp[0] = 1 # \u300c\u9078\u3070\u306a\u3044\u300d 1 \u901a\u308a\n for y in average:\n for k, v in list(dp.items()): # for \u6587\u4e2d\u3067\u8981\u7d20\u6570\u304c\u5909\u308f\u3063\u3066\u306f\u3044\u3051\u306a\u3044\u305f\u3081\n dp[k + y] += v\n return dp[0] - 1\n\nprint(c_tak_and_cards())", "import sys\nimport heapq, math\nfrom itertools import zip_longest, permutations, combinations, combinations_with_replacement\nfrom itertools import accumulate, dropwhile, takewhile, groupby\nfrom functools import lru_cache\nfrom copy import deepcopy\n\nN, A = map(int, input().split())\nX = list(map(int, input().split()))\n\ndp = [[0] * (N * A + 1) for _ in range(N + 1)]\n\ndp[0][0] = 1\n\nfor i in range(0, N):\n for cnt in range(N, 0, -1):\n for val in range(N * A, -1, -1):\n if val - X[i] >= 0:\n dp[cnt][val] += dp[cnt - 1][val - X[i]]\n\nans = 0\nfor i in range(1, N + 1):\n ans += dp[i][i * A]\n\nprint(ans)", "import numpy as np\n\nn, a = list(map(int, input().split()))\nx = list(map(int, input().split()))\nMAX = 50 * n\n\ndp = np.zeros((n + 1, MAX + 1), np.int64)\ndp[0][0] = 1\n\nfor e in x:\n dp[1:, e:] += dp[:-1, :-e]\n\ncnt = np.arange(1, n + 1)\nsm = cnt * a\nans = dp[cnt, sm].sum()\n\nprint(ans)\n", "def abc044_c():\n N, A = map(int, input().split())\n X = list(map(lambda x: int(x) - A, input().split())) # \u5e73\u5747\u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u5f15\u3044\u305f\u72b6\u614b\n dp = [dict() for _ in range(N+1)] # \u8ca0\u306e\u5024\u3092\u53d6\u308a\u5f97\u308b\u305f\u3081\u3001\u914d\u5217\u3067\u306a\u304f\u8f9e\u66f8\u3067\u6301\u3064\n dp[0][0] = 1 # 0\u679a\u6642\u70b9\u3067\u4f55\u3082\u9078\u3070\u306a\u3044\u3001\u3092\u521d\u671f\u5024\u3068\u3059\u308b\n for i, x in enumerate(X):\n dp[i+1] = dp[i].copy() # \u524d\u306e\u72b6\u614b\u3092\u5f15\u304d\u7d99\u3050\n for val, cnt in dp[i].items():\n dp[i+1][val + x] = dp[i].get(val + x, 0) + cnt # \u524d\u306e\u30bf\u30fc\u30f3\u306ex\u30b7\u30d5\u30c8\u5206\u3092\u52a0\u7b97\n ans = dp[N][0] - 1\n print(ans)\n\ndef __starting_point():\n abc044_c()\n__starting_point()", "import sys\n\nn,a=list(map(int, input().split()))\ncards=list(map(int, input().split()))\n\nintegers=[x-a for x in cards]\ncards.append(a)\nf=max(cards)*n\n\n\ndp=[[0 for i in range(n+1)] for j in range(2*f+1) ]\n\nfor y in range(n+1):\n for x in range(2*f+1):\n if y==0 and x==f:\n dp[x][y]=1\n elif y>0 and (x-integers[y-1]<0 or x-integers[y-1]>2*f):\n dp[x][y]=dp[x][y-1]\n elif y>0 and x-integers[y-1]>=0 and x-integers[y-1]<=2*f:\n dp[x][y]=dp[x-integers[y-1]][y-1]+dp[x][y-1]\n else:\n dp[x][y]=0\nprint((dp[f][n]-1))\n\n", "n,a,=map(int,input().split())\nx=list(map(lambda y:int(y)-a,input().split()))\nw=2*n*(max(max(x),a))\ndp=[[0]*(w+1) for _ in range(n+1)]\ndp[0][w//2]=1\nfor i in range(1,n+1):\n for j in range(w+1):\n dp[i][j]=dp[i-1][j]+(dp[i-1][j-x[i-1]] if 0<=j-x[i-1]<=w else 0)\nprint(dp[n][w//2]-1)", "import numpy as np\nn,a = map(int,input().split())\nx = list(map(int,input().split()))\n\"\"\"\n\u5e73\u5747\u304ca <=> \u96c6\u5408\u3092l\u3068\u3057\u3066, len(l)a = sum(l)\ndp[i][j][k] := i\u756a\u76ee\u307e\u3067\u306e\u30ab\u30fc\u30c9\u3092\u9078\u3093\u3060\u3068\u304d, \u9078\u3093\u3060\u679a\u6570\u304ck\u3067\u306e\u7dcf\u548c\u304c\u3061\u3087\u3046\u3069j\u306b\u306a\u308b\u5834\u5408\u306e\u6570.\n\u3053\u308c\u3060\u3068\u30e1\u30e2\u30ea\u304c\u8db3\u308a\u306a\u3044\u306e\u3067, i\u3092\u7701\u7565\u3059\u308b.\n\"\"\"\nsumx = sum(x)\ndp = np.zeros((n, sumx+1), dtype=np.int64)\nfor i in range(n):\n\tfor j in range(i)[::-1]:\n\t\tdp[j+1][x[i]:] += dp[j][:-x[i]]\n\tdp[0][x[i]] += 1\nans = 0\nfor i in range(n):\n\tif (i+1)*a <= sumx:\n\t\tans += dp[i][(i+1)*a]\nprint(ans)", "import numpy as np\nn,a=map(int,input().split())\nx=list(map(int,input().split()))\ns=sum(x)\ndp=np.zeros((n,s+1),dtype=np.int64)\nfor i in range(n):\n for j in range(i)[::-1]:\n dp[j+1][x[i]:]+=dp[j][:-x[i]]\n dp[0][x[i]]+=1\nt=0\nfor k in range(n):\n if (k+1)*a<=s:\n t+=dp[k][(k+1)*a]\nprint(t)", "n,a=list(map(int, input().split()))\nx=list(map(int, input().split()))\n\ndp=[[[0]*(2550) for _ in range(55)] for _ in range(55)]\ndp[0][0][0]=1\nfor i in range(n):\n for j in range(n+1):\n for sm in range(n*a+1):\n if dp[i][j][sm]==0:\n continue\n dp[i+1][j][sm]+=dp[i][j][sm]\n dp[i+1][j+1][sm+x[i]]+=dp[i][j][sm]\n\nans=0\nfor k in range(1,n+1):\n ans+=dp[n][k][a*k]\nprint(ans)\n", "N,A=map(int,input().split())\nx=list(map(int,input().split()))\nx=[i-A for i in x]\ndp=[[0]*50*N*2 for i in range(N+1)]\ndp[0][50*N]=1\nfor i in range(1,N+1):\n for j in range(50*N*2):\n n=j-x[i-1]\n if n>=0 and n<50*N*2:\n dp[i][j]=dp[i-1][j]+dp[i-1][n]\n else:\n dp[i][j]=dp[i-1][j]\n #else:\n #print(dp[i])\n\nprint(dp[N][50*N]-1)", "N,A = map(int, input().split())\nalist = list(map(int, input().split()))\n\nblist = list(map(lambda x:x-A,alist))\nsum_plus = 0\nsum_minus = 0\nfor i in blist:\n if i >0:\n sum_plus +=i\n else:\n sum_minus +=i\n\nN=len(alist)\ndp = [[0 for i in range(sum_plus - sum_minus + 1)] for j in range(N+1)]\ndp[0][0-sum_minus]=1\n\nfor i in range(N):\n for j in range(sum_plus - sum_minus+1):\n if j-blist[i] <= (sum_plus - sum_minus):\n dp[i+1][j]=dp[i][j-blist[i]]+dp[i][j]\n else:\n dp[i+1][j]=dp[i][j]\n\nprint(dp[N][0-sum_minus]-1)", "import sys\nreadline = sys.stdin.readline\n\ndef main():\n N, A = map(int, readline().rstrip().split())\n X = list(map(int, readline().rstrip().split()))\n lim = max(X) * N\n X = [x-A for x in X]\n dp = [[0]*(2*lim) for _ in range(N+1)]\n dp[0][lim] = 1\n for i in range(1, N+1):\n x = X[i-1]\n for j in range(2*lim):\n if 0 <= j - x < 2 * lim:\n dp[i][j] = dp[i-1][j] + dp[i-1][j-x]\n else:\n dp[i][j] = dp[i-1][j]\n \n print(dp[N][lim] - 1)\n\n\ndef __starting_point():\n main()\n__starting_point()", "import collections\nN, A = [int(_) for _ in input().split()]\nX = [int(_) for _ in input().split()]\n\n\ndef calc(W):\n #dp[m][s]=m\u679a\u306e\u30ab\u30fc\u30c9\u306e\u548c\u304cs\u3068\u306a\u308b\u3088\u3046\u306a\u9078\u3073\u65b9\u306e\u7dcf\u6570\n M = len(W)\n dp = [collections.defaultdict(int) for _ in range(M + 1)]\n dp[0][0] = 1\n for i, w in enumerate(W):\n for j in range(i, -1, -1):\n for k, v in list(dp[j].items()):\n dp[j + 1][k + w] += v\n return dp\n\n\ndpx = calc(X)\nprint((sum(dpx[i][i * A] for i in range(1, N + 1))))\n", "import sys\nimport numpy as np\n\nn, a, *x = map(int, sys.stdin.read().split())\n\ndef main():\n dp = np.zeros((n + 1, 2501), dtype=np.int64)\n dp[0, 0] = 1\n for i in range(n):\n dp[1:, x[i]:] += dp[:-1, :-x[i]].copy()\n i = np.arange(1, n + 1)\n print(dp[i, i * a].sum())\n\nif __name__ == '__main__':\n main()", "n,a=list(map(int,input().split()))\nx=list(map(int,input().split()))\n\nfor i in range(n):\n x[i]=x[i]-a\n \nnx=n*n\ndp=[[0]*(2*nx+1) for i in range(n+1)]\n\n#print(dp)\n\ndp[0][nx]=1\n\nfor j in range(1,n+1):\n jj=j-1\n for t in range(2*nx+1):\n if t-x[jj]<0 or 2*nx<t-x[jj]:\n dp[j][t]=dp[j-1][t]\n elif 0<t-x[jj] and t-x[jj]<2*nx:\n dp[j][t]=dp[j-1][t]+dp[j-1][t-x[jj]]\n else:\n dp[j][t]=0\n\nprint((dp[n][nx]-1))\n \n", "#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\ndef main():\n N, A = map(int, input().split())\n X = list(map(int, input().split()))\n X = [x-A for x in X]\n\n ret={0: 1}\n for xi in X:\n for y, cnt in list(ret.items()):\n ret[xi+y] = ret.get(xi+y, 0) + cnt\n print(ret[0]-1)\n\ndef __starting_point():\n main()\n__starting_point()", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N, A, *X = list(map(int, read().split()))\n\n X = [x - A for x in X]\n\n base = 2500\n dp = [[0] * 5001 for _ in range(N + 1)]\n dp[0][base] = 1\n for i in range(N):\n for j in range(-2500, 2501):\n if -2500 <= j - X[i] <= 2500:\n dp[i + 1][j + base] = dp[i][j + base] + dp[i][j - X[i] + base]\n else:\n dp[i + 1][j + base] = dp[i][j + base]\n\n print((dp[N][base] - 1))\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N,A = map(int,input().split())\nls1 = [0] + list(map(int,input().split()))\n\ndp = [[[0 for k in range(2600)] for j in range(51) ] for i in range(51)]\nfor i in range(51):\n dp[i][0][0] = 1\nfor j in range(1,N+1):\n for k in range(1,j+1):\n for s in range(2600):\n if s < ls1[j]:\n dp[j][k][s] = dp[j-1][k][s]\n elif s >= ls1[j]:\n dp[j][k][s] = dp[j-1][k-1][s-ls1[j]] + dp[j-1][k][s]\nans = 0\nfor k in range(1,N+1):\n ans += dp[N][k][k*A]\nprint(ans)", "n , a = list(map(int, input().split()))\nx = list(map(int,input().split()))\n\nx=[i-a for i in x]\ndp=[[0]*n*50*2 for i in range(n+1)]\n\ndp[0][n*50]=1\n\nfor i in range(n):\n for j in range(n*50*2):\n t=j-x[i]\n if 0<=t<n*50*2:\n dp[i+1][j]=dp[i][j]+dp[i][t]\n else:\n dp[i+1][j]=dp[i][j]\nprint((dp[n][n*50]-1))\n", "def abc044_c():\n import numpy as np\n n, a = map(int, input().split())\n x = list(map(lambda x: int(x) - a, input().split())) # \u5e73\u5747\u30bf\u30fc\u30b2\u30c3\u30c8\u5024\u3092\u5f15\u3044\u3066\u304a\u304f\n x = np.array(x, dtype=np.int64)\n\n vrange = n * (a + np.max(x)) # \u53d6\u308a\u3046\u308b\u5024\u306e\u5e45(\u7247\u5074), \u5e83\u3081\u306b\u3068\u3063\u3066\u3082\u304b\u307e\u308f\u306a\u3044\n dp = np.zeros((n+1, 2*vrange+1), dtype=np.int64) # DP\u30c6\u30fc\u30d6\u30eb\n dp[0, vrange] = 1 # 0\u679a\u6642\u70b9\u3067\u4f55\u3082\u9078\u3070\u305a\u306b\u7dcf\u548c0(\u5e73\u5747\u30bf\u30fc\u30b2\u30c3\u30c8)\u306b\u306a\u308b\u5834\u5408\u3092\u521d\u671f\u5024\u306b\u30bb\u30c3\u30c8\n\n for i in np.arange(n):\n # 1\u3064\u524d\u306e\u30bf\u30fc\u30f3\u3092\u5f15\u304d\u7d99\u3050\n dp[i+1, :] += dp[i, :]\n if 0 < x[i]:\n # x[i]\u304c\u6b63\u306e\u5024\u30011\u3064\u524d\u306ex[i]\u500b\u3076\u3093\u5de6\u5074\u3092\u30b9\u30e9\u30a4\u30c9\u3057\u3066\u6301\u3063\u3066\u304f\u308b\n dp[i+1, x[i]:] += dp[i, :-x[i]]\n elif x[i] < 0:\n # x[i]\u304c\u8ca0\u306e\u5024\u30011\u3064\u524d\u306ex[i]\u500b\u3076\u3093\u53f3\u5074\u3092\u30b9\u30e9\u30a4\u30c9\u3057\u3066\u6301\u3063\u3066\u304f\u308b\n dp[i+1, :x[i]] += dp[i, -x[i]:]\n else:\n # x[i]\u304c\u30bc\u30ed\n dp[i+1, :] += dp[i, :]\n\n ans = dp[n, vrange] - 1 # \u521d\u671f\u5024(\u4f55\u3082\u9078\u3070\u306a\u3044)\u306e1\u901a\u308a\u3092\u9664\u304f\n print(ans)\n\ndef __starting_point():\n abc044_c()\n__starting_point()", "N, A = map(int,input().split())\nX = [int(x) for x in input().split()]\n\ndp = [[0]*(N*A+1) for _ in range(N+1)] #dp[i][j]:i\u679a\u306e\u548c\u304cj\u3068\u306a\u308b\u3088\u3046\u306a\u30ab\u30fc\u30c9\u306e\u9078\u3073\u65b9\ndp[0][0] = 1 \nfor x in X:\n for i in reversed(range(1,N+1)):\n for j in reversed(range(N*A+1)):\n if j < x:\n continue\n dp[i][j] += dp[i-1][j-x]\nans = sum(dp[k][k*A] for k in range(1,N+1)) \nprint(ans) ", "N,A = list(map(int,input().split()))\nls1 = [0] + list(map(int,input().split()))\n\ndp = [[[0 for k in range(2600)] for j in range(51) ] for i in range(51)]\nfor i in range(51):\n dp[i][0][0] = 1\nfor j in range(1,N+1):\n for k in range(1,j+1):\n for s in range(2600):\n if s < ls1[j]:\n dp[j][k][s] = dp[j-1][k][s]\n elif s >= ls1[j]:\n dp[j][k][s] = dp[j-1][k-1][s-ls1[j]] + dp[j-1][k][s]\nans = 0\nfor k in range(1,N+1):\n ans += dp[N][k][k*A]\nprint(ans)\n", "n, a = map(int, input().split())\nx = list(map(int, input().split()))\n\nfor i in range(n):\n x[i] -= a\n\nd = [0] * 6000\nans = 0\nfor dif in x:\n ans += d[-dif+3000]\n if dif == 0:\n ans += 1\n if dif < 0:\n for i in range(6000):\n if 0 <= i+dif < 6000:\n d[i+dif] += d[i]\n else:\n for i in range(5999, -1, -1):\n if 0 <= i+dif < 6000:\n d[i+dif] += d[i]\n d[dif+3000] = d[dif+3000] + 1\n \nprint(ans)", "n,a=map(int,input().split())\nfrom collections import Counter\nX = [int(x) - a for x in input().split()]\nd=Counter([0])\nfor i in X:\n tmp=Counter()\n for j,k in d.items():\n tmp[i+j]+=k\n d+=tmp\nprint(d[0]-1)", "#\u60f3\u5b9a\u89e3\u6cd5\nN, A = list(map(int, input().split()))\nX = sorted(list(map(int, input().split())))\nxm = max(X)\nxm = max(xm, A)\nfor i in range(N):\n X[i] -= A \n#print(X, xm)\ndp = [[0] * (2 * N * xm + 1) for i in range(N + 1)]\ndp[0][N * xm] = 1\n\nfor i in range(1, N + 1):\n for j in range(2 * N * xm + 1):\n if 0 <= j - X[i - 1] <= 2 * N * xm:\n dp[i][j] = dp[i - 1][j] + dp[i - 1][j - X[i - 1]]\n else:\n dp[i][j] = dp[i - 1][j]\n\nprint((dp[N][N * xm] - 1))\n", "import numpy as np\nn, a = map(int, input().split())\nx = list(map(int, input().split()))\n\ns = sum(x)\ndp = np.zeros((n, s+1), dtype = np.int64)\nfor i in range(n):\n for j in range(i)[::-1]:\n dp[j+1][x[i]:] += dp[j][:-x[i]]\n dp[0][x[i]] += 1\nans = 0\nfor i in range(n):\n if (i+1)*a <= s:\n ans += dp[i][(i+1)*a]\nprint(ans)", "f=lambda:map(int,input().split())\nn,a=f()\nl=[i-a for i in f()]\ndp=[[0]*5000 for _ in range(51)]\nZ=2500\ndp[0][Z]=1\nfor i in range(n):\n for s in range(5000-max(l[i],0)):\n dp[i+1][s]+=dp[i][s]\n dp[i+1][s+l[i]]+=dp[i][s]\nprint(dp[n][Z]-1)", "n,a=map(int,input().split())\nX=list(map(int,input().split()))\ndp=[[0]*2501 for _ in range(n+1)]\ndp[0][0]=1\nfor i in range(n):\n x=X[i]\n for j in range(n,0,-1):\n \tfor k in range(2501-x):\n \tdp[j][k+x]+=dp[j-1][k]\nans=0\nfor i in range(n):\n ans+=dp[i+1][(i+1)*a]\nprint(ans)", "N, A = map(int, input().split())\nX = list(map(int, input().split()))\ndp = [[[0] * 6000 for _ in range(N + 1) ] for _ in range(N + 1)]\ndp[0][0][0] = 1\nfor i in range(N):\n for j in range(N):\n for k in range(5000):\n if dp[i][j][k] == 0:\n continue\n dp[i + 1][j][k] += dp[i][j][k]\n dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]\nC = 0\nfor i in range(N + 1):\n C += dp[N][i][i * A]\nprint(C - 1)", "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n N, A, *X = list(map(int, read().split()))\n\n X = [x - A for x in X]\n\n neg = pos = 0\n for x in X:\n if x > 0:\n pos += x\n else:\n neg += x\n\n M = pos - neg\n base = -neg\n\n dp = [[0] * (M + 1) for _ in range(N + 1)]\n dp[0][base] = 1\n\n for i in range(N):\n for s in range(M + 1):\n dp[i + 1][s] = dp[i][s]\n if 0 <= s - X[i] <= M:\n dp[i + 1][s] += dp[i][s - X[i]]\n\n print((dp[N][base] - 1))\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N, A = map(int, input().split())\nX = list(map(int, input().split()))\nsumX = 2501\n\ndp = [[[0 for _ in range(sumX)] for _ in range(N+1)] for _ in range(N+1)]\ndp[0][0][0] = 1\n\nfor j in range(N):\n for k in range(N):\n for s in range(sumX):\n if dp[j][k][s]==0:\n continue\n dp[j+1][k][s] += dp[j][k][s]\n dp[j+1][k+1][s+X[j]] += dp[j][k][s]\nans = 0\n\nfor i in range(N+1):\n ans += dp[N][i][i*A]\nprint(ans-1)", "\nNMAX = 55\nT = 2500\nN, A = list(map(int, input().split()))\nX = list([int(x) - A for x in input().split()])\n\ndp = [[0]*5001 for i in range(NMAX)] # i\u6642\u70b9\u3067\u7dcf\u548c\u304cS\u306b\u306a\u308b\u3082\u306e\u306e\u500b\u6570\n\ndp[0][T] = 1\n\nfor i in range(N):\n for s in range(5001):\n if s+X[i] > 5001 or dp[i][s] == 0:\n continue\n dp[i+1][s] += dp[i][s]\n dp[i+1][s+X[i]] += dp[i][s]\n\nprint((dp[N][T]-1))\n\n", "n,a=map(int,input().split())\nA=list(map(int,input().split()))\nfor i in range(n):\n A[i]=A[i]-a\nB=[]\nc=0\nfor i in range(n):\n if A[i]==0:\n c=c+1\n else:\n B.append(A[i])\nn=len(B)\ndp=[[0]*5010 for i in range(n+1)]#0\u30682505\u3092\u5bfe\u5fdc\nfor i in range(1,n+1):\n dp[i]=dp[i-1][0:5010]\n dp[i][2505+B[i-1]]+=1\n for j in range(5010):\n if 0<=j+B[i-1] and j+B[i-1]<=5009:\n dp[i][j+B[i-1]]+=dp[i-1][j]\nans=dp[n][2505]\nprint((ans+1)*2**c-1)", "\nNMAX = 55\n\nN, A = list(map(int, input().split()))\nX = list(map(int, input().split()))\n\ndp = [[[0] * NMAX for s in range(3000)] for i in range(NMAX)]\n\ndp[0][0][0] = 1 # dp[i][s][k]: i\u500b\u304b\u3089k\u500b\u9078\u3076\u3068\u304d\u3001\u7dcf\u548c\u304cs\u306e\u3082\u306e\u306e\u500b\u6570\nfor i in range(N): # N-1\u6642\u70b9\u3067N\u304c\u66f4\u65b0\u3055\u308c\u308b\u306e\u3067\u3053\u3053\u307e\u3067\u3067\u5341\u5206\n for s in range(3000):\n for k in range(N+1):\n if dp[i][s][k] == 0:\n continue\n dp[i+1][s][k] += dp[i][s][k]\n dp[i+1][s+X[i]][k+1] += dp[i][s][k]\n\nans = 0\nfor k in range(1, N+1):\n ans += dp[N][A*k][k]\n\nprint(ans)\n", "import numpy as np\nn, a = map(int, input().split())\nx = list(map(int, input().split()))\n\n# dp[i][j][k]\uff1a\u3000i\u679a\u76ee\u307e\u3067\u306e\u30ab\u30fc\u30c9\u3092j\u679a\u4f7f\u7528\u3057\u3066\u5408\u8a08k\u3092\u4f5c\u308c\u308b\u7d44\u307f\u5408\u308f\u305b\ndp = np.zeros((n+1, n+1, 3001)).astype(np.int64)\ndp[0][0][0] = 1\n\nfor i in range(n):\n _x = x[i]\n for j in range(n):\n dp[i+1, j+1, _x:] += dp[i, j, :-_x]\n dp[i+1, j, :] += dp[i, j, :]\n\nans = 0\nfor j in range(1, n+1):\n ans += dp[n, j, j*a]\nprint(ans)", "n,a = map(int,input().split())\nx = list(map(int,input().split()))\nt = [[[0] * (50*(j+1)+1) for j in range(i+2)] for i in range(n+1)]\nans = 0\nt[0][0][0] = 1\n\nfor i in range(1, n+1):\n for j in range(i+1):\n for k in range(50*j + 1):\n if j >= 1 and k >= x[i-1]:\n t[i][j][k] = t[i - 1][j - 1][k - x[i-1]] + t[i - 1][j][k]\n else:\n t[i][j][k] = t[i - 1][j][k]\nfor i in range(1,n+1):\n ans += t[n][i][i*a]\nprint(ans)", "#!/usr/bin/env python3\n\nimport sys\n# import math\n# from string import ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits\n# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)\n# from operator import itemgetter # itemgetter(1), itemgetter('key')\n# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()\n# from collections import defaultdict # subclass of dict. defaultdict(facroty)\n# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)\n# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).\n# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).\n# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])\n# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]\n# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]\n# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])\n# from itertools import combinations, combinations_with_replacement\n# from itertools import accumulate # accumulate(iter[, f])\n# from functools import reduce # reduce(f, iter[, init])\n# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)\n# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).\n# from copy import deepcopy # to copy multi-dimentional matrix without reference\n# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)\n\n\ndef main():\n mod = 1000000007 # 10^9+7\n inf = float('inf') # sys.float_info.max = 1.79...e+308\n # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19\n sys.setrecursionlimit(10**6) # 1000 -> 1000000\n def input(): return sys.stdin.readline().rstrip()\n def ii(): return int(input())\n def mi(): return list(map(int, input().split()))\n def mi_0(): return [int(x)-1 for x in input().split()]\n def lmi(): return list(map(int, input().split()))\n def lmi_0(): return list([int(x)-1 for x in input().split()])\n def li(): return list(input())\n \n \n n, a = mi()\n L = lmi()\n diff = [elm - a for elm in L]\n # dp[i][num] = (diff \u304b\u3089 i \u756a\u76ee\u307e\u3067\u3092\u4f7f\u7528\u3057\u3066\u548c\u3092 num - 2500 \u306b\u3059\u308b\u5834\u5408\u306e\u6570)\n dp = [[0] * 5001 for _ in range(n + 1)]\n dp[0][2500] = 1\n\n for i in range(n):\n for j in range(5001):\n if dp[i][j]:\n dp[i+1][j + diff[i]] += dp[i][j]\n dp[i+1][j] += dp[i][j]\n \n\n print((dp[n][2500] - 1)) # n \u756a\u76ee\u307e\u3067\u3092\u4f7f\u7528\u3057\u3066\u548c\u3092 0 \u306b\u3059\u308b\u306b\u306f\uff1f \u6700\u521d\u306e\u4f55\u3082\u9078\u3070\u306a\u3044 1 \u901a\u308a\u3092\u9664\u304f\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys\nimport numpy as np\n\nn, a, *x = map(int, sys.stdin.read().split())\n\ndef main():\n m = 2500\n dp = np.zeros((n + 1, m + 1), dtype=np.int64)\n dp[0, 0] = 1\n for i in range(n):\n ndp = np.copy(dp)\n ndp[1:, x[i]:] += dp[:-1, :m-x[i]+1]\n dp = ndp\n i = np.arange(1, n + 1)\n print(np.sum(dp[i, i * a]))\n\nif __name__ == '__main__':\n main()", "def main():\n N, A = list(map(int, input().split()))\n X = list(map(int, input().split()))\n\n dp = [[0] * (A * N + 1) for _ in range(N + 1)]\n dp[0][0] = 1\n for i, x in enumerate(X):\n for j in reversed(list(range(1, i + 2))):\n for a in range(x, A * N + 1):\n dp[j][a] += dp[j - 1][a - x]\n return sum(dp[i][A * i] for i in range(1, N + 1))\n\nprint((main()))\n", "import sys\nfrom collections import defaultdict\n\nn, a, *x = map(int, sys.stdin.read().split())\nfor i in range(n): x[i] -= a\n\ndef main():\n dp = defaultdict(int); dp[0] = 1\n for i in range(n):\n ndp = dp.copy()\n for k, v in dp.items():\n ndp[k+x[i]] += v\n dp = ndp\n print(dp[0] - 1)\n \ndef __starting_point():\n main()\n__starting_point()", "N,A = map(int,input().split())\nX = list(map(int,input().split()))\nY = [x-A for x in X]\ndp = {0:1}\n\nfor y in Y:\n tmp = list(dp.items())\n for k,v in tmp:\n dp[k+y]=dp.get(k+y,0)+v\n\nprint(dp[0]-1)", "n,a=list(map(int,input().split()))\nx=list(map(int,input().split()))\nimport numpy as np\ndp=np.zeros((n+1,2501),int)\ndp[0,0]=1\nfor xi in x:\n for i in range(n-1,-1,-1):\n dp[i+1][xi:]+=dp[i,:-xi]\nans=0\nfor i in range(1,n+1):\n ans+=dp[i,i*a]\nprint(ans)\n", "import numpy as np\nn,avea=tuple([int(x) for x in input().split()])\nx=list([int(x) for x in input().split()])\nx=np.array(x)\nx=x-avea\nw=max(abs(min(x)),abs(max(x)))*n\ndp=np.zeros((n+1,2*w+1),dtype=int)\ndp[0,w]=1\nfor i in range(1,n+1):\n for j in range(2*w+1):\n if 0<=j-x[i-1]<=2*w:\n dp[i,j]=dp[i-1,j]+dp[i-1,j-x[i-1]]\n else:\n dp[i,j]=dp[i-1,j]\nprint((dp[n,w]-1))\n", "N, A = map(int, input().split())\nx = list(map(int, input().split()))\nmaxX = max(max(x), A)\ndp = [[[0 for _ in range(N * maxX + 1)] for _ in range(N + 1)] for _ in range(N + 1)]\ndp[0][0][0] = 1\nfor i in range(N):\n for j in range(N + 1):\n for k in range(N * A + 1):\n if dp[i][j][k] == 0: continue\n dp[i + 1][j][k] += dp[i][j][k]\n dp[i + 1][j + 1][k + x[i]] += dp[i][j][k]\n\nans = 0\nfor i in range(1, N + 1):\n ans += dp[N][i][A * i]\nprint(ans)", "n, a = map(int, input().split())\nl = list(map(int, input().split()))\nans = 0\ndp = list([0]*(n*a+1) for _ in range(n+1))#\u52d5\u7684\u8a08\u753b\u6cd5\u3067\u89e3\u304f\ndp[0][0] = 1\nfor x in l:\n for i in range(n, 0, -1):#\u4e0b\u884c\u304b\u3089\u9806\u306b\u683c\u7d0d\u3057\u3066\u3044\u304f(\u4e0a\u304b\u3089\u3060\u3068\u683c\u7d0d\u3057\u305f\u3070\u304b\u308a\u306e\u5024\u304c\u53c2\u7167\u3055\u308c\u3066\u3057\u307e\u3046)\n for j in range(n*a+1):\n if x > j:\n continue\n dp[i][j] += dp[i-1][j-x]\n\nfor i in range(n):\n ans += dp[i+1][(i+1)*a]\n\nprint(ans)", "import numpy as np\nn,avea=tuple([int(x) for x in input().split()])\nx=list([int(x) for x in input().split()])\nx=np.array(x)\nx=x-avea\nw=max(abs(min(x)),abs(max(x)))*n\ndp=np.zeros((n+1,2*w+1),dtype=int)\ndp[0,w]=1\nfor i in range(n):\n for j in range(2*w+1):\n if 0<=j-x[i]<=2*w:\n dp[i+1,j]=dp[i,j]+dp[i,j-x[i]]\n else:\n dp[i+1,j]=dp[i,j]\nprint((dp[n,w]-1))\n", "from collections import Counter\n\n\nN, A = list(map(int, input().split()))\nX = list(map(int, input().split()))\nY = [x - A for x in X]\nL = Counter()\nL[0] = 1\n\nfor y in Y:\n for key, value in list(L.items()):\n L[key + y] += value\n\nprint((L[0] - 1))\n", "n,a,*l=map(int,open(0).read().split())\nR=2500\ndp=[[0]*R*2,[0]*R*2]\ndp[0][0]=1\nfor i in range(n):\n for s in range(-R,R):\n dp[i+1&1][s]=dp[i&1][s]+dp[i&1][s-l[i]+a]\nprint(dp[n&1][0]-1)", "n,a=map(int,input().split())\nx=list(map(int,input().split()))\ndp=[[0]*(n*a+1) for i in range(n+1)]\ndp[0][0]=1\nans=0\nfor i in x:\n for j in range(n,0,-1):\n for k in range(n*a,i-1,-1):\n dp[j][k]+=dp[j-1][k-i]\nfor i in range(1,n+1):\n ans+=dp[i][i*a]\nprint(ans)", "def resolve():\n N, A = list(map(int, input().split()))\n X = [int(i) - A for i in input().split()]\n d = {0: 1}\n for x in X:\n for _sum, count in list(d.items()):\n d[_sum+x] = d.get(_sum+x, 0) + count\n\n print((d[0]-1))\n \n\n\nif '__main__' == __name__:\n resolve()\n\n", "n,a=list(map(int,input().split()))\nx=list(map(int,input().split()))\nfor i in range(n):\n x[i]-=a\n# dp[i][j] = i\u756a\u76ee\u307e\u3067\u3067(j-2500)\u3092\u4f55\u500b\u4f5c\u308c\u308b\u304b\ndp=[[0]*5001 for i in range(n+1)]\ndp[0][2500]=1\nfor i in range(n):\n for j in range(5000):\n for k in range(2):\n if 0<=j-k*x[i]<=5000:\n dp[i+1][j]+=dp[i][j-k*x[i]]\nprint((dp[n][2500]-1))\n", "n,a=list(map(int,input().split()))\nx=list(map(int,input().split()))\nfor i in range(n):\n x[i]-=a\n# dp[i][j] = i\u756a\u76ee\u307e\u3067\u3067(j-2500)\u3092\u4f55\u500b\u4f5c\u308c\u308b\u304b\ndp=[[0]*5001 for i in range(n)]\ndp[0][x[0]+2500]=1\nfor i in range(1,n):\n dp[i][x[i]+2500]=1\n for j in range(5000):\n for k in range(2):\n if 0<=j-k*x[i]<=5000:\n dp[i][j]+=dp[i-1][j-k*x[i]]\nprint((dp[n-1][2500]))\n", "def main():\n N, A = list(map(int, input().split()))\n x = list(map(int, input().split()))\n dp = [[0] * (50*N + 1) for _ in range(N+1)]\n dp[0][0] = 1\n for k in range(N):\n for i in reversed(list(range(k+1))):\n for j in range(50 * N + 1 -x[k]):\n dp[i+1][j+x[k]] += dp[i][j]\n r = 0\n for i in range(1, N+1):\n r += dp[i][i*A]\n return r\nprint((main()))\n", "N, A = map(int, input().split())\nx = list(map(int, input().split()))\nmaxX = max(max(x), A)\ndp = [[[0 for _ in range(N * maxX + 1)] for _ in range(N + 1)] for _ in range(N + 1)]\ndp[0][0][0] = 1\nfor i in range(N):\n for j in range(N + 1):\n for k in range(N * A + 1):\n if dp[i][j][k] == 0: continue\n dp[i + 1][j][k] += dp[i][j][k]\n dp[i + 1][j + 1][k + x[i]] += dp[i][j][k]\n\nans = 0\nfor i in range(1, N + 1):\n ans += dp[N][i][A * i]\nprint(ans)", "import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom heapq import heappush, heappop\nfrom functools import reduce, lru_cache\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(): return list(map(int, input().split()))\ndef TUPLE(): return tuple(map(int, input().split()))\ndef ZIP(n): return list(zip(*(MAP() for _ in range(n))))\nsys.setrecursionlimit(10 ** 9)\nINF = 10**6#float('inf')\nmod = 10 ** 9 + 7 \n#mod = 998244353\n#from decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nN, A = MAP()\nx = LIST()\n\nbig = []\nsmall = []\ncnt = 0\n\nfor y in x:\n\tif y == A:\n\t\tcnt += 1\n\telif y < A:\n\t\tsmall.append(A-y)\n\telse:\n\t\tbig.append(y-A)\n\nbig_possible = [0]*2501\nsmall_possible = [0]*2501\nbig_possible[0] = 1\nsmall_possible[0] = 1\n\nfor a in big:\n\tfor i in range(2500-a, -1, -1):\n\t\tif big_possible[i]:\n\t\t\tbig_possible[i+a] += big_possible[i]\n\nfor b in small:\n\tfor i in range(2500-b, -1, -1):\n\t\tif small_possible[i]:\n\t\t\tsmall_possible[i+b] += small_possible[i]\n\nans = 1\nfor i in range(1, 2501):\n\tans += small_possible[i]*big_possible[i]\n\n\nans *= 2**cnt\nprint((ans-1))\n", "n,a = map(int, input().split())\nX = list(map(int, input().split()))\nx = [i-a for i in X]\ndp = [[0]*5201 for i in range(n+1)]\ndp[0][2600] = 1 \nfor i,xi in enumerate(x):\n for k in range(99,5101):\n dp[i+1][k+xi] += dp[i][k] \n dp[i+1][k] += dp[i][k]\nans = dp[n][2600] - 1\nprint(ans)", "N,A = map(int,input().split())\nY = list(map(lambda x:int(x)-A,input().split()))\ndp = {0:1}\n\nfor y in Y:\n\tfor k,v in list(dp.items()):\n\t\tdp[k+y]=dp.get(k+y,0)+v\n\nprint(dp[0]-1)", "N,A = list(map(int,input().split()))\nY = list([int(x)-A for x in input().split()])\ndp = {0:1}\n\nfor y in Y:\n\tfor k,v in list(dp.items()):\n\t\tdp[k+y]=dp.get(k+y,0)+v\n\nprint((dp[0]-1))\n", "n, a = map(int, input().split())\nxlst = list(map(int, input().split()))\ndp = [[0 for _ in range(5001)] for _ in range(n + 1)]\ncenter = 2500\ndp[0][center] = 1\nfor i, x in enumerate(xlst, 1):\n num = x - a\n for j in range(5001):\n dp[i][j] = dp[i - 1][j]\n if 0 <= j - num <= 5000:\n dp[i][j] += dp[i - 1][j - num]\nprint(dp[-1][center] - 1)", "from collections import defaultdict\nn, a = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\nx = list(map(lambda x:x - a, x))\ndic = defaultdict(int)\ndic[0] = 1\nfor i in x:\n for j, k in list(dic.items()):\n dic[j + i] = dic.get(j + i, 0) + k\nprint(dic[0] - 1)", "from collections import defaultdict\n\nN, A = map(int, input().split())\nX = list(map(int, input().split()))\nX =[x - A for x in X]\n\nd = defaultdict(int)\nd[0] = 1\n\nfor x in X:\n for k, v in list(d.items()):\n d[k+x] += v\n\nprint(d[0]-1)", "n, a = map(int, input().split())\nx = [int(x) for x in input().split()]\n\ndp = [[0]*2501 for _ in range(n+1)]\nfor i in range(n+1):\n for j in range(i-1, -1, -1):\n if j == 0:\n dp[j+1][x[i-1]] += 1\n for k in range(2500, -1, -1):\n if dp[j][k] and k+x[i-1] <= 2500:\n dp[j+1][k+x[i-1]] += dp[j][k]\n\nans = 0\nfor i in range(1, n+1):\n ans += dp[i][i*a]\nprint(ans)", "import sys\nimport numpy as np\n\nn, a, *x = map(int, sys.stdin.read().split())\n\ndef main():\n m = 2500\n dp = np.zeros((n + 1, m + 1), dtype=np.int64)\n dp[0, 0] = 1\n for i in range(n):\n ndp = np.copy(dp)\n for j in range(1, n + 1):\n ndp[j][x[i]:] += dp[j-1][:m-x[i]+1]\n dp = ndp\n i = np.arange(1, n + 1)\n print(np.sum(dp[i, i * a]))\n\nif __name__ == '__main__':\n main()", "_,a,*l=map(int,open(0).read().split())\nd={0:1}\nfor i in l:\n for k,v in d.copy().items(): d[i-a+k]=d.get(i-a+k,0)+v\nprint(d[0]-1)", "n, a = list(map(int, input().split()))\nx = list(map(int, input().split()))\nMAX = 50 * n\n\ndp = [[[0] * (MAX + 1) for _ in range(n + 1)] for _ in range(n + 1)]\ndp[0][0][0] = 1\n\nfor i, e in enumerate(x, 1):\n for j in range(i):\n for k in range(MAX + 1):\n dp[i][j][k] += dp[i-1][j][k]\n\n for j in range(i):\n for k in range(MAX - e + 1):\n dp[i][j+1][k+e] += dp[i-1][j][k]\n\nans = 0\nfor cnt in range(1, n + 1):\n sm = cnt * a\n ans += dp[n][cnt][sm]\n\nprint(ans)\n", "N,A = (int(T) for T in input().split())\nX = [int(T)-A for T in input().split()]\nDP = [[0]*(2*(50*N)+1) for TI in range(0,N+1)]\nDP[0][50*N] = 1\nfor TI in range(0,N):\n for TS in range(0,2*50*N+1):\n if DP[TI][TS]!=0:\n DP[TI+1][TS] += DP[TI][TS]\n DP[TI+1][TS+X[TI]] += DP[TI][TS]\nprint(DP[N][50*N]-1)", "import sys\nimport numpy as np\n\nn, a, *x = map(int, sys.stdin.read().split())\n\ndef main():\n m = 2500\n dp = np.zeros((n + 1, m + 1), dtype=np.int64)\n dp[0, 0] = 1\n for i in range(n):\n dp[1:, x[i]:] += dp[:-1, :-x[i]].copy()\n i = np.arange(1, n + 1)\n print(dp[i, i * a].sum())\n\nif __name__ == '__main__':\n main()", "n, a = list(map(int, input().split()))\nX = tuple(map(int, input().split()))\ndp = [[[0] * (2550) for _ in range(n+1)] for _ in range(n+1)]\ndp[0][0][0] = 1\nfor i in range(n):\n # i\u679a\u76ee\u307e\u3067\u3067\n for j in range(n):\n # j\u679a\u306e\u30ab\u30fc\u30c9\u3092\u9078\u3093\u3067\n for s in range(n*a+1):\n # \u5408\u8a08\u304cs\u306b\u306a\u308b\u30d1\u30bf\u30fc\u30f3\n if dp[i][j][s] == 0:\n continue\n # i\u679a\u76ee\u306e\u30ab\u30fc\u30c9\u304c\u9078\u3070\u308c\u306a\u3044\u5834\u5408\n dp[i+1][j][s] += dp[i][j][s]\n # i\u679a\u76ee\u306e\u30ab\u30fc\u30c9\u304c\u9078\u3070\u308c\u308b\u5834\u5408\n dp[i+1][j+1][s+X[i]] += dp[i][j][s]\nans = 0\nfor k in range(1, n+1):\n ans += dp[n][k][k*a]\nprint(ans)\n", "N, A = list(map(int, input().split()))\nlst = [int(x) - A for x in input().split()]\ndp = [[0] * (100 * N + 1) for _ in range(N + 1)]\ndp[0][50 * N] = 1\nfor i in range(N):\n for j in range(50, 100 * N + 1 - 50):\n dp[i + 1][j] = dp[i][j] + dp[i][j - lst[i]]\nprint((dp[N][50 * N] - 1))\n", "N,A=map(int,input().split())\nx=list(map(int,input().split()))\ndp=[[[0]*(2501) for i in range(N+1)] for k in range(N+1)]\ndp[0][0][0]=1\nfor j in range(N):\n for k in range(N):\n for i in range(2501):\n if dp[j][k][i]==0:\n continue\n dp[j+1][k][i]+=dp[j][k][i]\n dp[j+1][k+1][i+x[j]]+=dp[j][k][i]\nans=0\nfor j in range(N+1):\n ans+=dp[N][j][j*A]\nprint(ans-1)"] | {"inputs": ["4 8\n7 9 8 9\n", "3 8\n6 6 9\n", "8 5\n3 6 2 8 7 6 5 9\n", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n"], "outputs": ["5\n", "0\n", "19\n", "8589934591\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 53,526 | |
9e6962d27702269fb46808ec3304631c | UNKNOWN | You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
- Append a_i to the end of b.
- Reverse the order of the elements in b.
Find the sequence b obtained after these n operations.
-----Constraints-----
- 1 \leq n \leq 2\times 10^5
- 0 \leq a_i \leq 10^9
- n and a_i are integers.
-----Input-----
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n
-----Output-----
Print n integers in a line with spaces in between.
The i-th integer should be b_i.
-----Sample Input-----
4
1 2 3 4
-----Sample Output-----
4 2 1 3
- After step 1 of the first operation, b becomes: 1.
- After step 2 of the first operation, b becomes: 1.
- After step 1 of the second operation, b becomes: 1, 2.
- After step 2 of the second operation, b becomes: 2, 1.
- After step 1 of the third operation, b becomes: 2, 1, 3.
- After step 2 of the third operation, b becomes: 3, 1, 2.
- After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.
- After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.
Thus, the answer is 4 2 1 3. | ["n = int(input())\na = list(map(int, input().split()))\no = [a[i] for i in range(0,n,2)]\ne = [a[h] for h in range(1,n,2)]\nif n%2 == 0:\n e.reverse()\n l = e + o\n print(*l)\nelse:\n o.reverse()\n l = o + e\n print(*l)", "from collections import deque\n\nn = int(input())\nA = list(map(int, input().split()))\n\nb = deque()\n\nfor i in range(1, n + 1):\n if i % 2 == 1:\n b.append(A[i - 1])\n else:\n b.appendleft(A[i - 1])\n\nif n % 2 == 1:\n for i in range(n - 1, -1, -1):\n print(b[i], end='')\n if i != 0:\n print(' ', end='')\nelse:\n for i in range(n):\n print(b[i], end='')\n if i != n - 1:\n print(' ', end='')", "#!/usr/bin/env python3\nimport queue\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n q = queue.deque()\n for i in range(n):\n if i % 2 == 1:\n q.appendleft(a[i])\n else:\n q.append(a[i])\n if n % 2 == 1:\n q.reverse()\n print(*q, sep=\" \")\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\na = list(map(str, input().split()))\nb = []\n'''\nb = [str(a[0])]\nif (n == 1):\n print(a[0])\n return\n\na = a[1:]\n\nfor i in a:\n b.append(str(i))\n b.reverse()\n'''\n'''\nloop = int(n / 2)\nloop_rest = n - loop\n\nfor i in range(loop):\n tar_index = (n - 1) - 2 * i\n tar = a[tar_index]\n\n b.append(str(tar))\n\n\nif (n % 2 == 0):\n tar_index = 0\nelse:\n tar_index = 1\n\nfor i in range(loop_rest):\n b.append(str(a[tar_index]))\n tar_index += 2\n'''\n\n# \u4e00\u3064\u304a\u304d\u3067List\u3092\u53d6\u308b\u5834\u5408\u3002\n# a[0::2]\n# 1\u3064\u76ee\uff1a\u8d77\u70b9\u3002\n# 2\u3064\u76ee\uff1aStep\n\n# a[::-1]\n# > -1step,\u3064\u307e\u308aReverse\n\nif n % 2 == 1:\n print((\" \".join((a[0::2][::-1] + a[1::2]))))\nelse:\n print((\" \".join((a[1::2][::-1] + a[0::2]))))\n", "n = int(input())\nl = list(map(int,input().split()))\nif n % 2 == 0:\n a = l[::-2]+ l[0::2]\nelse:\n a = l[::-2]+ l[1::2]\nprint(*a)", "n = int(input())\na = list(map(int, input().split()))\na1, a2 = [],[]\nfor index, i in enumerate(a, start=1):\n if index % 2 == 0:\n a2.append(i)\n else:\n a1.append(i)\n\nans = []\nif n % 2 == 0:\n ans = a2[::-1] + a1\nelse:\n ans = a1[::-1] + a2\n\nprint(\" \".join(str(i) for i in ans))", "n = int(input())\na = list(map(int,input().split()))\n\nb = [0] * n\n\nif n % 2 == 0 :\n c = n//2 - 1\nelse :\n c = n // 2\n\nb[c] = a[0]\n\nfor i in range(1,n) :\n if i % 2 == 1 :\n b[c + i] = a[i]\n c += i\n else :\n b[c - i] = a[i]\n c -= i\n\nif c != 0 :\n b.reverse()\n print(*b,sep=\" \")\nelse :\n print(*b,sep=\" \")\n", "from collections import deque\nn = int(input())\na = list(map(int, input().split()))\n\nans = deque()\nif n%2==0:\n for i in range(n):\n if i%2==1:\n ans.appendleft(a[i])\n else:\n ans.append(a[i])\nelse:\n for i in range(n):\n if i%2==0:\n ans.appendleft(a[i])\n else:\n ans.append(a[i])\n\nans = list(ans)\nprint((*ans))\n", "n = int(input())\na = list(map(int, input().split()))\n'''\nb = []\n\nfront = False\nfor i in a:\n if front:\n b.insert(0, i)\n front = False\n else:\n b.append(i)\n front = True\n\n\n\n\nif front:\n b.reverse()\n\n\nb = list(map(str, b))\nb = \" \".join(b)\nprint(b)\n'''\n\n\nfirst = a[0:n:2]\nlast = a[1:n:2]\nlast = last[::-1]\nanswer = last + first\nif n%2 != 0:\n answer = answer[::-1]\n\nprint(*answer, sep=\" \")", "from collections import deque\nn = int(input())\na = list(map(int,input().split()))\nans = deque()\ncheck = n % 2\nfor i in range(len(a)):\n if (i + check) % 2 == 0:\n ans.append(a[i])\n else:\n ans.appendleft(a[i])\nprint(*ans)", "from collections import deque\n\nb=deque()\n\nn=int(input())\na=[int(i) for i in input().split()]\n\nfor i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nb=list(b)\n\nif n%2==1:\n b=b[::-1]\nb=[str(i) for i in b]\n\nprint((\" \".join(b)))\n", "import math\nfrom math import gcd,pi,sqrt\nINF = float(\"inf\")\n\nimport sys\nsys.setrecursionlimit(10**6)\nimport itertools\nfrom collections import Counter,deque\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\n\nimport string\n\ndef main():\n n = i_input()\n a = i_list()\n even = []\n odd = []\n for i,k in enumerate(a):\n if i%2==0:\n even.append(k)\n else:\n odd.append(k)\n\n even.reverse()\n even.extend(odd)\n if n%2==0:\n even.reverse()\n print((\" \".join(map(str, even))))\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "from collections import deque\nN = int(input())\nA = list(map(int, input().split()))\ndeq = deque()\nfor i in range(N):\n if i % 2 == 0:\n deq.appendleft(A[i])\n else:\n deq.append(A[i])\nif N % 2 == 0:\n for i in reversed(range(N)):\n print(deq[i],end=\" \")\nelse:\n for i in range(N):\n print(deq[i],end=\" \")", "import collections\nN = int(input())\nlsa = list(map(str,input().split()))\nlsb = collections.deque()\nif N%2 == 0:\n for i in range(N): \n if i % 2 == 0:\n lsb.append(lsa[i])\n else:\n lsb.appendleft(lsa[i])\nif N%2 == 1:\n for i in range(N):\n if i % 2 == 1:\n lsb.append(lsa[i])\n else:\n lsb.appendleft(lsa[i])\n\nprint(' '.join(lsb))", "n = int(input())\nA = list(map(int, input().split()))\nb = [0]*n\nif n % 2 == 0:\n k = 1\nelse:\n k = -1\nindex_= int(n/2)\nfor i in range(n):\n index_ += i * k\n b[index_] = A[i]\n k *= -1\nprint(*b)", "n=int(input())\na=list(map(int,input().split()))\nans=[]\nif n%2==1:\n i=n\n while i>=1:\n ans.append(str(a[i-1]))\n i-=2\n i=2\n while i<=n:\n ans.append(str(a[i-1]))\n i+=2\n print(\" \".join(ans))\nelse:\n i = n\n while i >= 1:\n ans.append(str(a[i - 1]))\n i -= 2\n i = 1\n while i <= n:\n ans.append(str(a[i - 1]))\n i += 2\n print(\" \".join(ans))", "from collections import deque\nfrom typing import List\n\n\ndef main():\n n = int(input())\n v = input().split(\" \")\n print((*pp(n, v)))\n\n\ndef pp(n: int, v: List[str]) -> List[str]:\n x = []\n y = deque([])\n\n if n % 2 == 0:\n for i in range(n):\n if i % 2 == 0:\n y.append(v[i])\n else:\n x.append(v[i])\n else:\n for i in range(n):\n if i % 2 == 0:\n x.append(v[i])\n else:\n y.append(v[i])\n\n ret = []\n for i in range(len(x)):\n ret.append(x.pop())\n\n for i in range(len(y)):\n ret.append(y.popleft())\n\n return ret\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\na = list(map(int, input().split()))\n\nif n % 2 == 0:\n for i in range(n):\n if i < int(n / 2):\n print(a[n - 2 * i - 1],'', end = '')\n else:\n print(a[2 * i - n],'', end = '')\nelse:\n for i in range(n):\n if i <= n // 2:\n print(a[n - 2 * i - 1],'', end = '')\n else:\n print(a[2 * i - n],'', end = '')\nprint()\n", "n=int(input())\na=list(map(int,input().split()))\nodd=[]\neven=[]\nif n%2==0:\n m=n//2\n for i in range(m):\n odd.append(a[n-1-2*i])\n even.append(a[2*i])\n print(*(odd+even))\nelse:\n m=n//2\n for i in range(m):\n odd.append(a[n-1-2*i])\n even.append(a[n-2-2*i])\n even.reverse()\n odd=odd+[a[0]]\n print(*(odd+even))", "from collections import deque\n\n\ndef solve(a):\n ans = deque()\n\n for i, aa in enumerate(a):\n if i % 2 == 0:\n ans.append(str(aa))\n else:\n ans.appendleft(str(aa))\n\n if len(a) % 2 == 1:\n ans.reverse()\n\n return list(ans)\n\n\ndef __starting_point():\n n = int(input())\n a = list(map(int, input().split()))\n print((' '.join(solve(a))))\n\n__starting_point()", "n,a=int(input()),list(map(int,input().split()))\nprint(*[a[1::2][::-1]+a[::2],a[::2][::-1]+a[1::2]][n%2],sep=' ')", "from collections import deque\n\nn = int(input())\na = deque(list(map(int, input().split())))\nb = deque() if n % 2 == 0 else deque([a.popleft()])\nfor _ in range(n // 2):\n b.append(a.popleft())\n b.appendleft(a.popleft())\nprint(*b)", "n = int(input())\na_list = [int(x) for x in input().split()]\nprint(*(a_list[n-1::-2] + a_list[n % 2::2]))", "n = int(input())\na = list(map(int, input().split()))\n\na_even = a[0::2]\na_odd = a[1::2] \n\n# even\nif (n - 1) % 2 == 0: # 0-(n-1)\u306e\u5b9f\u65bd\u306a\u306e\u3067(n-1)\u306e\u5076\u5947\u3092\u5224\u5b9a\n b = a_even.copy()\n b.reverse()\n b = b + a_odd\n# odd\nelse:\n b = a_odd.copy()\n b.reverse()\n b = b + a_even\n\nb = list(map(str, b))\nprint(' '.join(b))", "#https://atcoder.jp/contests/abc066/tasks/arc077_a\nN = int(input())\nN_List = list(map(str,input().split()))\nif N % 2 == 0:\n ans = ' '.join(reversed(N_List[1::2])) + ' ' + ' '.join(N_List[::2])\nelse:\n ans = ' '.join(reversed(N_List[::2])) + ' ' + ' '.join(N_List[1::2])\n\nprint(ans)", "N = int(input())\nA = list(map(int,input().split()))\n\nfrom collections import deque\nB = deque([])\n\nrev = False\n\nfor i in range(N):\n if not rev:\n B.append(A[i])\n else:\n B.appendleft(A[i])\n rev ^= True\n \nif rev:\n B = list(B)[::-1]\n \nprint((*B))\n", "import collections\n\ndef f(myList):\n ans = ''\n if len(myList)%2==0:\n for i in range(len(myList)):\n ans += str(myList[i]) + ' '\n else:\n for i in range(len(myList)):\n ans += str(myList[-(i+1)]) + ' '\n return ans[:-1]\n\nn = int(input())\na = list(map(int,input().split()))\nb = collections.deque()\nfor i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nprint((f(b)))\n", "from collections import deque\nn = int(input())\nA = list(map(int, input().split()))\nB = deque()\n\nfor i in range(n):\n if i%2 == 0:\n B.append(A[i])\n else:\n B.appendleft(A[i])\nB = list(B) \nif n%2 != 0:\n B = B[::-1]\nprint((*B))\n\n", "n = int(input())\na = list(map(int, input().split()))\nfrom collections import deque\nd = deque()\n\n\nif len(a) %2 == 0:\n d.extend(a[::2])\n d.extendleft(a[1::2])\nelse:\n d.extend(a[1::2])\n d.extendleft(a[::2])\nprint(*list(d))", "from collections import deque\nn = int(input())\na = list(map(int,input().split()))\nb = deque()\nfor i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nif n%2 ==0:\n print(*list(b))\nelse:\n print(*list(b)[::-1])", "n = int(input())\nL = list(map(int, input().split()))\n\nif n % 2 == 0:\n A = L[n-1::-2] + L[::2]\nelse:\n A = L[n-1::-2] + L[1::2]\n \nprint(*A)", "n = int(input())\na = list(map(int, input().split()))\n\nodd, even = a[::2], a[1::2]\n\nif n % 2 == 0:\n ans = even[::-1] + odd\nelse:\n ans = odd[::-1] + even\n\nprint(*ans)", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# FileName: \tC_fix\n# CreatedDate: 2020-10-08 14:55:40 +0900\n# LastModified: 2020-10-08 15:22:52 +0900\n#\n\n\nimport os\nimport sys\n# import numpy as np\n# import pandas as pd\n\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n i = N-1\n\n if N % 2 == 1:\n while i < N:\n if i == N-1:\n print(\"{}\".format(A[i]), end='')\n else:\n print(\" {}\".format(A[i]), end='')\n if i == 0:\n i += 1\n continue\n if i % 2 == 0:\n i -= 2\n else:\n i += 2\n\n else:\n while i < N:\n if i == N-1:\n print(\"{}\".format(A[i]), end='')\n else:\n print(\" {}\".format(A[i]), end='')\n if i == 1:\n i -= 1\n continue\n if i % 2 == 0:\n i += 2\n else:\n i -= 2\n print()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys \nfrom collections import deque\nN = int(input())\nA = list(map(int, input().split()))\n\n\nif N == 1:\n print((A[0]))\n return\n\nmae = deque()\nusiro = deque()\n\n#0\u306e\u6642\u306b\u524d 1\u306e\u6642\u306b\u5f8c\u308d\nFlag = 0\n\nfor i in reversed(list(range(0,N,1))):\n \n if Flag == 0: # \u524d\u306e\u6642\n mae.append(str(A[i]))\n mae.append(\" \")\n Flag = 1\n else:\n usiro.insert(0,str(A[i]))\n usiro.appendleft(\" \")\n Flag = 0\n\nmoziretu = (mae + usiro)\ndel moziretu[((len(moziretu))//2)]\nmoziretu = ''.join(moziretu)\nprint(moziretu)\n \n \n\n\n", "n = int(input())\na = list(map(int,input().split()))\nb = []\nif n%2==0:\n for i in range(n//2):\n b.append(a[n-1-2*i])\n for i in range(n//2):\n b.append(a[2*i])\nelse:\n for i in range((n+1)//2):\n b.append(a[n-1-2*i])\n for i in range((n-1)//2):\n b.append(a[1+2*i])\nprint(*b)", "from collections import deque\nn=int(input())\na=list(map(int,input().split()))\nb=deque()\nfor i in range(n):\n if i%2:\n b.appendleft(a[i])\n else:\n b.append(a[i])\nif n%2:\n print(*reversed(list(b)))\nelse:\n print(*list(b))", "from collections import deque\n\nN=int(input())\na=list(map(int,input().strip().split()))\n\nb=deque()\nfor n in range(N):\n if n%2==0:\n b.append(a[n])\n else:\n b.appendleft(a[n])\nans=\" \".join(list(map(str,b))) if n%2==1 else \" \".join(list(map(str,list(deque(b))[::-1])))\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\no = [a[i] for i in range(2,n,2)]\ne = [a[h] for h in range(1,n,2)]\nif n%2 == 0:\n e.reverse()\n l = e + [a[0]] + o\n print(*l)\nelse:\n o.reverse()\n l = o + [a[0]] + e\n print(*l)", "n = int(input())\na = list(map(int, input().split()))\n\nif n % 2 == 0:\n b = a[n-1::-2] + a[::2]\nelse:\n b = a[n-1::-2] + a[1::2]\n\nprint(*b)", "#44 C - pushpush AC\nn = int(input())\na = list(map(int,input().split()))\n\nodd = [a[i] for i in range(n) if i%2 == 1] # O(n)\neven = [a[j] for j in range(n) if j%2 == 0]# O(n)\n\nif n%2 == 0:\n ans = list(reversed(odd)) + even # O(n)\nelse:\n ans = list(reversed(even)) + odd # O(n)\nprint(*ans)", "n = int(input())\na = list(map(int,input().split()))\nb = []\nif n%2 == 0:\n for i in range(n-1,0,-2):\n b.append(a[i])\n for i in range(0,n-1,2):\n b.append(a[i])\nelse:\n for i in range(n-1,-1,-2):\n b.append(a[i])\n for i in range(1,n-1,2):\n b.append(a[i])\nprint(*b)", "N = int(input())\nA = list(map(int,input().split()))\n\nfrom collections import deque\nB = deque([])\n\nrev = False\n\nfor i in range(N):\n if rev:\n B.appendleft(A[i])\n else:\n B.append(A[i])\n rev ^= True\n \nif rev:\n B = list(B)[::-1]\n \nprint((*B))\n", "from collections import deque\nn=int(input())\na=[int(x) for x in input().rstrip().split()]\n\nans=deque()\nfor i in range(n):\n if (i+1)%2==1:\n ans.appendleft(str(a[i]))\n else:\n ans.append(str(a[i]))\n\nans=list(ans)\nif n%2==0:\n print((*ans[::-1]))\nelse:\n print((*ans))\n", "from collections import deque\nn = int(input())\na = list(map(int, input().split()))\nb = deque([])\nfor i in range(n):\n if i % 2 == 0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nif n % 2 == 0:\n print(*list(b))\nelse:\n print(*list(b)[::-1])", "n = int(input())\nA = [a for a in input().split(\" \")]\n\nif n == 1:\n print(A[0])\nelse:\n odd = A[::2]\n even = A[1::2]\n if n % 2 == 0:\n even.reverse()\n print(\" \".join(even + odd))\n else:\n odd.reverse()\n print(\" \".join(odd + even))", "from collections import deque\nn = int(input())\na = list(input().split())\nq = deque()\nfor i in range(n):\n if n&1:\n if i&1:\n q.append(a[i])\n else:\n q.appendleft(a[i])\n else:\n if i&1:\n q.appendleft(a[i])\n else:\n q.append(a[i])\n\nfor i in q:\n print(i,end=\" \")", "from collections import deque\n\nn = int(input())\na = list(map(int, input().split()))\n\nd = deque()\nfor i in range(n):\n if n % 2 == (i + 1) % 2:\n d.appendleft(a[i])\n else:\n d.append(a[i])\n\nprint((*d))\n", "n = int(input())\na = input().split()\n \nif n % 2 == 1:\n print(\" \".join((a[0::2][::-1] + a[1::2])))\nelse:\n print(\" \".join((a[1::2][::-1] + a[0::2])))", "N = int(input())\na = list(map(int,input().split()))\n\nb = [0]*N \n\nif N % 2 == 0:\n even = N//2\n odd = even - 1\n for i in range(N):\n if i % 2 == 0:\n b[even] = str(a[i])\n even += 1\n else:\n b[odd] = str(a[i])\n odd -= 1\nelse:\n even = N//2\n odd = even + 1\n for i in range(N):\n if i % 2 == 0:\n b[even] = str(a[i])\n even -= 1\n else:\n b[odd] = str(a[i])\n odd += 1\n\nprint((' '.join(b)))\n", "n=int(input())\na=list(map(int,input().split()))\n\nodd,even=a[::2],a[1::2]\n\nif n%2==0:\n ans=even[::-1]+odd\nelse:\n ans=odd[::-1]+even\n\nprint(*ans)", "N = int(input())\nA = list(map(int,input().split()))\n\n# 0\n# 1, 0\n# 2, 0, 1\n# 3, 1, 0, 2\n# 4, 2 ,0, 1, 3\n\nans = None\nif N % 2 == 1:\n ans = A[::2][::-1] + A[1::2]\nelse:\n ans = A[1::2][::-1] + A[::2]\nprint(*ans)", "N=int(input())\nA=list(map(int,input().split()))\nprint(*A[::-2],*A[N%2::2])", "from collections import deque\n\nn = int(input())\nA = list(map(int, input().split()))\n\ndeq = deque()\nfor i in range(n):\n if i%2==0:\n deq.appendleft(A[i])\n else:\n deq.append(A[i])\nif n%2==0:\n for i in reversed(range(n)):\n print(deq[i],end=\" \")\nelse:\n for i in range(n):\n print(deq[i],end=\" \")", "from collections import deque\n\n\nN = int(input())\nAS = [int(i) for i in input().split()]\n\nb = deque()\n\nx = 0 if len(AS) % 2 == 0 else 1\n\nfor i, a in enumerate(AS):\n if i % 2 == x:\n b.append(str(a))\n else:\n b.appendleft(str(a))\n\nprint((' '.join(list(b))))\n", "n = int(input())\na = list(map(int,input().split()))\n\nq = a[::2]\np = a[1::2]\n\nif n%2 == 0:\n print(*p[::-1],*q)\nelse:\n print(*q[::-1],*p)", "n,a=int(input()),list(map(int,input().split()))\nprint(*[a[1::2][::-1]+a[::2],a[0::2][::-1]+a[1::2]][n%2],sep=' ')", "n = int(input())\na = list(map(int, input().split()))\n\nb = []\nif n%2 == 1:\n for i in a[n-1:0:-2]:\n b.append(\"{0}\".format(i))\n b.append(str(a[0]))\n for i in a[1:n:2]:\n b.append(\"{0}\".format(i))\n\nif n%2 == 0:\n for i in a[n-1:0:-2]:\n b.append(\"{0}\".format(i))\n for i in a[0:n:2]:\n b.append(\"{0}\".format(i))\n\nprint((' '.join(b)))\n", "from collections import deque\nn = int(input())\na = list(map(int,input().split()))\nb = deque()\nfor i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nif n%2==0:\n print(*b)\nelse:\n print(*reversed(b))", "N=int(input())\n*A,=map(int,input().split())\n\nif N%2==0:\n print(' '.join(map(str,A[1::2][::-1]+A[::2])))\nelse:\n print(' '.join(map(str,A[::2][::-1]+A[1::2])))", "n = 4\na = [1, 2, 3, 4]\n\nn = int(input())\na = input().split()\n\n\nif n % 2 == 0:\n y = [a[j] for j in range(1, n, 2)][::-1]\n z = [a[j] for j in range(0, n, 2)]\n\nelse:\n y = [a[j] for j in range(0, n, 2)][::-1]\n z = [a[j] for j in range(1, n, 2)]\n\nprint((\" \".join(map(str, y + z))))\n", "from collections import deque\nn = int(input())\na = list(map(int, input().split()))\nb = deque()\nreverse = 1\nfor i in range(n):\n if reverse == 1:\n b.append(a[i])\n reverse *= -1\n else:\n b.appendleft(a[i])\n reverse *= -1\n\nb_list = list(b)\nif reverse == 1:\n print(*b_list)\nelse:\n print(*b_list[::-1])", "n = int(input())\na = list(map(int, input().split()))\nfrom collections import deque\nd = deque()\n\n\nif len(a) %2 == 0:\n d.extend(a[::2])\n d.extendleft(a[1::2])\nelse:\n d.extend(a[1::2])\n d.extendleft(a[::2])\nprint((*list(d)))\n", "from collections import deque\n\nn = int(input())\na = list(map(int, input().split()))\nb = deque()\nflip = False\nfor i, x in enumerate(a):\n if flip:\n b.appendleft(x)\n else:\n b.append(x)\n flip = not flip\n\nif flip:\n b = list(reversed(b))\nprint(*b) ", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 02:46:15 2020\n\n@author: liang\n\"\"\"\n\nfrom collections import deque\n\nn = int(input())\nA = [int(x) for x in input().split()]\n\nres = deque()\n\nfor i in range(n):\n if i % 2 == 0:\n res.append(A[i])\n else:\n res.appendleft(A[i])\n \nif n % 2 == 1:\n print(\" \".join(map(str,reversed(res))))\nelse:\n print(\" \".join(map(str,res)))", "from collections import deque\nn = int(input())\n#a, b, c = map(int, input().split())\nal = list(map(int, input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\n\nq = deque([])\n\nfor i in range(1, n+1):\n if i % 2 == 0:\n q.appendleft(al[i-1])\n else:\n q.append(al[i-1])\n\nansl = list(q)\nansl = ansl[::-1] if n % 2 != 0 else ansl\n\nprint(*ansl, sep=\" \")\n", "from collections import deque\n\nn = int(input())\na_s = list(map(int, input().split()))\n\nd = deque()\n\nfor i in range(n):\n if i % 2 == 0:\n d.append(a_s[i])\n else:\n d.appendleft(a_s[i])\n\nif n%2==1:\n d.reverse()\n\nprint((' '.join(map(str, d))))\n", "from collections import deque\nfrom typing import List\n\n\ndef main():\n n = int(input())\n v = input().split(\" \")\n print((*pp(n, v)))\n\n\ndef pp(n: int, v: List[str]) -> List[str]:\n x = []\n y = deque([])\n\n if n % 2 == 0:\n for i in range(n):\n if i % 2 == 0:\n y.append(v[i])\n else:\n x.append(v[i])\n else:\n for i in range(n):\n if i % 2 == 0:\n x.append(v[i])\n else:\n y.append(v[i])\n\n x_len = len(x)\n ret = [\"\"] * (x_len + len(y))\n for i in range(x_len):\n ret[i] = x.pop()\n\n for i in range(len(y)):\n ret[x_len + i] = y.popleft()\n\n return ret\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "n = int(input())\na = list(map(int,input().split()))\n\nb = [-1] * n\nl = 0\nr = n-1\nfor i in range(n-1, -1, -1):\n if i % 2:\n b[l] = a[i]\n l += 1\n else:\n b[r] = a[i]\n r -= 1\n\nif n % 2:\n b.reverse()\nb = [str(i) for i in b]\nprint(' '.join(b))", "n=int(input())\na=list(input().split())\nfrom collections import deque\nb=deque()\nif n%2==0:\n for i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nelse:\n for i in range(n):\n if i%2==0:\n b.appendleft(a[i])\n else:\n b.append(a[i])\nB=[]\nfor i in range(n):\n B.append(b.popleft())\nprint(\" \".join(B))", "'''\nCreated on 2020/08/28\n\n@author: harurun\n'''\ndef main():\n from collections import deque\n import sys\n pin=sys.stdin.readline\n pout=sys.stdout.write\n perr=sys.stderr.write\n \n n=int(pin())\n a=list(map(int,pin().split()))\n b=deque([])\n if n%2==0:\n for i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\n else:\n for j in range(n):\n if j%2==0:\n b.appendleft(a[j])\n else:\n b.append(a[j])\n for k in range(n):\n pout(str(b[k]))\n if k!=n-1:\n pout(\" \")\n pout(\"\\n\")\n return \nmain()\n", "n = int(input())\na = [int(x) for x in input().split()]\nb = []\n\nif n % 2 == 0:\n i = n-1\n while i >= 0:\n b.append(a[i])\n i -= 2\n i = 0\n while i < n:\n b.append(a[i])\n i += 2\nelse:\n i = n-1\n while i >= 0:\n b.append(a[i])\n i -= 2\n i = 1\n while i < n:\n b.append(a[i])\n i += 2\n\nb = [str(x) for x in b]\nprint(\" \".join(b))", "n = int(input())\na = [ int(x) for x in input().split() ]\n\nl = []\nif n % 2 == 1:\n i = n-1\n while i >= 0:\n l.append(a[i])\n i -= 2\n\n j = 1\n while j < n:\n l.append(a[j])\n j += 2\nelse:\n i = n-1\n while i >= 0:\n l.append(a[i])\n i -= 2\n\n j = 0\n while j < n:\n l.append(a[j])\n j += 2\n\nprint((' '.join(map(str, l))))\n", "n = int(input())\na = list(map(int, input().split()))\n\nodd_index = []\neven_index = []\nfor i in range(n):\n if (i + 1) % 2 == 1:\n odd_index.append(a[i])\n else:\n even_index.append(a[i])\n\nif n % 2 == 1:\n res = odd_index[::-1] + even_index\nelse:\n res = even_index[::-1] + odd_index\n\nprint((*res))\n", "from collections import deque\nwith open(0) as f:\n n, *a = map(int, f.read().split())\nb = deque()\nfor idx, value in enumerate(a):\n if (idx & 1) ^ (n & 1):\n b.appendleft(value)\n else:\n b.append(value)\nprint(*b)", "n = int(input())\na_list = [int(x) for x in input().split()]\nif n % 2 == 0:\n b_list = a_list[n-1::-2] + a_list[0::2]\nelse:\n b_list = a_list[n-1::-2] + a_list[1::2]\nprint(*b_list)", "def main():\n n = int(input())\n a_lst = list(map(int, input().split()))\n lst1 = []\n lst2 = []\n\n if n % 2 == 0:\n for i in range(n // 2):\n lst1.append(a_lst[-1 - i * 2])\n for i in range(n // 2):\n lst2.append(a_lst[i * 2])\n\n else:\n for i in range(n // 2):\n lst1.append(a_lst[-1 - i * 2])\n lst2.append(a_lst[0])\n for i in range(n // 2):\n lst2.append(a_lst[1 + i * 2])\n\n lst = lst1 + lst2\n ans = ''\n for i in range(n - 1):\n ans += '{} '.format(lst[i])\n ans += '{}'.format(lst[-1])\n print(ans)\n\n\ndef __starting_point():\n main()\n__starting_point()", "n = int(input())\na_list = [int(x) for x in input().split()]\nb = []\nc = []\nfor i, a in enumerate(a_list):\n if i % 2 == 0:\n b.append(a)\n else:\n c.append(a)\nif n % 2 == 0:\n d = list(reversed(c)) + b\nelse:\n d = list(reversed(b)) + c\nprint(*d)", "n = int(input())\na_list = [int(x) for x in input().split()]\nprint(*(a_list[::-2] + a_list[n&1::2]))", "# coding: utf-8\nimport math\nfrom collections import deque\nn = int(input())\n#x, y = map(int,input().split())\nA = list(map(int,input().split()))\nans = 0\nB = deque()\nif n%2==0:\n for i in range(n):\n a=str(A[i])\n if i%2==1:\n B.appendleft(a)\n else:\n B.append(a)\nif n%2==1:\n for i in range(n):\n a=str(A[i])\n if i%2==0:\n B.appendleft(a)\n else:\n B.append(a)\nprint(' '.join(B))", "n,a=int(input()),list(map(int,input().split()))\nb=[a[1::2][::-1]+a[::2],a[0::2][::-1]+a[1::2]][n%2]\nprint(*b,sep=' ')", "from collections import deque\nwith open(0) as f:\n n, *a = map(int, f.read().split())\nb = deque()\nfor idx, value in enumerate(a):\n if (idx & 1) ^ (n & 1):\n b.appendleft(value)\n else:\n b.append(value)\nprint(*b)", "from collections import deque\nn = int(input())\na = list(map(int, input().split()))\nb = deque()\n\nfor i in range(n):\n if i%2 == 0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nif n%2 == 1:\n b.reverse()\nprint(*b, sep=' ')\n", "n = int(input())\na = list(map(int,input().split()))\nb = []\nfor i in range(n):\n b.append(0)\nk = 0\nif(n%2==1):\n k = (n-1)//2\n m = -1\nelse:\n k = n//2\n m = 1\nfor i in range(n):\n if(i%2==0):\n b[k+m*i//2]=a[i]\n else:\n b[k-m*(i+1)//2]=a[i]\nans = \"\"\nfor i in range(n):\n ans += str(b[i])+\" \"\nprint(ans) \n \n \n\n", "N=int(input())\nA=list(map(int,input().split()))\nprint(*A[::-2],*A[N%2::2])", "from collections import deque\n\nn = int(input())\na = list(map(int, input().split()))\nb = deque()\n\nfor i in range(n):\n if i % 2 == 0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\n\nif n % 2 == 1:\n b.reverse()\n\nprint((\" \".join(map(str, b))))\n", "n = int(input())\na = list(map(int, input().split()))\nb = []\nfor i in range(n, 0, -2):\n b.append(a[i - 1])\nfor j in range(i % 2, n, +2):\n b.append(a[j])\nprint((*b))\n", "n = int(input())\nla = list(map(int, input().split()))\nl1 = []\nl2 = []\nfor i in range(n):\n if i % 2 == 0:\n l1.append(la[i])\n else:\n l2.append(la[i])\n\nif n % 2 == 0:\n for i in reversed(l2):\n print(i, end=' ')\n for i in l1:\n print(i, end=' ')\nelse:\n for i in reversed(l1):\n print(i, end=' ')\n for i in l2:\n print(i, end=' ')", "from collections import deque\nn,a,b=int(input()),deque(map(int,input().split())),deque()\nfor i in range(n):\n if n%2==0:\n if i%2==0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\n else:\n if i%2==0:\n b.appendleft(a[i])\n else:\n b.append(a[i])\nprint(*b,sep=' ')", "n=int(input())\na=list(map(str,input().split()))\nb,c=[],[]\nif n%2==0:\n for i in range(n):\n if i%2==0:\n b.append(a[i])\n else:\n c.append(a[i])\n c.reverse()\nelse:\n for i in range(n):\n if i%2==1:\n b.append(a[i])\n else:\n c.append(a[i])\n c.reverse()\nprint(\" \".join(c+b))", "from collections import deque\nimport sys\n\n\nstdin = sys.stdin\ndef ns(): return stdin.readline().rstrip()\ndef ni(): return int(stdin.readline().rstrip())\ndef nm(): return list(map(int, stdin.readline().split()))\ndef nl(): return list(map(int, stdin.readline().split()))\n\n\ndef main():\n n = ni()\n A = nl()\n A = deque(A)\n B = deque()\n if n % 2 == 0:\n while A:\n B.append(A.popleft())\n B.appendleft(A.popleft())\n B = list(B)\n print((*B))\n else:\n while len(A) != 1:\n B.append(A.popleft())\n B.appendleft(A.popleft())\n B.append(A.popleft())\n B = list(B)[::-1]\n print((*B))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "N = int(input())\nA = list(map(int,input().split()))\n\n# 0\n# 1, 0\n# 2, 0, 1\n# 3, 1, 0, 2\n# 4, 2 ,0, 1, 3\n\nfront = []\nback = []\n\nfor i in range(N):\n if i % 2 == 0:\n back.append(A[i])\n else:\n front.append(A[i])\n \nans = None\nif N % 2 == 0:\n ans = front[::-1] + back\nelse:\n ans = back[::-1] + front\n \nprint(*ans)", "n = int(input())\naa = list(map(int, input().split()))\nif n % 2 == 0:\n a = aa[n-1:0:-2]+aa[0:n-1:2]\nelse:\n a = aa[n-1::-2]+aa[1:n-1:2]\nprint(*a)", "n=int(input())\na=list(map(int,input().split()))\n\nif n%2==0:\n S=a[-1::-2]+a[::2]\n for x in S:\n print(x,end=' ')\nelse:\n S=a[-1::-2]+a[1::2]\n for x in S:\n print(x,end=' ')\nprint()\n", "n = int(input())\nA = list(input().split())\n\nif (n - 1) % 2 == 0:\n top = [\"\"] * ((n - 1) // 2)\n bottom = [\"\"] * ((n - 1) // 2)\n \n t = (n - 1) // 2 - 1\n b = 0\n for i in range(1,n):\n if i % 2 == 1:\n bottom[b] = A[i]\n b += 1\n else:\n top[t] = A[i]\n t -= 1\nelse:\n top = [\"\"] * ((n - 1) // 2 + 1)\n bottom = [\"\"] * ((n - 1) // 2)\n \n t = (n - 1) // 2\n b = 0\n \n for j in range(1,n):\n if j % 2 == 1:\n top[t] = A[j]\n t -= 1\n else:\n bottom[b] = A[j]\n b += 1\n \nprint(*(top + [A[0]] + bottom))", "n=int(input())\na=list(map(int,input().split()))\n\neven = [a[i] for i in range(1,n,2)]\nodd = [a[i] for i in range(0,n,2)]\n\nif n % 2 == 0:\n print(*(even[::-1]+odd))\nelse:\n print(*(odd[::-1]+even))", "from collections import deque\nn = int(input())\na = list(map(int,input().split()))\nb_1 = deque()\nb_2 = deque()\nswitch = 0\nfor i in a:\n if switch == 0:\n b_1.append(i)\n b_2.appendleft(i)\n switch = 1\n else:\n b_2.append(i)\n b_1.appendleft(i)\n switch = 0\nb_1 = list(b_1)\nb_2 = list(b_2)\nif switch == 0:\n print((' '.join(list(map(str,b_1)))))\nelse:\n print((' '.join(list(map(str,b_2)))))\n"] | {"inputs": ["4\n1 2 3 4\n", "3\n1 2 3\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["4 2 1 3\n", "3 1 2\n", "1000000000\n", "0 6 6 0 7 7\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 32,843 | |
7a9a48a679e3dad1c4764b2b7dd011f3 | UNKNOWN | Raccoon is fighting with a monster.
The health of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.
-----Constraints-----
- 1 \leq H \leq 10^9
- 1 \leq N \leq 10^5
- 1 \leq A_i \leq 10^4
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N
-----Output-----
If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.
-----Sample Input-----
10 3
4 5 6
-----Sample Output-----
Yes
The monster's health will become 0 or below after, for example, using the second and third moves. | ["h, n = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nif h <= sum(a):\n print('Yes')\nelse:\n print('No')\n", "H, N = map(int, input().split())\nlst = list(map(int, input().split()))\n\nfor i in range (0, N):\n H -= lst[i]\n\nif H <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\n\nprint(('Yes' if H - sum(A) <= 0 else \"No\"))\n", "h,n=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(n):\n h=h-a[i]\nif h<=0:\n print(\"Yes\")\nelse:\n print(\"No\")", "H,N = map(int,input().split())\nlsA = list(map(int,input().split()))\nprint('Yes' if H <= sum(lsA) else 'No')", "import numpy as np\n\nH,N=map(int,input().split())\nA=np.array(list(map(int,input().split())))\n\nif H<=np.sum(A):\n print('Yes')\nelse:\n print('No')", "H,N =list(map(int,input().split()))\nA = list(map(int,input().split()))\na_sum =sum(A)\n\nif sum(A) - H >= 0:\n print('Yes')\nelse:\n print('No')\n", "h,n = map(int,input().split())\nxlist = list(map(int,input().split()))\nif sum(xlist)>=h:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n = map(int, input().split())\nA = list(map(int, input().split()))\n\ntot = sum(A)\nhp = h - tot\nif(hp <= 0) :\n print(\"Yes\")\nelse :\n print(\"No\")", "h, n = map(int, input().split())\nA = list(map(int, input().split()))\nflag = False\n\nfor a in A:\n h -= a\n if h<=0:\n flag = True\n break\n\nprint(\"Yes\" if flag else \"No\")", "def main():\n\th, n = list(map(int, input().split()))\n\tl = [int(v) for v in input().split()]\n\ttotal = sum(l)\n\tif total>= h:\n\t\treturn \"Yes\"\n\treturn \"No\"\t\n\ndef __starting_point():\n print((main()))\n\n__starting_point()", "H,N = map(int,input().split())\nA = map(int,input().split())\nif H <= sum(A):\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = map(int, input().split())\nA_list = []\nfor i in range(1, N+1):\n A_list.append(\"A_\" + str(i))\n\nA_list = map(int, input().split())\nA_total = sum(A_list)\n\nif A_total >= H:\n print(\"Yes\")\nelse:\n print(\"No\") ", "H,N=map(int,input().split())\nList=list(map(int,input().split()))\n\nSum=sum(List)\n\nif H <= Sum:\n print(\"Yes\")\nelse:\n print(\"No\")", "#\u30a2\u30e9\u30a4\u30b0\u30de\u306f\u30e2\u30f3\u30b9\u30bf\u30fc\u3068\u6226\u3063\u3066\u3044\u307e\u3059\u3002\n# \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u306f H \u3067\u3059\u3002\n#\u30a2\u30e9\u30a4\u30b0\u30de\u306f N \u7a2e\u985e\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u3001\n#i \u756a\u76ee\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3068\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092 Ai \u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n#\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092 0 \u4ee5\u4e0b\u306b\u3059\u308c\u3070\u30a2\u30e9\u30a4\u30b0\u30de\u306e\u52dd\u3061\u3067\u3059\u3002\n\nH,N=map(int,input().split())\nA = list(map(int,input().split()))\n\nif H - sum(A) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", " \nH, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nif H - sum(A) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "N,M = map(int,input().split())\nattack = list(map(int,input().split()))\nif sum(attack) >= N:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n=map(int,input().split())\nl=list(map(int,input().split()))\na=0\nfor i in range(n):\n a+=l[i]\nif a>=h:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n=map(int,input().split());print('YNeos'[sum(map(int,input().split()))<h::2])", "h = input()\nh = h.split()\nn = int(h[1])\nh = int(h[0])\na = input()\na = a.split()\nc = int(a[0])\nfor b in range(n-1):\n c = c + int(a[b+1])\nif h>c:\n print(\"No\")\nelse:\n print(\"Yes\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nAA = sum(A)\n\nif AA >= H:\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\nA1 = sum(A)\n\nif H - A1 <= 0:\n print('Yes')\nelse:\n print('No')", "H,N = map(int,input().split())\ni = map(int,input().split())\n\nif sum(i) >= H :\n print(\"Yes\")\nelse :\n print(\"No\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\nif sum(A) >= H:\n print('Yes')\nelse:\n print('No')", "H, N = map(int, input().split())\nA = map(int, input().split())\na_sum = sum(A)\n\nif H - a_sum <= 0:\n print('Yes')\nelse:\n print('No')", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\nsum = 0\nfor i in range(N):\n sum += A[i]\nif sum >= H:\n print('Yes')\nelse:\n print('No')", "h,n = map(int,input().split())\nli = list(map(int,input().split()))\nif h <= sum(li):\n print('Yes')\nelse:\n print('No')", "h,n=map(int, input().split())\n\nA=list(map(int,input().split()))\n\n\nprint('YNeos'[sum(A)<h::2])", "h,n = map(int,input().split())\na = list(map(int,input().split()))\nprint(\"Yes\" if sum(a) >= h else \"No\")", "H,M = map(int,input().split())\nattack = list(map(int,input().split()))\nif H - sum(attack) <=0:\n print('Yes')\nelse:\n print('No')", "H, N = [int(n) for n in input().split()]\nA = sum([int(n) for n in input().split()])\n\nprint('Yes' if A >= H else 'No')", "h,n = map(int,input().split())\na = map(int,input().split())\n\nif sum(a) >= h:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n=map(int, input().split())\na=list(map(int, input().split()))\nprint(\"Yes\" if sum(a)>=h else \"No\")", "H,N = map(int,input().split())\nA = [int(i) for i in input().split()]\nfor i in range(N):\n H -= A[i]\nif(H <= 0):\n print(\"Yes\")\nelse:\n print(\"No\")", "H,N=map(int,input().split())\nA=list(map(int,input().split()))\nsum=0\nfor i in range(len(A)):\n sum+=A[i]\nif H<=sum :\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = map(int, input().split())\nA = map(int, input().split())\n\nif H <= sum(A):\n print(\"Yes\")\nelse:\n print(\"No\")", "H,N=map(int,input().split())\nA = list(map(int,input().split()))\nif sum(A)>=H:\n print(\"Yes\")\nelse:\n print(\"No\")", "H,N = map(int,input().split())\nAlist = list(map(int,input().split()))\n\nif H>sum(Alist):\n print ('No')\nelse :\n print ('Yes')", "h,n = map(int,input().split())\na = list(map(int,input().split()))\nprint(\"Yes\" if sum(a)>=h else \"No\")", "H,M = map(int,input().split())\nattack = list(map(int,input().split()))\nif H - sum(attack) <=0:\n print('Yes')\nelse:\n print('No')", "H, N = list(map(int,input().split()))\nA = list(map(int, input().split()))\nif H<=sum(A):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "h, n = map(int, input().split())\na = list(map(int, input().split()))\nprint(\"Yes\" if sum(a) >= h else \"No\")", "\nH, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nTotal_attack = sum(A)\n\nif H - Total_attack <= 0:\n print('Yes')\n\nelse:\n print('No')", "H, N = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nprint(('Yes' if H <= sum(A) else 'No'))\n", "H, N = map(int, input().split())\n\nA = list(map(int, input().split()))\nsum_A = sum(A)\n\nif H <= sum_A:\n print(\"Yes\")\nelse:\n print(\"No\")", "\nH, N = map(int, input().split())\nA_list = []\nfor i in range(1, N+1):\n A_list.append(\"A_\" + str(i))\n\nA_list = map(int, input().split())\nA_total = sum(A_list)\n\nif A_total >= H:\n print(\"Yes\")\nelse:\n print(\"No\")", "h, n = map(int, input().split())\na = list(map(int, input().split()))\n\nprint('Yes') if sum(a)>=h else print('No')", "h,n = map(int,input().split())\nl = list(map(int,input().split()))\n\nif h-sum(l) <= 0:\n print('Yes')\nelse :\n print('No')", "H,N = map(int,input().split())\nA = map(int,input().split())\nif H <= sum(A):\n print(\"Yes\")\nelse:\n print(\"No\")", "\nH,N=map(int,input().split())\nA = list(map(int,input().split()))\n\nif H - sum(A) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "health, num = map(int, input().split())\nnum_list = [num for num in list(map(int, input().split()))]\nfor _ in num_list:\n health -= _\n \nif health > 0:\n print(\"No\")\nelse:\n print(\"Yes\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\nA1 = sum(A)\n\nif H - A1 <= 0:\n print('Yes')\nelse:\n print('No')", "h,n = map(int,input().split())\nlst = list(map(int,input().split()))\nif sum(lst) < h:\n print('No')\nelse:\n print('Yes')", "h, n = map(int, input().split())\na = list(map(int, input().split()))\n\nif h<=sum(a):\n print('Yes')\nelse:\n print('No')", "H, N = list(map(int, input().split()))\nS = sum(list(map(int, input().split())))\n\nif H <= S:\n print('Yes')\nelse:\n print('No')\n", "h,n = map(int,input().split())\na = list(map(int,input().split()))\nprint(\"Yes\" if sum(a)>=h else \"No\")", "h,m = map(int,input().split())\na = list(map(int,input().split()))\nif h - sum(a) > 0:\n print('No')\nelse:\n print('Yes')", "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\n\ndef solve():\n h, n = inl()\n a = inl()\n return sum(a) >= h\n\n\nprint(\"Yes\" if solve() else \"No\")\n\n", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nattack = sum(A)\nif attack >= H:\n print(\"Yes\")\nelse:\n print(\"No\")", "h, n = list(map(int,input().split()))\na = list(map(int,input().split()))\nhitpoint=h\natack = a[:]\nfor e in atack:\n hitpoint -= e\n if hitpoint <= 0:\n break\nif hitpoint <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nif H - sum(A) <= 0:\n print('Yes')\nelse:\n print('No')", "H,N= list(map(int,input().split())) \nA= list(map(int,input().split())) \n\nlife=H\nfor i in range(N):\n life-=A[i]\n \nif life<=0:\n print('Yes')\nelse:\n print('No')", "H,N = list(map(int,input().split()))\nA = list(map(int,input().split()))\n\nif sum(A) >= H:\n print('Yes')\nelse:\n print('No')\n", "H,N = map(int, input().split())\n\ndata = list(map(int,input().split()))\n\nif H <= sum(data):\n print('Yes')\nelse:\n print('No')", "H,N = map(int,input().split())\nA = sum(list(map(int,input().split())))\n\nif H - A <= 0:\n print('Yes')\nelse:\n print('No')", "h, n = map(int, input().split())\na = list(map(int, input().split()))\n\nif sum(a) >= h:\n print(\"Yes\")\nelse:\n print(\"No\")", "# \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529bH\n# \u30a2\u30e9\u30a4\u30b0\u30de\u306e\u5fc5\u6bba\u6280\u306e\u7a2e\u985eN\n# i\u756a\u76ee\u306e\u5fc5\u6bba\u6280\u4f7f\u3046\u3068\u3001\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529bAi\u6e1b\u3089\u305b\u308b\n\n# H - (A1 + A2 + A3...) <= 0 \u3068\u306a\u308b\u306a\u3089 'Yes',\n# \u306a\u3089\u306a\u3044\u306a\u3089'No'\u304c\u51fa\u529b\u3055\u308c\u308b\n\nh, n = map(int, input().split())\ndamage = list(map(int, input().split()))\n\nif h - sum(damage) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nfor i in range(n):\n ans+=a[i]\nif ans>=h:\n print(\"Yes\")\nelse:\n print(\"No\")", "h, n = map(int, input().split())\n\nlst = [ int(i) for i in input().split() ]\n\nif sum(lst) >= h:\n print(\"Yes\")\nelse:\n print(\"No\")", "h,n = list(map(int,input().split()))\na = list(map(int,input().split()))\nans = 0\nsum_a = sum(a)\n \nif(sum_a >= h):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "H, N = map(int, input().split())\nSkills = list(map(int, input().split()))\nTotal = sum(Skills)\n\nif H <= Total:\n print(\"Yes\")\nelse:\n print(\"No\")", "h, n = map(int, input(). split())\nlist01 = input().split()\nlist02 = [int(a) for a in list01]\nif sum(list02) >= h:\n print('Yes')\nelse:\n print('No')", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nanswer = sum(A)\n\nif answer >= H:\n print('Yes')\nelse:\n print('No')", "H, N, *A = map(int, open(0).read().split())\nprint(\"Yes\") if H <= sum(A) else print(\"No\")\n", "H,N = map(int,input().split())\nA = [int(x) for x in input().split()]\n\nfor i in range(N) :\n H = H - A[i]\n\nif H > 0 :\n print(\"No\")\nelse :\n print(\"Yes\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\nprint(\"YNeos\"[sum(A)<H::2])", "h, n = map(int, input().split())\nd = list(map(int, input().split()))\n\nif h - sum(d) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\ndef hissatu():\n HP = H -sum(A)\n if HP>0:\n return \"No\"\n else:\n return \"Yes\"\nprint(hissatu())", "h,n=map(int,input().split())\nl=list(map(int,input().split()))\ns=0\nfor i in range(n):\n s=s+l[i]\nif s>=h:\n print(\"Yes\")\nelse:\n print(\"No\")", "H, N = map(int, input().split())\nfor Ai in list(map(int, input().split())):\n H -= Ai\nif H > 0:\n print('No')\nelse:\n print('Yes')", "h,n = list(map(int,input().split()))\na = list(map(int,input().split()))\nprint(('Yes' if h <= sum(a) else 'No'))\n", "H,N = map(int, input().split())\nA = list(map(int, input().split()))\n\ns = sum(A)\nif s >= H:\n print('Yes')\nelse:\n print('No')", "H, N = map(int, input().split())\ndata = list(map(int, input().split()))\n\nif H - sum(data) > 0:\n print('No')\nelse:\n print('Yes')", "'''\n\u554f\u984c\uff1a\n \u30a2\u30e9\u30a4\u30b0\u30de\u306f\u30e2\u30f3\u30b9\u30bf\u30fc\u3068\u6226\u3063\u3066\u3044\u307e\u3059\u3002\n\n \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u306f H \u3067\u3059\u3002\n \u30a2\u30e9\u30a4\u30b0\u30de\u306f N \u7a2e\u985e\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u3001\n i \u756a\u76ee\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3068\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092 Ai \u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n \u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u4ee5\u5916\u306e\u65b9\u6cd5\u3067\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092\u6e1b\u3089\u3059\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\n\n \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092 0 \u4ee5\u4e0b\u306b\u3059\u308c\u3070\u30a2\u30e9\u30a4\u30b0\u30de\u306e\u52dd\u3061\u3067\u3059\u3002\n\n \u30a2\u30e9\u30a4\u30b0\u30de\u304c\u540c\u3058\u5fc5\u6bba\u6280\u3092\n 2 \u5ea6\u4ee5\u4e0a\u4f7f\u3046\u3053\u3068\u306a\u304f\u30e2\u30f3\u30b9\u30bf\u30fc\u306b\u52dd\u3064\u3053\u3068\u304c\u3067\u304d\u308b\u306a\u3089 Yes \u3092\u3001\n \u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n'''\n\n'''\n\u5236\u7d04\uff1a\n 1 \u2266 H \u2266 1000000000\n 1 \u2266 N \u2266 100000\n 1 \u2266 Ai \u2266 10000\n \u5165\u529b\u4e2d\u306e\u3059\u3079\u3066\u306e\u5024\u306f\u6574\u6570\u3067\u3042\u308b\u3002\n'''\n\n# \u6a19\u6e96\u5165\u529b\u304b\u3089 H, N, Ai \u3092\u53d6\u5f97\u3059\u308b\nh, m = list(map(int, input().split()))\na = list(map(int, input().split()))\n\n# \u5fc5\u6bba\u6280\u30921\u56de\u305a\u3064\u4f7f\u3063\u305f\u5834\u5408\u3001\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092\u3069\u308c\u3060\u3051\u524a\u308c\u308b\u304b\u8a08\u7b97\u3059\u308b\nhissatsu_hp = 0\nfor i in range(0, m):\n hissatsu_hp += a[i]\n\n# \u540c\u3058\u5fc5\u6bba\u6280\u3092\u4f7f\u308f\u305a\u30a2\u30e9\u30a4\u30b0\u30de\u3092\u5012\u305b\u308b\u304b\u5224\u5b9a\u3057\u3066\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\nresult = \"\"\nif hissatsu_hp >= h:\n result = \"Yes\"\nelse:\n result = \"No\"\n\nprint(result)\n", "attack = []\nh, n = map(int, input().split())\na = input().split()\n\nfor move in a:\n move = int(move)\n attack.append(move)\n\nresult = h - sum(attack)\nif result <= 0:\n print('Yes')\nelse:\n print('No')", "H,N=list(map(int,input().split()))\nA=list(map(int,input().split()))\nA1=sum(A)\n\nif H-A1<=0:\n print('Yes')\nelse:\n print('No')\n", "h,n = map(int,input().split())\na = list(map(int,input().split()))\nif sum(a) < h:\n print('No')\nelse:\n print('Yes')", "H,N=list(map(int,input().split()))\nA=list(map(int,input().split()))\ns=0\nflg=True\nfor i in range(N):\n s+=A[i]\n if s>=H:\n print('Yes')\n flg=False\n break\nif flg:\n\tprint('No')\n", "h, n = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nhp = 0\nresult = 'No'\n\nfor i in range(n):\n hp = hp + a[i]\n if hp >= h:\n result = 'Yes'\n break\n\nprint(result)\n", "H, M = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\n\na = (sum(A))\n\nif a >= H:\n ans = \"Yes\"\nelse:\n ans = \"No\"\n\nprint(ans)\n", "# B - Common Raccoon vs Monster\n\n# H N\nH, N = list(map(int, input().split()))\nmy_list = list(map(int, input().split(maxsplit=N)))\n\nif H <= sum(my_list):\n answer = 'Yes'\nelse:\n answer = 'No'\n\nprint(answer)\n", "H,N = list(map(int, input() .split()))\nA = list(map(int,input().split()))\nif H <= sum(A):\n print('Yes')\nelse:\n print('No')\n", "h, n = map(int, input().split())\na = list(map(int, input().split()))\n\nx = sum(a)\n\nif (h - x) <= 0:\n print('Yes')\nelse:\n print('No')", "# \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u306f H\n# \u30a2\u30e9\u30a4\u30b0\u30de\u306f N \u7a2e\u985e\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\n# i\u756a\u76ee\u306e\u5fc5\u6bba\u6280\u3092\u4f7f\u3046\u3068\u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u3092 Ai \u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n# \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u30920\u4ee5\u4e0b\u306b\u3059\u308c\u3070\u3001\u30a2\u30e9\u30a4\u30b0\u30de\u52dd\u3061\n# \u30a2\u30e9\u30a4\u30b0\u30de\u304c\u540c\u3058\u5fc5\u6bba\u6280\u3092 2 \u5ea6\u4ee5\u4e0a\u4f7f\u3046\u3053\u3068\u306a\u304f\u30e2\u30f3\u30b9\u30bf\u30fc\u306b\u52dd\u3064\u3053\u3068\u304c\u3067\u304d\u308b\u306a\u3089 Yes \u3092\u3001\n# \u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\nH, N = list(map(int, input().split()))\ndata = list(map(int, input().split()))\n\nif H - sum(data) > 0:\n print('No')\nelse:\n print('Yes')\n", "H, N = map(int, input().split())\nA = list(map(int, input().split()))\n\nif H - sum(A) <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "#ABC153B\nh,n = map(int,input().split())\na = list(map(int,input().split()))\nprint(\"Yes\" if sum(a) >= h else \"No\")", "import math\nH,N = map(int,input().split())\nA = list(map(int,input().split()))\n\nif H <= sum(A):\n print(\"Yes\")\nelse:\n print(\"No\")", "# \u30e2\u30f3\u30b9\u30bf\u30fc\u306e\u4f53\u529b\u306f H\n# \u30a2\u30e9\u30a4\u30b0\u30de\u306e\u5fc5\u6bba\u6280\u306f N \u7a2e\u985e\n# \u30a2\u30e9\u30a4\u30b0\u30de\u304c\u540c\u3058\u5fc5\u6bba\u6280\u3092 2 \u5ea6\u4ee5\u4e0a\u4f7f\u3046\u3053\u3068\u306a\u304f\n# \u30e2\u30f3\u30b9\u30bf\u30fc\u306b\u52dd\u3064\u3053\u3068\u304c\u3067\u304d\u308b\u306a\u3089 Yes \u3092\u3001\n# \u3067\u304d\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u3002\n\nH, N = map(int,input().split())\nA = list(map(int,input().split()))\nanswer = sum(A)\n\nif H <= answer :\n print( \"Yes\" )\nelse:\n print( \"No\" )", "H,N=map(int,input().split())\nA=list(map(int,input().split()))\nif sum(A)>=H:\n print('Yes')\nelse:\n print('No')"] | {"inputs": ["10 3\n4 5 6\n", "20 3\n4 5 6\n", "210 5\n31 41 59 26 53\n", "211 5\n31 41 59 26 53\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 19,640 | |
ff7380686244938cb505c853846eeb4c | UNKNOWN | We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.
You are given an even string S consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S.
It is guaranteed that such a non-empty string exists for a given input.
-----Constraints-----
- 2 \leq |S| \leq 200
- S is an even string consisting of lowercase English letters.
- There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.
-----Input-----
Input is given from Standard Input in the following format:
S
-----Output-----
Print the length of the longest even string that can be obtained.
-----Sample Input-----
abaababaab
-----Sample Output-----
6
- abaababaab itself is even, but we need to delete at least one character.
- abaababaa is not even.
- abaababa is not even.
- abaabab is not even.
- abaaba is even. Thus, we should print its length, 6. | ["S = input()\nx = len(S)\n\nfor i in range(0, x, 2):\n y = x - 2 - i\n if S[:y//2] == S[y//2 : y]:\n \n print(len(S[:y]))\n break", "S = input()\nN = len(S)\n\nfor i in range(N-1,0,-1):\n if i % 2 == 1:\n continue\n if S[:i//2] == S[i//2:i]:\n ans = i\n break\n \nprint(ans)", "n = input()\nnum = len(n)-2\nfor i in range(num,0,-2):\n f = int(i/2)\n if n[:f]==n[f:i]:\n print(i)\n break", "s = input()\nnum = len(s)-2\nfor i in range(num,0,-2):\n f = int(i / 2)\n if s[:f] == s[f:i]:\n print(i)\n break", "s = input()\nfor i in range(len(s)):\n s = s[:-1]\n if len(s) % 2 == 0:\n if s[:len(s) // 2] ==s[len(s) // 2:]:\n print(len(s))\n break", "import sys\nS = input()\nans = 0\n\n\nfor i in range(len(S)//2):\n S = S[:len(S)-2]\n #print(S)\n count = 0\n for j in range(len(S)//2):\n if S[j] != S[len(S)//2+j]:\n break\n else:\n count += 1\n if count == len(S)//2:\n print((len(S)))\n return\n\n", "import sys\nimport copy\nimport math\nimport itertools\nimport numpy as np\nS=input()\nfor i in range(1,len(S)):\n l = len(S[0:len(S)-i]) \n if l%2==0:\n if S[0:len(S)-i] == S[0:int(l/2)]+S[0:int(l/2)]:\n print(l)\n return", "s = input()\ns = s[0: -1]\nfor i in range(len(s)):\n l = len(s)\n if s[0: l // 2] == s[l // 2:]:\n print(len(s))\n break\n s = s[0: -1]", "# -*- coding: utf-8 -*-\nimport numpy as np\nimport sys\nfrom collections import deque\nfrom collections import defaultdict\nimport heapq\nimport collections\nimport itertools\nimport bisect\nfrom scipy.special import comb\nimport copy\nsys.setrecursionlimit(10**6)\n\n\ndef zz():\n return list(map(int, sys.stdin.readline().split()))\n\n\ndef z():\n return int(sys.stdin.readline())\n\n\ndef S():\n return sys.stdin.readline()[:-1]\n\n\ndef C(line):\n return [sys.stdin.readline() for _ in range(line)]\n\n\ndef check(s):\n if (s[len(s) // 2:] == s[:len(s) // 2]):\n print((len(s)))\n return\n\n\nS = S()\nn = len(S)\nif (n % 2 == 0):\n while S:\n S = S[:-2]\n check(S)\nelse:\n S = S[:-1]\n check(S)\n while S:\n S = S[:-2]\n check(S)\n", "S = list(input())\n\nfor _ in range(len(S)-1):\n del S[-1]\n if S[:int(len(S)/2)] == S[int(len(S)/2):]:\n break\n \nprint(len(S))", "s = str(input())\nsl = list(s)\nans = 0\ndel sl[-1]\nfor i in range(1,len(sl)):\n if(len(sl)%2==0):\n if(sl[:len(sl)//2]==sl[len(sl)//2:]):\n ans = len(sl)\n break\n del sl[-1] \nprint(ans)\n \n\n", "S=input()\n\nfor i in range(1, len(S)):\n s=S[0:len(S)-i]\n #print(s)\n if len(s)%2==1:\n continue\n #print('pre', s[0:int(len(s)/2)+1])\n #print('follow', s[int(len(s)/2):len(s)])\n if s[0:int(len(s)/2)]==s[int(len(s)/2):len(s)]:\n print(len(S)-i)\n break", "S = list(input())\n\nS.pop(-1)\nif (len(S)) % 2 == 1:\n S.pop(-1)\nwhile True:\n count = 0\n for i in range(int(len(S)/2)):\n if S[i] == S[int(len(S)/2) + i]:\n count += 1\n continue\n else:\n break\n if count == len(S)/2:\n print(len(S))\n break\n S.pop(-1)\n S.pop(-1)", "s=input()\nfor i in range(len(s)-1, 0, -1):\n L = len(s[:i])\n if L % 2 == 0 and s[:L//2] == s[L//2:L]:\n print(i)\n return\n", "s = input()\nn = len(s)\n\nfor i in range(n // 2 - 1):\n s = s[:len(s)-2]\n if s[:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n break", "s = str(input())\n\n\n#print(kind)\nfor i in range(2, len(s), 2):\n line = s[:len(s)-i]\n #print(line)\n if line[:len(line)//2] == line[len(line)//2:]:\n ans = len(line) \n break\n\n\nprint(ans)\n", "s=str(input())\nflag=0\nfor i in range(1,len(s)):\n s=s[:len(s)-2]\n for j in range(len(s)//2):\n if s[j]!=s[len(s)//2+j]:\n flag=1\n break\n if flag==0:\n print(len(s))\n return\n else:\n flag=0\n continue", "s = input ()\nwhile len(s) != 0:\n s = s[:-2]\n le = round (len(s)/2)\n if s[:le] == s[le:len(s)]:\n print (len(s))\n break", "s = input()\nn = len(s)\nfor i in range(n-1,0,-1):\n s = s[0:i]\n n = len(s) \n if n%2 != 0:\n pass\n else:\n if s[0:i//2] == s[i//2:n]:\n print(n)\n return", "S = list(str(input()))\ndel S[-1]\ndel S[-1]\n\ndef ss(string):\n if len(string)&2==1:\n retrun(False)\n else:\n for i in range(len(string)//2):\n if S[i]!=S[len(string)//2+i]:\n return(False)\n return(True)\n\nwhile True:\n if ss(S):\n print((len(S)))\n return\n else:\n del S[-1]\n del S[-1]\n", "s = input()\n\ndef judge(S):\n if (len(S) % 2 == 0) and (S[:len(S) // 2] == S[(-1) * len(S) // 2:]):\n return True\n else:\n return False\n\nfor i in range(len(s)):\n s = s[:-1]\n if judge(s):\n print(len(s))\n break", "s=input()\nn=len(s)\nfor i in range(n//2-1, 0, -1):\n if s[:i]==s[i:2*i]:\n print(2*i)\n return", "S = input()\nfor i in range(1,len(S)):\n S_short = S[0:-i]\n if len(S_short)%2!=0:\n continue\n else:\n half = len(S_short)//2\n if S_short[0:half]==S_short[half:]:\n break\n else:\n continue\nprint(len(S)-i) ", "s = input()\nfor i in range(1,201):\n if (len(s)-i)%2 == 0:\n if s[:(len(s)-i)//2]*2 == s[:len(s)-i]:\n print(len(s[:len(s)-i]))\n break", "s=input()\nm=0\nif s[0]==s[1]:\n m=1\nfor i in range(1,len(s)//2):\n if i==len(s)//2-1:\n break\n if s[:i]==s[i:2*i]:\n m=i\nprint(2*m)", "s = input()\ns = s[:len(s) - 2]\n\nwhile s[:len(s)//2] != s[len(s)//2:]:\n s = s[:len(s) - 2]\nprint(len(s))", "s = input()\nfor i in range(1,len(s)-1):\n t = s[:-i]\n if t[len(t)//2:] == t[:len(t)//2]:\n print(len(t))\n return", "import sys, re\nfrom math import ceil, floor, sqrt, pi, factorial, gcd\nfrom copy import deepcopy\nfrom collections import Counter, deque\nfrom heapq import heapify, heappop, heappush\nfrom itertools import accumulate, product, combinations, combinations_with_replacement\nfrom bisect import bisect, bisect_left, bisect_right\nfrom functools import reduce\nfrom decimal import Decimal, getcontext\n# input = sys.stdin.readline \ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\ndef lcm(a, b): return a * b // gcd(a, b)\nsys.setrecursionlimit(10 ** 6)\nINF = float('inf')\nMOD = 10 ** 9 + 7\nnum_list = []\nstr_list = []\n\ndef main():\n s = input()\n if len(s) % 2 == 0:\n i = len(s) - 2\n else:\n i = len(s) - 1\n while True:\n if s[:int(i/2)] == s[int(i/2):i]:\n print(i)\n break\n i -= 2\n \n\n\ndef __starting_point():\n main()\n\n__starting_point()", "S = input()\nfor i in range(2, len(S)+2, 2):\n split = int(len(S[:-i])/2)\n if S[:split] == S[split:-i]:\n print((len(S[:-i])))\n return\n", "s = str(input())\nfor i in range(len(s)):\n s = s[:len(s)-1]\n if len(s)%2 == 0:\n a = s[:len(s)//2]\n b = s[len(s)//2:]\n if a == b:\n print(len(s))\n break", "#!/usr/local/bin/python3\n# https://atcoder.jp/contests/abc066/tasks/abc066_b\n\nS = list(input())[:-2]\n\ndef check(S):\n half = len(S) // 2\n if S[:half] == S[half:]:\n return True\n else:\n return False\n\nwhile True:\n if check(S):\n print((len(S)))\n break\n S = S[:-2]\n", "S=list(input())\n\n\nimport sys\nfor i in range(len(S)):\n del S[-1]\n for j in range(len(S)):\n if len(S)%2==0:\n if S[0:len(S)//2]==S[len(S)//2:len(S)]:\n print(len(S))\n return\nelse:\n print(0)", "#4 B - ss\nS = list(input())\n\ndef judge(A):\n if len(A)%2 == 0:\n if A[:len(A)//2] == A[len(A)//2:]:\n return True\n return False\n\nfor i in range(len(S)):\n S.pop()\n if judge(S):\n break\nprint(len(S))", "N = str(input())\n\nwhile True:\n N = N[0:-1]\n if len(N) % 2 == 0:\n if N[0:int(len(N)/2)] == N[int(len(N)/2):]:\n break\n\nprint(len(N))", "#!/usr/bin/env python3\nS = input()\n\nn = 0\nfor i in range(200):\n n += 2\n s = S[:len(S) - n]\n\n if s[: len(s) // 2] == s[len(s) // 2:]:\n print((len(s)))\n return\n", "S = input()\nN = len(S)\n\nif N%2 == 1:\n M = N-1\nelse:\n M = N-2\n\nfor i in range(M,0,-2):\n if S[:i//2]==S[i//2:i]:\n break\nprint(i)\n", "s=input()\nn=len(s)\nfor i in range(1,n):\n if s[:n-i]==s[:(n-i)//2]*2:\n print(n-i)\n break", "s = input()\nfor i in range(1000):\n s = s[:-2]\n tnp = 0\n for j in range(len(s)//2):\n if (s[j]!=s[len(s)//2+j]):\n tnp += 1\n if (tnp==0):\n print(len(s))\n break", "s = input()\nres = 0\n\nfor i in range(len(s)):\n if i % 2 != 0:\n pass\n else:\n if s[:i//2] == s[i//2:i]:\n res = i\nprint(res)", "s = input()\n\nwhile True:\n l = len(s)\n s = s[:l - 1]\n if len(s) % 2 != 0:\n pass\n else:\n if s[:len(s) // 2] == s[len(s) // 2:]:\n print((len(s)))\n break\n", "S=input()\nN=len(S)\nfor i in range((N-1)//2,0,-1):\n if S[0:i]==S[i:2*i]:\n print((2*i))\n break\n", "S = input()\nfor i in range(2, len(S), 2):\n end = len(S)-i\n center = int(end/2)\n if S[:center] == S[center:end]:\n print(end)\n break", "S = input()\ntest = \"\"\ntmp = 0\nfor i in range(1, len(S)):\n j = -1 * i\n test = S[:j]\n tmp = len(test) // 2\n if len(test) % 2 == 0 and test[0:tmp] == test[tmp:]:\n print(len(test))\n return", "s = input()\nn = len(s)\nfor i in range(1,len(s)//2):\n if s[:(n-2*i)//2] == s[(n-2*i)//2:n-2*i]:\n print(n-2*i)\n return", "s = list(input())\n\ns = s[:len(s)-1]\n\nfor i in range (len(s)):\n if len(s) %2 == 0:\n if s[:len(s)//2]==s[len(s)//2:]:\n print(len(s))\n return\n s.pop(-1)", "S = input()\n\nl = len(S)\n\nl = (l-2)//2\nwhile l > 0:\n if S[0:l] == S[l:2*l]:\n print((2*l))\n break\n l = l-1\n", "n = input()[:-1]\nwhile n[:len(n)//2] != n[len(n)//2:]:\n n = n[:-1]\nprint(len(n))", "s = str(input())\nwhile True:\n s = s[:-1]\n n = len(s) // 2\n if s[:n] == s[n:]:\n print(2 * n)\n return", "s=list(input())\nfor i in range(len(s)):\n s.pop()\n if s[:len(s)//2]==s[len(s)//2:]:\n print(len(s))\n break", "def answer(s: str) -> int:\n if len(s) % 2 == 1:\n s += ' '\n\n for _ in range(len(s) // 2):\n s = s[:-2]\n l = len(s)\n middle = l // 2\n\n if s[:middle] == s[middle:]:\n return l\n\n\ndef main():\n s = input()\n print(answer(s))\n\n\ndef __starting_point():\n main()\n__starting_point()", "S = input()\n\nfor i in range(1, len(S)):\n gumozi = S[0:len(S)-i]\n\n if gumozi[0:len(gumozi)//2] == gumozi[(len(gumozi)//2):len(gumozi)]:\n print((len(gumozi)))\n return\nprint((0))\n", "s = input()\nn = len(s)\n\nans = n\n\nfor i in range(n):\n s = s[0:-1]\n ans -= 1\n\n if s[0:ans//2] == s[ans//2:]:\n break\n\nprint(ans)", "s=input()\nn=len(s)\nfor i in range(2,n,2):\n h=(n-i)//2\n if s[:h]==s[h:n-i]:\n print(n-i)\n break", "s = input()\nn = len(s)\nimport sys\nfor i in range(1,n//2):\n if s[:(n-2*i)//2]==s[(n-2*i)//2:n-2*i]:\n print(n-2*i)\n return", "s=input()\ntemp = 1 if len(s) % 2 != 0 else 2\nfor i in range(temp, len(s), 2):\n moji = s[:len(s)-i]\n #print(moji[:len(moji)//2], moji[len(moji)//2:])\n if moji[:len(moji)//2] == moji[len(moji)//2:]:\n print((len(moji)))\n break\n", "s = input()\nnum = len(s)\n\ntar_index = len(s) - 1\ncount = 0\n\nwhile (count < num):\n tar = s[:tar_index]\n tar_num = len(tar)\n # \u6587\u5b57\u6570\u304c\u5947\u6570\u306e\u6642\u306f\u3001\u5076\u6587\u5b57\u5217\u306b\u306f\u306a\u3089\u306a\u3044\u3002\n if (tar_num % 2 == 0):\n half = int(tar_num / 2)\n\n if (tar[:half] == tar[half:]):\n print((int(2 * len(tar[:half]))))\n return\n else:\n pass\n\n else:\n pass\n\n tar_index -= 1\n count += 1\n", "import sys\n\ninput = sys.stdin.readline\n\ndef main():\n ans = 0\n s = input().rstrip('\\n')\n ls = len(s)\n for i in range(1,ls):\n if (ls - i)%2 != 0:\n continue\n temps = s[:-i]\n if temps[:(ls-i)//2] == temps[(ls-i)//2:]:\n ans = ls - i \n break\n\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "s = list(input())\nfor i in range(len(s)):\n s.pop(-1)\n if len(s)%2 == 1:\n continue\n if s[:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n break", "# B - ss\ndef main():\n s = list(input())\n\n for _ in range(len(s)):\n s.pop()\n if len(s) % 2 == 0:\n p = len(s)//2\n if s[0:p] == s[p:]:\n print(len(s))\n return\n\n\nif __name__ == \"__main__\":\n main()", "from sys import stdin, stdout # only need for big input\nimport numpy as np\n\ndef solve():\n s = input()\n n = len(s)\n ans = 1 \n for end in range(2,n,2):\n even = True\n for i in range(end//2):\n if s[i] != s[end//2 + i]:\n even = False\n break\n if even:\n ans = end\n print(ans)\n\ndef main():\n solve()\n\n\ndef __starting_point():\n main()\n__starting_point()", "S = str(input())\nfor i in range(1, int(len(S) / 2)):\n T = S[0: len(S) - 2 * i]\n clear = 0\n m = int(len(T) / 2)\n for j in range(m):\n if T[j] == T[m + j]:\n clear += 1\n if clear == m:\n print((len(T)))\n break\n", "n = input()[:-1]\nwhile n[:len(n)//2] != n[len(n)//2:]:\n n = n[:-1]\nprint((len(n)))\n", "s = input()\nfor i in range(len(s)):\n ss = s[:-2-i]\n size = len(ss)\n if size%2==0 and ss[:size//2] == ss[size//2:]:\n print(size)\n return", "S = str(input())\nS = S[:-2]\n\nfor _ in range(len(S)//2):\n \n if S[:len(S)//2] == S[len(S)//2:]:\n print(len(S))\n break\n\n else:\n S = S[:-2]", "s = list(input())\nans = 0\nif len(s)%2==0:\n s = s[:-2]\nelse:\n s.pop(-1)\n\nwhile len(s)>0:\n if s[0:int(len(s)/2)]==s[int(len(s)/2):len(s)]:\n ans = len(s)\n break\n else:\n s = s[:-2]\n \nprint(ans)", "s = input()\nans = 0\nfor _ in range(1,len(s)):\n s = s[:-1]\n if len(s)%2==0:\n if s[:len(s)//2]==s[len(s)//2:]:\n ans = max(ans,len(s))\n else:\n continue\nprint(ans)", "S = input()\n\nodd = len(S) % 2\nlittle = odd + (1-odd)*2\nstart = len(S)-1-little\n\nans = 0\nfor i in range(start,0,-2):\n half = (i+1)//2\n a = S[:half]\n b = S[half:half*2]\n if a == b:\n #print(a,b)\n ans = len(a)*2\n break\n \n \nprint(ans)", "s = input()\ni = len(s) - 1\nwhile True:\n if i % 2 == 0:\n if s[: i//2] == s[i//2 : i]:\n print(i)\n break\n i -= 1", "s = str(input())\nans = 0\n\nfor i in range(len(s)-1,0,-1):\n if i%2!=0:\n continue\n\n if s[0:i//2] == s[i//2:i] and i > ans :\n ans = i\n elif i <= ans:\n break\n\nif len(s)==2:\n ans = 2\nprint(ans)", "s = list(input())\n\nwhile len(s) != 0:\n s.pop()\n if len(s)%2 == 0 and s[:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n break", "s=input()\nfor i in range(len(s)-1,-1,-1):\n if i%2==0 and s[:i//2]==s[i//2:i]:\n print(i)\n break", "import sys\nS = input()\n\nfor i in range(1, len(S)):\n s = S[:-i]\n l = len(s) // 2\n if s[:l] == s[l:]:\n print((len(s)))\n return\n", "# \u611a\u76f4\ns = input()\nfor i in range(2, len(s), 2):\n t = s[:len(s) - i]\n u = t[:len(t) // 2]\n if u + u == t:\n print(len(t))\n return", "s = input()\ns=s[:-1]\nans = 0\nfor i in range(1, len(s)):\n if i*2 > len(s):\n break\n \n if s[0:i] == s[i:i*2]:\n ans = i*2\n \nprint(ans)", "s = input()\nn = len(s)\nn -= 1\nif n % 2:\n n -= 1\nwhile n > 0:\n if s[:n//2] == s[n//2:n]:\n break\n n -= 2\nprint(n)", "S = list(input())\n\nfor i in range(2, len(S)):\n miniS = S[0:-i]\n if len(miniS) % 2 == 0:\n front = ''.join(miniS[0:len(miniS)//2])\n back = ''.join(miniS[len(miniS)//2:len(miniS)])\n if front == back:\n print(len(miniS))\n return", "import sys\nS = input()\n\nfor i in range(1, len(S)):\n s = S[:-i]\n l = len(s) // 2\n if s[:l] == s[l:]:\n print((len(s)))\n return\n", "s=list(input())\nfor i in range(len(s)):\n s.pop()\n if s[:len(s)//2]==s[len(s)//2:]:\n print(len(s))\n break", "class mystr:\n def __init__(self,string):\n self.value = string\n\n def isEven(self):\n l = len(self.value)\n if (not l & 1) and self.value[:l//2] == self.value[l//2:]:\n return True\n else:\n return False\n\n def pop(self):\n l = len(self.value)\n self.value = self.value[:l-1]\n\ns = mystr(input())\nl = len(s.value)\nfor i in reversed(list(range(l))):\n s.pop()\n if s.isEven():\n print(i)\n break\n", "S = input()\ns = S\nfor i in range(len(S)):\n s = s[:-1]\n if s[:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n return", "S: str = input()\n\nfor i in range(len(S)-2, 0, -2):\n words: str = S[:i]\n half: int = len(words)//2\n\n if words[:half] == words[half:]:\n print((half * 2))\n break\n", "\nS = input()\nif len(S) %2 == 0 :\n S = S[:-2]\nelse :\n S =S[:-1]\nwhile(1) :\n l = int(len(S)/2)\n\n if S[:l] == S[l:] :\n print(len(S))\n return\n S = S[:-2]", "s = input()\nwhile True:\n s = s[:-1]\n if s[0:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n return", "s = input()[:-1]\nwhile True:\n n = len(s)\n if n%2 == 0:\n if s[:n//2] == s[n//2:]:\n print(n)\n return\n s = s[:-1]\n", "S=input()\nS2=S[:(len(S))//2]\nwhile len(S)>=2:\n S=S[:-2]\n S2=S2[:-1]\n if S==S2+S2:\n print((len(S)))\n return\n", "s = input()\n\ndef check(a):\n if len(a) % 2 == 1:\n return False\n if a[:len(a)//2] == a[len(a)//2:]:\n return True\n return False\n\nfor i in range(len(s)):\n if check(s[:-1-i]):\n print(len(s) - i - 1)\n break", "#n = int(input())\n#a, b = map(int,input().split())\n#l = list(map(int,input().split()))\n#l = [list(map(int,input().split())) for i in range(n)]\ns = input()\nn = len(s)\n\n\ndef isrepeat(s):\n res = False\n n = len(s)\n if s[0:n//2]+s[0:n//2] == s:\n res = True\n return res\n\n\nfor delnum in range(1, n):\n if (n-delnum) % 2 == 0:\n if isrepeat(s[0:n-delnum]):\n ans = n-delnum\n break\nprint(ans)\n", "s = [i for i in input()]\ns = s[:-1]\nwhile s[:len(s)//2] != s[len(s)//2:]:\n s = s[:-1]\nprint((len(s)))\n", "s=input()\nwhile s:\n s=s[:-1]\n n=len(s)//2\n if s[:n]==s[n:]:\n print(2*n)\n break", "S = input()\nlenS = len(S)\nif lenS%2 == 0:\n S = S[:-1]\n\nans = 0\nfor i in range(1, lenS, 2):\n idx = -i\n _S = S[:idx]\n #print(_S)\n idx = len(_S)//2\n if _S[:idx] == _S[idx:]:\n ans = len(_S)\n break\nprint(ans)", "s = input()\nfor i in range(1,len(s)):\n if s[:(len(s)-i)//2] == s[(len(s)-i)//2:-i]:\n print(len(s)-i)\n break", "s = input()\nn = len(s)\nfor i in range(2,n,2):\n if s[0:(n-i)//2] == s[(n-i)//2:n-i]:\n print(len(s[0:n-i]))\n break", "def f():\n s = list(input())\n for i in range(len(s)):\n s.pop(-1)\n s.pop(-1)\n c = 0\n for j in range(len(s)//2):\n if s[j] == s[len(s)//2 + j]:\n c += 1\n if c == len(s)//2:\n return len(s)\n else:\n break\nprint(f())", "S = input()\nfor i in range(len(S)):\n S = S[0:len(S)-1]\n if(len(S) % 2 == 0):\n if((S[0:(len(S)//2)]) == (S[(len(S)//2):len(S)+1])):\n print(str(len(S)))\n return", "s=input()\nn=len(s)\n\nfor i in range(1,n):\n if (n-i)%2==0:\n m=(n-i)//2\n if s[0:m]==s[m:n-i]:\n print(n-i)\n return", "S=str(input())\nfor i in range(len(S)-1,0,-1):\n S=S[:i]\n if len(S)%2==0:\n x=len(S)//2\n if S[:x]==S[x:]:\n print(len(S))\n break", "s = input()\nfor i in range(1, 101):\n s_del_end = s[:len(s) - i]\n len_s_del_end = len(s_del_end)\n if s_del_end[:len_s_del_end // 2] == s_del_end[len_s_del_end // 2:] and len_s_del_end % 2 == 0:\n print(len_s_del_end)\n return\n", "s=input()\ns = list(s)\ndel s[-1]\ndel s[-1]\nwhile True:\n if s[:len(s)//2] == s[len(s)//2:]:\n print(len(s))\n return\n else:\n del s[-1]\n del s[-1]", "s = input()\n\ns = s[::-1]\nif len(s) % 2 ==1:\n s = s[1:]\nelse:\n s = s[2:]\n\nwhile len(s) >= 2:\n half = len(s) // 2\n if s[:half] == s[half:]:\n print(len(s))\n break\n s = s[2:]", "def judge(Str, Len):\n if Str[:Len//2] == Str[Len//2:]:\n return True\n else:\n return False\n\nS = input()\nL = len(S)\ni = 2 - (L % 2)\nS = S[:-i]\nL -= i\nif judge(S, L):\n print(L)\nelse:\n while not judge(S, L):\n S = S[:-2]\n L -= 2\n print(L)"] | {"inputs": ["abaababaab\n", "xxxx\n", "abcabcabcabc\n", "akasakaakasakasakaakas\n"], "outputs": ["6\n", "2\n", "6\n", "14\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 22,009 | |
e47768110ae1014227cecbf3f75089ed | UNKNOWN | You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.
-----Constraints-----
- |S|=3
- S consists of a, b and c.
-----Input-----
Input is given from Standard Input in the following format:
S
-----Output-----
If S can be obtained by permuting abc, print Yes; otherwise, print No.
-----Sample Input-----
bac
-----Sample Output-----
Yes
Swapping the first and second characters in bac results in abc. | ["S = list(input())\nS.sort()\nif S == ['a', 'b', 'c']:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\nif 'a' in s and 'b' in s and 'c' in s:\n print('Yes')\nelse:\n print('No')", "S = input()\nprint('Yes' if len(set(S)) == 3 else 'No')", "print('Yes' if sorted(input()) == list('abc') else 'No')", "# a,b,c\u304b\u3089\u306a\u308b\u4e09\u6587\u5b57\u306es\u3092\u5165\u529b\ns = input()\n# \u4e26\u3079\u66ff\u3048\u305f\u3089abc\u306b\u306a\u308b\u306a\u3089Yes\nif \"a\" in s and \"b\" in s and \"c\" in s:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = str(input())\nabc = [S[0], S[1], S[2]]\nif \"a\" in abc and \"b\" in abc and \"c\" in abc:\n print(\"Yes\")\nelse:\n print(\"No\")", "word = input()\n\nif word.count('a') == 1 and word.count('b') == 1:\n print('Yes')\nelse:\n print('No')", "s = input('')\nif ''.join(sorted(s)) == 'abc':\n print('Yes')\nelse:\n print('No')\n", "S = list(input())\nif len(set(S)) == 3:\n print('Yes')\nelse:\n print('No')", "a = input()\nprint(\"Yes\" if len(set(a)) == len(a) else \"No\" )", "S = input()\nprint(\"Yes\" if S.count(\"a\") == 1 and S.count(\"b\") == 1 and S.count(\"c\") == 1 else \"No\")", "s = sorted(input())\n\nif \"\".join(s) == \"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")", "'''\n\u554f\u984c\uff1a\n a,b,c \u304b\u3089\u306a\u308b\u9577\u3055 3 \u306e\u6587\u5b57\u5217 S \u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002\n S \u3092 abc \u3092\u4e26\u3073\u66ff\u3048\u3066\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u5224\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n'''\n'''\n\u5236\u7d04\uff1a\n |S|=3\n S \u306f a,b,c \u304b\u3089\u306a\u308b\n'''\n\ndef abc093a(input: str) -> str:\n str_list = [\"abc\", \"acb\", \"bac\", \"bca\", \"cab\", \"cba\"]\n\n if input not in str_list:\n return \"No\"\n else:\n return \"Yes\"\n\ns = str(input())\nprint((abc093a(s)))\n", "# A - abc of ABC\n# https://atcoder.jp/contests/abc093/tasks/abc093_a\n\ns = input()\n\nif ''.join(sorted(s)) == 'abc':\n print('Yes')\nelse:\n print('No')\n", "a,b,c=input()\n\nif a!=b and b!=c and c!=a:\n print(\"Yes\")\nelse:\n print(\"No\")", "# A - abc of ABC\n\n# \u6a19\u6e96\u5165\u529bS\nS = input()\nabc_list = [\"a\", \"b\", \"c\"]\n\nfor i in S:\n if i in abc_list:\n abc_list.remove(i)\n\nif len(abc_list) == 0:\n print('Yes')\nelse:\n print('No')\n \n\n", "# \u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3066abc\u306b\u306a\u3063\u305f\u3089Yes\n\nS = list(input())\n\nS_ascending_order = ''.join(sorted(S))\n# print(S_ascending_order)\n\nif 'abc' == S_ascending_order:\n print('Yes')\nelse:\n print('No')\n", "s=input()\nif 'a'in s and'b'in s and'c'in s:print('Yes')\nelse:print('No')", "s = input()\nif s.count('a')==1 and s.count('b')==1 and s.count('c')==1:\n print(\"Yes\")\nelse:\n print(\"No\")", "li = list(input())\n\nif li[0] != li[1] and li[1] != li[2] and li[0] != li[2]:\n print('Yes')\nelse:\n print('No')\n", "list01 = list(input())\nlist02 = list(set(list01))\nif len(list02) == 3:\n print('Yes')\nelse:\n print('No')", "print([\"No\",\"Yes\"][\"\".join(sorted(input()))==\"abc\"])", "s = input()\nif \"\".join(sorted(list(s))) == \"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\n\nif \"a\" in S and \"b\" in S and \"c\" in S:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = ''.join(sorted(input()))\nprint('Yes' if S == 'abc' else 'No')", "s=input()\nprint(\"Yes\" if len(set(s))==3 else \"No\")", "a = input()\nif a[0] == a[1] or a[0] == a[2] or a[1] == a[2]:\n print('No')\nelse:\n print('Yes')", "S = input()\nif \"a\" in S and \"b\" in S and \"c\" in S:\n print( \"Yes\" )\nelse:\n print( \"No\" )", "s = input()\ns = ''.join(sorted(s))\nif s == 'abc':\n print('Yes')\nelse:\n print('No')", "#ABC093\ns = input()\nprint(\"Yes\" if len(set(s))==3 else \"No\")", "a = list(input())\na.sort()\n#sort\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u9806\u756a\u306b\u4e26\u3079\u308b\u3002\n# \u305f\u3068\u3048bca\u3067\u3082cba\u3067\u3082abc\u306e\u9806\u306b\u3057\u3066\u304f\u308c\u308b\nif a[0] == 'a' and a[1] == 'b' and a[2] == 'c':\n print(\"Yes\")\nelse:\n print(\"No\")", "if ''.join(sorted(input()))==\"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s = list(input())\ns.sort()\n\nif s[0] + s[1] + s[2] == \"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\nS1 =len(set(S))\n\nif ('a' and 'b' and 'c' in S) and (S1 == 3):\n print('Yes')\nelse:\n print('No')\n", "S = input()\nA = sorted(S)\nhantei = \"\".join(A)\n#print(hantei)\n \nif hantei == \"abc\" :\n result = \"Yes\"\nelse:\n result =\"No\"\nprint(result)", "S = input()\na_list = list(S)\na_ct = 0\nb_ct = 0\nc_ct = 0\n\nfor i in range(0,3):\n if a_list[i] == 'a':\n a_ct = a_ct + 1\n\nfor i in range(0,3):\n if a_list[i] == 'b':\n b_ct = b_ct + 1\n\nfor i in range(0,3):\n if a_list[i] == 'c':\n c_ct = c_ct + 1\n\nif a_ct == 1 and b_ct == 1 and c_ct == 1:\n print('Yes')\nelse:\n print('No')", "s = input()\n\nif (\"a\" in s) and (\"b\" in s ) and (\"c\" in s):\n print(\"Yes\")\nelse:\n print(\"No\")", "print(\"Yes\" if len(set(input())) == 3 else \"No\")", "s = input()\nif s[0] != s[1] and s[1] != s[2] and s[2] != s[0]:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\nif \"a\" in S and \"b\" in S and \"c\" in S:\n print(\"Yes\")\nelse:\n print(\"No\")", "import numpy as np\n\nS=input()\n\ns = [st for st in S]\nif len(np.unique(s)) == 3:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\n\nif 'a' in S and 'b' in S and 'c' in S:\n print('Yes')\nelse:\n print('No')", "S = input()\n\nif S[0] == S[1] or S[1] == S[2] or S[2] == S[0]:\n print('No')\nelse:\n print('Yes')", "s = set(input())\n\nif len(s) == 3:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = sorted(input())\n\nif S[0] == \"a\" and S[1] == \"b\" and S[2] == \"c\":\n print(\"Yes\")\nelse:\n print(\"No\")", "s=input()\nif s[0]!=s[1] and s[0]!=s[2] and s[1]!=s[2]:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\nif s.count('a') and s.count('b') and s.count('c'):\n print('Yes')\nelse:\n print('No')\n", "S = len(set(input()))\nprint(\"Yes\") if S==3 else print(\"No\")", "s=input()\nif s.count('a')==1 and s.count('b')==1 and s.count('c')==1:\n print('Yes')\nelse:\n print('No')", "print(\"Yes\" if sorted(input()) == [\"a\",\"b\",\"c\"] else \"No\")", "s = list(input())\n\ns.sort()\n\nprint(\"Yes\" if s[0] + s[1] + s[2] == \"abc\" else \"No\")", "S = input()\n\nif S[0] != S[1] and S[1] != S[2] and S[2] != S[0]:\n print('Yes')\n\nelse:\n print('No')", "\nS = str(input())\n\nif S[0] != S[1] and S[1] != S[2] and S[2] != S[0]:\n print('Yes')\n\nelse:\n print('No')\n\n", "s = list(input())\ns.sort()\n#print(s)\nif s == [\"a\",\"b\",\"c\"]:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "s=input()\n\nif s.count(\"a\")==1 and s.count(\"b\")==1:\n print(\"Yes\")\n \nelse:\n print(\"No\")", "s = input()\ns = sorted(s)\ns = \"\".join(s)\nif s == \"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")\n", "# \u6587\u5b57\u5217\u3092\u53d6\u5f97\u6b7b\u4e26\u3073\u66ff\u3048\nS = str(input())\n\n# \u6587\u5b57\u5217\u306e\u691c\u67fb\u7d50\u679c\u3092\u51fa\u529b\nget_list = sorted(S)\nabc_list = [\"a\",\"b\",\"c\"]\nif get_list == abc_list:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\n\nif 'a' in S and 'b' in S and 'c' in S:\n print('Yes')\nelse:\n print('No')", "s = input()\n\nif s.count('a') == 1 and s.count('b') == 1 and s.count('c'):\n print('Yes')\n \nelse:\n print('No')", "S = str(input())\nif 'a' in S and 'b' in S and 'c' in S:\n print('Yes')\nelse:\n print('No')", "import sys\nsys.setrecursionlimit(10**9)\n\ndef mi(): return map(int,input().split())\ndef ii(): return int(input())\ndef isp(): return input().split()\ndef deb(text): print(\"-------\\n{}\\n-------\".format(text))\n\nINF=10**20\nclass Counter:\n def __init__(self):\n self.dict = {}\n\n def add(self,x):\n if x in self.dict: self.dict[x] += 1\n else: self.dict[x] = 1\n\n def decrement(self,x):\n self.dict[x] -= 1\n if self.dict[x] <= 0:\n del self.dict[x]\n\n def get_dict(self):\n return self.dict\n\ndef main():\n S=input()\n counter = Counter()\n for s in S:\n counter.add(s)\n\n d = counter.get_dict()\n for s in ['a','b','c']:\n if not s in d or d[s] != 1:\n print(\"No\")\n return\n \n print(\"Yes\")\n\n\n\n\n\n\ndef __starting_point():\n main()\n__starting_point()", "S = input()\n\nprint(\"Yes\" if len(set(S)) == 3 else \"No\")", "s = input()\nprint(\"Yes\" if len(set(s)) == 3 else \"No\")", "a = list(input())\na.sort()\n\nif a[0] == 'a' and a[1] == 'b' and a[2] == 'c':\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\n\nif ('a' in s) and ('b' in s) and ('c' in s):\n print('Yes')\nelse:\n print('No')", "s = input()\nif \"a\" in s and \"b\" in s and \"c\" in s:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\nif S.count(\"a\") == 1 and S.count(\"b\") == 1 and S.count(\"c\") == 1:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\nif 'a' in s and 'b' in s and 'c' in s:\n print('Yes')\nelse:\n print('No')", "s = list(input())\ns.sort()\nif s == ['a', 'b', 'c']:\n print('Yes')\nelse:\n print('No')", "abc=input()\nif abc.count('a')==1 and abc.count('b')==1 and abc.count('c')==1:\n print('Yes')\nelse:\n print('No')", "s = input()\n\nif s[0] != s[1] and s[0] != s[2] and s[1] != s[2]:\n print('Yes')\nelse:\n print('No')", "a=input()\nif a.count(\"a\")==1and a.count(\"b\")==1and a.count(\"c\")==1:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = str(input())\n\nlist_S = list(S)\n\nif 'a' in list_S and 'b' in list_S and 'c' in list_S:\n print('Yes')\nelse:\n print('No')", "S = input()\n\nif \"a\" in S and \"b\"in S and \"c\" in S:\n print('Yes')\nelse:\n print('No')", "moji = list(map(str,input().strip()))\nprint((\"No\",\"Yes\")[len(set(moji))==3])", "string = input()\nif string[0] != string[1] and string[1] != string[2] and string[2] != string[0]:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = str(input())\n\n# S \u3092 abc \u3092\u4e26\u3073\u66ff\u3048\u3066\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306a\u3089 Yes \u3092\u3001\u305d\u3046\u3067\u306a\u3044\u306a\u3089 No \u3092\u51fa\u529b\u305b\u3088\u3002\n\nabc = [S[0], S[1], S[2]]\nif \"a\" in abc and \"b\" in abc and \"c\" in abc:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = input()\nif 'a' in S and 'b' in S and 'c' in S:\n print('Yes')\nelse:\n print('No')", "S = str(input())\nabc = S[0],S[1],S[2]\nif \"a\" in abc and \"b\" in abc and \"c\" in abc:\n print('Yes')\nelse:\n print('No')", "s=input()\ns=sorted(s)\n\nif s[0]=='a' and s[1]=='b' and s[2]=='c':\n print('Yes')\nelse:\n print('No')", "s = input()\nif 'a' in s and 'b' in s and 'c' in s:\n print('Yes')\nelse:\n print('No')\n", "S = input()\nABC = (list(S))\nABC.sort()\n# print(ABC)\n\nif ABC == [\"a\",\"b\",\"c\"]:\n print(\"Yes\")\nelse:\n print(\"No\")", "s=input()\nif len(set(s))==3:\n print(\"Yes\")\nelse:\n print(\"No\")", "print(\"Yes\" if \"\".join(sorted(input()))==\"abc\" else \"No\")", "S = list(input())\nif 'a' in S and 'b' in S and 'c' in S:\n print('Yes')\nelse:\n print('No')\n", "def main():\n s = set(input())\n\n if len(s) == 3:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\nmain()", "#\n# abc093 a\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n\n def test_\u5165\u529b\u4f8b_1(self):\n input = \"\"\"bac\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_2(self):\n input = \"\"\"bab\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_3(self):\n input = \"\"\"abc\"\"\"\n output = \"\"\"Yes\"\"\"\n self.assertIO(input, output)\n\n def test_\u5165\u529b\u4f8b_4(self):\n input = \"\"\"aaa\"\"\"\n output = \"\"\"No\"\"\"\n self.assertIO(input, output)\n\n\ndef resolve():\n S = input()\n if \"a\" in S and \"b\" in S and \"c\" in S:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\ndef __starting_point():\n # unittest.main()\n resolve()\n\n__starting_point()", "S = str(input())\n\nlist_S = list(S)\n\nif 'a' in list_S and 'b' in list_S and 'c' in list_S:\n print('Yes')\nelse:\n print('No')", "S = input()\nS = sorted(S)\n\nif S[0] == 'a' and S[1] == 'b' and S[2] == 'c':\n print('Yes')\nelse:\n print('No')", "S = str(input())\n\nif S[0] == S[1] or S[1] == S[2] or S[0] == S[2]:\n print('No')\nelse:\n print('Yes')", "n = input()\nif len(set(n))==3:\n print(\"Yes\")\nelse:\n print(\"No\")", "S = list(input())\nS.sort()\n\nif S == ['a', 'b', 'c']:\n print('Yes')\nelse:\n print('No')\n", "S = str(input())\n\nif S[0] != S[1] and S[0] != S[2] and S[1] != S[2]:\n result = 'Yes'\nelse:\n result = 'No'\n\nprint(result)", "s = list(input())\n\ns.sort()\nif ''.join(s) == 'abc':\n print('Yes')\nelse:\n print('No')", "s=str(input())\n\nif ord(s[0])+ord(s[1])+ord(s[2])==ord('a')+ord('b')+ord('c'):\n ans=\"Yes\"\nelse:\n ans=\"No\"\nprint(ans)", "def atc_093a(input_value):\n try:\n input_value.index(\"a\")\n input_value.index(\"b\")\n input_value.index(\"c\")\n return \"Yes\"\n except ValueError:\n return \"No\"\n\ninput_value = input()\nprint(atc_093a(input_value))", "S = input()\nif set(S) == {'a', 'b', 'c'}:\n print('Yes')\nelse:\n print('No')", "S=str(input())\nS_list=sorted(S)\nif S_list[0]+S_list[1]+S_list[2]==\"abc\":\n print(\"Yes\")\nelse:\n print(\"No\")\n", "# 093a\n\ndef atc_093a(input_value):\n try:\n input_value.index(\"a\")\n input_value.index(\"b\")\n input_value.index(\"c\")\n return \"Yes\"\n except ValueError:\n return \"No\"\n\ninput_value = input()\nprint((atc_093a(input_value)))\n", "S = str(input())\n\nif S[0] != S[1] and S[0] != S[2] and S[1] != S[2]:\n result = 'Yes'\nelse:\n result = 'No'\n\nprint(result)\n"] | {"inputs": ["bac\n", "bab\n", "abc\n", "aaa\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]} | INTRODUCTORY | PYTHON3 | ATCODER.JP | 14,800 | |
5f9320b0a6c15c560843dd8ba3e855eb | UNKNOWN | You are given two arrays $a$ and $b$, both of length $n$.
Let's define a function $f(l, r) = \sum\limits_{l \le i \le r} a_i \cdot b_i$.
Your task is to reorder the elements (choose an arbitrary order of elements) of the array $b$ to minimize the value of $\sum\limits_{1 \le l \le r \le n} f(l, r)$. Since the answer can be very large, you have to print it modulo $998244353$. Note that you should minimize the answer but not its remainder.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of elements in $a$ and $b$.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), where $a_i$ is the $i$-th element of $a$.
The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_j \le 10^6$), where $b_j$ is the $j$-th element of $b$.
-----Output-----
Print one integer β the minimum possible value of $\sum\limits_{1 \le l \le r \le n} f(l, r)$ after rearranging elements of $b$, taken modulo $998244353$. Note that you should minimize the answer but not its remainder.
-----Examples-----
Input
5
1 8 7 2 4
9 7 2 9 3
Output
646
Input
1
1000000
1000000
Output
757402647
Input
2
1 3
4 2
Output
20 | ["n = int(input())\n\na = list(map(int, input().split()))\naord = sorted([i for i in range(n)], key=lambda x: a[x] * (n - x) * (x + 1))\n\nb = sorted(map(int, input().split()))[::-1]\nnew_b = [0] * n\nfor i in range(n):\n new_b[aord[i]] = b[i]\nb = new_b\n\nm = 998244353\n\nc = [0] * n\nfor i in range(n):\n c[i] = a[i] * b[i] % m\n\nans = 0\nfor i in range(n):\n u = c[i] * (n - i) * (i + 1) % m\n ans = (ans + u) % m\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\ncount = []\nfor i in range(n):\n count.append((n-i)*(i+1)*a[i])\nb.sort()\ncount.sort(reverse = True)\nans = 0\nfor i in range(n):\n\n ans += count[i]*b[i]\n ans %= 998244353\nprint(ans)\n", "MOD = 998244353\nn = int(input())\na = [*map(int, input().split())]\nb = [*map(int, input().split())]\nfor i in range(n):\n a[i] = (a[i] * (n - i) * (i + 1))\na.sort(reverse = True)\nb.sort()\nres = 0\nfor i in range(n):\n a[i] %= MOD\n res += (a[i] * b[i]) % MOD\n res %= MOD\nprint(res)", "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nfor i in range(n):\n\ta[i] = a[i] * (i + 1) * (n - i)\na = sorted(a)\nb = sorted(b)\nans = 0\nfor i in range(n):\n\tans += b[n - i - 1] * a[i] % 998244353\n\tans %= 998244353\nprint(ans)\n", "def main():\n n = int(input())\n mod = 998244353\n a = list(map(int, input().split()))\n b = sorted(map(int, input().split()))\n for i in range(n):\n a[i] *= (i + 1) * (n - i)\n a.sort(reverse = 1)\n ans = 0\n for i in range(n):\n ans = (ans + a[i] * b[i]) % mod\n print(ans)\n \n return 0\n\nmain()", "n=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nmod=998244353\n\nAX=[]\n\nfor i in range(n):\n AX.append(A[i]*(i+1)*(n-i))\n\nAX.sort()\nB.sort(reverse=True)\n\nANS=0\nfor i in range(n):\n ANS=(ANS+AX[i]*B[i])%mod\n\nprint(ANS)\n", "n = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nfor i in range(n):\n A[i] *= (i + 1) * (n - i)\nA.sort()\nB.sort(reverse=True)\nC = []\ncnt = 0\nM = 998244353\nfor i in range(n):\n cnt += A[i] * B[i]\n cnt %= M\nprint(cnt)\n", "def getN():\n return int(input())\ndef getList():\n return list(map(int, input().split()))\nMOD = 998244353\n\nn = getN()\nanums = getList()\nbnums = getList()\nanums = [a * (i+1) * (n-i) for i, a in enumerate(anums)]\nanums.sort()\nbnums.sort(reverse=True)\nans = 0\nfor a, b in zip(anums, bnums):\n ans += a * b\n ans = ans % MOD\n\nprint(ans)", "n=int(input())\na=[int(x) for x in input().split()]\nb=[int(x) for x in input().split()]\ncounter=0\nb.sort(reverse=True)\nc=[]\nfor i in range(n):\n c.append(a[i]*b[i])\ntot=[]\nfor i in range(n):\n x=(min(i,n-i-1)+1)\n tot.append((x*(x+1)+(n-2*x)*x)*a[i])\ntot.sort()\nfor i in range(n):\n counter+=tot[i]*b[i]\n \nprint(counter%998244353)\n", "n = int(input())\na = list(map(int, input().split()))\na1 = sorted([a[i] * (n - i) * (i + 1) for i in range(n)])\nb = sorted(list(map(int, input().split())), key=lambda x: -x)\nans = 0\nc = 998244353\nfor i in range(n):\n ans = (ans + a1[i] * b[i]) % c\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = []\nfor i in range(n):\n c.append(a[i] * (n - i) * (i + 1))\nc.sort()\nb.sort(reverse=True)\nans = 0\nfor i in range(n):\n ans = (ans + c[i] * b[i]) % 998244353\nprint(ans)", "n=int(input())\na=[int(s) for s in input().split()]\nb=[int(s) for s in input().split()]\nans=0\nb.sort()\nfor i in range(n):\n k=(i+1)*(n-i)\n a[i]*=k\na.sort()\nfor i in range(n):\n ans+=b[n-i-1]*a[i]\n ans%=998244353\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\na = [0] + a\nb = [0] + b\n# print(n, a, b)\nfor i in range(1, n+1) :\n a[i] *= i\n a[i] *= n+1-i\na.sort()\nb.sort()\n# print(n, a, b)\nans = 0\nmod = 998244353\nfor i in range(1, 1+n) :\n ans += ( a[i] * b[n+1-i] ) % mod\n if ans >= mod : ans -= mod\nprint(ans)\n", "# 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 = self.next_line()\n self.index = 0\n val = self.buff[self.index]\n self.index += 1\n return val\n\n def next_line(self):\n return sys.stdin.readline().split()\n\n def next_ints(self):\n return [int(x) for x in sys.stdin.readline().split()]\n\n def next_int(self):\n return int(next(self))\n\n def solve(self):\n n = self.next_int()\n a = self.next_ints()\n b = sorted(self.next_ints())[::-1]\n for i in range(0, n):\n mm = (i + 1) * (n - i)\n a[i] *= mm\n a = sorted(a)\n mod = 998244353\n c = [a[i] * b[i] % mod for i in range(0, n)]\n print(sum(c) % mod)\n\n\ndef __starting_point():\n Main().solve()\n\n__starting_point()", "n = int(input())\na = [[q*(n-q1)*(q1+1), q1] for q1, q in enumerate(list(map(int, input().split())))]\ns = sorted(list(map(int, input().split())), reverse=True)\nd = sorted(a)\nans = [0]*len(s)\nfor q in range(n):\n ans[d[q][1]] = s[q]\nprint(sum(a[q][0]*ans[q] for q in range(n)) % 998244353)\n", "from sys import stdin, stdout\n\nMOD = 998244353\n\ndef __starting_point():\n n = int(stdin.readline())\n A = [int(x) for x in stdin.readline().rstrip().split()]\n B = [int(x) for x in stdin.readline().rstrip().split()]\n\n for i, a in enumerate(A):\n A[i] *= (i+1)*(n-i)\n\n A.sort(reverse = True)\n B.sort()\n\n res = 0\n for a, b in zip(A, B):\n res += a * b\n res %= MOD\n \n print(res)\n\n__starting_point()", "n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nmn = [a[i] * (i + 1) * (n - i) for i in range(n)]\nmn.sort()\nb.sort()\nb.reverse()\nwyn = 0\nfor i in range(n):\n\twyn = (wyn + b[i] * mn[i]) % 998244353\nprint(wyn)", "n=int(input())\na=list(map(int,input().split()))\nb=sorted(list(map(int,input().split())),reverse=True)\n\nans=0\n\nmmm=998244353\n\nc=sorted([a[i]*(i+1)*(n-i) for i in range(n)])\n\nfor i in range(n):\n ans=(ans+c[i]*b[i])%mmm\n\nprint(ans)\n", "R = lambda: map(int, input().split())\n\nm = 998244353\nn = int(input())\na = list(R())\nb = list(R())\nfor i in range(n): a[i] *= (i+1)*(n-i)\na.sort()\nb.sort(reverse=True)\nprint(sum([x*y%m for x,y in zip(a, b)]) % m)", "n = int(input())\nar = list(map(int, input().split()))\nbr = list(map(int, input().split()))\n\nMOD = 998244353\n\nfor i in range(n):\n ar[i] *= (i + 1) * (n - i)\n\nar = sorted(ar)\nbr = sorted(br)\n\nans = 0\n\nfor i in range(n):\n ans = (ans + ar[i] * br[n - i - 1]) % MOD\n\nprint(ans)\n \n", "from bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nfrom math import *\nfrom decimal import *\nfrom copy import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 10**6+10\nMOD = 10**9+7\ndef isprime(n):\n n = abs(int(n))\n if n < 2:\n return False\n if n == 2: \n return True \n if not n & 1: \n return False\n for x in range(3, int(n**0.5) + 1, 2):\n if n % x == 0:\n return False\n return True\n\ndef mhd(a,b,x,y):\n return abs(a-x)+abs(b-y)\n\ndef numIN(x = \" \"):\n return(map(int,sys.stdin.readline().strip().split(x)))\n\ndef charIN(x= ' '):\n return(sys.stdin.readline().strip().split(x))\n\ndef arrIN():\n return list(numIN())\n\ndef dis(x,y):\n a = y[0]-x[0]\n b = x[1]-y[1]\n return (a*a+b*b)**0.5\n\ndef lgcd(a):\n g = a[0]\n for i in range(1,len(a)):\n g = math.gcd(g,a[i])\n return g\n\ndef ms(a):\n msf = -MAX\n meh = 0\n st = en = be = 0\n for i in range(len(a)):\n meh+=a[i]\n if msf<meh:\n msf = meh\n st = be\n en = i\n if meh<0:\n meh = 0\n be = i+1\n return msf,st,en\n\n\ndef res(ans,t):\n print('Case #{}: {} {}'.format(t,ans[0],ans[1]))\n\ndef divi(n):\n l = []\n for i in range(1,int(n**0.5)+1):\n if n%i==0:\n if n//i==i:\n l.append(i)\n else:\n l.append(i)\n l.append(n//i)\n return l\n\nn = int(input())\na = arrIN()\nb = arrIN()\nc = [0]*n\nb.sort()\nfor i in range(n):\n a[i]*=((i+1)*(n-i))\n\nl = [[i,a[i]] for i in range(n)]\nl.sort(key = lambda x:x[1],reverse=True)\nj = 0\nfor i in l:\n c[i[0]] = b[j]\n j+=1\nans = 0\nfor i in range(n):\n ans+=((a[i]*c[i])%998244353)\n\nprint(ans%998244353)", "N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nfor i in range(N):\n\tA[i] = A[i]*(i+1)*(N-i)\n\nA.sort()\nB.sort()\n\nans = 0\nfor i in range(N):\n\tans = ans + (A[i]*B[N-i-1])%998244353\n\nprint(ans%998244353)\n", "IN = input\nrint = lambda: int(IN())\nrmint = lambda: map(int, IN().split())\nrlist = lambda: list(rmint())\n\nn = rint()\na = rlist()\nb = rlist()\nb.sort()\nb.reverse()\nfor i in range(n):\n a[i] *= (i + 1) * (n - i)\na.sort()\nans = 0\nfor i in range(n):\n ans += b[i] * a[i]\n ans %= 998244353\nprint(ans)", "N = int(input())\nA = [int(a) for a in input().split()]\nB = sorted([int(a) for a in input().split()])[::-1]\n\nAA = []\nfor i in range(N):\n AA.append(A[i]*(i+1)*(N-i))\n\nAA = sorted(AA)\n\nprint(sum([B[i]*AA[i] for i in range(N)]) % 998244353)\n"] | {
"inputs": [
"5\n1 8 7 2 4\n9 7 2 9 3\n",
"1\n1000000\n1000000\n",
"2\n1 3\n4 2\n"
],
"outputs": [
"646\n",
"757402647\n",
"20\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 9,699 | |
2dccfaf89e39b3013e1cef09dc154874 | UNKNOWN | There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles.
Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once.
Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset.
There are also $m$ special offers in the shop. The $j$-th of them is given as a pair $(x_j, y_j)$, and it means that if Misha buys exactly $x_j$ shovels during one purchase then $y_j$ most cheapest of them are for free (i.e. he will not pay for $y_j$ most cheapest shovels during the current purchase).
Misha can use any offer any (possibly, zero) number of times, but he cannot use more than one offer during one purchase (but he can buy shovels without using any offers).
Your task is to calculate the minimum cost of buying $k$ shovels, if Misha buys them optimally.
-----Input-----
The first line of the input contains three integers $n, m$ and $k$ ($1 \le n, m \le 2 \cdot 10^5, 1 \le k \le min(n, 2000)$) β the number of shovels in the shop, the number of special offers and the number of shovels Misha has to buy, correspondingly.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the cost of the $i$-th shovel.
The next $m$ lines contain special offers. The $j$-th of them is given as a pair of integers $(x_i, y_i)$ ($1 \le y_i \le x_i \le n$) and means that if Misha buys exactly $x_i$ shovels during some purchase, then he can take $y_i$ most cheapest of them for free.
-----Output-----
Print one integer β the minimum cost of buying $k$ shovels if Misha buys them optimally.
-----Examples-----
Input
7 4 5
2 5 4 2 6 3 1
2 1
6 5
2 1
3 1
Output
7
Input
9 4 8
6 8 5 1 8 1 1 2 1
9 2
8 4
5 3
9 7
Output
17
Input
5 1 4
2 5 7 4 6
5 4
Output
17
-----Note-----
In the first example Misha can buy shovels on positions $1$ and $4$ (both with costs $2$) during the first purchase and get one of them for free using the first or the third special offer. And then he can buy shovels on positions $3$ and $6$ (with costs $4$ and $3$) during the second purchase and get the second one for free using the first or the third special offer. Then he can buy the shovel on a position $7$ with cost $1$. So the total cost is $4 + 2 + 1 = 7$.
In the second example Misha can buy shovels on positions $1$, $2$, $3$, $4$ and $8$ (costs are $6$, $8$, $5$, $1$ and $2$) and get three cheapest (with costs $5$, $1$ and $2$) for free. And then he can buy shovels on positions $6$, $7$ and $9$ (all with costs $1$) without using any special offers. So the total cost is $6 + 8 + 1 + 1 + 1 = 17$.
In the third example Misha can buy four cheapest shovels without using any special offers and get the total cost $17$. | ["import sys\nimport copy\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\nSHOP=[list(map(int,input().split())) for i in range(m)]\n\nA=sorted(A)[:k]\nA=A[::-1]\n\nSHOP.sort(key=lambda x:x[0])\n\nfrom itertools import accumulate \n\nDP=[0]+list(accumulate(A))\nSUM=copy.deepcopy(DP)\n\nfor i in range(k+1):\n for x,y in SHOP:\n if x>i:\n break\n DP[i]=min(DP[i],DP[i-x]+SUM[i]-SUM[i-x]-SUM[i]+SUM[i-y],DP[i-1]+A[i-1])\n\nprint(DP[-1])\n \n", "IN = input\nrint = lambda: int(IN())\nrmint = lambda: list(map(int, IN().split()))\nrlist = lambda: list(rmint())\n\nn, m, k = rmint()\na = rlist()\nt = []\nfor i in range(m):\n x, y = rmint()\n t.append((x, y))\nt.sort()\na.sort()\npr = [0]\nfor i in a: pr.append(pr[-1] + i)\nf = 4096 * [0]\n\n\ndef s(l, r):\n if l > r: return 0\n else: return pr[r + 1] - pr[l]\n\n\nans = s(0, k-1)\n\n\ndef upd(x, y):\n nonlocal ans\n f[x] = min(f[x], y)\n ans = min(ans, y + s(x, k - 1))\n\n\nfor i in range(1, k + 1):\n f[i] = f[i - 1] + a[i - 1]\n for p in t:\n x, y = p\n if i - x < 0: break\n upd(i, f[i - x] + s(i - x + y, i - 1))\n\nprint(ans)\n", "N, M, K = list(map(int, input().split()))\nA = sorted([int(a) for a in input().split()])[:K][::-1]\nB = [0]\nfor a in A:\n B.append(B[-1]+a)\nX = [0] * (K+1)\nfor _ in range(M):\n x, y = list(map(int, input().split()))\n if x <= K:\n X[x] = max(X[x], y)\n\nY = [0] * (K+1)\n\nfor i in range(1, K+1):\n mi = 10**100\n for j in range(1, i+1):\n s = Y[i-j] + B[i-X[j]] - B[i-j]\n mi = min(mi, s)\n \n Y[i] = mi\n\nprint(Y[K])\n", "n,m,k = list(map(int,input().split()))\nai = list(map(int,input().split()))\nar = [0] * k\nfor i in range(m):\n x,y = list(map(int,input().split()))\n x -= 1\n if x < k:\n ar[x] = max(ar[x],y)\nai.sort()\nbig = 10**9\nar2 = [big] * (k+1)\nar3 = [0] * (k+1)\nar3[0] = 0\nfor i in range(1,k+1):\n ar3[i] = ar3[i-1] + ai[i-1]\nar2[k] = 0\nfor i in range(k,0,-1):\n for j in range(i):\n ar2[i-j-1] = min(ar2[i-j-1],ar2[i] + ar3[i] - ar3[i - (j + 1 - ar[j])])\nprint(ar2[0])\n", "from collections import defaultdict\nfrom heapq import heapify, heappop\nn, m, k = map(int, input().split())\nitems = list(map(int, input().split()))\nheapify(items)\nitems2 = []\nfor i in range(k):\n items2 += [heappop(items)]\nitems = items2\noffers = defaultdict(lambda :0)\nfor i in range(m):\n a, b = map(int, input().split())\n if a <= k:\n offers[a] = max(offers[a], b)\ndp = [1e20] * (k + 1)\ndp[0] = 0\nprefix = [0]\nfor i in items:\n prefix += [prefix[-1] + i]\nfor i in range(1, k + 1):\n for j in range(1, i + 1):\n b = offers[j]\n # buy j items, b free\n dp[i] = min(dp[i], dp[i - j] + prefix[i] - prefix[i - j + b])\nprint(dp[-1])", "N, M, K = map(int, input().split())\nA = sorted([int(a) for a in input().split()])[:K][::-1]\nB = [0]\nfor a in A:\n B.append(B[-1]+a)\nX = [0] * (K+1)\nfor _ in range(M):\n x, y = map(int, input().split())\n if x <= K:\n X[x] = max(X[x], y)\nY = [0] * (K+1)\nfor i in range(1, K+1):\n mi = 10**100\n for j in range(1, i+1):\n s = Y[i-j] + B[i-X[j]] - B[i-j]\n mi = min(mi, s)\n Y[i] = mi\nprint(Y[K])", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"Codeforces Round #552 (Div. 3)\n\nProblem F. Shovels Shop\n\n:author: Kitchen Tong\n:mail: [email protected]\n\nPlease feel free to contact me if you have any question\nregarding the implementation below.\n\"\"\"\n\n__version__ = '2.0'\n__date__ = '2019-04-17'\n\nimport sys\nfrom heapq import heappush, heappop\n\n\ndef buy_shovels(k, shovels, discounts):\n if 1 not in discounts:\n discounts[1] = 0\n accums = [0]\n for s in shovels:\n accums.append(s + accums[-1])\n for i in range(k):\n for x, y in list(discounts.items()):\n if i + x > k:\n continue\n perhaps = accums[i] + sum(shovels[i+y:i+x])\n accums[i+x] = min(accums[i+x], perhaps)\n return accums[-1]\n\n\ndef main(argv=None):\n n, m, k = list(map(int, input().split()))\n costs = list(map(int, input().split()))\n discounts = dict()\n for line in range(m):\n x, y = list(map(int, input().split()))\n if x > k:\n # this discount is useless as we can't buy more than k\n continue\n if x not in discounts:\n discounts[x] = y\n else:\n discounts[x] = max(discounts[x], y)\n print(buy_shovels(k, sorted(costs)[:k], discounts))\n return 0\n\n\ndef __starting_point():\n STATUS = main()\n return(STATUS)\n\n\n__starting_point()", "from collections import defaultdict\n\n\ndef buy(k, sums, offset, discounts):\n return sums[offset + k] - sums[offset + discounts[k]]\n\n\ndef main():\n n, m, k = list(map(int, input().split()))\n prices = sorted(list(map(int, input().split())))[:k]\n sums = [0] * (k + 1)\n for i in range(1, k + 1):\n sums[i] = sums[i - 1] + prices[i - 1]\n\n discounts = defaultdict(int)\n for _ in range(m):\n x, y = tuple(map(int, input().split()))\n discounts[x] = max(discounts[x], y)\n\n d = [0] * (k + 1)\n\n for i in range(1, k + 1):\n d[i] = buy(i, sums, 0, discounts)\n\n for j in range(1, i + 1):\n d[i] = min(d[i], d[j] + buy(i - j, sums, j, discounts))\n\n print(d[k])\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "'''input\n9 4 8\n6 8 5 1 8 1 1 2 1\n9 2\n8 4\n5 3\n9 7\n'''\nfrom sys import stdin\nimport math\nfrom copy import deepcopy\nfrom collections import defaultdict\n\n\ndef process_offer(offers):\n\taux = []\n\tfor i in offers:\n\t\ttemp = offers[i]\n\t\ttemp.sort()\n\t\taux.append([i, temp[-1]])\n\n\taux = sorted(aux, key = lambda x: x[0])\n\treturn aux\n\n\ndef make(first, second):\n\treturn str(first) + ' ' + str(second)\n\n\ndef brute(arr, dp, offers, index, remain):\n\t#print(index, remain)\n\t# base case:\n\tif remain == 0:\n\t\treturn 0\n\n\tif make(index, remain) in dp:\n\t\treturn dp[make(index, remain)]\n\n\tmin_cost = arr[index] + brute(arr, dp, offers, index + 1, remain - 1)\n\t#print(min_cost)\n\tfor i in range(len(offers)):\n\t\tcost = 0\n\t\tif offers[i][0] <= remain:\n\t\t\tfree = offers[i][1]\n\t\t\tfor j in range(index + free, index + offers[i][0]):\n\t\t\t\tcost += arr[j]\n\t\t\tcost += brute(arr, dp, offers, index + offers[i][0], remain - offers[i][0])\n\t\t\tmin_cost = min(min_cost, cost)\n\t\telse:\n\t\t\tbreak\n\tdp[make(index, remain)] = min_cost\n\treturn min_cost\n\n\n\n# main starts\nn, m, k = list(map(int, stdin.readline().split()))\narr = list(map(int, stdin.readline().split()))\narr.sort()\noffers = defaultdict(list)\nfor _ in range(m):\n\tx, y = list(map(int, stdin.readline().split()))\n\toffers[x].append(y)\n\noffers = process_offer(offers)\ndp = dict()\nprint(brute(arr, dp, offers, 0, k))\n#print(dp)\n\n", "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na = sorted(a)\na = a[:k]\nd = [(1, 0)]\nfor i in range(m):\n x, y = list(map(int, input().split()))\n if x > k:\n continue\n d.append((x, y))\nd = sorted(d)\n\ns = [0] * (k + 1)\ns[1] = a[0]\nfor i in range(1, k + 1):\n s[i] = s[i - 1] + a[i - 1]\nINF = float('inf')\ndp = [INF] * (k + 1)\ndp[0] = 0\nfor i in range(k + 1):\n for j in range(len(d)):\n x, y = d[j]\n if i + x <= k:\n dp[i + x] = min(dp[i + x], dp[i] + s[i + x] - s[i + y])\n else:\n break\n\nprint(dp[k])\n\n", "from sys import stdin\nimport math\nfrom copy import deepcopy\nfrom collections import defaultdict\ndef process_offer(offers):\n\taux = []\n\tfor i in offers:\n\t\ttemp = offers[i]\n\t\ttemp.sort()\n\t\taux.append([i, temp[-1]])\n\taux = sorted(aux, key = lambda x: x[0])\n\treturn aux\ndef make(first, second):\n\treturn str(first) + ' ' + str(second)\n\ndef brute(arr, dp, offers, index, remain):\n\t#print(index, remain)\n\t# base case:\n\tif remain == 0:\n\t\treturn 0\n\tif make(index, remain) in dp:\n\t\treturn dp[make(index, remain)]\n\tmin_cost = arr[index] + brute(arr, dp, offers, index + 1, remain - 1)\n\t#print(min_cost)\n\tfor i in range(len(offers)):\n\t\tcost = 0\n\t\tif offers[i][0] <= remain:\n\t\t\tfree = offers[i][1]\n\t\t\tfor j in range(index + free, index + offers[i][0]):\n\t\t\t\tcost += arr[j]\n\t\t\tcost += brute(arr, dp, offers, index + offers[i][0], remain - offers[i][0])\n\t\t\tmin_cost = min(min_cost, cost)\n\t\telse:\n\t\t\tbreak\n\tdp[make(index, remain)] = min_cost\n\treturn min_cost\nn, m, k = list(map(int, stdin.readline().split()))\narr = list(map(int, stdin.readline().split()))\narr.sort()\noffers = defaultdict(list)\nfor _ in range(m):\n\tx, y = list(map(int, stdin.readline().split()))\n\toffers[x].append(y)\n\noffers = process_offer(offers)\ndp = dict()\nprint(brute(arr, dp, offers, 0, k))", "from sys import stdin, stdout\n\nn, m, k = tuple(map(lambda x: int(x), stdin.readline().split()))\na = stdin.readline().split()\nfor i in range(len(a)):\n a[i] = int(a[i])\nprefix_sum = []\na = sorted(a, key=lambda x: x)\nfor x in a:\n if prefix_sum:\n prefix_sum.append(prefix_sum[-1] + x)\n else:\n prefix_sum.append(x)\n\noffers = {}\nfor i in range(m):\n x, y = stdin.readline().split()\n x = int(x)\n y = int(y)\n if x not in offers or y > offers[x]:\n offers[x] = y\n\n\nanswer = []\nfor i in range(k):\n if i == 0:\n if 1 in offers and offers[1] > 0:\n answer.append(0)\n else:\n answer.append(a[0])\n continue\n answer.append(400000002)\n for j in range(i):\n cursum = answer[j]\n answer[i] = min(answer[i], answer[j] + prefix_sum[i] - prefix_sum[j + (offers[i - j] if (i - j) in offers else 0)])\n answer[i] = min(answer[i], prefix_sum[i] if (i+1) not in offers else (-prefix_sum[offers[i+1]-1] + prefix_sum[i]))\n\n\nprint(answer[k-1])", "#Bhargey Mehta (Sophomore)\n#DA-IICT, Gandhinagar\nimport sys, math, queue\n#sys.stdin = open(\"input.txt\", \"r\")\nMOD = 10**9+7\n\nn, m, k = map(int, input().split())\na = sorted(map(int, input().split()))\na = a[:k]\nps = [0]\nfor i in range(k):\n ps.append(ps[-1]+a[i])\nbf = []\ntemp = [0 for i in range(k+1)]\nfor i in range(m):\n b, f = map(int, input().split())\n if b <= k:\n temp[b] = max(temp[b], f)\nfor i in range(1, k+1):\n if temp[i] != 0:\n bf.append((i, temp[i]))\nbf = [(1, 0)] + sorted(bf, key = lambda x: (x[0]-x[1], b))\n\ndp = [[-1 for i in range(len(bf))] for i in range(k+1)]\n\nfor i in range(len(bf)): dp[0][i] = 0\nfor i in range(1, k+1): dp[i][0] = ps[i]\n\nfor i in range(1, k+1):\n for j in range(1, len(bf)):\n dp[i][j] = dp[i][j-1]\n b = bf[j][0]\n f = bf[j][1]\n if b <= i:\n dp[i][j] = min(dp[i][j], dp[i-b][len(bf)-1]+ps[i]-ps[i-b+f])\n\nprint(dp[k][len(bf)-1])", "# http://codeforces.com/contest/1154/problem/F\n# Explain: https://codeforces.com/blog/entry/66586?locale=en\nfrom collections import defaultdict\n\n\ndef input2int():\n return list(map(int, input().split()))\n\n\nn, m, k = input2int()\ncost = list(input2int())\ncost = sorted(cost)[:k]\n# cost.reverse()\n# print(cost)\n\npreSum = defaultdict(int)\nfor i in range(k):\n preSum[i] = preSum[i - 1] + cost[i]\npreSum[k] = preSum[k - 1]\n# print(preSum)\n\noffer = []\nfor i in range(m):\n x, y = input2int()\n if x <= k:\n offer.append((x, y))\n\n# print(offer)\n\ndp = defaultdict(lambda: int(1e9))\ndp[0] = 0\n\nfor i in range(k + 1):\n if i < k:\n dp[i + 1] = min(dp[i] + cost[i], dp[i + 1])\n for _ in offer:\n x, y = _\n # print(\"i: {}, x: {}, y: {}\".format(i, x, y))\n if i + x > k:\n continue\n # print('sum: {}'.format(preSum[i + x] - preSum[i + y]))\n dp[i + x] = min(dp[i + x], dp[i] + preSum[i + x - 1] - preSum[i + y - 1])\n # print(dp)\n\n# print(dp)\nprint(dp[k])\n", "import math\nfrom collections import defaultdict\nimport sys\ninput = sys.stdin.readline\n\n\ndef main():\n n, m, k = list(map(int, input().split()))\n a = sorted(list(map(int, input().split())))\n pref = [0] + a.copy()\n for i in range(1, n+1):\n pref[i] += pref[i-1]\n\n def getPref(start, end):\n if start > end:\n return 0\n if start == 0:\n return pref[end]\n return pref[end] - pref[start-1]\n\n offers = {}\n for i in range(m):\n a, b = list(map(int, input().split()))\n if a not in offers:\n offers[a] = b\n else:\n if b > offers[a]:\n offers[a] = b\n\n if 1 not in offers:\n offers[1] = 0\n\n dp = [math.inf] * (k+1)\n dp[0] = 0\n for i in range(0, k+1):\n for j in offers:\n if i + j <= k:\n dp[i+j] = min(dp[i+j], dp[i] + getPref(i + offers[j]+1, i+j))\n\n print(dp[k])\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "from audioop import reverse\nn, m, k = list(map(int,input().split()))\nprice = list(map(int,input().split()))\noffer = [0] * (k + 1)\nfor i in range(m):\n x , y = list(map(int,input().split()))\n if x <= k:\n offer[x] = max(offer[x] , y)\nprice.sort()\nfor _ in range(n-k):\n price.pop()\nprice.sort(reverse=True)\nprep = [0] * (k + 1)\nfor i in range(k):\n prep[i + 1] = prep[i] + price[i] \nmin_price = [prep[k]] * (k + 1)\nmin_price[0] = 0\nfor i in range(k):\n min_price[i + 1] = min(min_price[i + 1],min_price[i] + price[i])\n for j in range(1 , k + 1):\n if offer[j] == 0:\n continue\n if i + j > k:\n break\n min_price[i + j] = min(min_price[i + j] , min_price[i] + prep[i + j - offer[j]] -prep[i])\nprint(min_price[k]) \n \n \n \n \n \n \n \n \n \n \n \n", "n, m, k = (int(i) for i in input().split())\ncost = sorted([int(i) for i in input().split()])[:k] + [0]\n\ndiscount = [0] * n\nfor i in range(m):\n a, b = (int(j) for j in input().split())\n discount[a - 1] = max(discount[a - 1], b)\n\nS = [0] * (k + 1)\nfor i in range(k):\n S[i] = cost[i] + S[i - 1]\n cost[i] += cost[i - 1] \n for j in range(i + 1):\n S[i] = min(S[i], S[j - 1] + cost[i] - cost[j - 1 + discount[i - j]])\nprint(S[k - 1])", "import sys\n\ndp = []\nsum = []\nINF = sys.maxsize / 2\n\ndef sum_range(a, b):\n\tif a == 0:\n\t\treturn sum[b]\n\treturn sum[b] - sum[a - 1]\n\ndef rec(pos, sale, n, k):\n\tif k == 0:\n\t\treturn 0\n\tif dp[k] != -1:\n\t\treturn dp[k]\n\t\n\tres = INF\n\tfor x in range(1, k + 1):\n\t\tif sale[x] != -1:\n\t\t\tres = min(res, rec(pos + x, sale, n, k - x) + sum_range(pos + sale[x], pos + x - 1))\n\tdp[k] = res\n\treturn res\n\ninp = [int(x) for x in sys.stdin.read().split()]\n\nn, m, k = inp[0], inp[1], inp[2]\ninp_idx = 3\n\na = []\nfor _ in range(n):\n\ta.append(inp[inp_idx])\n\tinp_idx += 1\n\nsale = [-1] * (k + 1)\nsale[1] = 0\nfor _ in range(m):\n\tx, y = inp[inp_idx], inp[inp_idx + 1]\n\tinp_idx += 2\n\tif x > k:\n\t\tcontinue\n\tsale[x] = max(sale[x], y)\n\t\na.sort()\n\nsum = [0] * n\nsum[0] = a[0]\nfor i in range(1, n):\n\tsum[i] = sum[i - 1] + a[i]\n\ndp = [-1] * (k + 1)\ncost = rec(0, sale, n, k)\nprint(cost)", "n,m,k=map(int,input().split())\narr=list(map(int,input().split()))\noffer=[list(map(int,input().split())) for _ in range(m)]\narr=sorted(arr)\narr=arr[:k]\narr=arr[::-1]\nacum=[0]\nfor i in range(k):\n acum.append(acum[-1]+arr[i])\ndp=[acum[i] for i in range(k+1)]\nfor x,y in offer:\n if x>k:\n continue\n for i in range(x,k+1):\n dp[i]=min(dp[i],dp[i-x]+(acum[i]-acum[i-x])-(acum[i]-acum[i-y]))\n tmp=dp[0]\n for i in range(1,k+1):\n tmp=min(tmp,dp[i-1])+arr[i-1]\n dp[i]=min(dp[i],tmp)\nfor x,y in offer:\n if x>k:\n continue\n for i in range(x,k+1):\n dp[i]=min(dp[i],dp[i-x]+(acum[i]-acum[i-x])-(acum[i]-acum[i-y]))\n tmp=dp[0]\n for i in range(1,k+1):\n tmp=min(tmp,dp[i-1])+arr[i-1]\n dp[i]=min(dp[i],tmp)\nprint(dp[k])"] | {
"inputs": [
"7 4 5\n2 5 4 2 6 3 1\n2 1\n6 5\n2 1\n3 1\n",
"9 4 8\n6 8 5 1 8 1 1 2 1\n9 2\n8 4\n5 3\n9 7\n",
"5 1 4\n2 5 7 4 6\n5 4\n"
],
"outputs": [
"7\n",
"17\n",
"17\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 16,226 | |
871de1efd17ead8f22746bbf5da84fee | UNKNOWN | You are given two positive integers $n$ and $k$. Print the $k$-th positive integer that is not divisible by $n$.
For example, if $n=3$, and $k=7$, then all numbers that are not divisible by $3$ are: $1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$. The $7$-th number among them is $10$.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Next, $t$ test cases are given, one per line.
Each test case is two positive integers $n$ ($2 \le n \le 10^9$) and $k$ ($1 \le k \le 10^9$).
-----Output-----
For each test case print the $k$-th positive integer that is not divisible by $n$.
-----Example-----
Input
6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1
Output
10
15
1999999999
113
1000000001
1 | ["from sys import *\nfrom collections import *\nfrom math import *\n\ninput = stdin.readline\n\ntc = int(input())\nfor tcase in range(tc):\n\tn, k = map(int, input().split())\n\tlo = 1\n\thi = 10 ** 19\n\tans = -1\n\twhile (lo <= hi):\n\t\tmid = (lo + hi) // 2\n\t\tdivi = mid - mid // n\n\t\tif (divi >= k):\n\t\t\tans = mid\n\t\t\thi = mid - 1\n\t\telse:\n\t\t\tlo = mid + 1\n\tprint(ans)", "for _ in range(int(input())):\n n, k = list(map(int, input().split()))\n k -= 1\n print(k//(n-1)*n+k % (n-1)+1)\n", "import math \nfor i in range(int(input())):\n n,k=list(map(int,input().split()))\n e=math.ceil(k/(n-1))-1\n print(k+e)\n", "t = int(input())\nfor _ in range(t):\n\tn, k = map(int, input().split())\n\tprint(n * ((k-1) // (n-1)) + ((k-1) % (n-1)) + 1)", "for _ in range(int(input())):\n n, k = list(map(int, input().split()))\n num = k // (n - 1)\n if k % (n - 1) == 0:\n ans = num * n - 1\n else:\n ans = num * n + k % (n - 1)\n print(ans)", "for t in range(int(input())):\n n, k = list(map(int, input().split()))\n if k % (n - 1) == 0:\n print(k // (n - 1) * n - 1)\n else:\n print(k // (n - 1) * n + k % (n - 1))", "def f(x, n):\n return x // n\n\ndef ff(l, r, n):\n return f(r, n) - f(l - 1, n)\n\nfor _ in range(int(input())):\n # n = int(input())\n # arr = list(map(int, input().split()))\n n, k = list(map(int, input().split()))\n k -= 1\n s = 1\n while k > 0:\n nk = ff(s, s + k, n)\n s += k\n k = nk\n if s % n == 0:\n s -= 1\n if k == 1:\n k = 0\n s += 1\n if s % n == 0:\n s += 1\n\n print(s)\n", "t = int(input())\nfor _ in range(t):\n n, k = map(int, input().split())\n\n ans = n*(k//(n-1))\n if k%(n-1)==0:\n ans -= 1\n else:\n ans += k%(n-1)\n\n print(ans)", "t = int(input())\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n k -= 1\n out = (k % (n - 1))\n k //= (n - 1)\n out += k * n\n out += 1\n print(out)\n", "t = int(input())\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n print(k+(k-1)//(n-1))\n", "for tc in range(int(input())):\n n, k = [int(s) for s in input().split()]\n k -= 1\n print(k // (n-1) * n + k % (n-1) + 1)\n", "for _ in range(int(input())):\n n,k=map(int,input().split())\n lo=0 \n hi=10**20\n def check(mi):\n return mi-mi//n>=k \n while lo<=hi:\n mi=(lo+hi)//2 \n if check(mi):\n ans=mi \n hi=mi-1 \n else:\n lo=mi+1 \n print(ans)", "import math\nfor _ in range(int(input())):\n\tn,k=list(map(int,input().split()))\n\tl=k//(n-1)\n\tr=k%(n-1)\n\tif r==0:\n\t\tr=-1\n\tprint(l*n+r)\n\n\n\n\t\n"] | {
"inputs": [
"6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1\n",
"7\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
"1\n841 4832526\n"
],
"outputs": [
"10\n15\n1999999999\n113\n1000000001\n1\n",
"1\n1\n1\n1\n1\n1\n1\n",
"4838279\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 2,807 | |
837299b595c2322550ea905f3ec34a0c | UNKNOWN | The only difference between easy and hard versions are constraints on $n$ and $k$.
You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $k$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $0$).
Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.
You (suddenly!) have the ability to see the future. You know that during the day you will receive $n$ messages, the $i$-th message will be received from the friend with ID $id_i$ ($1 \le id_i \le 10^9$).
If you receive a message from $id_i$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.
Otherwise (i.e. if there is no conversation with $id_i$ on the screen):
Firstly, if the number of conversations displayed on the screen is $k$, the last conversation (which has the position $k$) is removed from the screen. Now the number of conversations on the screen is guaranteed to be less than $k$ and the conversation with the friend $id_i$ is not displayed on the screen. The conversation with the friend $id_i$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.
Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $n$ messages.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 2 \cdot 10^5)$ β the number of messages and the number of conversations your smartphone can show.
The second line of the input contains $n$ integers $id_1, id_2, \dots, id_n$ ($1 \le id_i \le 10^9$), where $id_i$ is the ID of the friend which sends you the $i$-th message.
-----Output-----
In the first line of the output print one integer $m$ ($1 \le m \le min(n, k)$) β the number of conversations shown after receiving all $n$ messages.
In the second line print $m$ integers $ids_1, ids_2, \dots, ids_m$, where $ids_i$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $i$ after receiving all $n$ messages.
-----Examples-----
Input
7 2
1 2 3 2 1 3 2
Output
2
2 1
Input
10 4
2 3 3 1 1 2 1 2 3 3
Output
3
1 3 2
-----Note-----
In the first example the list of conversations will change in the following way (in order from the first to last message):
$[]$; $[1]$; $[2, 1]$; $[3, 2]$; $[3, 2]$; $[1, 3]$; $[1, 3]$; $[2, 1]$.
In the second example the list of conversations will change in the following way:
$[]$; $[2]$; $[3, 2]$; $[3, 2]$; $[1, 3, 2]$; and then the list will not change till the end. | ["from collections import deque\nn, k = map(int, input().split())\nA = list(map(int, input().split()))\nB = deque()\nB.append(A[0])\nnc = {}\nfor i in set(A):\n nc[i] = 0\nnc[A[0]] = 1\nfor i in range(1, n):\n if nc[A[i]] == 0:\n if len(B) == k:\n nc[B[0]] -= 1\n B.popleft()\n B.append(A[i])\n nc[A[i]] += 1\n else:\n pass\nprint(len(B))\nprint(*list(B)[::-1])", "n, k = map(int, input().split())\na = map(int, input().split())\n\nlt = dict()\ntimer = 0\nfor Id in a :\n if Id not in lt :\n lt[Id] = -k\n cur_time = lt[Id]\n if cur_time <= timer - k :\n timer += 1\n lt[Id] = timer\n \nscreen = list(lt.items())\nscreen.sort(key=(lambda t: -t[1]))\n# print(screen)\nscreen = screen[:min(n, k)]\nprint(len(screen))\nfor v in screen :\n print(v[0], end=' ')\nprint()\n", "from collections import deque\na, b = map(int, input().split())\nli = list(map(int, input().split()))\ns = set()\nl = deque([])\nle = 0\nfor i in li:\n if i in s:\n pass\n elif le < b:\n le += 1\n s.add(i)\n l.appendleft(i)\n else:\n s.remove(l.pop())\n s.add(i)\n l.appendleft(i) \nprint(len(l))\nprint(*list(l))", "from collections import deque\nn,k=map(int,input().split())\nd=deque()\ns=set()\nfor i in map(int,input().split()):\n if i in s:continue\n d.appendleft(i);s.add(i)\n if len(d)>k:s.discard(d.pop())\nprint(len(d))\nprint(*d)", "import sys\ninput = sys.stdin.readline\n\nn,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\nSET=set()\n\nfrom collections import deque\n\nQ=deque()\n\nfor a in A:\n if a in SET:\n continue\n else:\n if len(Q)==k:\n x=Q.pop()\n SET.remove(x)\n Q.appendleft(a)\n SET.add(a)\n else:\n SET.add(a)\n Q.appendleft(a)\n\nprint(len(Q))\nprint(*Q)\n \n \n", "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())\n\nn, k = mapin()\na = listin()\ns = set([])\nd = deque([])\nfor i in a:\n if len(d) < k:\n if i not in s:\n s.add(i)\n d.append(i)\n else:\n if i not in s:\n s.remove(d.popleft())\n d.append(i)\n s.add(i)\nprint(len(d))\nd = list(d)\nd.reverse()\nprint(*d)", "import heapq\nimport math\n\nimport sys\ninput = sys.stdin.readline\n\ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef value():return int(input())\n\nn,k = li()\na = li()\n\ncurr = []\ncurrd = {}\ncurrd2 = {}\nfor i in range(n):\n if a[i] not in currd2:\n if len(curr) == k:\n \n currd2.pop(currd.pop(heapq.heappop(curr)))\n heapq.heappush(curr,i)\n currd[i] = a[i]\n currd2[a[i]] = i\ncurr.sort(reverse = 1)\nans = []\nfor i in curr:\n ans.append(currd[i])\nprint(len(ans))\nprint(*ans)", "n, k = map(int, input().split())\na = [*map(int, input().split())]\n\nfrom collections import deque\n\nans = deque()\nins = set()\n\nfor i in a:\n\tif i not in ins:\n\t\tif len(ans) == k:\n\t\t\tins.remove(ans[0])\n\t\t\tans.popleft()\n\t\tans.append(i)\n\t\tins.add(i)\n\nans.reverse()\n\nprint(len(ans))\n\nprint(*ans)", "from collections import deque\nn, k = map(int, input().split())\na = [int(i) for i in input().split()]\nnow = set()\nletters = deque()\nfor i in range(n):\n if a[i] not in now:\n now.add(a[i])\n if len(letters) < k:\n letters.append(a[i])\n else:\n now.remove(letters.popleft())\n letters.append(a[i])\nprint(len(letters))\nprint(*list(letters)[::-1])", "from collections import deque\nn, k = list(map(int,input().split()))\n\nq = deque()\na = list(map(int, input().split()))\nvis = set()\n\nfor i in range(n):\n if len(q) < k:\n if a[i] not in vis:\n q.append(a[i])\n vis.add(a[i])\n else:\n if a[i] not in vis:\n q.append(a[i])\n vis.remove(q.popleft())\n vis.add(a[i])\n\nprint(len(q))\nprint(str(list(q)[::-1]).replace('[','').replace(']','').replace(', ',' '))\n", "from collections import OrderedDict\nclass LRUCache:\n\n def __init__(self, capacity):\n self.capacity = capacity\n self.cache = OrderedDict()\n\n def set(self, key, value):\n if len(self.cache) == self.capacity:\n self.cache.popitem(last=False)\n self.cache[key] = value\n\nn, k = map(int, input().strip().split())\nids = map(int, input().strip().split())\nconvs = LRUCache(k)\nfor i in ids:\n if i in convs.cache:\n continue\n else:\n convs.set(i, None)\nprint(len(convs.cache))\nprint(\" \".join(map(str, reversed(convs.cache.keys()))))", "from collections import defaultdict as df\nimport heapq\nimport bisect \nimport math\nfrom itertools import combinations,permutations\nfrom collections import deque\n\nn,k=list(map(int,input().split()))\na=list(map(int,input().rstrip().split()))\nans=deque()\np=df(int)\nfor i in range(n):\n p[i]=0\nfor i in a:\n if p[i]>0:\n pass\n \n else:\n if len(ans)>=k:\n g=ans.pop()\n ans.appendleft(i)\n p[i]+=1\n p[g]-=1\n else:\n ans.appendleft(i)\n p[i]+=1\nprint(len(ans))\nprint(*ans)", "a=list(map(int,input().split()))\nsc=a[1]\nm=a[0]\na=list(map(int,input().split()))\nd={}\ns=[]\nfor i in a:\n if i in d: continue\n if len(s)<sc: \n s.append(i)\n d[i]=1\n else:\n d.pop(s.pop(0))\n s.append(i)\n d[i]=1\nprint(len(s))\nprint(*s[::-1])", "'''input\n10 4\n2 3 3 1 1 2 1 2 3 3\n'''\nfrom sys import stdin\nfrom collections import deque\nimport math\n\n\n# main starts\nn, k = list(map(int, stdin.readline().split()))\narr = list(map(int, stdin.readline().split()))\nmyq = deque([])\nmyset = set()\nfor i in range(n):\n\tif arr[i] in myset:\n\t\tpass\n\telse:\n\t\tif len(myq) == k:\n\t\t\tel = myq[-1]\n\t\t\tmyset.remove(el)\n\t\t\tmyq.pop()\n\t\tmyq.appendleft(arr[i])\n\t\tmyset.add(arr[i])\n\nprint(len(myq))\n\nprint(*myq)", "from collections import deque\nn, k = list(map(int, input().split()))\ns = set()\nd = deque()\nfor i in map(int, input().split()):\n if i in s:\n continue\n if len(d) == k:\n s.discard(d.pop())\n d.appendleft(i)\n s.add(i)\nprint(len(d))\nprint(*d)\n", "from bisect import *\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nfrom decimal import *\nfrom copy import *\nfrom heapq import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 1000010\nMOD = 10**9+7\nspf = [i for i in range(MAXN)]\ndef sieve():\n for i in range(2,MAXN,2):\n spf[i] = 2\n for i in range(3,int(MAXN**0.5)+1):\n if spf[i]==i:\n for j in range(i*i,MAXN,i):\n if spf[j]==j:\n spf[j]=i\ndef fib(n,m):\n if n == 0:\n return [0, 1]\n else:\n a, b = fib(n // 2)\n c = ((a%m) * ((b%m) * 2 - (a%m)))%m\n d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m\n if n % 2 == 0:\n return [c, d]\n else:\n return [d, c + d]\n\ndef charIN(x= ' '):\n return(sys.stdin.readline().strip().split(x))\n\ndef arrIN(x = ' '):\n return list(map(int,sys.stdin.readline().strip().split(x)))\n\ndef ncr(n,r):\n num=den=1\n for i in range(r):\n num = (num*(n-i))%MOD\n den = (den*(i+1))%MOD\n\n return (num*(pow(den,MOD-2,MOD)))%MOD\n\ndef flush():\n return sys.stdout.flush()\n\n'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''\n\nn,k = arrIN()\na = arrIN()\nst = []\nls = 0\nf = defaultdict(int)\nj = 0\nfor i in a:\n if f[i]==0:\n if ls<k:\n st.append(i)\n f[i] = 1\n ls+=1\n else:\n f[st[j]] = 0\n j+=1\n st.append(i)\n f[i] = 1\n #print(st)\nprint(len(st)-j)\nfor i in range(len(st)-1,j-1,-1):\n print(st[i],end=' ')\n", "import sys\nfrom collections import deque, defaultdict\n\n# stdin = open(\"testdata.txt\", \"r\")\nn, k = map(int, sys.stdin.readline().split())\n\na = list(map(int, sys.stdin.readline().split()))\ndq = deque()\non_dq = defaultdict(int)\nlength = 0\nfor ele in a:\n\tif not on_dq[ele]:\n\t\ton_dq[ele] = 1\n\t\tlength += 1\n\t\tdq.appendleft(ele)\n\t\tif length > k:\n\t\t\titem = dq.pop()\n\t\t\ton_dq[item] = 0\n\t\t\tlength -= 1\nprint(length)\nprint(*dq)", "N, K = map(int, input().split())\nid_list = list(map(int, input().split()))\n\nfrom collections import deque\n\nque = deque()\nused = set()\n\nfor id in id_list:\n if id in used:\n continue\n else:\n if len(que) >= K:\n q = que.pop()\n used.remove(q)\n que.appendleft(id)\n used.add(id)\n\nprint(len(que))\nwhile len(que) != 0:\n print(que.popleft(), end=\" \")\n", "# -*- coding: utf-8 -*-\n\nimport sys\nfrom collections import deque\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\nN, K = MAP()\nA = LIST()\n\nque = deque()\nS = set()\nfor a in A:\n if len(que) < K:\n if a not in S:\n que.appendleft(a)\n S.add(a)\n else:\n if a not in S:\n b = que.pop()\n S.remove(b)\n que.appendleft(a)\n S.add(a)\nprint(len(que))\nprint(*que)\n", "n,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nfrom collections import deque\nfrom collections import defaultdict\nb = deque()\nc = defaultdict(int)\nfor i in a:\n c[i]=0\nl = 0\ni = 0\nwhile i<n:\n if l<k:\n if c[a[i]]==1:\n i=i+1\n continue\n else:\n b.appendleft(a[i])\n c[a[i]]=1\n l=l+1\n i=i+1\n else:\n if c[a[i]]==1:\n i=i+1\n continue\n else:\n e=b.pop()\n c[e]=0\n c[a[i]]=1\n b.appendleft(a[i])\n i=i+1\nprint(len(b))\nprint(*b)\n", "from queue import Queue\n\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n\n checked = {}\n for a in A:\n checked[a] = False\n\n q = Queue()\n for i, a in enumerate(A):\n if checked[a]:\n continue\n else:\n checked[a] = True\n q.put(a)\n if q.qsize() > K:\n b = q.get()\n checked[b] = False\n L = q.qsize()\n ans = []\n for i in range(L):\n a = q.get()\n ans.append(a)\n print(L)\n print(' '.join([str(a) for a in ans[::-1]]))\n\ndef __starting_point():\n main()\n__starting_point()"] | {
"inputs": [
"7 2\n1 2 3 2 1 3 2\n",
"10 4\n2 3 3 1 1 2 1 2 3 3\n",
"1 4\n1\n"
],
"outputs": [
"2\n2 1 \n",
"3\n1 3 2 \n",
"1\n1 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 11,534 | |
a49aa6a6e8775e0457bf8744d1b2a6d9 | UNKNOWN | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed $3$. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.
Your character has also found an artifact that boosts the damage of some of your actions: every $10$-th card you play deals double damage.
What is the maximum possible damage you can deal during $n$ turns?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of turns.
Then $n$ blocks of input follow, the $i$-th block representing the cards you get during the $i$-th turn.
Each block begins with a line containing one integer $k_i$ ($1 \le k_i \le 2 \cdot 10^5$) β the number of cards you get during $i$-th turn. Then $k_i$ lines follow, each containing two integers $c_j$ and $d_j$ ($1 \le c_j \le 3$, $1 \le d_j \le 10^9$) β the parameters of the corresponding card.
It is guaranteed that $\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5$.
-----Output-----
Print one integer β the maximum damage you may deal.
-----Example-----
Input
5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100
Output
263
-----Note-----
In the example test the best course of action is as follows:
During the first turn, play all three cards in any order and deal $18$ damage.
During the second turn, play both cards and deal $7$ damage.
During the third turn, play the first and the third card and deal $13$ damage.
During the fourth turn, play the first and the third card and deal $25$ damage.
During the fifth turn, play the only card, which will deal double damage ($200$). | ["import sys\nimport math\nimport cProfile\n\nDEBUG = False\ndef log(s):\n if DEBUG and False:\n print(s)\n \ndef calc_dmg(num, arr):\n maximum = 0\n if num - len(arr) < 0:\n maximum = max(arr)\n return sum(arr) + maximum\n\nif DEBUG:\n sys.stdin = open('input.txt')\n pr = cProfile.Profile()\n pr.enable()\n\nn = sys.stdin.readline()\nn = int(n)\n\ndmg = [-sys.maxsize for _ in range(10)]\n\nfor i in range(n):\n log(dmg)\n cards = [_[:] for _ in [[-sys.maxsize] * 3] * 4]\n\n k = sys.stdin.readline()\n k = int(k)\n for _ in range(k):\n c, d = sys.stdin.readline().split()\n c = int(c)\n d = int(d)\n cards[c].append(d)\n cards[1].sort(reverse=True)\n cards[2].sort(reverse=True)\n cards[3].sort(reverse=True)\n log(cards)\n\n # dmg[j] = max(dmg[j],\n # dmg[j - 1] + D(one card),\n # dmg[j - 2] + D(two cards),\n # dmg[j - 3] + D(three cards))\n # Plus, if 1 <= j <= 3, dmg[j] = max(dmg[j], D(cards))\n new_dmg = []\n for j in range(10):\n use1 = max(cards[1][0], cards[2][0], cards[3][0])\n use2 = max(cards[1][0] + cards[1][1],\n cards[1][0] + cards[2][0])\n use3 = cards[1][0] + cards[1][1] + cards[1][2]\n\n maximum = dmg[j]\n if use1 > 0:\n maximum = max(maximum, dmg[j - 1] + calc_dmg(j, [use1]))\n if j == 1:\n maximum = max(maximum, use1)\n if use2 > 0:\n maximum = max(maximum, dmg[j - 2] +\n calc_dmg(j, [cards[1][0], cards[1][1]]\n if cards[1][0] + cards[1][1] == use2\n else [cards[1][0], cards[2][0]]))\n if j == 2:\n maximum = max(maximum, use2)\n if use3 > 0:\n maximum = max(maximum, dmg[j - 3] +\n calc_dmg(j, [cards[1][0], cards[1][1], cards[1][2]]))\n if j == 3:\n maximum = max(maximum, use3)\n new_dmg.append(maximum)\n dmg = new_dmg\n\nlog(dmg)\nprint(max(dmg))\n\nif DEBUG:\n pr.disable()\n pr.print_stats()"] | {
"inputs": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n"
],
"outputs": [
"263\n",
"211\n",
"4\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 2,185 | |
ceace9abfadd512012305a2de7238a11 | UNKNOWN | You are given a string $s$ consisting of lowercase Latin letters and $q$ queries for this string.
Recall that the substring $s[l; r]$ of the string $s$ is the string $s_l s_{l + 1} \dots s_r$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top".
There are two types of queries: $1~ pos~ c$ ($1 \le pos \le |s|$, $c$ is lowercase Latin letter): replace $s_{pos}$ with $c$ (set $s_{pos} := c$); $2~ l~ r$ ($1 \le l \le r \le |s|$): calculate the number of distinct characters in the substring $s[l; r]$.
-----Input-----
The first line of the input contains one string $s$ consisting of no more than $10^5$ lowercase Latin letters.
The second line of the input contains one integer $q$ ($1 \le q \le 10^5$) β the number of queries.
The next $q$ lines contain queries, one per line. Each query is given in the format described in the problem statement. It is guaranteed that there is at least one query of the second type.
-----Output-----
For each query of the second type print the answer for it β the number of distinct characters in the required substring in this query.
-----Examples-----
Input
abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7
Output
3
1
2
Input
dfcbbcfeeedbaea
15
1 6 e
1 4 b
2 6 14
1 7 b
1 12 c
2 6 8
2 1 6
1 7 c
1 2 f
1 10 a
2 7 9
1 10 a
1 14 b
1 1 f
2 1 11
Output
5
2
5
2
6 | ["# -*- coding: utf-8 -*-\n\nimport sys\nfrom operator import add\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\nclass SegTree:\n \n def __init__(self, n, func, init):\n\n self.n = n\n self.func = func\n self.init = init\n\n n2 = 1\n while n2 < n:\n n2 <<= 1\n self.n2 = n2\n self.tree = [self.init] * (n2 << 1)\n \n def update(self, i, x):\n\n i += self.n2\n self.tree[i] = x\n while i > 1:\n self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])\n i >>= 1\n \n def query(self, a, b):\n\n l = a + self.n2\n r = b + self.n2\n s = self.init\n while l < r:\n if r & 1:\n r -= 1\n s = self.func(s, self.tree[r])\n if l & 1:\n s = self.func(s, self.tree[l])\n l += 1\n l >>= 1\n r >>= 1\n return s\n\nA = [ord(s)-97 for s in list(input())]\nN = len(A)\n\nst = [None] * 26\nfor i in range(26):\n st[i] = SegTree(N, add, 0)\nfor i, a in enumerate(A):\n st[a].update(i, 1)\n\nfor _ in range(INT()):\n a, b, c = input().split()\n if a == '1':\n b = int(b)\n cur = A[b-1]\n nxt = ord(c) - 97\n st[cur].update(b-1, 0)\n st[nxt].update(b-1, 1)\n A[b-1] = nxt\n else:\n b = int(b)\n c = int(c)\n cnt = 0\n for i in range(26):\n if st[i].query(b-1, c) >= 1:\n cnt += 1\n print(cnt)\n", "import heapq\nimport math\n\nimport sys\ninput = sys.stdin.readline\n\ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef value():return int(input())\n\n\ndef givesum(a,b):\n c=[0]*26\n for i in range(len(a)):\n c[i] = a[i]+b[i]\n return c\ndef dolist(a):\n c = [0]*26\n c[ord(a)-ord('a')] = 1\n return c\n \nclass Node:\n def __init__(self,s,e):\n self.start=s\n self.end=e\n self.lis=[0]*26\n self.left=None\n self.right=None\n\ndef build(nums,l,r):\n if l == r:\n temp = Node(l,l)\n # print(temp.start,ord(nums[l])-ord('a'),nums)\n temp.lis[ord(nums[l])-ord('a')] = 1\n else:\n mid=(l+r)>>1\n # print(mid,l,r)\n temp=Node(l,r)\n temp.left=build(nums,l,mid)\n temp.right=build(nums,mid+1,r)\n temp.lis=givesum(temp.left.lis,temp.right.lis)\n return temp\n\ndef update(root,start,value):\n if root.start==root.end==start:\n root.lis=dolist(value)\n elif root.start<=start and root.end>=start:\n mid=(root.start+root.end)>>1\n root.left=update(root.left,start,value)\n root.right=update(root.right,start,value)\n root.lis=givesum(root.left.lis,root.right.lis)\n return root\n \ndef query(root,start,end):\n if root.start>=start and root.end<=end:return root.lis\n elif root.start>end or root.end<start:return [0]*26;\n else:\n mid=(start+end)>>1\n return givesum(query(root.left,start,end),query(root.right,start,end))\n \ns = input().rstrip('\\n')\nroot = build(s,0,len(s)-1)\nansarun = []\n# print('arun')\nfor _ in range(int(input())):\n templist = list(input().split())\n if templist[0] == '1':\n root = update(root,int(templist[1])-1,templist[2])\n else:\n temp1 = query(root,int(templist[1])-1,int(templist[2])-1)\n total = 0\n for i in temp1:\n if i:total+=1\n ansarun.append(total)\nfor i in ansarun:print(i)\n \n \n \n \n", "from string import ascii_lowercase as lows\nimport sys\n\ninput = sys.stdin.readline\n\nN = (1<<17)\n\nclass bit:\n def __init__( self ):\n self.l = [0]*(1 + N)\n def set( self, i ):\n self.add( i, 1 )\n def unset( self, i ):\n self.add( i, -1 )\n def add( self, i, val ):\n while i <= N:\n self.l[ i ] += val\n i += (i & (-i))\n def get( self, i ):\n r = 0\n while i > 0:\n r += self.l[ i ]\n i -= (i & (-i))\n return r\n def range( self, l, r ):\n return self.get( r ) - self.get( l - 1 )\n\nbits = { c: bit() for c in lows }\n\ns = [ c for c in input().strip() ]\nfor i, c in enumerate(s):\n bits[ c ].set( i + 1 )\nq = int(input().strip())\n\nfor _ in range(q):\n ins = input().split()\n if ins[ 0 ] == '1':\n pos = int( ins[ 1 ] )\n bits[ s[ pos - 1 ] ].unset( pos )\n bits[ ins[ 2 ] ].set( pos )\n s[ pos - 1 ] = ins[ 2 ]\n else:\n l, r = list(map(int, ins[1:] ))\n sm = 0\n for b in list(bits.values()):\n if b.range( l, r ) > 0:\n sm += 1\n print( sm )\n", "from string import ascii_lowercase as lows\nimport sys\n\ninput = sys.stdin.readline\n\ns = [ c for c in input().strip() ]\nN = len(s)\n\nclass bit:\n def __init__( self ):\n self.l = [0]*(1 + N)\n def set( self, i ):\n self.add( i, 1 )\n def unset( self, i ):\n self.add( i, -1 )\n def add( self, i, val ):\n while i <= N:\n self.l[ i ] += val\n i += (i & (-i))\n def get( self, i ):\n r = 0\n while i > 0:\n r += self.l[ i ]\n i -= (i & (-i))\n return r\n def range( self, l, r ):\n return self.get( r ) - self.get( l - 1 )\n\nbits = { c: bit() for c in lows }\n\nfor i, c in enumerate(s):\n bits[ c ].set( i + 1 )\nq = int(input().strip())\n\nfor _ in range(q):\n ins = input().split()\n if ins[ 0 ] == '1':\n pos = int( ins[ 1 ] )\n bits[ s[ pos - 1 ] ].unset( pos )\n bits[ ins[ 2 ] ].set( pos )\n s[ pos - 1 ] = ins[ 2 ]\n else:\n l, r = list(map(int, ins[1:] ))\n sm = 0\n for b in list(bits.values()):\n if b.range( l, r ) > 0:\n sm += 1\n print( sm )\n", "s=input()\nq=int(input())\nT=[]\nfor i in range(4*len(s)+10):\n T.append(0)\n\ndef create(rt,l,r):\n if(l==r):\n T[rt]=1<<(ord(s[l-1])-97)\n return\n mid=(l+r)//2\n create(rt<<1,l,mid)\n create(rt<<1|1,mid+1,r)\n T[rt]=T[rt<<1]|T[rt<<1|1]\n\ndef update(rt,l,r,pos,now):\n if(l==r):\n T[rt]=1<<(ord(now)-97)\n return\n mid=(l+r)//2\n if(pos<=mid):\n update(rt<<1,l,mid,pos,now)\n else:\n update(rt<<1|1,mid+1,r,pos,now)\n T[rt]=T[rt<<1]|T[rt<<1|1]\n\ndef cal(rt,l,r,L,R):\n if(l==L and R==r):\n return T[rt]\n mid=(l+r)//2\n if(R<=mid):\n return cal(rt<<1,l,mid,L,R)\n elif(L>mid):\n return cal(rt<<1|1,mid+1,r,L,R)\n else:\n return cal(rt<<1,l,mid,L,mid)|cal(rt<<1|1,mid+1,r,mid+1,R)\n\nn=len(s)\ncreate(1,1,n)\n\nfor i in range(q):\n str=input().split()\n if(str[0]=='1'):\n pos=int(str[1])\n update(1,1,n,pos,str[2])\n else:\n l=int(str[1])\n r=int(str[2])\n res=cal(1,1,n,l,r)\n ans=0\n while(res>0):\n if(res%2==1):\n ans+=1\n res//=2\n print(ans)", "def update(v,w,s):\n \n while v<=length:\n l[s][v]+=w\n v+=(v&(-v))\ndef get_value(v,s):\n ans=0\n \n while v!=0:\n \n ans+=l[s][v]\n v-=(v&(-v))\n return ans\nfrom sys import stdin,stdout\ns=list(stdin.readline().strip())\nq=int(stdin.readline())\nlength=len(s)\nl=[[0 for i in range(length+1)] for _ in range(26)]\n\nfor i in range(length):\n x=ord(s[i])-97\n update(i+1,1,x)\n\nfor _ in range(q):\n \n n,m,k=stdin.readline().split()\n if n=='1':\n a=s[int(m)-1]\n x,y=ord(a)-97,ord(k)-97\n update(int(m),-1,x)\n update(int(m),1,y)\n s[int(m)-1]=k\n \n else:\n count=0\n left,r=int(m),int(k)\n for i in range(26):\n if get_value(r,i)-get_value(left-1,i)>=1:\n \n count+=1\n print(count)\n \n", "\nfrom sys import stdin,stdout\n\nR = lambda: map(int, input().split())\nS = list(stdin.readline().strip())\nQ = int(input())\nn = len(S)\nS = list(S)\nsum_array = [[0] * (n+1) for _ in range(26)]\n\n\ndef lowbit(x):\n return x & -x\n\ndef add(x, val, idx):\n while x <= n:\n sum_array[idx][x] += val\n x += lowbit(x)\n\ndef sum(x, idx):\n res = 0\n while x > 0:\n res += sum_array[idx][x]\n x -= lowbit(x)\n return res\n\n\nfor i in range(n):\n idx = ord(S[i]) - 97\n add(i+1, 1, idx)\n\nfor _ in range(Q):\n A = stdin.readline().split()\n a, b, c = int(A[0]), int(A[1]), A[2]\n if a == 1:\n pre = ord(S[b-1]) - 97\n cur = ord(c) - 97\n S[b-1] = c\n add(b, -1, pre)\n add(b, 1, cur)\n else:\n c = int(c)\n if c - b == 0:\n print(1)\n else:\n res = 0\n for i in range(26):\n diff = sum(c, i) - sum(b-1, i)\n res += int(diff > 0)\n print(res)", "def update(v,w,s):\n \n while v<=length:\n l[s][v]+=w\n v+=(v&(-v))\ndef get_value(v,s):\n ans=0\n \n while v!=0:\n \n ans+=l[s][v]\n v-=(v&(-v))\n return ans\nfrom sys import stdin,stdout\ns=list(stdin.readline().strip())\nq=int(stdin.readline())\nlength=len(s)\nl=[[0 for i in range(length+1)] for _ in range(26)]\n\nfor i in range(length):\n x=ord(s[i])-97\n update(i+1,1,x)\n\nfor _ in range(q):\n \n n,m,k=stdin.readline().split()\n if n=='1':\n a=s[int(m)-1]\n x,y=ord(a)-97,ord(k)-97\n update(int(m),-1,x)\n update(int(m),1,y)\n s[int(m)-1]=k\n \n else:\n count=0\n left,r=int(m),int(k)\n for i in range(26):\n if get_value(r,i)-get_value(left-1,i)>=1:\n \n count+=1\n print(count)\n", "#test\ns = list(input())\nt = [0 for i in range(len(s)*4)]\nbits = dict()\nb = 1\nfor i in range(97, 123):\n bits[chr(i)] = b\n b<<=1\ndef bit_repr(a):\n return bits[a]\n\ndef popcount(i):\n i = i - ((i >> 1) & 0x55555555)\n i = (i & 0x33333333) + ((i >> 2) & 0x33333333)\n return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24\n\ndef build(A, v, t_left, t_right):\n if t_left == t_right:\n t[v] |= bit_repr(A[t_left])\n return\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t_mid = (t_left + t_right)>>1\n build(A, left_son, t_left, t_mid)\n build(A, right_son, t_mid+1, t_right)\n t[v] = t[left_son] | t[right_son]\n \ndef _update(v, t_left, t_right, index, val):\n while t_left != t_right:\n t_mid = (t_left + t_right)//2\n left_son = (v<<1) + 1\n right_son = left_son + 1\n if index > t_mid:\n t_left = t_mid+1\n v = right_son\n else:\n t_right = t_mid\n v = left_son\n t[v] = bit_repr(val)\n while v:\n v = (v-1)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t[v] = t[left_son] | t[right_son]\n \ndef update(index, val):\n _update(0, 0, len(s)-1, index-1, val)\n \ndef get_set(v, t_left, t_right, left, right):\n if left>right:\n return 0\n if t_left == left and t_right == right:\n return t[v]\n t_mid = (t_left+t_right)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))\n b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)\n return a|b\n \ndef count(l, r):\n return popcount(get_set(0, 0, len(s)-1, l-1, r-1))\n \ndef get_request():\n req = iter(input().split())\n token = int(next(req))\n if token-1: #count\n l, r = list(map(int, req))\n return token, l, r\n else: #change\n pos = int(next(req))\n sym = next(req)\n return token, pos, sym\n \ndef response(req):\n token, a, b = req\n if token - 1: #count\n print(count(a,b))\n else:\n update(a, b)\n \n\nbuild(s,0,0,len(s)-1)\nn = int(input())\nfor i in range(n):\n req = get_request()\n response(req)\n", "#last solution was AC with 1965 ms\n# Test 2\ns = list(input())\nt = [0 for i in range(len(s)*4)]\nbits = dict()\nb = 1\nfor i in range(97, 123):\n bits[chr(i)] = b\n b<<=1\ndef bit_repr(a):\n return bits[a]\n\ndef popcount(i):\n i = i - ((i >> 1) & 0x55555555)\n i = (i & 0x33333333) + ((i >> 2) & 0x33333333)\n return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24\n\ndef build(A, v, t_left, t_right):\n if t_left == t_right:\n t[v] |= bit_repr(A[t_left])\n return\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t_mid = (t_left + t_right)>>1\n build(A, left_son, t_left, t_mid)\n build(A, right_son, t_mid+1, t_right)\n t[v] = t[left_son] | t[right_son]\n \ndef _update(v, t_left, t_right, index, val):\n while t_left != t_right:\n t_mid = (t_left + t_right)//2\n left_son = (v<<1) + 1\n right_son = left_son + 1\n if index > t_mid:\n t_left = t_mid+1\n v = right_son\n else:\n t_right = t_mid\n v = left_son\n t[v] = bit_repr(val)\n while v:\n v = (v-1)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t[v] = t[left_son] | t[right_son]\n \ndef update(index, val):\n _update(0, 0, len(s)-1, index-1, val)\n \ndef get_set(v, t_left, t_right, left, right):\n if left>right:\n return 0\n if t_left == left and t_right == right:\n return t[v]\n t_mid = (t_left+t_right)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))\n b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)\n return a|b\n \ndef count(l, r):\n return popcount(get_set(0, 0, len(s)-1, l-1, r-1))\n \ndef get_request():\n req = iter(input().split())\n token = int(next(req))\n if token-1: #count\n l, r = list(map(int, req))\n return token, l, r\n else: #change\n pos = int(next(req))\n sym = next(req)\n return token, pos, sym\n \ndef response(req):\n token, a, b = req\n if token - 1: #count\n print(count(a,b))\n else:\n update(a, b)\n \n\nbuild(s,0,0,len(s)-1)\nn = int(input())\nfor i in range(n):\n req = get_request()\n response(req)\n", "# Test 3\n\n#basic input\ns = input()\nn = int(input())\nt = [0 for i in range(len(s)*4)]\n\n#precalculating masks\nbits = dict()\nb = 1\nfor i in range(97, 123):\n bits[chr(i)] = b\n b<<=1\n\ndef bit_repr(a):\n return bits[a]\n\ndef popcount(i):\n i = i - ((i >> 1) & 0x55555555)\n i = (i & 0x33333333) + ((i >> 2) & 0x33333333)\n return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24\n\ndef build(A, v, t_left, t_right):\n\n if t_left == t_right:\n t[v] |= bit_repr(A[t_left])\n return\n\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t_mid = (t_left + t_right)>>1\n\n build(A, left_son, t_left, t_mid)\n build(A, right_son, t_mid+1, t_right)\n\n t[v] = t[left_son] | t[right_son]\n \ndef _update(v, t_left, t_right, index, val):\n #find destination\n while t_left != t_right:\n t_mid = (t_left + t_right)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n if index > t_mid:\n t_left = t_mid+1\n v = right_son\n else:\n t_right = t_mid\n v = left_son\n #change val\n t[v] = bit_repr(val)\n #update upper nodes\n while v:\n v = (v-1)>>1\n left_son = (v<<1) + 1\n right_son = left_son + 1\n t[v] = t[left_son] | t[right_son]\n \ndef get_set(v, t_left, t_right, left, right):\n if left > right:\n return 0\n if t_left == left and t_right == right:\n return t[v]\n t_mid = (t_left+t_right)>>1\n \n left_son = (v<<1) + 1\n right_son = left_son + 1\n\n a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))\n b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)\n\n return a|b\n \n\n\ndef update(index, val):\n '''Interface for _update function'''\n _update(0, 0, len(s)-1, index-1, val)\n\ndef count(l, r):\n '''Interface for popcount(get_set())'''\n return popcount(get_set(0, 0, len(s)-1, l-1, r-1))\n\ndef process():\n req = iter(input().split())\n token = int(next(req))\n if token-1: #count\n l, r = list(map(int, req))\n print(count(l, r))\n else: #change\n pos = int(next(req))\n sym = next(req)\n update(pos, sym)\n\nbuild(s, 0, 0, len(s)-1)\n\n#request - response part\nfor i in range(n):\n process()\n", "import math\nimport bisect\nfrom functools import reduce\nimport sys\nfrom collections import defaultdict\ninput=sys.stdin.readline\ndef inn():\n return int(input())\n \ndef inl():\n return list(map(int, input().split()))\n \nMOD = 10**9+7\nINF = inf = 10**18+5\n \ns = list(input().strip())\nn = len(s)\nt = [[0]*26 for i in range(2*n)]\n \nfor i in range(n):\n t[i+n][ord(s[i])-97] = 1\n \ndef build():\n for i in range(n-1, 0, -1):\n for j in range(26):\n t[i][j] = t[i<<1][j] + t[i<<1|1][j]\n \ndef modify(p, val):\n t[p+n][ord(s[p])-97] = 0\n t[p+n][ord(val)-97] = 1\n s[p] = val\n p = p+n\n while p>1:\n for i in range(26):\n t[p>>1][i] = t[p][i] + t[p^1][i]\n p >>= 1\n \ndef query(l, r):\n res = [0]*26\n l += n\n r += n\n while l<r:\n if l&1:\n for i in range(26):\n res[i] += t[l][i]\n l += 1\n if r&1:\n r -= 1\n for i in range(26):\n res[i] += t[r][i]\n l >>= 1\n r >>= 1\n return res\n \nbuild()\n \nfor q in range(inn()):\n tp, l, r = input().split()\n tp = int(tp)\n l = int(l)\n if tp==1:\n modify(l-1, r)\n elif tp==2:\n r = int(r)\n res = query(l-1, r)\n c = len([i for i in range(26) if res[i]>0])\n print(c)\n # print(t)\n", "import sys\ninput = sys.stdin.readline\n\nS = list(input().rstrip())\nL = len(S)\nQ = int(input())\ndata = []\nfor _ in range(Q):\n A = list(map(str, input().split()))\n data.append(A)\n\nalp = [chr(i) for i in range(97, 97+26)]\nBITs = {}\nfor a in alp:\n BITs[a] = [0]*(L+1)\n\ndef query_sum(i, al):\n s = 0\n while i > 0:\n s += BITs[al][i]\n i -= i & -i\n return s\n\ndef add(i, x, al):\n while i <= L:\n BITs[al][i] += x\n i += i & -i\n\ndef main():\n for i, s in enumerate(S):\n add(i+1, 1, s)\n\n for A in data:\n if A[0] == '1':\n l, s = int(A[1]), A[2]\n for al in alp:\n if query_sum(l, al) - query_sum(l-1, al) == 1:\n add(l, -1, al)\n break\n add(l, 1, s)\n else:\n l, r = int(A[1]), int(A[2])\n c = 0\n for al in alp:\n if query_sum(r, al) - query_sum(l-1, al) > 0:\n c += 1\n print(c)\n\ndef __starting_point():\n main()\n__starting_point()", "import sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\n\nclass SegmentTree():\n def __init__(self, n):\n self.n = 2**(n-1).bit_length()\n self.data = [0 for _ in range(2*self.n)]\n\n def set(self, k, v):\n v_val = ord(v)-ord('a')\n self.data[k+self.n-1] = 1 << v_val\n\n def build(self):\n for k in reversed(list(range(self.n-1))):\n self.data[k] = self.data[k*2+1] | self.data[k*2+2]\n\n def update(self, k, a):\n k += self.n-1\n v_val = ord(a)-ord(\"a\")\n self.data[k] = 1 << v_val\n\n while k > 0:\n k = (k-1)//2\n self.data[k] = self.data[k*2+1] | self.data[k*2+2]\n\n def query(self, l, r):\n L = l+self.n\n R = r+self.n\n ret = 0\n while L < R:\n if R & 1:\n R -= 1\n ret |= self.data[R-1]\n if L & 1:\n ret |= self.data[L-1]\n L += 1\n L >>= 1\n R >>= 1\n return ret\n\n\nS = [v for v in input()[:-1]]\nN = len(S)\nQ = int(input())\nquery = [[v for v in input()[:-1].split()] for _ in range(Q)]\n\nSeg = SegmentTree(N)\nfor i, s in enumerate(S):\n Seg.set(i, s)\n\nSeg.build()\n\nfor q, v1, v2 in query:\n if q == \"1\":\n Seg.update(int(v1)-1, v2)\n else:\n val = Seg.query(int(v1)-1, int(v2))\n print(bin(val)[2:].count(\"1\"))\n", "import math\nimport bisect\nfrom functools import reduce\nfrom collections import defaultdict\nimport sys\ninput = sys.stdin.readline\n\ndef inn():\n return int(input())\n\ndef inl():\n return list(map(int, input().split()))\n\nMOD = 10**9+7\nINF = inf = 10**18+5\n\ns = list(input().strip())\nn = len(s)\nt = [[0]*26 for i in range(2*n)]\n\nfor i in range(n):\n\tt[i+n][ord(s[i])-97] = 1\n\ndef build():\n\tfor i in range(n-1, 0, -1):\n\t\tfor j in range(26):\n\t\t\tt[i][j] = t[i<<1][j] + t[i<<1|1][j]\n\ndef modify(p, val):\n\tt[p+n][ord(s[p])-97] = 0\n\tt[p+n][ord(val)-97] = 1\n\ts[p] = val\n\tp = p+n\n\twhile p>1:\n\t\tfor i in range(26):\n\t\t\tt[p>>1][i] = t[p][i] + t[p^1][i]\n\t\tp >>= 1\n\ndef query(l, r):\n\tres = [0]*26\n\tl += n\n\tr += n\n\twhile l<r:\n\t\tif l&1:\n\t\t\tfor i in range(26):\n\t\t\t\tres[i] += t[l][i]\n\t\t\tl += 1\n\t\tif r&1:\n\t\t\tr -= 1\n\t\t\tfor i in range(26):\n\t\t\t\tres[i] += t[r][i]\n\t\tl >>= 1\n\t\tr >>= 1\n\treturn res\n\nbuild()\n\nfor q in range(inn()):\n\ttp, l, r = input().split()\n\ttp = int(tp)\n\tl = int(l)\n\tif tp==1:\n\t\tmodify(l-1, r)\n\telif tp==2:\n\t\tr = int(r)\n\t\tres = query(l-1, r)\n\t\tc = len([i for i in range(26) if res[i]>0])\n\t\tprint(c)\n\t# print(t)\n", "import sys\n\ninput = sys.stdin.readline\n\nclass SegmentTree:\n a = ord('a')\n\n def __init__(self):\n data = [1 << ord(c) - self.a for c in input()[:-1]]\n\n self.n = 1 << len(bin(len(data) - 1)) - 2\n self.data = [0] * self.n + data + [0] * (self.n - len(data))\n\n for k in range(self.n - 1, 0, -1):\n self.data[k] = self.data[2 * k + 1] | self.data[2 * k]\n\n def update(self, k, c):\n k += self.n\n self.data[k] = 1 << ord(c) - self.a\n\n while k > 1:\n k >>= 1\n self.data[k] = self.data[2 * k + 1] | self.data[2 * k]\n\n def query(self, l, r):\n l += self.n\n r += self.n\n s = self.data[r] | self.data[l]\n\n while l < r - 1:\n if r & 1: s |= self.data[r - 1]\n if not l & 1: s |= self.data[l + 1]\n l >>= 1\n r >>= 1\n return s\n\ntree = SegmentTree()\n\nfor i in range(int(input())):\n q = input()[:-1].split()\n if q[0] == \"1\":\n tree.update(int(q[1]) - 1, q[2])\n else:\n s = tree.query(int(q[1]) - 1, int(q[2]) - 1)\n print(bin(s)[2:].count(\"1\"))"] | {
"inputs": [
"abacaba\n5\n2 1 4\n1 4 b\n1 5 b\n2 4 6\n2 1 7\n",
"dfcbbcfeeedbaea\n15\n1 6 e\n1 4 b\n2 6 14\n1 7 b\n1 12 c\n2 6 8\n2 1 6\n1 7 c\n1 2 f\n1 10 a\n2 7 9\n1 10 a\n1 14 b\n1 1 f\n2 1 11\n",
"aaab\n1\n2 4 4\n"
],
"outputs": [
"3\n1\n2\n",
"5\n2\n5\n2\n6\n",
"1\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 23,853 | |
56a4274ac455207fd9defbcad03f9684 | UNKNOWN | Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $a$ coins, Barbara has $b$ coins and Cerene has $c$ coins. Recently Polycarp has returned from the trip around the world and brought $n$ coins.
He wants to distribute all these $n$ coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives $A$ coins to Alice, $B$ coins to Barbara and $C$ coins to Cerene ($A+B+C=n$), then $a + A = b + B = c + C$.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all $n$ coins between sisters in a way described above.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
The next $t$ lines describe test cases. Each test case is given on a new line and consists of four space-separated integers $a, b, c$ and $n$ ($1 \le a, b, c, n \le 10^8$) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
-----Output-----
For each test case, print "YES" if Polycarp can distribute all $n$ coins between his sisters and "NO" otherwise.
-----Example-----
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES | ["a = int(input())\nfor i in range(a):\n a1, b, c, n = list(map(int, input().split()))\n t = max(a1, b, c)\n if ((a1 + b + c + n) % 3 == 0 and t <= (a1 + b + c + n)//3 ):\n print('YES')\n else:\n print('NO')\n", "t = int(input())\nfor _ in range(t):\n\ta, b, c, n = map(int, input().split())\n\n\tm = max(a, b, c)\n\n\tsu = m-a + m-b + m-c\n\n\tif n < su:\n\t\tprint(\"NO\")\n\t\tcontinue\n\n\tn -= su\n\tif n%3 == 0:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")", "import sys\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n\ta, b, c, n = map(int, input().split())\n\ta, b, c = sorted([a, b, c])\n\tn -= (c-a)\n\tn -= (c-b)\n\tif n >= 0 and n%3 == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')", "t=int(input())\nfor _ in range(t):\n a,b,c,n=list(map(int,input().split()))\n a,b,c=sorted([a,b,c])\n x=2*c-b-a\n # print(x)\n if n<x:\n print(\"NO\")\n elif (x-n)%3==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "#!/usr/bin/env python3\n# coding: utf-8\n# Last Modified: 22/Jan/20 08:07:33 PM\n\n\nimport sys\n\n\ndef main():\n for tc in range(int(input())):\n a, b, c, n = get_ints()\n x = a + b + c + n\n if x % 3 != 0:\n print(\"NO\")\n else:\n y = max(a, b, c)\n if (x // 3) >= y:\n print(\"YES\")\n else:\n print(\"NO\")\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()", "#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())\nfor tt in range(t):\n #n=int(input())\n a,b,c,n= map(int, sys.stdin.readline().split(' '))\n give = (a+b+c+n)//3\n x=give-a\n y=give-b\n z=give-c\n\n if (give*3==a+b+c+n) and (x>=0) and (y>=0) and (z>=0) and (x+y+z==n):\n print(\"YES\")\n else:\n print(\"NO\")\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()", "for _ in range(int(input())):\n a,b,c,n = [int(s) for s in input().split()]\n a,b,c = sorted([a,b,c])\n w = c-a+c-b\n if w>n:\n print(\"NO\")\n else:\n if (n-w)%3==0:\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\nwhile(t):\n t-=1\n a,b,c,n=list(map(int,input().split()))\n d=max(a,b,c)\n f=(d-a)+(d-b)+(d-c)\n if(f>n):\n print(\"NO\")\n continue\n n-=f\n if(n%3==0):\n print(\"YES\")\n else:\n print(\"NO\")\n", "t = int(input())\nfor _ in range (t):\n a, b, c, n = list(map(int, input().split()))\n d = 3 * max(a, b, c) - a - b- c\n e = n - d\n if e >= 0 and e % 3 == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "#-------------Program--------------\n#----Kuzlyaev-Nikita-Codeforces----\n#-------------Round615-------------\n#----------------------------------\n\nt=int(input())\nfor i in range(t):\n a,b,c,n=map(int,input().split())\n a=[a,b,c];a.sort()\n k=a[2]-a[1]+a[2]-a[0]\n if n<k:\n print('NO')\n else:\n if (n-k)%3!=0:\n print('NO')\n else:\n print('YES')", "for _ in range(int(input())):\n a,b,c,n=map(int,input().split())\n s=a+b+c\n mx=max(a,b,c)\n if((s+n)%3==0 and (s+n)//3 >= mx):\n print(\"YES\")\n else:\n print(\"NO\")", "import sys\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nfrom itertools import combinations\nfrom itertools import permutations\ninput = lambda : sys.stdin.readline().rstrip()\nread = lambda : list(map(int, input().split()))\ngo = lambda : 1/0\ndef write(*args, sep=\"\\n\"):\n for i in args:\n sys.stdout.write(\"{}{}\".format(i, sep))\nINF = float('inf')\nMOD = int(1e9 + 7)\nYES = \"YES\"\nNO = \"NO\"\n\nfor _ in range(int(input())):\n try:\n a, b, c, n = read()\n x = max([a, b, c])\n n -= x - a \n n -= x - b \n n -= x - c \n\n if n < 0:\n print(NO)\n go()\n \n if n % 3 == 0:\n print(YES)\n else:\n print(NO)\n\n except:\n continue", "import sys\n\n# inf = open('input.txt', 'r')\n# reader = (line.rstrip() for line in inf)\nreader = (line.rstrip() for line in sys.stdin)\ninput = reader.__next__\n\nt = int(input())\nfor _ in range(t):\n a, b, c, n = list(map(int, input().split()))\n if (a + b + c + n) % 3 == 0:\n each = (a + b + c + n) // 3\n if a <= each and b <= each and c <= each:\n print('YES')\n else:\n print('NO')\n else:\n print('NO')\n\n# inf.close()\n", "\nT=int(input())\nfor _ in range(T):\n a,b,c,n=list(map(int,input().split()))\n mx=max(a,b,c)\n tot=mx-a+mx-b+mx-c\n\n if(n<tot):\n print('NO')\n else:\n n=n-tot\n if(n%3==0):\n print('YES')\n else:\n print('NO')\n \n", "import sys\ninput = sys.stdin.readline\n\nt=int(input())\n\nfor test in range(t):\n a,b,c,n=list(map(int,input().split()))\n\n M=max(a,b,c)\n n-=(M-a)+(M-b)+(M-c)\n\n if n<0:\n print(\"NO\")\n else:\n if n%3==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "t = int(input())\nans = list()\nfor i in range(t):\n (a, b, c, n) = map(int, input().split())\n d = [a, b, c]\n d.sort()\n if d[2] - d[0] + d[2] - d[1] > n:\n ans.append('NO')\n else:\n n -= d[2] - d[0]\n n -= d[2] - d[1]\n if n %3 != 0:\n ans.append('NO')\n else:\n ans.append('YES')\nprint(*ans,sep='\\n')\n", "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nimport heapq\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\n \n# M = mod = 998244353\n# def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] forn() i in range(1, int(n**0.5) + 1) if n % i == 0)))))\n# def inv_mod(n):return pow(n, mod - 2, mod)\n \ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef li2():return [i for i in input().rstrip('\\n').split(' ')]\ndef li3():return [int(i) for i in input().rstrip('\\n')]\n\n\nfor _ in range(val()):\n a,b,c,n = li()\n a,b,c = sorted([a,b,c])\n if c - a>n:\n print('NO')\n continue\n else:\n n -= (c-a)\n a = c\n if c -b > n:\n print('NO')\n continue\n else:\n n -= (c-b)\n b = c\n if n%3:\n print('NO')\n continue\n print('YES')", "for _ in range(int(input())):\n a, b, c, n = list(map(int, input().split()))\n a, b, c = sorted([a, b, c])\n delta = (c - a) + (c - b)\n if n >= delta and (n - delta) % 3 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "\nt = int(input())\n\nfor loop in range(t):\n\n a,b,c,n = list(map(int,input().split()))\n\n n -= max(a,b,c) - a\n n -= max(a,b,c) - b\n n -= max(a,b,c) - c\n\n if n >= 0 and n % 3 == 0:\n print (\"YES\")\n else:\n print (\"NO\")\n", "n = int(input())\nfor i in range(n):\n a, b, c, d = list(map(int, input().split()))\n need = max(a, b, c)\n d -= (need - a)\n d -= (need - b)\n d -= (need - c)\n if d >= 0 and d % 3 == 0:\n print('YES')\n else:\n print('NO')\n", "for _ in range(int(input())):\n a, b, c, n = list(map(int, input().split()))\n s = (a+b+c+n)\n if s % 3 == 0 and s // 3 >= a and s // 3 >= b and s // 3 >= c:\n print('YES')\n else:\n print('NO')\n", "for _ in range(int(input())):\n a, b, c, n = map(int, input().split())\n mm = max(a, b, c)\n n -= (mm-a)\n n -= mm-b\n n-= mm - c\n if n >= 0 and n % 3 == 0:\n print(\"YES\")\n else:\n print(\"NO\")"] | {
"inputs": [
"5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3\n",
"1\n1 1 1 1111\n",
"1\n3 798 437 1804\n"
],
"outputs": [
"YES\nYES\nNO\nNO\nYES\n",
"NO\n",
"YES\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 8,650 | |
338dff03e7e8d0255b6d25dcf53f952f | UNKNOWN | Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples: $p_1(4) = [1, 2, 3, 4]$; $p_2(4) = [2, 1, 3, 4]$; $p_3(4) = [3, 1, 2, 4]$; $p_4(4) = [4, 1, 2, 3]$.
You are given an array $x_1, x_2, \dots, x_m$ ($1 \le x_i \le n$).
Let $pos(p, val)$ be the position of the element $val$ in $p$. So, $pos(p_1(4), 3) = 3, pos(p_2(4), 2) = 1, pos(p_4(4), 4) = 1$.
Let's define a function $f(p) = \sum\limits_{i=1}^{m - 1} |pos(p, x_i) - pos(p, x_{i + 1})|$, where $|val|$ is the absolute value of $val$. This function means the sum of distances between adjacent elements of $x$ in $p$.
Your task is to calculate $f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($2 \le n, m \le 2 \cdot 10^5$) β the number of elements in each permutation and the number of elements in $x$.
The second line of the input contains $m$ integers ($m$, not $n$) $x_1, x_2, \dots, x_m$ ($1 \le x_i \le n$), where $x_i$ is the $i$-th element of $x$. Elements of $x$ can repeat and appear in arbitrary order.
-----Output-----
Print $n$ integers: $f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$.
-----Examples-----
Input
4 4
1 2 3 4
Output
3 4 6 5
Input
5 5
2 1 5 3 5
Output
9 8 12 6 8
Input
2 10
1 2 1 1 2 2 2 2 2 2
Output
3 3
-----Note-----
Consider the first example:
$x = [1, 2, 3, 4]$, so for the permutation $p_1(4) = [1, 2, 3, 4]$ the answer is $|1 - 2| + |2 - 3| + |3 - 4| = 3$; for the permutation $p_2(4) = [2, 1, 3, 4]$ the answer is $|2 - 1| + |1 - 3| + |3 - 4| = 4$; for the permutation $p_3(4) = [3, 1, 2, 4]$ the answer is $|2 - 3| + |3 - 1| + |1 - 4| = 6$; for the permutation $p_4(4) = [4, 1, 2, 3]$ the answer is $|2 - 3| + |3 - 4| + |4 - 1| = 5$.
Consider the second example:
$x = [2, 1, 5, 3, 5]$, so for the permutation $p_1(5) = [1, 2, 3, 4, 5]$ the answer is $|2 - 1| + |1 - 5| + |5 - 3| + |3 - 5| = 9$; for the permutation $p_2(5) = [2, 1, 3, 4, 5]$ the answer is $|1 - 2| + |2 - 5| + |5 - 3| + |3 - 5| = 8$; for the permutation $p_3(5) = [3, 1, 2, 4, 5]$ the answer is $|3 - 2| + |2 - 5| + |5 - 1| + |1 - 5| = 12$; for the permutation $p_4(5) = [4, 1, 2, 3, 5]$ the answer is $|3 - 2| + |2 - 5| + |5 - 4| + |4 - 5| = 6$; for the permutation $p_5(5) = [5, 1, 2, 3, 4]$ the answer is $|3 - 2| + |2 - 1| + |1 - 4| + |4 - 1| = 8$. | ["n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nfoo = [0 for _ in range(2+n)]\n\nfor i in range(1, m) :\n p, q = x[i-1], x[i]\n\n if p == q : continue\n\n r = min(p, q)\n\n s = max(p, q)\n\n foo[0] += abs(p-q)\n foo[r] -= abs(p-q)\n foo[r] += max(p, q) - 1\n foo[r+1] -= max(p, q) - 1\n\n foo[r+1] += abs(p-q)-1\n foo[s] -= abs(p-q)-1\n\n foo[s] += min(p, q)\n foo[s+1] -= min(p, q)\n\n foo[s+1] += abs(p-q)\n foo[n+1] -= abs(p-q)\n\n # print(p, q, foo)\n\nfor i in range(1,n+1) :\n foo[i] += foo[i-1]\n print(foo[i], end=' ')\nprint()\n", "import io, sys, atexit, os\nimport math as ma\nfrom decimal import Decimal as dec\nfrom itertools import permutations\nfrom itertools import combinations\n\n\ndef li ():\n\treturn list (map (int, sys.stdin.readline ().split ()))\n\n\ndef num ():\n\treturn map (int, sys.stdin.readline ().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\ndef lcm ( x, y ):\n\tgg = find_gcd (x, y)\n\treturn (x * y // gg)\n\n\n\n\n\n\nmm = 1000000007\n\ndef solve ():\n\tt = 1\n\tfor tt in range (t):\n\t\tn,m=num()\n\t\ta=li()\n\t\tp=[0]*(n+1)\n\t\tfor i in range(0,m-1):\n\t\t\tif(a[i]==a[i+1]):\n\t\t\t\tcontinue\n\t\t\tl=a[i]\n\t\t\tr=a[i+1]\n\t\t\tif(l>r):\n\t\t\t\tl,r=r,l\n\t\t\thp=r-l\n\t\t\tkp=l-1\n\t\t\tko=r-1\n\t\t\tp[ko+1]+=hp\n\t\t\tp[n]-=hp\n\t\t\tp[kp]-=hp\n\t\t\tp[0]+=hp\n\t\t\tp[kp+1]+=hp-1\n\t\t\tp[ko]-=(hp-1)\n\t\t\tp[ko]+=(l)\n\t\t\tp[ko+1]-=(l)\n\t\t\tp[kp]+=(r-1)\n\t\t\tp[kp+1]-=(r-1)\n\t\tfor i in range(1,n+1):\n\t\t\tp[i]=p[i]+p[i-1]\n\t\tprint(*(p[0:n]))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ndef __starting_point():\n\tsolve ()\n__starting_point()", "n, m = map(int, input().split())\na = list(map(int, input().split()))\n\nleft = [0] * (n + 1)\nleft_sum = left[:]\nright = left[:]\ncross = left[:]\nrang = left[:]\nans = left[:n]\ntotal = 0\n\nfor i in range(1, m):\n p = a[i - 1]\n q = a[i]\n if p == q:\n continue\n if q < p:\n p, q = q, p\n total += q - p\n rang[p] += 1\n rang[q - 1] -= 1\n right[p] += 1\n left[q] += 1\n left_sum[q] += q - p\n\nstart = 0\nfor i in range(n):\n cross[i] = start\n start += rang[i]\n\nans[0] = total\nfor i in range(2, n + 1):\n ans[i - 1] = total - cross[i] + left[i] * i - 2 * left_sum[i] + (i - 1) * right[i]\nprint(*ans)", "N, M = map(int, input().split())\n*X, = map(int, input().split())\nfor i in range(M):\n X[i] -= 1\n\nR = 0\nS = [0]*N\nT = [0]*N\nD = [0]*(N+1)\nfor i in range(M-1):\n if X[i] < X[i+1]:\n D[X[i]+1] += 1\n D[X[i+1]] -= 1\n elif X[i] > X[i+1]:\n D[X[i+1]+1] += 1\n D[X[i]] -= 1\n\n d = abs(X[i] - X[i+1])\n S[X[i]] += d\n S[X[i+1]] += d\n if X[i] < X[i+1]:\n T[X[i]] += X[i+1]\n T[X[i+1]] += X[i] + 1\n elif X[i] > X[i+1]:\n T[X[i]] += X[i+1] + 1\n T[X[i+1]] += X[i]\n R += d\nfor i in range(N-1):\n D[i+1] += D[i]\nans = [0]*N\nfor i in range(N):\n ans[i] = R + T[i] - S[i] - D[i]\nprint(*ans)", "import sys\n \nn,m = [int(x) for x in input().split()]\nX = [int(x) - 1 for x in input().split()]\n \ns = 0\nright = [[] for _ in range(n)]\nleft = [[] for _ in range(n)]\nfor j in range(m - 1):\n a,b = X[j], X[j + 1]\n if a == b:\n continue\n if a > b:\n a,b = b,a \n right[a].append(b)\n left[b].append(a)\n s += b - a\n \nout = [s]\nfor i in range(1, n): \n for b in right[i - 1]:\n s -= b\n for b in left[i - 1]:\n s -= b + 1\n \n for b in right[i]:\n s -= b - i\n for b in left[i]:\n s -= i - b - 1\n \n for b in right[i]:\n s += b\n for b in left[i]:\n s += b + 1\n \n for b in right[i - 1]:\n s += b - (i - 1) - 1\n for b in left[i - 1]:\n s += (i - 1) - b\n out.append(s)\nprint (' '.join(str(x) for x in out))", "# print(sum(map(lambda x: len(str(x).strip(\"47\")) == 0, range(int(input()) + 1))))\n\nn, m = map(int, input().split())\nadj = [0 for _ in range(n + 1)]\ncnt = [0 for _ in range(n + 1)]\nx = map(int, input().split())\nf1 = 0\nx1 = next(x)\nfor i in range(m - 1):\n x2 = next(x)\n minx = min(x1, x2)\n maxx = x1 + x2 - minx\n x1 = x2\n dx = maxx - minx\n if dx > 0:\n adj[minx] += minx - 1\n adj[maxx] += minx - dx\n f1 += dx\n if dx >= 2:\n cnt[minx + 1] += 1\n cnt[maxx] -= 1\nprint(f1, end=' ')\nc = cnt[1]\nfor i in range(2, n + 1):\n c += cnt[i]\n print(f1 - c + adj[i], end=' ')\n", "# print(sum(map(lambda x: len(str(x).strip(\"47\")) == 0, range(int(input()) + 1))))\n\nn, m = map(int, input().split())\nadj = [0 for _ in range(n + 1)]\ncnt = [0 for _ in range(n + 1)]\nx = map(int, input().split())\nf1 = 0\nx1 = next(x)\nfor i in range(m - 1):\n x2 = next(x)\n minx = min(x1, x2)\n maxx = x1 + x2 - minx\n x1 = x2\n dx = maxx - minx\n if dx > 0:\n adj[minx] += minx - 1\n adj[maxx] += minx - dx\n f1 += dx\n if dx >= 2:\n cnt[minx + 1] += 1\n cnt[maxx] -= 1\nprint(f1, end=' ')\nc = cnt[1]\nfor i in range(2, n + 1):\n c += cnt[i]\n print(f1 - c + adj[i], end=' ')\n", "n, m = map(int, input().split())\nadj = [0 for _ in range(n + 1)]\ncnt = [0 for _ in range(n + 1)]\nx = map(int, input().split())\nf1 = 0\nx1 = next(x)\nfor i in range(m - 1):\n x2 = next(x)\n minx = min(x1, x2)\n maxx = x1 + x2 - minx\n x1 = x2\n dx = maxx - minx\n if dx > 0:\n adj[minx] += minx - 1\n adj[maxx] += minx - dx\n f1 += dx\n if dx >= 2:\n cnt[minx + 1] += 1\n cnt[maxx] -= 1\nprint(f1, end=' ')\nc = cnt[1]\nfor i in range(2, n + 1):\n c += cnt[i]\n print(f1 - c + adj[i], end=' ')\n", "import sys\ninput = sys.stdin.readline\n\nn,m=map(int,input().split())\nX=list(map(int,input().split()))\n\nPLUS=[[0,0] for i in range(n+1)]\n\nDIFF1=[0]*(n+1)\nDIFF2=[0]*(n+1)\n\n\nfor i in range(m):\n if 0<=i-1:\n if X[i-1]<X[i]-1:\n DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(X[i-1]+1-X[i])\n\n elif X[i-1]==X[i]-1:\n DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(1-X[i])\n\n elif X[i-1]>=X[i]+1:\n DIFF1[X[i]]+=abs(X[i-1]-1)-abs(X[i-1]-X[i])\n\n if i+1<m:\n if X[i+1]<X[i]-1:\n DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(X[i+1]+1-X[i])\n\n elif X[i+1]==X[i]-1:\n DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(1-X[i])\n\n elif X[i+1]>=X[i]+1:\n DIFF1[X[i]]+=abs(X[i+1]-1)-abs(X[i+1]-X[i])\n\n#print(DIFF1)\n\nfor i in range(m):\n if 0<=i-1:\n if X[i-1]<X[i]:\n DIFF2[X[i]]+=abs(X[i-1]-X[i])-abs(X[i-1]+1-1)\n\n elif X[i-1]>X[i]+1:\n DIFF2[X[i]]+=abs(X[i-1]-X[i]-1)-abs(X[i-1]-1)\n\n if i+1<m:\n if X[i+1]<X[i]:\n DIFF2[X[i]]+=abs(X[i+1]-X[i])-abs(X[i+1]+1-1)\n\n elif X[i+1]>X[i]+1:\n DIFF2[X[i]]+=abs(X[i+1]-X[i]-1)-abs(X[i+1]-1)\n\n#print(DIFF2)\n\n\n\nANS=0\nfor i in range(1,m):\n ANS+=abs(X[i]-X[i-1])\n\nprint(ANS,end=\" \")\n\nfor i in range(2,n+1):\n ANS+=DIFF1[i]+DIFF2[i-1]\n print(ANS,end=\" \")\n", "def pos(x, i):\n if x > i:\n return x\n elif x < i:\n return x + 1\n else:\n return 1\n\n\nn, m = map(int, input().split())\nx = list(map(int, input().split()))\ndelta_ = [0] * (n + 2)\nfunc = sum(abs(x[i + 1] - x[i]) for i in range(m - 1))\nfor i in range(m):\n if x[i] < n:\n if i > 0:\n prev_l = abs(pos(x[i], x[i]) - pos(x[i - 1], x[i]))\n cur_l = abs(pos(x[i], x[i] + 1) - pos(x[i - 1], x[i] + 1))\n delta_[x[i] + 1] += cur_l - prev_l\n if i < m - 1:\n prev_r = abs(pos(x[i], x[i]) - pos(x[i + 1], x[i]))\n cur_r = abs(pos(x[i], x[i] + 1) - pos(x[i + 1], x[i] + 1))\n delta_[x[i] + 1] += cur_r - prev_r\n if x[i] > 1:\n if i > 0:\n prev_l = abs(pos(x[i], x[i] - 1) - pos(x[i - 1], x[i] - 1))\n cur_l = abs(pos(x[i], x[i]) - pos(x[i - 1], x[i]))\n delta_[x[i]] += cur_l - prev_l\n if i < m - 1:\n prev_r = abs(pos(x[i], x[i] - 1) - pos(x[i + 1], x[i] - 1))\n cur_r = abs(pos(x[i], x[i]) - pos(x[i + 1], x[i]))\n delta_[x[i]] += cur_r - prev_r\n\nfor i in range(1, n + 1):\n print(func, end=\" \")\n func += delta_[i + 1]\n\n", "f=[]\n\ndef mdy(l,r,x):\n\tf[l]+=x\n\tf[r+1]-=x\n\nn,m=map(int,input().split())\n\nP=list(range(n+2))\n\nfor i in range(n+5):\n\tf.append(0)\n\na=list(map(int,input().split()))\n\nfor i in range(m-1):\n\tl=a[i]\n\tr=a[i+1]\n\tif l==r:\n\t\tcontinue\n\tif l>r:\n\t\t(l,r)=(r,l)\n\tmdy(1,l-1,r-l)\n\tmdy(l,l,r-1)\n\tmdy(l+1,r-1,r-l-1)\n\tmdy(r,r,l)\n\tmdy(r+1,n,r-l)\n\nfor i in P[1:n+1]:\n\tf[i]+=f[i-1]\n\tprint(f[i],end=\" \")", "def readint():\n return [int(e) for e in input().split()]\n\nn, m = readint()\nx = readint()\n\nsm = [0] * (n+2)\n\ndef addvalue(s, e, v):\n if s > e:\n return\n sm[s] += v\n sm[e+1] -= v\n\nfor (a, b) in zip(x, x[1:]):\n if a == b:\n continue\n if a > b:\n a, b = b, a\n addvalue(1, a-1, b - a)\n addvalue(a, a, b-1)\n addvalue(a+1, b-1, b - a - 1)\n addvalue(b, b, a)\n addvalue(b+1, n, b - a)\n\nfor i in range(1, n+2):\n sm[i] += sm[i-1]\n\nprint(' '.join(map(str, sm[1:n+1])))\n \n \n", "f=[]\n \ndef mdy(l,r,x):\n\tf[l]+=x\n\tf[r+1]-=x\n \nn,m=map(int,input().split())\n \nP=list(range(n+4))\n \nfor j in range(n+7):\n\tf.append(0)\n \na=list(map(int,input().split()))\n \nfor j in range(m-1):\n\tl=a[j]\n\tr=a[j+1]\n\tif l==r:\n\t\tcontinue\n\tif l>r:\n\t\t(l,r)=(r,l)\n\tmdy(1,l-1,r-l)\n\tmdy(l,l,r-1)\n\tmdy(l+1,r-1,r-l-1)\n\tmdy(r,r,l)\n\tmdy(r+1,n,r-l)\n \nfor j in P[1:n+1]:\n\tf[j]+=f[j-1]\n\tprint(f[j],end=\" \")", "3\n\nimport array\nimport math\nimport os\nimport sys\n\n\ndef main():\n N, M = read_ints()\n X = [x - 1 for x in read_ints()]\n print(*solve(N, M, X))\n\n\ndef solve(N, M, X):\n pos = list(range(N))\n pairs = [dict() for _ in range(N)]\n fsum = 0\n for i in range(M - 1):\n a = X[i]\n b = X[i + 1]\n if a == b:\n continue\n if b not in pairs[a]:\n pairs[a][b] = 0\n if a not in pairs[b]:\n pairs[b][a] = 0\n pairs[a][b] += 1\n pairs[b][a] += 1\n fsum += abs(pos[a] - pos[b])\n\n ans = [fsum]\n fst = 0\n for i in range(N - 1):\n j = i + 1\n pi = pos[i]\n pj = pos[j]\n\n d = 0\n for k, c in pairs[i].items():\n if k == j:\n continue\n pk = pos[k]\n d -= abs(pi - pk) * c\n d += abs(pj - pk) * c\n for k, c in pairs[j].items():\n if k == i:\n continue\n pk = pos[k]\n d -= abs(pj - pk) * c\n d += abs(pi - pk) * c\n\n fsum += d\n ans.append(fsum)\n pos[i], pos[j] = pj, pi\n\n return ans\n\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef read_int():\n return int(inp())\n\n\ndef read_ints():\n return [int(e) for e in inp().split()]\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "import sys\ninput = sys.stdin.readline\n \nn,m=map(int,input().split())\nX=list(map(int,input().split()))\n \nPLUS=[[0,0] for i in range(n+1)]\n \nDIFF1=[0]*(n+1)\nDIFF2=[0]*(n+1)\n \n \nfor i in range(m):\n if 0<=i-1:\n if X[i-1]<X[i]-1:\n DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(X[i-1]+1-X[i])\n \n elif X[i-1]==X[i]-1:\n DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(1-X[i])\n \n elif X[i-1]>=X[i]+1:\n DIFF1[X[i]]+=abs(X[i-1]-1)-abs(X[i-1]-X[i])\n \n if i+1<m:\n if X[i+1]<X[i]-1:\n DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(X[i+1]+1-X[i])\n \n elif X[i+1]==X[i]-1:\n DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(1-X[i])\n \n elif X[i+1]>=X[i]+1:\n DIFF1[X[i]]+=abs(X[i+1]-1)-abs(X[i+1]-X[i])\n \n#print(DIFF1)\n \nfor i in range(m):\n if 0<=i-1:\n if X[i-1]<X[i]:\n DIFF2[X[i]]+=abs(X[i-1]-X[i])-abs(X[i-1]+1-1)\n \n elif X[i-1]>X[i]+1:\n DIFF2[X[i]]+=abs(X[i-1]-X[i]-1)-abs(X[i-1]-1)\n \n if i+1<m:\n if X[i+1]<X[i]:\n DIFF2[X[i]]+=abs(X[i+1]-X[i])-abs(X[i+1]+1-1)\n \n elif X[i+1]>X[i]+1:\n DIFF2[X[i]]+=abs(X[i+1]-X[i]-1)-abs(X[i+1]-1)\n \n#print(DIFF2)\n \n \n \nANS=0\nfor i in range(1,m):\n ANS+=abs(X[i]-X[i-1])\n \nprint(ANS,end=\" \")\n \nfor i in range(2,n+1):\n ANS+=DIFF1[i]+DIFF2[i-1]\n print(ANS,end=\" \")\n\n", "def __starting_point():\n n, m = input().split(' ')\n n = int(n)\n m = int(m)\n x = [int(i) for i in input().split(' ')]\n pre = [0] * (n + 2)\n tmp = 0\n for i in range(m - 1):\n a, b = x[i], x[i + 1]\n if a > b:\n a, b = b, a\n if a == b:\n continue\n pre[1] += b - a\n pre[a] -= b - a\n pre[a] += b - 1\n pre[a + 1] -= b - 1\n pre[a + 1] += b - a - 1\n pre[b] -= b - a - 1\n pre[b] += a\n pre[b + 1] -= a\n pre[b + 1] += b - a\n pre[n + 1] -= b - a\n for i in range(1,n+1):\n pre[i] += pre[i-1]\n print(pre[i],end=' ')\n print('')\n__starting_point()", "f=[]\n \ndef mdy(l,r,x):\n\tf[l]+=x\n\tf[r+1]-=x\n \nn,m=map(int,input().split())\n \nP=list(range(n+2))\n \nfor i in range(n+5):\n\tf.append(0)\n \na=list(map(int,input().split()))\n \nfor i in range(m-1):\n\tl=a[i]\n\tr=a[i+1]\n\tif l==r:\n\t\tcontinue\n\tif l>r:\n\t\t(l,r)=(r,l)\n\tmdy(1,l-1,r-l)\n\tmdy(l,l,r-1)\n\tmdy(l+1,r-1,r-l-1)\n\tmdy(r,r,l)\n\tmdy(r+1,n,r-l)\n \nfor i in P[1:n+1]:\n\tf[i]+=f[i-1]\n\tprint(f[i],end=\" \")", "n,m=map(int,input().split())\nx=[int(x1) for x1 in input().split()]\n\npre1=[0]*(n+2)\npre2=[0]*(n+1)\npre3=[0]*(n+1)\n\nfor i in range(0,len(x)-1):\n a=min(x[i],x[i+1])\n b=max(x[i],x[i+1])\n\n if(b-a>1):\n\n pre1[a+1]+=1\n pre1[b]+=-1\n\n if(a!=b):\n pre2[a]+=(b-1)-(b-a)#(b-a-1)+b\n pre3[b]+=a-(b-a)\n\n\n\n\nt=0\nfor i in range(0,len(pre1)):\n pre1[i]=t+pre1[i]\n t=pre1[i]\n\n#print('pre1',pre1)\n#print('pre2',pre2)\n#print('pre3',pre3)\n\n\nans=0\nfor i in range(0,m-1):\n ans+=abs(x[i]-x[i+1])\n\n\n\nprint(ans,end=\" \")\nfor i in range(2,n+1):\n temp=ans+pre2[i]+pre3[i]+-pre1[i]\n print(temp,end=\" \")\n\nprint(\" \")\n \n", "n,m=map(int,input().split())\nx=[int(x1) for x1 in input().split()]\n\npre1=[0]*(n+2)\npre2=[0]*(n+1)\npre3=[0]*(n+1)\n\nfor i in range(0,len(x)-1):\n a=min(x[i],x[i+1])\n b=max(x[i],x[i+1])\n\n if(b-a>1):\n\n pre1[a+1]+=1\n pre1[b]+=-1\n\n if(a!=b):\n pre2[a]+=(b-1)-(b-a)\n pre3[b]+=a-(b-a)\n\n\nt=0\nfor i in range(0,len(pre1)):\n pre1[i]=t+pre1[i]\n t=pre1[i]\n\n\nans=0\nfor i in range(0,m-1):\n ans+=abs(x[i]-x[i+1])\n\n\n\nprint(ans,end=\" \")\nfor i in range(2,n+1):\n temp=ans+pre2[i]+pre3[i]+-pre1[i]\n print(temp,end=\" \")\n\nprint(\" \")\n \n", "import math\nimport functools\nfrom collections import defaultdict\n\nn, m = map(int, input().split(' '))\n\nv = [i for i in map(int, input().split(' '))]\n\ns = [0 for i in range(n + 2)]\n\nfor i in range(m - 1):\n if abs(v[i] - v[i + 1]) < 2:\n continue\n s[min(v[i], v[i + 1]) + 1] += 1\n s[max(v[i], v[i + 1])] -= 1\n\np = 0\n\nfor i in range(m - 1):\n p += abs(v[i] - v[i + 1])\n\nans = [0 for i in range(n + 2)]\n\nd = 0\n\nfor i in range(n + 2):\n d += s[i]\n ans[i] = d\n\na = defaultdict(lambda : 0, {})\nb = defaultdict(lambda : [], {})\n\nfor i in range(m - 1):\n if v[i] == v[i + 1]:\n continue\n a[min(v[i], v[i + 1])] += 1\n b[max(v[i], v[i + 1])].append(min(v[i], v[i + 1]))\n\nfor i in range(1, n + 1):\n q = p\n q = ans[i]\n q = a[i] * (i - 1)\n q = len(b[i]) * i\n q = 2 * sum(b[i])\n print(p -\n ans[i] +\n a[i] * (i - 1) -\n len(b[i]) * i +\n 2 * sum(b[i]), end=' ')", "import math\nimport functools\nfrom collections import defaultdict\n\nn, m = map(int, input().split(' '))\n\nv = [i for i in map(int, input().split(' '))]\n\ns = [0 for i in range(n + 2)]\n\nfor i in range(m - 1):\n if abs(v[i] - v[i + 1]) < 2:\n continue\n s[min(v[i], v[i + 1]) + 1] += 1\n s[max(v[i], v[i + 1])] -= 1\n\np = 0\n\nfor i in range(m - 1):\n p += abs(v[i] - v[i + 1])\n\nans = [0 for i in range(n + 2)]\n\nd = 0\n\nfor i in range(n + 2):\n d += s[i]\n ans[i] = d\n\na = defaultdict(lambda : 0, {})\nb = defaultdict(lambda : [], {})\n\nfor i in range(m - 1):\n if v[i] == v[i + 1]:\n continue\n a[min(v[i], v[i + 1])] += 1\n b[max(v[i], v[i + 1])].append(min(v[i], v[i + 1]))\n\nfor i in range(1, n + 1):\n q = p\n q = ans[i]\n q = a[i] * (i - 1)\n q = len(b[i]) * i\n q = 2 * sum(b[i])\n print(p -\n ans[i] +\n a[i] * (i - 1) -\n len(b[i]) * i +\n 2 * sum(b[i]), end=' ')", "#bouncipie\ndef readint():\n return [int(e) for e in input().split()]\n \nn, m = readint()\nx = readint()\n \nsm = [0] * (n+2)\n \ndef addvalue(s, e, v):\n if s > e:\n return\n sm[s] += v\n sm[e+1] -= v\n \nfor (a, b) in zip(x, x[1:]):\n if a == b:\n continue\n if a > b:\n a, b = b, a\n addvalue(1, a-1, b - a)\n addvalue(a, a, b-1)\n addvalue(a+1, b-1, b - a - 1)\n addvalue(b, b, a)\n addvalue(b+1, n, b - a)\n \nfor i in range(1, n+2):\n sm[i] += sm[i-1]\n \nprint(' '.join(map(str, sm[1:n+1])))\n"] | {"inputs": ["4 4\n1 2 3 4\n", "5 5\n2 1 5 3 5\n", "2 10\n1 2 1 1 2 2 2 2 2 2\n"], "outputs": ["3 4 6 5 \n", "9 8 12 6 8 \n", "3 3 \n"]} | INTRODUCTORY | PYTHON3 | CODEFORCES | 17,913 | |
39af458d2bfa4cea995c3b4b35948706 | UNKNOWN | There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other.
You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two districts can be connected directly or through other connected districts).
If two districts belonging to the same gang are connected directly with a road, this gang will revolt.
You don't want this so your task is to build $n-1$ two-way roads in such a way that all districts are reachable from each other (possibly, using intermediate districts) and each pair of directly connected districts belong to different gangs, or determine that it is impossible to build $n-1$ roads to satisfy all the conditions.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 500$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($2 \le n \le 5000$) β the number of districts. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the gang the $i$-th district belongs to.
It is guaranteed that the sum of $n$ does not exceed $5000$ ($\sum n \le 5000$).
-----Output-----
For each test case, print:
NO on the only line if it is impossible to connect all districts satisfying the conditions from the problem statement. YES on the first line and $n-1$ roads on the next $n-1$ lines. Each road should be presented as a pair of integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n; x_i \ne y_i$), where $x_i$ and $y_i$ are two districts the $i$-th road connects.
For each road $i$, the condition $a[x_i] \ne a[y_i]$ should be satisfied. Also, all districts should be reachable from each other (possibly, using intermediate districts).
-----Example-----
Input
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
Output
YES
1 3
3 5
5 4
1 2
NO
YES
1 2
2 3
3 4
YES
1 2
1 3
1 4 | ["from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush,heappop\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\nM = mod = 998244353\ndef factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))\ndef inv_mod(n):return pow(n, mod - 2, mod)\n \ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef li2():return [i for i in input().rstrip('\\n')]\ndef li3():return [int(i) for i in input().rstrip('\\n')]\n\n\nfor _ in range(val()):\n n = val()\n l = li()\n \n if max(l) == min(l):\n print('NO')\n continue\n \n print('YES')\n root = l[0]\n same = set()\n other = -1\n for i in range(1, n):\n if l[i] == root:\n same.add(i)\n else:\n other = i\n print(1, i + 1)\n \n for i in same:\n print(i + 1, other + 1)", "for _ in range(int(input())):\n am = int(input())\n arr = list(map(int,input().split()))\n if len(set(arr)) == 1:\n print(\"NO\")\n continue\n print(\"YES\")\n f = (0,arr[0])\n s = (0,0)\n for i in range(am):\n if arr[i] != f[1]:\n s = (i, arr[i])\n print(f[0]+1,s[0]+1)\n for i in range(am):\n if i != f[0] and i != s[0]:\n if arr[i] == f[1]:\n print(i+1,s[0]+1)\n else:\n print(i+1,f[0]+1)\n", "'''\n Auther: ghoshashis545 Ashis Ghosh\n College: jalpaiguri Govt Enggineering College\n\n'''\nfrom os import path\nimport sys\nfrom heapq import heappush,heappop\nfrom functools import cmp_to_key as ctk\nfrom collections import deque,defaultdict as dd \nfrom bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right\nfrom itertools import permutations\nfrom datetime import datetime\nfrom math import ceil,sqrt,log,gcd\ndef ii():return int(input())\ndef si():return input().rstrip()\ndef mi():return list(map(int,input().split()))\ndef li():return list(mi())\nabc='abcdefghijklmnopqrstuvwxyz'\nmod=1000000007\n# mod=998244353\ninf = float(\"inf\")\nvow=['a','e','i','o','u']\ndx,dy=[-1,1,0,0],[0,0,1,-1]\n\ndef bo(i):\n return ord(i)-ord('a')\n\nfile = 1\n\n\n\n \ndef solve():\n\n\n \n\n for _ in range(ii()):\n\n n = ii()\n a = li()\n if len(set(a)) == 1:\n print('NO')\n continue\n print('YES')\n ans,p = [],[]\n x = a[0]\n y = -1\n for i in range(1,n):\n if a[i] != x:\n y = i+1\n ans.append([1,i+1])\n else:\n p.append(i+1)\n\n for i in p:\n ans.append([y,i])\n\n for i in ans:\n print(*i)\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \ndef __starting_point():\n\n if(file):\n\n if path.exists('input.txt'):\n sys.stdin=open('input.txt', 'r')\n sys.stdout=open('output.txt','w')\n else:\n input=sys.stdin.readline\n solve()\n\n__starting_point()", "import sys\ninput=sys.stdin.readline\nT=int(input())\nfor _ in range(T):\n n=int(input())\n A=list(map(int,input().split()))\n D={}\n flag=0\n for i in range(n):\n if A[i] in D:\n D[A[i]].append(i+1)\n\n else:\n D[A[i]]=[i+1]\n flag=flag+1\n\n if (flag==1):\n print(\"NO\")\n\n else:\n print(\"YES\")\n\n v=A[0]\n v1=0\n for i in range(n):\n if (i+1 not in D[v]):\n print(D[v][0],i+1)\n v1=i+1\n\n l=len(D[v])\n for i in range(1,l):\n print(v1,D[v][i])\n", "\"\"\"\n pppppppppppppppppppp\n ppppp ppppppppppppppppppp\n ppppppp ppppppppppppppppppppp\n pppppppp pppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp pppppppp\n ppppppppppppppppppppp ppppppp\n ppppppppppppppppppp ppppp\n pppppppppppppppppppp\n\"\"\"\n\n\nimport sys\nfrom functools import lru_cache, cmp_to_key\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque, Counter as C\nfrom itertools import combinations as comb, permutations as perm\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nfrom time import perf_counter\nfrom fractions import Fraction\nfrom decimal import Decimal\nfrom copy import deepcopy\n# sys.setrecursionlimit(pow(10, 6))\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"output.txt\", \"w\")\n# mod = 10 ** 9 + 7\nmod2 = 998244353\ndef data(): return sys.stdin.readline().strip()\ndef out(var, end=\"\\n\"): sys.stdout.write(str(var)+end)\ndef outa(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var)) + end)\ndef l(): return list(sp())\ndef sl(): return list(ssp())\ndef sp(): return list(map(int, data().split()))\ndef ssp(): return list(map(str, data().split()))\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\n\n\nfor _ in range(int(data())):\n n = int(data())\n arr = l()\n if len(set(arr)) == 1:\n out(\"NO\")\n continue\n out(\"YES\")\n no, L = -1, []\n for i in range(1, n):\n if arr[i] == arr[0]:\n L.append(i + 1)\n else:\n no = i + 1\n outa(1, i + 1)\n for i in L:\n outa(no, i)\n"] | {
"inputs": [
"4\n5\n1 2 2 1 3\n3\n1 1 1\n4\n1 1000 101 1000\n4\n1 2 3 4\n",
"1\n5\n6756657 32231 86 234 23442\n",
"1\n2\n7 7\n"
],
"outputs": [
"YES\n1 2\n1 3\n1 5\n5 4\nNO\nYES\n1 2\n1 3\n1 4\nYES\n1 2\n1 3\n1 4\n",
"YES\n1 2\n1 3\n1 4\n1 5\n",
"NO\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 7,130 | |
7928cdc9f0416fe24aac881bbb52d0c3 | UNKNOWN | You are given a binary string of length $n$ (i. e. a string consisting of $n$ characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $k$ moves? It is possible that you do not perform any moves at all.
Note that you can swap the same pair of adjacent characters with indices $i$ and $i+1$ arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.
You have to answer $q$ independent test cases.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) β the number of test cases.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 10^6, 1 \le k \le n^2$) β the length of the string and the number of moves you can perform.
The second line of the test case contains one string consisting of $n$ characters '0' and '1'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ($\sum n \le 10^6$).
-----Output-----
For each test case, print the answer on it: the lexicographically minimum possible string of length $n$ you can obtain from the given one if you can perform no more than $k$ moves.
-----Example-----
Input
3
8 5
11011010
7 9
1111100
7 11
1111100
Output
01011110
0101111
0011111
-----Note-----
In the first example, you can change the string as follows: $1\underline{10}11010 \rightarrow \underline{10}111010 \rightarrow 0111\underline{10}10 \rightarrow 011\underline{10}110 \rightarrow 01\underline{10}1110 \rightarrow 01011110$.
In the third example, there are enough operations to make the string sorted. | ["q=int(input())\nfor t in range(q):\n n,k=map(int,input().split())\n a=input()\n ko=0\n used=[0]*n\n ans=''\n g=True\n for i in range(n):\n if a[i]=='1':\n ko+=1\n else:\n if ko<=k:\n k-=ko\n ans=ans+'0'\n else:\n for j in range(ko-k):\n ans=ans+'1'\n ans=ans+'0'\n for j in range(k):\n ans=ans+'1'\n for j in range(i+1,n):\n ans=ans+a[j]\n print(ans)\n g=False\n break\n if g==True:\n for j in range(ko):\n ans=ans+'1'\n print(ans)", "'''\nhttps://codeforces.com/contest/1256/problem/D\n'''\n\n\nq = int(input())\nfor _ in range(q):\n n, k = map(int, input().split())\n s = list(input())\n l = 0\n for i in range(n):\n if k <= 0:\n break\n if s[i] == '0':\n if k >= i - l:\n s[i] = s[l]\n s[l] = '0'\n k -= i - l\n l += 1\n else:\n s[i] = s[i - k]\n s[i - k] = '0'\n break\n print(''.join(s))", "for _ in range(int(input())):\n n,k=map(int,input().split())\n s=input()\n zeroes=[]\n for i in range(n):\n if s[i]=='0':\n zeroes.append(i)\n s=list(s)\n ind=0 \n le=len(zeroes)\n i=0 \n # print(zeroes)\n while i<n:\n # print(k)\n if s[i]=='1':\n while ind<le and zeroes[ind]<i:\n ind+=1 \n if ind==le:\n break\n a=zeroes[ind]\n #print(a)\n # print(i,a)\n if a-i<=k:\n k-=(a-i)\n s[i],s[a]=s[a],s[i]\n #print(s)\n ind+=1 \n #ind+=1 \n i+=1 \n print(''.join(s))", "import bisect\n\n\nq = int(input())\nfor _ in range(q):\n n, k = list(map(int, input().split()))\n s = input()\n ans = []\n for i in range(n):\n if s[i] == \"0\":\n ans.append(i)\n cnt = 0\n for i, pos in enumerate(ans):\n if cnt + pos - i <= k:\n cnt += (pos - i)\n else:\n res = list(\"0\"*i + \"1\"*(pos-i) + s[pos:])\n res[pos] = \"1\"\n res[pos - (k-cnt)] = \"0\"\n print(\"\".join(res))\n break\n else:\n print(\"0\"*len(ans) + \"1\"*(n-len(ans)))\n \n", "import sys\ninput = sys.stdin.readline\n\nq=int(input())\nfor testcases in range(q):\n n,k=list(map(int,input().split()))\n S=input().strip()\n\n count=0\n LIST=[0]\n\n for s in S:\n if s==\"1\":\n count+=1\n else:\n LIST.append(count)\n\n ind=1\n while ind<len(LIST) and k>0:\n if LIST[ind]<=k:\n k-=LIST[ind]\n LIST[ind]=0\n else:\n LIST[ind]-=k\n k=0\n ind+=1\n\n #print(LIST)\n\n ones=0\n ANS=[]\n\n for i in range(1,len(LIST)):\n ANS+=[1]*(LIST[i]-LIST[i-1])\n ANS.append(0)\n ANS+=[1]*(count-LIST[-1])\n\n print(\"\".join(map(str,ANS)))\n\n \n \n \n\n \n", "import io, sys, atexit, os\nimport math as ma\nfrom decimal import Decimal as dec\nfrom itertools import permutations\nfrom itertools import combinations\n\n\ndef li ():\n\treturn list (map (int, sys.stdin.readline ().split ()))\n\n\ndef num ():\n\treturn map (int, sys.stdin.readline ().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\ndef lcm ( x, y ):\n\tgg = find_gcd (x, y)\n\treturn (x * y // gg)\n\n\nmm = 1000000007\n\n\ndef solve ():\n\tt = nu()\n\tfor tt in range (t):\n\t\tn,k=num()\n\t\ts=list(input())\n\t\tol=[0]*(n+1)\n\t\tmove=0\n\t\tlast=0\n\t\tind=-1\n\t\tfor i in range(n):\n\t\t\tif(s[i]==\"0\"):\n\t\t\t\tox=i-last\n\t\t\t\tif(k-ox>=0):\n\t\t\t\t\tk-=ox\n\t\t\t\telse:\n\t\t\t\t\tind=i\n\t\t\t\t\tbreak\n\t\t\t\tlast+=1\n\t\tif(ind==-1):\n\t\t\ts.sort()\n\t\t\tprint(*s,sep=\"\")\n\t\telse:\n\t\t\top=s[0:ind]\n\t\t\toz=s[ind:]\n\t\t\top.sort()\n\t\t\top+=oz\n\t\t\twhile(k>0):\n\t\t\t\top[ind-1],op[ind]=op[ind],op[ind-1]\n\t\t\t\tind-=1\n\t\t\t\tk-=1\n\t\t\tprint(*op,sep=\"\")\n\n\n\n\n\n\n\n\n\ndef __starting_point():\n\tsolve ()\n__starting_point()", "import sys\nq = int(input())\nfor qi in range(q):\n n, k = list(map(int, input().split()))\n s = list(input())\n s = [0 if x == '0' else 1 for x in s]\n zc = oc = 0\n found = False\n for i in range(len(s)):\n if s[i] == 1:\n oc += 1\n else:\n if oc <= k:\n k -= oc\n zc += 1\n else:\n res = [0] * zc\n res += [1] * (oc - k)\n res += [0]\n res += [1] * k\n res += s[i + 1:]\n print(''.join(str(x) for x in res))\n found = True\n break\n if not found:\n res = [0] * zc\n res += [1] * oc\n print(''.join(str(x) for x in res))\n\n", "q = int(input())\n#q = 1\nfor _ in range(q):\n n, k = map(int, input().split())\n\n line = list(input())\n\n zero = 0\n non_zero = 0\n while zero < n:\n if line[zero] != '0':\n zero += 1\n continue\n pos = zero\n # print(\"<\", line, zero)\n if zero - non_zero < k:\n k -= zero - non_zero\n line[zero] = '1'\n line[non_zero] = '0'\n non_zero += 1\n else:\n line[zero - k] = '0'\n line[zero] = '1'\n break\n # print(\">\", line, zero)\n # print()\n if k == 0:\n break\n zero += 1\n print(*line, sep=\"\")", "q = int(input())\nwhile q > 0:\n q -= 1\n n, d = list(map(int, input().split()))\n s = input()\n l =[]\n for c in s:\n l.append(c)\n j = 0\n ans = [\"\" for i in range(n)]\n for i in range(n):\n if l[i] == \"0\":\n if i - j <= d:\n ans[j] = \"0\"\n l[i] = \"*\"\n d -= (i-j)\n j += 1\n else:\n ans[i-d] = \"0\"\n l[i] = \"*\"\n break\n i = 0\n index = 0\n while i < n:\n while l[index] == \"*\":\n index += 1\n if index >= n:\n break\n if index >= n:\n break\n if ans[i] == \"\":\n ans[i] = l[index]\n index += 1\n i += 1\n for k in ans:\n print(k, end = \"\")\n print()\n\n \n \n print()\n \n\n ", "from collections import deque\nimport sys\ninput = sys.stdin.readline\n\nq = int(input())\nfor _ in range(q):\n n, k = list(map(int, input().split()))\n s = input()\n ans = deque()\n cnt = 0\n flg = 1\n for i in range(n):\n if flg:\n if s[i] == '0':\n if i - cnt <= k:\n ans.appendleft(0)\n k -= i - cnt\n cnt += 1\n else:\n flg = 0\n j = i - k\n else:\n ans.append(1)\n else:\n ans.append(int(s[i]))\n if flg:\n print(''.join(map(str, ans)))\n else:\n ans = list(ans)\n ans1 = ans[:j]\n ans2 = ans[j:]\n print(''.join(map(str, ans1)) + '0' + ''.join(map(str, ans2)))\n", "for _ in range(int(input())):\n n, k = map(int, input().split())\n s = [*input()]\n t = 0\n ans = ['1'] * n\n\n for i in range(n):\n if s[i] == '0':\n z = min(k, i - t)\n k -= z\n ans[i - z] = '0'\n t += 1\n\n print(''.join(ans))", "q = int(input())\nfor __ in [0]*q:\n n,k = list(map(int,input().split()))\n a = list(input())\n q = k\n p = -1\n res = []\n for i in range(n):\n if p == -1 and a[i] == '1':\n p = i\n res.append('1')\n elif p != -1 and a[i] == '0':\n if q >= i-p:\n res[p] = '0'\n res.append('1')\n q -= i-p\n p += 1\n else:\n if q != 0:\n res[i-q] = '0'\n res.append('1')\n q = 0\n else:\n res.append('0')\n else:\n res.append(a[i])\n ans = ''.join(res)\n print(ans)\n \n \n \n\n", "t = int(input())\nfor _ in range(t):\n n,k = list(map(int, input().split()))\n s = input()\n ans = \"\"\n ones = 0\n zeros = 0\n flag = 0\n for i in range(n):\n if(s[i]==\"1\"):\n ones = ones + 1\n else:\n if(k>=ones): # would go to start\n k = k - ones\n zeros = zeros + 1\n else:\n # print(zeros)\n \n # print(ones-k)\n# print(s[i+1:])\n ans = \"0\"*zeros + \"1\"*(ones-k) + \"0\" + \"1\"*k + s[i+1:]\n flag = 1\n break\n if(flag==0):\n ans = \"0\"*zeros + \"1\"*ones\n print(ans)\n\n\n", "q = int(input())\nfor _ in q*' ':\n n, k = map(int, input().split())\n s = list(input())\n i = 0\n t = k\n c = 0\n while i < n and s[i] == '0':\n i += 1\n c += 1\n while i < n and k > 0:\n if s[i] == '0':\n u = min(i-c, k)\n k -= u\n s[i], s[i-u] = s[i-u], s[i]\n c += 1\n i += 1\n print(*s, sep='')", "from collections import deque\n\nfor __ in range(int(input())):\n n, k = list(map(int, input().split()))\n ar = list(map(int, input()))\n lol = deque([])\n for i in range(n):\n if ar[i] == 0:\n lol.append(i)\n i = 0\n while lol and len(lol) > i and lol[i] == i:\n i += 1\n num = i\n for __ in range(i):\n lol.popleft()\n while lol and k > 0:\n x = lol[0]\n if k >= x - num:\n k -= x\n k += num\n lol.popleft()\n i += 1\n num += 1\n else:\n break\n ans = []\n for j in range(i):\n ans.append(0)\n if lol:\n lol[0] -= k\n for j in range(i, n):\n if lol and j == lol[0]:\n ans.append(0)\n lol.popleft()\n else:\n ans.append(1)\n print(''.join(map(str, ans)))", "import sys\n\n\ndef main():\n for _ in range(int(input())):\n n, k = get_ints()\n s = list(input())\n x = []\n for i in range(n):\n if s[i] == \"0\":\n x.append((i, i - len(x)))\n i = 0\n while k > 0 and i < len(x):\n if x[i][1] < k:\n s[i], s[x[i][0]] = s[x[i][0]], s[i]\n k -= x[i][1]\n i += 1\n else:\n s[x[i][0] - k], s[x[i][0]] = s[x[i][0]], s[x[i][0] - k]\n break\n print(*s, sep=\"\")\n\n\ninput = lambda: sys.stdin.readline().strip()\nget_ints = lambda: map(int, input().split())\nget_array = lambda: list(map(int, input().split()))\nmain()\n", "import sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nq = int( I() )\nfor _ in range( q ):\n n, k = list(map( int, I().split() ))\n l = I()\n r = []\n o = 0\n for i in l:\n if i == '1':\n o += 1\n else:\n t = max( 0, o - k )\n r.extend( [ '1' ] * t )\n o -= t\n k -= o\n r.append( '0' )\n r.extend( [ '1' ] * o )\n print( \"\".join( r ) )\n", "t=int(input())\nwhile t>0:\n t-=1\n n,k=list(map(int,input().split()))\n z=[]\n a=list(input())\n for i in range(n):\n if a[i]=='0':\n z.append(i)\n y=0\n #print(z)\n for i in range(len(z)):\n if k-(z[i]-y)>0:\n k-=(z[i]-y)\n z[i]=y\n y+=1\n else:\n z[i]-=k\n break\n v=[0 for i in range(n)] \n for i in range(len(z)):\n a[z[i]]='0'\n v[z[i]]=1\n for i in range(n):\n if v[i]==0:\n a[i]='1'\n print(\"\".join(a)) \n", "t = int(input())\nwhile(t > 0):\n t -= 1\n a = list(map(int, input().split()))\n s = input()\n ans = \"\"\n tmp = 0\n n = a[0]\n k = a[1]\n for i in range(n):\n if k >= 0 :\n if(s[i] == '1'):\n tmp += 1\n if(i == n-1):\n for x in range(tmp): ans += '1'\n else:\n if(k >= tmp):\n ans += '0'\n if(i == n-1):\n for x in range(tmp): ans += '1'\n else:\n for x in range(tmp - k): ans += '1'\n ans += '0'\n for x in range(k):ans += '1'\n k-=tmp\n else:ans += s[i] \n print(ans)", "import sys\nimport itertools\nimport math\nimport collections\nfrom collections import Counter\n\n#########################\n# imgur.com/Pkt7iIf.png #\n#########################\n\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 divs(n, start=1):\n r = []\n for i in range(start, int(math.sqrt(n) + 1)):\n if (n % i == 0):\n if (n / i == i):\n r.append(i)\n else:\n r.extend([i, n // i])\n return r\ndef ceil(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)))\ndef dd(): return collections.defaultdict(int)\n\nt = ii()\nfor _ in range(t):\n n, k = mi()\n s = input()\n state = []\n pos = 0\n for i in range(n):\n if s[i] == '0':\n if k != 0 and i - pos <= k:\n state.append(pos)\n k -= (i - pos)\n pos += 1\n elif k != 0:\n state.append(i - k)\n k = 0\n else:\n state.append(i)\n res = [1]*n\n for i in state:\n res[i] = 0\n prr(res, '')", "def __starting_point():\n\n q = int(input())\n\n for t in range(q):\n n, k = [int(i) for i in input().split(\" \")]\n s = list(input())\n\n zero = []\n for i in range(len(s)):\n if s[i] == '0':\n zero.append(i)\n\n var = 0\n index = 0\n\n while k > 0 and var < len(zero) and index < len(s):\n temp = zero[var]\n if k < zero[var]-index:\n s[zero[var]-k], s[zero[var]] = s[zero[var]], s[zero[var]-k]\n k = 0\n else:\n s[index], s[zero[var]] = s[zero[var]], s[index]\n k -= zero[var]-index\n var += 1\n index += 1\n\n print(\"\".join(s))\n\n\n\n\n__starting_point()", "def solve(k, bits):\n indices = []\n for i, b in enumerate(bits):\n if b == '0':\n indices.append(i)\n cur = k\n for i in range(len(indices)):\n index = indices[i]\n move = index - i\n if move > cur:\n indices[i] = index - cur\n break\n else:\n indices[i] = i\n cur -= move\n ans = ['1'] * len(bits)\n for index in indices:\n ans[index] = '0'\n return ''.join(ans)\n\n\ndef __starting_point():\n q = int(input())\n for _ in range(q):\n n, k = [int(r) for r in input().split(' ')]\n print(solve(k, input()))\n\n__starting_point()", "t = int(input())\nfor test in range(t):\n n,k = [int(x) for x in input().split()]\n s = list(input())\n\n zer = []\n for i in range(n):\n if s[i]=='0':\n zer.append(i)\n curr = 0\n #print(s)\n while k>0 and curr<len(zer):\n if curr==0:\n swaps=zer[curr]\n else:\n swaps = zer[curr]-zer[curr-1]-1\n\n if swaps>k:\n swaps = k\n #print(swaps,'ss')\n if swaps==0:\n curr+=1\n continue\n\n x = zer[curr]\n y = x-swaps\n s[x]='1'\n #print(s,y)\n s[y]='0'\n k = k-swaps\n zer[curr]=y\n curr+=1\n #print(s)\n\n for i in range(n):\n print(s[i],end=\"\")\n print()\n", "from collections import defaultdict\nfrom math import sqrt,factorial,gcd,log2,inf,ceil\n# map(int,input().split())\n# l = list(map(int,input().split()))\nmod = 10**9 + 7\n\n\nq = int(input())\n\nfor _ in range(q):\n n,k = list(map(int,input().split()))\n s = list(input())\n cnt = 0\n flag = 0\n yo = 0\n ha = 0\n for i in range(n):\n\n if s[i] == '0':\n if cnt<=k:\n k-=cnt\n yo+=1\n else:\n flag = 1\n ha = k\n break\n else:\n cnt+=1\n if flag == 0:\n z = list(map(int,s))\n z.sort()\n z = list(map(str,z))\n print(''.join(z))\n\n else:\n ans = []\n for i in range(yo):\n ans.append('0')\n cnt = 0\n ma = 0\n\n for j,i in enumerate(s):\n if i == '1':\n ma+=1\n if i == '0':\n cnt+=1\n if cnt > yo:\n posn = j\n break\n z = ['1'*(ma-ha) + '0']+['1'*(ha)]\n z1 = s[posn+1:]\n ans+=z+z1\n print(''.join(ans))\n\n"] | {
"inputs": [
"3\n8 5\n11011010\n7 9\n1111100\n7 11\n1111100\n",
"2\n8 5\n11011010\n7 9\n1111100\n",
"1\n2 1\n00\n"
],
"outputs": [
"01011110\n0101111\n0011111\n",
"01011110\n0101111\n",
"00\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 18,061 | |
d6485c12310d1558e580ae2f952f4438 | UNKNOWN | The only difference between easy and hard versions is constraints.
You are given $n$ segments on the coordinate axis $OX$. Segments can intersect, lie inside each other and even coincide. The $i$-th segment is $[l_i; r_i]$ ($l_i \le r_i$) and it covers all integer points $j$ such that $l_i \le j \le r_i$.
The integer point is called bad if it is covered by strictly more than $k$ segments.
Your task is to remove the minimum number of segments so that there are no bad points at all.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 200$) β the number of segments and the maximum number of segments by which each integer point can be covered.
The next $n$ lines contain segments. The $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 200$) β the endpoints of the $i$-th segment.
-----Output-----
In the first line print one integer $m$ ($0 \le m \le n$) β the minimum number of segments you need to remove so that there are no bad points.
In the second line print $m$ distinct integers $p_1, p_2, \dots, p_m$ ($1 \le p_i \le n$) β indices of segments you remove in any order. If there are multiple answers, you can print any of them.
-----Examples-----
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
Output
3
1 4 7
Input
5 1
29 30
30 30
29 29
28 30
30 30
Output
3
1 2 4
Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3
Output
4
1 3 5 6 | ["from operator import itemgetter\nimport sys\ninput = sys.stdin.readline\n\n\nn, m = map(int, input().split())\ninfo = [list(map(int, input().split())) + [i] for i in range(n)]\ninfo = sorted(info, key = itemgetter(1))\nmax_num = info[-1][1]\n\nN = max_num\nINF = 0\nLV = (N-1).bit_length()\nN0 = 2**LV\ndata = [0]*(2*N0)\nlazy = [0]*(2*N0)\n\ndef gindex(l, r):\n L = (l + N0) >> 1; R = (r + N0) >> 1\n lc = 0 if l & 1 else (L & -L).bit_length()\n rc = 0 if r & 1 else (R & -R).bit_length()\n for i in range(LV):\n if rc <= i:\n yield R\n if L < R and lc <= i:\n yield L\n L >>= 1; R >>= 1\n\ndef propagates(*ids):\n for i in reversed(ids):\n v = lazy[i-1]\n if not v:\n continue\n lazy[2*i-1] += v; lazy[2*i] += v\n data[2*i-1] += v; data[2*i] += v\n lazy[i-1] = 0\n\ndef update(l, r, x):\n *ids, = gindex(l, r)\n propagates(*ids)\n\n L = N0 + l; R = N0 + r\n while L < R:\n if R & 1:\n R -= 1\n lazy[R-1] += x; data[R-1] += x\n if L & 1:\n lazy[L-1] += x; data[L-1] += x\n L += 1\n L >>= 1; R >>= 1\n for i in ids:\n data[i-1] = max(data[2*i-1], data[2*i])\n\ndef query(l, r):\n propagates(*gindex(l, r))\n L = N0 + l; R = N0 + r\n\n s = INF\n while L < R:\n if R & 1:\n R -= 1\n s = max(s, data[R-1])\n if L & 1:\n s = max(s, data[L-1])\n L += 1\n L >>= 1; R >>= 1\n return s\n\nans = []\nfor i in range(n):\n l, r, j = info[i]\n r += 1\n if query(l, r) < m:\n update(l, r, 1)\n else:\n ans.append(j+1)\nprint(len(ans))\nprint(*ans)", "\nn,k = list(map(int,input().split()))\nL = [list(map(int,input().split())) for i in range(n)]\n\nfor i in range(n):\n L[i].append(i)\n\nL.sort(key=lambda x:x[1])\n\n# print(L)\n\n\ndef c(x):\n for i in range(x[0],x[1]+1):\n if T[i] >= k:\n return 0\n return 1\n\nans = 0\nA=[]\nT = [0] * 203\ni = 0\nt = 0\nwhile i < n :\n if c(L[i]) == 1:\n for j in range(L[i][0], L[i][1]+1):\n T[j] += 1\n t = L[i][0]\n else:\n A.append(L[i][2]+1)\n ans += 1\n\n i += 1\n# print(T)\nA.sort()\nprint(ans)\nprint(\" \".join([str(i) for i in A]))\n\n", "n, k = list(map(int, input().split()))\nar = []\nfor i in range(n):\n lolk = list(map(int, input().split()))\n ar.append([lolk[0], 0, lolk[1], i + 1])\n ar.append([lolk[1], 1, lolk[0], i + 1])\nar.sort()\nqueue = []\nkek = 0\nans = 0\nans1 = []\nksjdfks = set()\nfor time, type, end, lol in ar:\n if lol not in ksjdfks:\n if type == 0:\n kek += 1\n queue.append([time, type, end, lol])\n queue.sort(key=lambda x: x[2])\n if kek > k:\n ans += 1\n ans1.append(queue[-1][3])\n ksjdfks.add(queue[-1][3])\n queue.pop()\n kek -= 1\n else:\n kek -= 1\n queue.pop(queue.index([end, 0, time, lol]))\nprint(ans)\nprint(*ans1)", "from heapq import heapify, heappop, heappush\nn, k = list(map(int, input().split()))\nN = 2*10**5+2\nsegs = []\nplus = [0 for _ in range(N)]\nminus = [0 for _ in range(N)]\nans = []\nheapmin = []\nheapmax = []\nfor i in range(n):\n x, y = list(map(int, input().split()))\n heappush(heapmin, (x-1,y-1,i+1))\n\nheight = 0\nfor i in range(N):\n height+=plus[i]\n height-=minus[i]\n while len(heapmin) > 0 and heapmin[0][0] <= i:\n x, y, ii = heappop(heapmin)\n heappush(heapmax, (-y, x, ii))\n height += 1 \n minus[y+1]+=1\n while height > k:\n y, x, ii = heappop(heapmax)\n y=-y\n height-=1\n plus[y+1]+=1\n ans.append(ii)\nprint(len(ans))\nprint(*ans)", "from math import *\nn,k = map(int,input().split())\na = []\npre = [0 for i in range(205)]\nfor i in range(n):\n u,v = map(int,input().split())\n a.append([u,v,i+1])\n for i in range(u,v+1):\n pre[i] += 1\nans = []\na.sort()\ni = 1\nwhile(1):\n flag = 0\n for i in range(205):\n if pre[i] > k:\n flag = i\n break\n if flag == 0:\n break\n m = 0\n m1 = 0\n for i in range(n):\n if a[i][0] > flag:\n break\n if m < a[i][1]:\n m = a[i][1]\n m1 =i\n ans.append(a[m1][2])\n for i in range(a[m1][0],a[m1][1]+1):\n pre[i] -= 1\n del(a[m1])\n n -= 1\nprint(len(ans))\nfor i in ans:\n print(i,end = \" \")\nprint()", "from math import *\n\nn,k = map(int, input().split())\n\nnum = [[] for i in range( 300) ]\n\nsegment = [0]\n\nfor i in range(1, n+1):\n l, r = map(int, input().split())\n\n num[l].append(i)\n num[r+1].append(-i)\n\n segment.append((l, r+1, r-l))\n\nrep = 0\ncurSegment = []\nrem = []\n\nfor i in range(300):\n for a in num[i]:\n if a >= 0:\n curSegment.append(a)\n elif (-a) in curSegment:\n curSegment.remove(-a)\n\n while len(curSegment) > k:\n rep += 1\n plusAdroite = 0\n aVirer = 0\n for j in curSegment:\n if segment[j][1] >= plusAdroite:\n plusAdroite = segment[j][1]\n aVirer = j\n \n curSegment.remove(aVirer)\n rem.append(aVirer)\n\nprint(rep)\nprint(*sorted(rem))", "import heapq\n\nn,k = list(map(int,input().split()))\n\nllis = [ [] for i in range(2 * (10**5) + 1) ]\nrlis = [ [] for i in range(2 * (10**5) + 1) ]\nflag = [0] * (2 * (10**5) + 1)\n\nfor i in range(n):\n\n l,r = list(map(int,input().split()))\n \n llis[l].append([i+1,r])\n rlis[r].append([i+1,l])\n\nnow = 0\nrq = []\nans = []\nfor i in range(2 * (10 ** 5)):\n \n i += 1\n\n for j in llis[i]:\n now += 1\n ind = j[0]\n r = j[1]\n flag[ind] = 1\n heapq.heappush(rq,[-1 * r,ind])\n\n for j in rlis[i-1]:\n \n ind = j[0]\n if flag[ind] == 1:\n now -= 1\n flag[ind] = 0\n\n while now > k:\n\n nowq = heapq.heappop(rq)\n ind = nowq[1]\n\n if flag[ind] == 1:\n ans.append(ind)\n now -= 1\n flag[ind] = 0\n\n\nprint(len(ans))\nprint(\" \".join(map(str,ans)))\n\n \n", "from bisect import insort_left as bs\nb=[]\na=[]\nn,k=list(map(int,input().split()))\nfor i in range(n):\n x,y=list(map(int,input().split()))\n a.append([x,y,i+1])\n b.append([x,y,i+1])\na.sort()\nans=[[a[0][1],a[0][2]]]\nle=1\nvis=[0]*201\nprintans=[]\nfor i in a:\n x,y,ind=i[0],i[1],i[2]\n if i!=a[0]:\n bs(ans,[y,ind],0,le)\n le+=1\n for j in range(x,y+1):\n if vis[j]>=k:\n p,q=ans.pop()\n le-=1\n for l in range(b[q-1][0],p+1):\n vis[l]-=1\n # print(\"cnkjsn\")\n printans.append(q) \n for l in range(x,y+1):\n vis[l]+=1\n # print(vis[28:31])\n break\n else:\n for j in range(x,y+1):\n vis[j]+=1\n # print(ans,vis[28:31]) \n \n # print(print(vis[1:10],ans)\n # \n # )\n # print(vis[1:10],ans)\n \nprint(len(printans))\nprint(*printans)\n \n \n \n", "import sys\ninput = sys.stdin.readline\n\nn,k=list(map(int,input().split()))\n\nS=[tuple(map(int,input().split()))+(i+1,) for i in range(n)]\nS.sort()\n\nsegtemp=2*10**5\nseg_el=1<<((segtemp).bit_length())# Segment tree\u306e\u53f0\u306e\u8981\u7d20\u6570\nSEG=[0]*(2*seg_el)# 1-indexed\u306a\u306e\u3067\u3001\u8981\u7d20\u65702*seg_el.Segment tree\u306e\u521d\u671f\u5024\u3067\u521d\u671f\u5316\n\ndef getvalue(n,seg_el):# \u4e00\u70b9\u306e\u5024\u3092\u53d6\u5f97\n i=n+seg_el\n ANS=0\n \n ANS+=SEG[i]\n i>>=1# \u5b50\u30ce\u30fc\u30c9\u3078\n \n while i!=0:\n ANS+=SEG[i]\n i>>=1\n\n return ANS\n\ndef updates(l,r,x):# \u533a\u9593[l,r)\u306emin\u3092\u66f4\u65b0.\n L=l+seg_el\n R=r+seg_el\n\n while L<R:\n if L & 1:\n SEG[L]+=x\n L+=1\n\n if R & 1:\n R-=1\n SEG[R]+=x\n L>>=1\n R>>=1\n\nind=0\nSH=[]\nANS=[]\nimport heapq\n\nfor point in range(segtemp):\n while ind<n and S[ind][0]<=point:\n l,r,x=S[ind]\n updates(l,r+1,1)\n ind+=1\n\n heapq.heappush(SH,(-r,l,x))\n\n #print(getvalue(point,seg_el),SH)\n\n while getvalue(point,seg_el)>k:\n r,l,x=heapq.heappop(SH)\n r=-r\n ANS.append(x)\n updates(l,r+1,-1)\n\n #print(point,ANS,getvalue(point,seg_el))\n \nprint(len(ANS))\nprint(*ANS)\n \n", "from heapq import *\nn, k = map(int, input().split())\nE = []\nopent = {}\nclos = {}\nfor i in range(n):\n l, r = map(int, input().split())\n E.append([l, 1, i])\n E.append([r, -1, i])\n opent[i] = r\n clos[i] = l\nE.sort(key=lambda x: (x[0], -x[1], -opent[x[2]]))\nb = 0\nnow_r = []\nheapify(now_r)\ncnt_delet = 0\nans = []\ndeleted = set()\nfor x, t, i in E:\n if t == 1:\n heappush(now_r, -(opent[i] * 10 ** 6 + i))\n else:\n if i not in deleted:\n cnt_delet += 1\n if len(now_r) - cnt_delet > k:\n for _ in range(len(now_r) - cnt_delet - k):\n nm = heappop(now_r)\n ind = (-nm) % 10 ** 6\n ans.append(ind + 1)\n deleted.add(ind)\nprint(len(ans))\nprint(*ans)", "import sys\nfrom collections import deque\nreadline = sys.stdin.readline\n\nn, k = map(int, readline().split())\n\ntmp = []\nfor i in range(n):\n a,b = map(int, readline().split())\n tmp.append([b,a,i])\ntmp.sort()\nans = []\nfor i in range(201):\n s = 0\n asd = []\n for x in tmp:\n if i <= x[0] and i >= x[1]:\n s+=1\n if s > k:\n ans.append(x[2] + 1)\n asd.append(x)\n for x in asd:\n tmp.remove(x)\nprint(len(ans))\nfor x in ans:\n print(x,end=' ')", "n, k = map(int,input().split())\nN = 2 * 10 ** 5 + 1\npre = [0] * (N+1)\nseg = []\nfor i in range(n):\n\tx, y = map(int,input().split())\n\tx -= 1\n\ty -= 1\n\tseg.append([y,-x, i+1])\n\tpre[x] += 1\n\tpre[y + 1] -= 1\nseg.sort()\nseg.reverse()\nseg = [[-seg[i][1], seg[i][0], seg[i][2]] for i in range(len(seg))]\ncov = [0] * (N+1)\ncov[0] = pre[0]\nfor i in range(1, N):\n\tcov[i] = cov[i - 1] + pre[i]\nwyn = 0\nziomy = []\nfor i in range(N):\n\tp = 0\n\twhile cov[i] > k:\n\t\tmaksi = -1\n\t\topti = -1\n\t\tmini = 100000000000\n\t\tfor d in range(len(seg)):\n\t\t\tif seg[d][1] > maksi and seg[d][0] <= i:\n\t\t\t\tmini = 100000000000000\n\t\t\t\tmaksi = seg[d][1]\n\t\t\t\topti = d\n\t\t\telif seg[d][1] == maksi and seg[d][0] < mini and seg[d][0] <= i:\n\t\t\t\tmini = seg[d][0]\n\t\t\t\topti = d\n\t\tpt = seg[opti][1]\n\t\tziomy.append(seg[opti][2])\n\t\tpre[pt + 1] += 1\n\t\tpre[i] -= 1\n\t\tcov[i] -= 1\n\t\tp += 1\n\t\tseg.pop(opti)\n\tcov[i+1] = cov[i] + pre[i + 1]\n\twyn += p\nprint(wyn)\nprint(*ziomy)", "N = int(2e5+3)\ncum = [0] * N\nn, k = list(map(int, input().split()))\narr = [0] * n\nfor i in range(n):\n arr[i] = [[0,0], i+1]\n arr[i][0] = list(map(int, input().split())) \n cum[arr[i][0][0]] += 1\n cum[arr[i][0][1]+1] -= 1\nfor i in range(1, N):\n cum[i] += cum[i-1]\narr.sort()\nst = set()\nres, j, prev = [], 0, 0\nrmv = [0] * N\nfor i in range(N):\n while j < n and arr[j][0][0] <= i:\n st.add((arr[j][0][1], arr[j][1]))\n j += 1\n prev -= rmv[i]\n while len(st) > 0 and cum[i] - prev > k:\n it = max(st)\n st.remove(it)\n res.append(it[1])\n rmv[it[0]+1] += 1\n prev += 1\n\nprint(len(res))\nprint(*res)\n", "n, k = list(map(int, input().split()))\nar = []\nfor i in range(n):\n lolk = list(map(int, input().split()))\n ar.append([lolk[0], 0, lolk[1], i + 1])\n ar.append([lolk[1], 1, lolk[0], i + 1])\nar.sort()\nqueue = []\nkek = 0\nans = 0\nans1 = []\nksjdfks = set()\nfor time, type, end, lol in ar:\n if lol not in ksjdfks:\n if type == 0:\n kek += 1\n queue.append([time, type, end, lol])\n queue.sort(key=lambda x: x[2])\n if kek > k:\n ans += 1\n ans1.append(queue[-1][3])\n ksjdfks.add(queue[-1][3])\n queue.pop()\n kek -= 1\n else:\n kek -= 1\n queue.pop(queue.index([end, 0, time, lol]))\nprint(ans)\nprint(*ans1)", "# -*- coding: utf-8 -*-\n\nimport sys\n\nline_count = 0\nsegments = []\nfor line in sys.stdin.readlines():\n inputs = line.split()\n if line_count == 0:\n n = int(inputs[0])\n k = int(inputs[1])\n else:\n l = int(inputs[0])\n r = int(inputs[1])\n segments.append((l, r))\n if line_count == n:\n break\n line_count += 1\n\nremoved = [False for i in range(n)]\nremove_count = 0\nremoved_list = []\nfor i in range(1, 201):\n max_i = 0\n covering = []\n for j in range(n):\n if removed[j]:\n continue\n l, r = segments[j]\n if l <= i and i <= r:\n covering.append((r, j))\n to_remove = len(covering) - k\n if to_remove > 0:\n covering.sort()\n for _ in range(to_remove):\n _, j = covering.pop()\n# print(i, j, segments[j])\n removed[j] = True\n removed_list.append(j)\n\nprint(len(removed_list))\nfor j in removed_list:\n print(j + 1, end = \" \")", "import sys\n\n[n,k]=[int(i) for i in sys.stdin.readline().split()]\n\narr=[0]*201\n\nseg=[]\n\nfor i in range(n):\n\t[l,r]=[int(j) for j in sys.stdin.readline().split()]\n\n\tseg.append([r,l,r,i+1])\n\n\tfor x in range(l,r+1):\n\t\tarr[x]+=1\n\nseg.sort(reverse=True)\n\nans_arr=[]\n# ind=0\ninc=[0]*n\n\nfor w in range(n):\n\t# check\n\tdone=1\n\tval=0\n\tfor g in range(1,201):\n\t\tif(arr[g]>k):\n\t\t\tdone=0\n\t\t\tval=g\n\t\t\tbreak\n\n\tif(done==1):\n\t\tbreak\n\telse:\n\t\tcur=n+2\n\t\tfor q in range(n):\n\t\t\tif(inc[q]==0):\n\t\t\t\tl1=seg[q][1]\n\t\t\t\tr1=seg[q][2]\n\t\t\t\tif(l1<=val<=r1):\n\t\t\t\t\tinc[q]=1\n\t\t\t\t\tcur=q\n\t\t\t\t\tans_arr.append(seg[q][3])\n\t\t\t\t\tbreak\t\t\t\t\t\n\n\t\t# l1=seg[ind][1]\n\t\t# r1=seg[ind][2]\n\n\t\tfor p in range(seg[cur][1],seg[cur][2]+1):\n\t\t\tarr[p]-=1\n\n\t\t# ans_arr.append(seg[ind][3])\n\t\t# ind+=1\n\nans_arr.sort()\n\nprint(len(ans_arr))\nfor e in range(len(ans_arr)):\n\tprint(ans_arr[e],end=\" \")\n\n\n\n\n", "n, k = map(int, input().split())\ns = []\nfor i in range(n):\n l, r = map(int, input().split())\n s.append([r, l, i]) # Greedy on largest right endpoint\ns.sort()\n\nans = []\nfor i in range(201):\n a = 0\n u = []\n for tmp in s:\n if i <= tmp[0] and i >= tmp[1]:\n a += 1\n if a > k:\n u.append(tmp)\n ans.append(tmp[2] + 1)\n for tmp in u:\n s.remove(tmp)\nprint(len(ans))\nprint(' '.join(map(str, ans)))", "'''\ntemplate author-: Pyduper\n'''\n \n# MAX = pow(10, 5)\n# stdin = open(\"testdata.txt\", \"r\")\n# ip = stdin\n# def input():\n# \treturn ip.readline().strip()\n\nN = 250\nn, k = map(int, input().split())\n\nsegs = [[0, 0] for _ in range(n)]\ncnt = [0]*N \nans = [0]*n\nfor i in range(n):\n\tsegs[i][0], segs[i][1] = map(int, input().split())\n\tcnt[segs[i][0]] += 1\n\tcnt[segs[i][1]+1] -= 1\n\nfor i in range(N-1):\n\tcnt[i+1] += cnt[i]\n\nfor i in range(N-1):\n\twhile cnt[i] > k:\n\t\tpos = -1\n\t\tfor p in range(n):\n\t\t\tif not ans[p] and segs[p][0] <= i <= segs[p][1] and (pos == -1 or segs[p][1] > segs[pos][1]):\n\t\t\t\tpos = p \n\t\tassert pos != -1\n\n\t\tfor j in range(segs[pos][0], segs[pos][1]+1):\n\t\t\tcnt[j] -= 1\n\t\tans[pos] = 1\nprint(ans.count(1))\nfor i in range(n):\n\tif ans[i]: print(i+1, end=\" \")\nprint()", "n, k = map(int, input().split())\n\np = []\n\nt = [0]*200\n\nfor i in range(n):\n l, r = map(int, input().split())\n p.append((i+1, l, r))\n\n\np.sort(key=lambda x:x[1])\n\n\nr = []\nopened = []\nfor pp in p:\n #print(\"---\")\n #print(pp)\n #print(opened)\n opened = list(filter(lambda x:x[2] >= pp[1], opened))\n #print(opened)\n opened.append(pp)\n #print(opened)\n if len(opened) > k:\n opened.sort(key=lambda x: x[2])\n x, _, _ = opened.pop()\n r.append(x)\nprint(len(r))\n\nprint(*r)", "scount, badness = [int(x) for x in input().split(' ')]\nsegments = []\nlength = 200\nfor i in range(scount):\n segments.append([int(x) - 1 for x in input().split(' ')])\n segments[-1].append(True)\narray = [[] for x in range(length)]\nbadcheck = [0 for x in range(length)]\nfor i in range(scount):\n for k in range(segments[i][0], segments[i][1] + 1):\n array[k].append([segments[i][1], i])\n badcheck[k] += 1\nfor i in range(length):\n array[i].sort()\nres = []\nfor i in range(length):\n while badcheck[i] > badness:\n fn = array[i].pop()\n while not segments[fn[1]][2] == True:\n fn = array[i].pop()\n segments[fn[1]][2] = False\n res.append(fn[1])\n for k in range(i, fn[0] + 1):\n badcheck[k] -= 1\nres.sort()\nprintable = ''\nfor i in res:\n printable += str(i + 1) + ' '\nprint(len(res))\nprint(printable)", "# -*- coding: utf-8 -*-\n \nimport sys\n \ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 7)\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n \nclass SegTreeIndex:\n \n def __init__(self, n, func, init):\n \n self.n = n\n self.func = func\n self.init = init\n n2 = 1\n while n2 < n:\n n2 <<= 1\n self.n2 = n2\n self.tree = [self.init] * (n2 << 1)\n self.index = [self.init] * (n2 << 1)\n for i in range(n2):\n self.index[i+n2] = i\n for i in range(n2-1, -1, -1):\n self.index[i] = self.index[i*2]\n \n def update(self, i, x):\n \n i += self.n2\n self.tree[i] = x\n while i > 1:\n left, right = min(i, i^1), max(i, i^1)\n if self.func(self.tree[left], self.tree[right]) == self.tree[left]:\n self.tree[i >> 1] = self.tree[left]\n self.index[i >> 1] = self.index[left]\n else:\n self.tree[i >> 1] = self.tree[right]\n self.index[i >> 1] = self.index[right]\n i >>= 1\n \n def query(self, a, b):\n \n l = a + self.n2\n r = b + self.n2\n s = (self.init, -1)\n while l < r:\n if r & 1:\n r -= 1\n res = self.func(s[0], self.tree[r])\n if res == s[0]:\n pass\n else:\n s = (self.tree[r], self.index[r])\n if l & 1:\n res = self.func(self.tree[l], s[0])\n if res == self.tree[l]:\n s = (self.tree[l], self.index[l])\n else:\n pass\n l += 1\n l >>= 1\n r >>= 1\n return s\n \nN, K = MAP()\nMAX = 200007\n \nLRs = [[] for i in range(MAX+2)]\nR = [0] * (N+1)\nfor i in range(N):\n l, r = MAP()\n LRs[l].append(i+1)\n LRs[r+1].append(-(i+1))\n R[i+1] = r\n \nsti = SegTreeIndex(N+1, max, -INF)\nsegcnt = 0\nans = []\nremoved = set()\nfor i in range(1, MAX+2):\n for idx in LRs[i]:\n if idx > 0:\n sti.update(idx, R[idx])\n segcnt += 1\n else:\n idx = abs(idx)\n if idx not in removed:\n sti.update(idx, -INF)\n segcnt -= 1\n while segcnt > K:\n mx, idx = sti.query(0, N+1)\n sti.update(idx, -INF)\n ans.append(idx)\n removed.add(idx)\n segcnt -= 1\nprint(len(ans))\nprint(*ans)\n", "import functools\nfrom math import inf\n\nclass event:\n\tdef __init__(self, x, type, index):\n\t\tself.x = x\n\t\tself.type = type\n\t\tself.i = index\n\ndef custom_sort(a, b):\n\t# if a.i == b.i:\n\t# \tif a.type == \"s\" and b.type == \"e\":\n\t# \t\treturn -1\n\t# \tif a.type == \"e\" and b.type == \"s\":\n\t# \t\treturn 1\n\tif a.x < b.x:\n\t\treturn - 1\n\tif a.x > b.x:\n\t\treturn 1\n\tif a.type == \"e\" and b.type == \"s\":\n\t\treturn 1\n\tif a.type == \"s\" and b.type == \"e\":\n\t\treturn -1\n\treturn 0\n\ndef __starting_point():\n\tline = input().split(\" \")\n\tn, k = int(line[0]), int(line[1])\n\n\tevents = []\n\toriginal_events = []\n\tfor i in range(n):\n\t\tline = input().split(\" \")\n\t\ts = int(line[0])\n\t\te = int(line[1])\n\n\t\tevents.append(event(s, \"s\", i))\n\t\tevents.append(event(e, \"e\", i))\n\t\toriginal_events.append([s, e])\n\n\tevents.sort(key=functools.cmp_to_key(custom_sort))\n\n\tactive = {}\n\tans = []\n\n\tcnt = 0\n\tfor curr in events:\n\t\t# print(curr.x, curr.type, curr.i, cnt)\n\t\tif curr.type == \"s\":\n\t\t\tcnt += 1\n\t\t\tactive[curr.i] = 1\n\n\t\t\tif cnt > k:\n\t\t\t\t# print(\"over:\", curr.i, cnt)\n\t\t\t\tto_remove = 0\n\t\t\t\trightmost = -inf\n\t\t\t\tfor i in active.keys():\n\t\t\t\t\tif original_events[i][1] > rightmost:\n\t\t\t\t\t\trightmost = original_events[i][1]\n\t\t\t\t\t\tto_remove = i\n\t\t\t\tans.append(str(to_remove + 1))\n\t\t\t\tdel active[to_remove]\n\t\t\t\tcnt -= 1\n\n\t\telse:\n\t\t\tif curr.i in active.keys():\n\t\t\t\tcnt -= 1\n\t\t\t\tdel active[curr.i]\n\n\tprint(len(ans))\n\tprint(\" \".join(ans))\n__starting_point()", "# -*- coding: utf-8 -*-\n\nimport sys\nimport bisect\n\nline_count = 0\nsegments = [None]\nnum_points = 200000\nfor line in sys.stdin.readlines():\n inputs = line.split()\n if line_count == 0:\n n = int(inputs[0])\n k = int(inputs[1])\n opening = {}\n closing = {}\n removed_right = {}\n segment_index = 0\n for i in range(1, num_points + 1):\n opening[i] = []\n closing[i] = []\n removed_right[i] = 0\n else:\n l = int(inputs[0])\n r = int(inputs[1])\n segment_index += 1\n segments.append((l, r))\n opening[l].append(segment_index)\n closing[r].append(segment_index)\n if line_count == n:\n break\n line_count += 1\n\nworking = []\nremoved = []\nfor i in range(1, num_points + 1):\n for segment_index in opening[i]:\n _, r = segments[segment_index]\n bisect.insort_right(working, (r, segment_index))\n working_count = len(working)\n while working_count > k:\n r, segment_index = working.pop()\n working_count -= 1\n removed.append(segment_index)\n removed_right[r] += 1\n squeezed_out = len(closing[i]) - removed_right[i]\n working = working[squeezed_out: ]\n\nprint(len(removed))\nfor j in removed:\n print(j, end = \" \")", "n, k = list(map(int, input().split()))\nl = [0] * n\nr = [0] * n\nevents = [(0, 0)] * 2 * n\nfor i in range(n):\n l[i], r[i] = list(map(int, input().split()))\n events[2 * i] = (l[i], 0, i)\n events[2 * i + 1] = (r[i], 1, i)\nevents.sort()\nimport heapq as h\ns = []\nans = []\nfor e in events:\n x, t, id = e\n if t == 0:\n h.heappush(s, (-r[id], l[id], id)) \n else:\n temp = []\n while s:\n x = h.heappop(s)\n if x == (-r[id], l[id], id):\n break\n temp.append(x)\n for x in temp:\n h.heappush(s, x)\n while len(s) > k:\n x = h.heappop(s)\n ans.append(x[2])\nprint(len(ans))\nprint(*[x + 1 for x in ans])\n\n"] | {
"inputs": [
"7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n",
"5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n",
"6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n"
],
"outputs": [
"3\n1 4 7 \n",
"3\n1 2 4 \n",
"4\n1 3 5 6 \n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 24,099 | |
e9c42eba83dcb4629e5057b451d74bd9 | UNKNOWN | There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of the $i$-th point at the moment $t$ ($t$ can be non-integer) is calculated as $x_i + t \cdot v_i$.
Consider two points $i$ and $j$. Let $d(i, j)$ be the minimum possible distance between these two points over any possible moments of time (even non-integer). It means that if two points $i$ and $j$ coincide at some moment, the value $d(i, j)$ will be $0$.
Your task is to calculate the value $\sum\limits_{1 \le i < j \le n}$ $d(i, j)$ (the sum of minimum distances over all pairs of points).
-----Input-----
The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β the number of points.
The second line of the input contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^8$), where $x_i$ is the initial coordinate of the $i$-th point. It is guaranteed that all $x_i$ are distinct.
The third line of the input contains $n$ integers $v_1, v_2, \dots, v_n$ ($-10^8 \le v_i \le 10^8$), where $v_i$ is the speed of the $i$-th point.
-----Output-----
Print one integer β the value $\sum\limits_{1 \le i < j \le n}$ $d(i, j)$ (the sum of minimum distances over all pairs of points).
-----Examples-----
Input
3
1 3 2
-100 2 3
Output
3
Input
5
2 1 4 3 5
2 2 2 3 4
Output
19
Input
2
2 1
-3 0
Output
0 | ["\ndef bitadd(a,w,bit):\n \n x = a\n while x <= (len(bit)-1):\n bit[x] += w\n x += x & (-1 * x)\n \ndef bitsum(a,bit):\n \n ret = 0\n x = a\n while x > 0:\n ret += bit[x]\n x -= x & (-1 * x)\n return ret\n\n\nn = int(input())\n\nx = list(map(int,input().split()))\nv = list(map(int,input().split()))\n\nvlis = []\nfor i in v:\n vlis.append(i)\nvlis.sort()\nvdic = {}\n\nfor i in range(n):\n vdic[vlis[i]] = i+1\n#print (vdic)\n\n\n\nxv = []\nfor i in range(n):\n xv.append([x[i],v[i]])\nxv.sort()\n\nans = 0\nBIT = [0] * (n+1)\nBIT2 = [0] * (n+1)\nfor i in range(n):\n\n x,v = xv[i]\n\n ans += x * bitsum(vdic[v],BIT2) - bitsum(vdic[v],BIT)\n bitadd(vdic[v] , x , BIT)\n bitadd(vdic[v] , 1 , BIT2)\n\nprint (ans)", "\nimport math\nimport bisect\n\nclass Fenwick:\n def __init__(self, n):\n self.data = [[0,0] for i in range(n)] \n \n def update(self, pos, dist):\n while pos<len(self.data):\n self.data[pos][0] += 1\n self.data[pos][1] += dist\n pos = pos | (pos+1)\n \n def query(self, pos):\n ans = [0,0]\n while pos > 0:\n ans[0] += self.data[pos-1][0]\n ans[1] += self.data[pos-1][1]\n pos = pos & (pos-1)\n return ans\n\n\ndef rints():\n return list(map(int,input().split()))\n\n\nn = int(input())\n\nx = rints()\nv = rints()\n\nascDist = list(range(n))\nascDist.sort(key=lambda i: x[i])\n\nuniqueSpeeds = sorted(list(set(v)))\n\ntree = Fenwick(len(uniqueSpeeds))\n\n\nans = 0\nfor i in ascDist:\n speedId = bisect.bisect_left(uniqueSpeeds, v[i])\n count, dsum = tree.query(speedId+1)\n ans += count*x[i] - dsum\n tree.update(speedId, x[i])\n\nprint(ans)\n\n", "import sys\ninput = sys.stdin.readline\n\nn=int(input())\nX=list(map(int,input().split()))\nV=list(map(int,input().split()))\n\nXV=[(X[i],V[i]) for i in range(n)]\n\n#compression_dict_x={a: ind for ind, a in enumerate(sorted(set(X)))}\ncompression_dict_v={a: ind+2 for ind, a in enumerate(sorted(set(V)))}\n\nXV=[(XV[i][0], compression_dict_v[XV[i][1]]) for i in range(n)]\nXV.sort(reverse=True)\n\nLEN=len(compression_dict_v)+3\n\nBIT1=[0]*(LEN+1)\n\ndef update1(v,w):\n while v<=LEN:\n BIT1[v]+=w\n v+=(v&(-v))\n\ndef getvalue1(v):\n ANS=0\n while v!=0:\n ANS+=BIT1[v]\n v-=(v&(-v))\n return ANS\n\nBIT2=[0]*(LEN+1)\n\ndef update2(v,w):\n while v<=LEN:\n BIT2[v]+=w\n v+=(v&(-v))\n\ndef getvalue2(v):\n ANS=0\n while v!=0:\n ANS+=BIT2[v]\n v-=(v&(-v))\n return ANS\n\nANS=0\nfor x,v in XV:\n ANS+=(getvalue2(LEN)-getvalue2(v-1))-(getvalue1(LEN)-getvalue1(v-1))*x\n #print(getvalue2(LEN),getvalue2(v-1),getvalue1(LEN),getvalue1(v-1))\n #print(x,v,ANS)\n\n update1(v,1)\n update2(v,x)\n\nprint(ANS)\n"] | {
"inputs": [
"3\n1 3 2\n-100 2 3\n",
"5\n2 1 4 3 5\n2 2 2 3 4\n",
"2\n2 1\n-3 0\n"
],
"outputs": [
"3\n",
"19\n",
"0\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 2,863 | |
36d67a5f68ad35658e6f8b116eef2857 | UNKNOWN | You are given the array $a$ consisting of $n$ positive (greater than zero) integers.
In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).
Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 50$) β the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.
-----Example-----
Input
5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100
Output
YES
YES
NO
NO
YES
-----Note-----
In the first test case of the example, we can perform the following sequence of moves: choose $i=1$ and $j=3$ and remove $a_i$ (so $a$ becomes $[2; 2]$); choose $i=1$ and $j=2$ and remove $a_j$ (so $a$ becomes $[2]$).
In the second test case of the example, we can choose any possible $i$ and $j$ any move and it doesn't matter which element we remove.
In the third test case of the example, there is no way to get rid of $2$ and $4$. | ["import sys\nimport math\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef MI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef SI():\n\treturn sys.stdin.readline().strip()\nt = II()\nfor q in range(t):\n\tn = II()\n\ta = sorted(LI())\n\tboo = True\n\tfor i in range(1,n):\n\t\tif a[i]-a[i-1]>1:\n\t\t\tboo = False\n\t\t\tbreak\n\tprint(\"YES\" if boo else \"NO\")\n", "import sys\ninput = sys.stdin.readline\nfor nt in range(int(input())):\n\tn = int(input())\n\ta = list(map(int,input().split()))\n\ta.sort()\n\tflag = \"YES\"\n\tfor i in range(1,n):\n\t\tif a[i]-a[i-1]>=2:\n\t\t\tflag = \"NO\"\n\t\t\tbreak\n\tprint (flag)", "for _ in range(int(input())):\n n=int(input())\n s=sorted(map(int,input().split()))\n ans='YES'\n for i in range(1,n):\n if s[i]-s[i-1]>1:ans='NO';break\n print(ans)", "\"\"\"\n pppppppppppppppppppp\n ppppp ppppppppppppppppppp\n ppppppp ppppppppppppppppppppp\n pppppppp pppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp\n ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp\n ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp\n pppppppppppppppppppppppp\n pppppppppppppppppppppppppppppppp\n pppppppppppppppppppppp pppppppp\n ppppppppppppppppppppp ppppppp\n ppppppppppppppppppp ppppp\n pppppppppppppppppppp\n\"\"\"\n\n\nimport sys\nfrom functools import lru_cache, cmp_to_key\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque, Counter as C\nfrom itertools import combinations as comb, permutations as perm\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nfrom time import perf_counter\nfrom fractions import Fraction\nfrom decimal import Decimal\n# sys.setrecursionlimit(pow(10, 6))\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"output.txt\", \"w\")\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef data(): return sys.stdin.readline().strip()\ndef out(var, end=\"\\n\"): sys.stdout.write(str(var)+end)\ndef outa(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var)) + end)\ndef l(): return list(sp())\ndef sl(): return list(ssp())\ndef sp(): return list(map(int, data().split()))\ndef ssp(): return list(map(str, data().split()))\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\n\n\nfor _ in range(int(data())):\n n = int(data())\n arr = l()\n r = True\n arr.sort()\n for i in range(1, n):\n if arr[i] - arr[i-1] > 1:\n r = False\n break\n out((\"YES\", \"NO\")[r == False])\n", "for _ in range(int(input())):\n am = int(input())\n arr = list(map(int,input().split()))\n fl = True\n arr.sort()\n for i in range(am-1):\n if arr[i+1]-arr[i] > 1:\n fl = False\n break\n if fl:\n print(\"YES\")\n else:\n print(\"NO\")", "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n \n s = set(a)\n if len(s) == max(s) - min(s) + 1:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# Author: S Mahesh Raju\n# Username: maheshraju2020\n# Date: 05/08/2020\n\nfrom sys import stdin, stdout, setrecursionlimit\nfrom math import gcd, ceil, sqrt\nfrom collections import Counter\nfrom bisect import bisect_left, bisect_right\nii1 = lambda: int(stdin.readline().strip())\nis1 = lambda: stdin.readline().strip()\niia = lambda: list(map(int, stdin.readline().strip().split()))\nisa = lambda: stdin.readline().strip().split()\nsetrecursionlimit(100000)\nmod = 1000000007\n\ntc = ii1()\nfor _ in range(tc):\n n = ii1()\n arr = sorted(iia())\n for i in range(1, n):\n if arr[i] - arr[i - 1] > 1:\n print('NO')\n break\n else:\n print('YES')\n \n", "import sys\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n n=int(input())\n L=list(map(int,input().split()))\n L.sort()\n for i in range(n-1):\n if L[i+1]-L[i]>1:\n print('NO')\n break\n else:\n print('YES')\n", "for _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n arr.sort()\n flag = 0\n for i in range(n - 1):\n if arr[i + 1] - arr[i] > 1:\n flag = 1\n break\n if flag:\n print(\"NO\")\n else:\n print(\"YES\")", "for _ in range(int(input())):\n n = int(input())\n lst = list(map(int, input().split()))\n lst.sort()\n ans = \"YES\"\n for i in range(n-1):\n if lst[i+1]-lst[i]>1:\n ans = \"NO\"\n break\n print(ans)", "import math\n\nT = int(input())\n\nfor i in range(T):\n n = int(input())\n #n,k = map(int, input().split())\n a = list(map(int,input().split()))\n #a = input()\n d = False\n \n a.sort()\n\n for i in range(1,n):\n if a[i]-a[i-1]>1:\n print('NO')\n d = True\n break\n \n if not d:\n print('YES')\n \n", "from sys import stdin,stdout\nimport math\nfrom collections import Counter,defaultdict\nLI=lambda:list(map(int,input().split()))\nMAP=lambda:list(map(int,input().split()))\nIN=lambda:int(input())\nS=lambda:input()\n\ndef case():\n n=IN()\n a=sorted(LI())\n for i in range(n-1):\n if a[i+1]-a[i]>=2:\n print(\"NO\")\n return\n print(\"YES\")\nfor _ in range(IN()):\n case()\n \n", "import math\nt = int(input())\nfor g in range(t):\n n = int(input())\n A = list(map(int,input().split()))\n A.sort()\n ans = \"YES\"\n for i in range(1,n):\n if(A[i]-A[i-1]>=2):\n ans = \"NO\"\n break\n print(ans)", "ans = []\nfor _ in range(int(input())):\n n = int(input())\n u = list(map(int, input().split()))\n u.sort()\n for i in range(1, n):\n if u[i] - u[i - 1] > 1:\n print('NO')\n break\n else:\n print('YES')\n", "#!/usr/bin/env python3\nimport os\nfrom sys import stdin, stdout\n\n\ndef solve(tc):\n n = int(stdin.readline().strip())\n seq = list(map(int, stdin.readline().split()))\n seq = sorted(seq)\n\n base = seq[0]\n for i in range(1,n):\n if seq[i]-base>1:\n print(\"NO\")\n return\n base = seq[i]\n print(\"YES\")\n\n\n\ntcs = 1\ntcs = int(stdin.readline().strip())\ntc = 1\nwhile tc <= tcs:\n solve(tc)\n tc += 1\n", "def solve():\n n = int(input())\n a = list(map(int, input().split()))\n a.sort()\n for i in range(n - 1):\n if abs(a[i + 1] - a[i]) > 1:\n print('NO')\n return\n print('YES')\n\nt = int(input())\nfor _ in range(t):\n solve()", "from sys import stdin, stdout \n \nt=int(stdin.readline())\nfor _ in range(t):\n n=int(stdin.readline() )\n #n,x=(map(int, stdin.readline().strip().split()))\n arr=list(map(int, stdin.readline() .strip().split()))\n #s=input()\n\n #stdout.write(str(cp))\n #stdout.write(\"\\n\")\n\n arr=sorted(arr)\n flg=0\n for i in range(1,n):\n if(arr[i]-arr[i-1]>1):\n flg=1\n break\n if(flg):\n print(\"NO\")\n else:\n print(\"YES\")\n", "for _ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.sort()\n np = False\n for i in range(n):\n if ar[i] - ar[i-1] > 1:\n np = True\n if np:\n print(\"NO\")\n else:\n print(\"YES\")", "for _ in range(int(input())):\n n = int(input())\n #n, k = map(int, input().split())\n a = list(map(int, input().split()))\n a.sort()\n s=1 \n for i in range(n-1):\n if(abs(a[i]-a[i+1])>1):\n s=0 \n if(s==1):\n print(\"YES\")\n else:\n print(\"NO\")", "import sys\n# from collections import deque\n# from collections import Counter\n# from math import sqrt\n# from math import log\n# from math import ceil\n# from bisect import bisect_left, bisect_right\n\n# alpha=['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# mod=10**9+7\n# mod=998244353\n\n# def BinarySearch(a,x): \n# \ti=bisect_left(a,x) \n# \tif(i!=len(a) and a[i]==x): \n# \t\treturn i \n# \telse: \n# \t\treturn -1\n\n# def sieve(n): \n# \tprime=[True for i in range(n+1)]\n# \tp=2\n# \twhile(p*p<=n): \n# \t\tif (prime[p]==True): \n# \t\t\tfor i in range(p*p,n+1,p): \n# \t\t\t\tprime[i]=False\n# \t\tp+=1\n# \tprime[0]=False\n# \tprime[1]=False\n# \ts=set()\n# \tfor i in range(len(prime)):\n# \t\tif(prime[i]):\n# \t\ts.add(i)\n# \treturn s\n\n# def gcd(a, b):\n# \tif(a==0):\n# \t\treturn b \n# \treturn gcd(b%a,a)\n\nfast_reader=sys.stdin.readline\nfast_writer=sys.stdout.write\n\ndef input():\n\treturn fast_reader().strip()\n\ndef print(*argv):\n\tfast_writer(' '.join((str(i)) for i in argv))\n\tfast_writer('\\n')\n\n#____________________________________________________________________________________________________________________________________\n\nfor _ in range(int(input())):\n\tn=int(input())\n\tl=list(map(int, input().split()))\n\tl.sort()\n\tans='YES'\n\tfor i in range(n-1):\n\t\tif(l[i+1]-l[i]>1):\n\t\t\tans='NO'\n\t\t\tbreak\n\tprint(ans)", "for _ in range(int(input())):\n n = int(input())\n A = list(map(int,input().split()))\n A.sort()\n ans = \"YES\"\n for i in range(1,n):\n if(A[i]-A[i-1]>=2):\n ans = \"NO\"\n break\n print(ans) \n"] | {
"inputs": [
"5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n",
"2\n3\n1 2 2\n4\n5 5 5 5\n",
"2\n3\n1 2 3\n4\n1 2 3 4\n"
],
"outputs": [
"YES\nYES\nNO\nNO\nYES\n",
"YES\nYES\n",
"YES\nYES\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 10,949 | |
8a2fe1b5416d63c4766ece032cfe46dc | UNKNOWN | You are given two huge binary integer numbers $a$ and $b$ of lengths $n$ and $m$ respectively. You will repeat the following process: if $b > 0$, then add to the answer the value $a~ \&~ b$ and divide $b$ by $2$ rounding down (i.e. remove the last digit of $b$), and repeat the process again, otherwise stop the process.
The value $a~ \&~ b$ means bitwise AND of $a$ and $b$. Your task is to calculate the answer modulo $998244353$.
Note that you should add the value $a~ \&~ b$ to the answer in decimal notation, not in binary. So your task is to calculate the answer in decimal notation. For example, if $a = 1010_2~ (10_{10})$ and $b = 1000_2~ (8_{10})$, then the value $a~ \&~ b$ will be equal to $8$, not to $1000$.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of $a$ and the length of $b$ correspondingly.
The second line of the input contains one huge integer $a$. It is guaranteed that this number consists of exactly $n$ zeroes and ones and the first digit is always $1$.
The third line of the input contains one huge integer $b$. It is guaranteed that this number consists of exactly $m$ zeroes and ones and the first digit is always $1$.
-----Output-----
Print the answer to this problem in decimal notation modulo $998244353$.
-----Examples-----
Input
4 4
1010
1101
Output
12
Input
4 5
1001
10101
Output
11
-----Note-----
The algorithm for the first example: add to the answer $1010_2~ \&~ 1101_2 = 1000_2 = 8_{10}$ and set $b := 110$; add to the answer $1010_2~ \&~ 110_2 = 10_2 = 2_{10}$ and set $b := 11$; add to the answer $1010_2~ \&~ 11_2 = 10_2 = 2_{10}$ and set $b := 1$; add to the answer $1010_2~ \&~ 1_2 = 0_2 = 0_{10}$ and set $b := 0$.
So the answer is $8 + 2 + 2 + 0 = 12$.
The algorithm for the second example: add to the answer $1001_2~ \&~ 10101_2 = 1_2 = 1_{10}$ and set $b := 1010$; add to the answer $1001_2~ \&~ 1010_2 = 1000_2 = 8_{10}$ and set $b := 101$; add to the answer $1001_2~ \&~ 101_2 = 1_2 = 1_{10}$ and set $b := 10$; add to the answer $1001_2~ \&~ 10_2 = 0_2 = 0_{10}$ and set $b := 1$; add to the answer $1001_2~ \&~ 1_2 = 1_2 = 1_{10}$ and set $b := 0$.
So the answer is $1 + 8 + 1 + 0 + 1 = 11$. | ["def mi():\n\treturn list(map(int, input().split()))\n\n'''\n4 4\n1010\n1101\n'''\nn,m = mi()\na = list(input())\nb = list(input())\n\npb = [0]*m\n\nif b[0]=='1':\n\tpb[0] = 1\nfor i in range(1,m):\n\tif b[i]=='1':\n\t\tpb[i] = 1\n\tpb[i]+=pb[i-1]\n\nans = 0\nif m>=n:\n\tfor i in range(n):\n\t\tif a[i]=='1':\n\t\t\tans+=(pb[m-n+i]*pow(2,n-i-1,998244353))%998244353\n\t\t\tans%=998244353\n\tprint(ans%998244353)\nelse:\n\tfor i in range(n-m,n):\n\t\tif a[i]=='1':\n\t\t\tans+=(pb[i-(n-m)]*pow(2,n-1-i,998244353))%998244353\n\t\t\tans%=998244353\n\tprint(ans%998244353)\n", "def power(x, y, p) : \n res = 1 # Initialize result \n \n # Update x if it is more \n # than or equal to p \n x = x % p \n \n while (y > 0) : \n \n # If y is odd, multiply \n # x with result \n if ((y & 1) == 1) : \n res = (res * x) % p \n \n # y must be even now \n y = y >> 1 # y = y/2 \n x = (x * x) % p \n \n return res \nn,m=list(map(int,input().split()))\ns=input()[::-1]\ns1=input()[::-1]\ndp=[0 for i in range(max(n,m)+1)]\nmod=998244353\nfor i in range(m-1,-1,-1):\n if s1[i]=='1':\n dp[i]=(dp[i+1]+1)%mod\n else:\n dp[i]=dp[i+1]\nans=0\nfor i in range(n):\n if s[i]=='1':\n ans=(ans+(dp[i]*power(2,i,mod))%mod)%mod\n \nprint(ans)\n", "mod=998244353\nn,m=map(int,input().split())\na=[0]*max(0,m-n)+list(int(ch) for ch in input())\nb=[0]*max(0,n-m)+list(int(ch) for ch in input())\npow2 = 1\nfor i in range(len(a)-2,-1,-1):\n\tpow2 = (pow2<<1)%mod\n\ta[i]=(pow2*a[i]+a[i+1])%mod\nans = 0\nfor i in range(len(b)):\n\tif b[i]:\n\t\tans=(ans+a[i])%mod\nprint(ans)", "s = 0\np = 998244353\n\na, b = map(int, input().split())\nA = input()[::-1]\nB = input()[::-1]\ndiff = b-a\ncount = 0\nexp = 1\n\nfor i in range(b):\n\tif B[i]=='1':\n\t\tcount += 1\n\nfor i in range(a):\n\t\n\tif A[i] == '1':\n\t\tval = (exp * count) % p\n\t\ts = (s+val)%p\n\n\texp = exp*2 % p\n\n\tif count > 0:\n\t\tif B[i] == '1':\n\t\t\tcount -= 1\n\nprint(s)", "TOT = 2*10**5\nmod = 998244353\naux = [0] * (TOT+1)\naux[0] = 1\nfor i in range(1,len(aux)):\n aux[i] = (2*aux[i-1]) % mod\n\nn,m = [int(x) for x in input().split()]\n\na = input()[::-1]\nar = [0] * (TOT+1)\nfor i in range(n):\n if i:\n ar[i] = ar[i-1]\n if a[i] == '1':\n ar[i] = (ar[i] + aux[i])%mod\n \nb = input()[::-1]\nans = 0\nfor i in range(m):\n if b[i] == '1':\n if i >= n:\n ans = (ans + ar[n-1]) % mod\n else:\n ans = (ans + ar[i])%mod\n \n \n# print(aux)\n# print(ar)\nprint(ans)\n\n", "n,m=map(int,input().split())\nta=input()\ntb=input()\ncount=0\nans=0\nr=n-m\nfor i in range(m):\n if tb[i]=='1':\n count+=1\n if i+r>=0:\n if ta[i+r]=='1':\n ans=(ans+pow(2,m-i-1,998244353)*count)%998244353\nprint(ans)", "input()\na = list(map(int, input()))\nb = list(map(int, input()))\n\nmod = 998244353\ndef binpow(a, n):\n if n == 0:\n return 1\n ans = binpow(a, n // 2)\n ans = (ans * ans) % mod\n if n % 2 == 1:\n ans = (ans * a) % mod\n return ans\n\nc = 1\nans = 0\ns = sum(b)\nfor i in range(min(len(a), len(b))):\n if a[-1 - i] == 1:\n ans = (ans + c * s) % mod\n s -= b[-1 - i]\n c = (c * 2) % mod\nprint(ans)\n", "n,m=map(int,input().split())\na=input()\nb=input()\ncountlist=[]\nman=0\nif len(a)<len(b):\n a=\"0\"*(len(b)-len(a))+a\nif len(b)<len(a):\n b=\"0\"*(len(a)-len(b))+b\nfor i in range(len(b)):\n if b[i]==\"1\":\n man+=1\n countlist.append(man)\npower=1\nsum=0\nfor i in range(len(a)):\n if a[-i-1]==\"1\":\n sum+=power*countlist[-i-1]\n power=(2*power)%998244353\nprint(sum%998244353)", "n, m = list(map(int, input().split()))\na = input()\nb = input()\nn, m = len(a), len(b)\nif n > m:\n addition = ''.join([\"0\"] * (n - m))\n b = addition + b\nelif m > n:\n addition = ''.join([\"0\"] * (m - n))\n a = addition + a\n\n#print(a)\n#print(b)\n\nl = max(m, n)\ncount_bigger = [0] * l\nacc = 0\nfor i in range(l):\n if b[i] == \"1\":\n acc += 1\n if a[i] == \"1\":\n count_bigger[i] = acc\n\ncount_bigger = count_bigger[::-1]\nanswer = 0\nmul = 1\nfor i in range(l):\n if count_bigger[i] != 0:\n answer += count_bigger[i] * mul\n mul *= 2\n mul %= 998244353\n\nanswer %= 998244353\nprint(answer)", "import math\ndict1={}\nmod=998244353\nfor i in range(20):\n\tdict1[i]=0\nn,m=list(map(int,input().split()))\ns1=str(input())\ns2=str(input())\ncount1=0\narr=[]\nfor i in range(len(s2)):\n\tif(s2[i]=='1'):\n\t\tcount1+=1\n\tarr.append(count1)\nj=len(s1)-1\nk=min(len(s1),len(s2))\ni=0\nwhile(k>0):\n\tif(s1[j]=='1'):\n\t\tdict1[i]=arr[len(s2)-i-1]\n\ti+=1\n\tj-=1\n\tk-=1\nans=0\nfor i in dict1:\n\tif(dict1[i]>0):\n\t\tans=((ans%mod)+(((dict1[i]%mod)*(pow(2,i,mod)%mod))%mod))%mod\nprint(ans)\n", "n,m=map(int,input().split())\nta=input()\ntb=input()\ncount=0\nans=0\nr=n-m\nfor i in range(m):\n if tb[i]=='1':\n count+=1\n if i+r>=0:\n if ta[i+r]=='1':\n ans=(ans+pow(2,m-i-1,998244353)*count)%998244353\nprint(ans)", "n, m = [int(i) for i in input().split()]\na = input()\nb = input()\nif m < n:\n m = n\n b = ('0'*(m-len(b)))+b\nelif n < m:\n n = m\n a = ('0'*(n-len(a)))+a\n\nones_left = [0]*m\nif b[0] == '1':\n ones_left[0] = 1\n \nfor i in range(1, n):\n ones_left[i] = ones_left[i-1]\n if b[i] == '1':\n ones_left[i] += 1\n\nans = 0\nk = 0\nmod = 998244353\nfor i in range(n):\n k = 1 if a[i] == '1' else 0\n ans += k*pow(2, n-1-i, mod)*ones_left[i]\n ans %= mod\n \nprint(ans)", "def modular_pow(base, exponent, modulus):\n result = 1\n base = base % modulus\n while exponent > 0:\n if exponent % 2 == 1:\n result = (result * base) % modulus\n exponent = exponent >> 1\n base = (base * base) % modulus\n return result\n\nlen_a, len_b = list(map(int, input().split()))\na = input()[::-1]\nb = input()[::-1]\n\n\ndp = list(range(len_b))\ndp[len(b) - 1] = 1\nfor i in range(len(b) - 2, -1, -1):\n dp[i] = dp[i + 1]\n if b[i] == '1':\n dp[i] += 1\n\nprimo = 998244353\nsoma = 0\nfor i in range(len_a - 1, -1, -1):\n if i < len(b) and a[i] == '1':\n partial = pow(2, i, primo)\n soma += partial * dp[i]\n soma = soma % primo\n\nprint(soma)\n\n", "n,m = [int(s) for s in input().split()]\na = input()\nb = input()\nones = 0\nans = 0\nfor i in range(m):\n if b[i] == '1':\n ones += 1\n if n >= m-i:\n ans <<= 1\n ans %= 998244353\n if a[n-(m-i)] == '1':\n ans += ones \n ans %= 998244353\n\nprint(ans)", "import sys\n\nn,m=list(map(int,sys.stdin.readline().split()))\na=list(map(int,sys.stdin.readline().strip()))\nb=list(map(int,sys.stdin.readline().strip()))\nmod=998244353\n\n\nANS=0\n\nfor i in range(1,m):\n b[i]=b[i-1]+b[i]\n\n\nif m>=n:\n b=b[-n:]\nelse:\n a=a[-m:]\n n=m\n\nA=[a[i]*b[i] for i in range(n)]\nA.reverse()\n\nfor i in range(n):\n ANS=(ANS+pow(2,i,mod)*A[i])%mod\n\nprint(ANS)\n\n\n\n", "import sys\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\nn,m = map(int,minp().split())\na = minp()\nb = minp()\nc = 0\nif n >= m:\n\ti = n-m\n\tj = 0\nelse:\n\tfor j in range(m-n):\n\t\tif b[j] == '1':\n\t\t\tc += 1\n\ti = 0\n\tj = m-n\nr = 0\nwhile i < n:\n\tr = (r*2)%998244353\n\tif b[j] == '1':\n\t\tc += 1\n\tif a[i] == '1':\n\t\tr += c\n\t#print(c,r)\n\ti += 1\n\tj += 1\nprint(r%998244353)", "n,m = list(map(int, input().split()))\na = input()\nb = input()\nif n > m:\n b = \"0\"*(n-m) + b\nelif n < m:\n a = \"0\"*(m-n) + a\ndem = 0\nA = []\nfor i in range(max(n,m)):\n if b[i] == \"1\":\n dem += 1\n A.append(dem)\nans =0\npows = 1\nfor i in range(max(n,m)-1,-1,-1):\n if a[i] ==\"1\":\n ans += pows*A[i]\n pows = (2*pows)%998244353\nprint(ans%998244353)\n", "n,m=map(int,input().split())\nta=input()\ntb=input()\ncount=0\nans=0\nr=n-m\nfor i in range(m):\n if tb[i]=='1':\n count+=1\n if i+r>=0:\n if ta[i+r]=='1':\n ans=(ans+pow(2,m-i-1,998244353)*count)%998244353\nprint(ans)", "'''\nn, m = map(int, input().split())\na = input()\nb = input()\nb_ind = []\nmo = 998244353\nans = 0\n\nb_ind.append(int(b[0]))\nfor i in range(1, m):\n\tb_ind.append(b_ind[i-1]+int(b[i]))\n\nfor i in range(1, n+1):\n\tif a[-i] == '1' and i<=m:\n\t\tans += (pow(2, i-1, mo)*b_ind[-i])%mo\n\nprint(ans%mo)\n\n'''\n\nn, m = list(map(int, input().split()))\na = input()\nb = input()\nb_ind = []\nmo = 998244353\nans = 0\n\nb_ind.append(int(b[0]))\nfor i in range(1, m):\n\tb_ind.append(b_ind[i-1]+int(b[i]))\n\nfor i in range(1, n+1):\n\tif a[-i] == '1' and i<=m:\n\t\tans += (pow(2, i-1, mo)*b_ind[-i])%mo\n\nprint(ans%mo)\n\n", "n,m=[int(x)for x in input().split()]\nns=input()\nms=input()\nif n>m:\n n=m\n ns=ns[-m:]\n\nmod=998244353\nsq2=[2]\n\nfor i in range(32):\n x=sq2[-1]*sq2[-1]%mod\n sq2.append(x)\n\np1=[1]\nfor i in range(n+1):\n p1.append(p1[-1]*2%mod)\n\n\ndef pow2(n):\n ans=1\n for i in range(32):\n if (n>>i)&1==1:\n ans*=sq2[i]\n ans%=mod\n return ans\n# if m==1:\n # print(ms)\n# print(sq2)\n\nz=[]\nsum=0\nfor i in range(m):\n if ms[i]=='0':\n sum+=1\n z.append(sum)\n\nans=0\nfor i in range(n):\n if ns[i]=='0':\n continue\n q=n-i-1\n\n l=i-(n-m)\n\n ti=0\n if l>=0: # musk\n zn=z[l]\n ti=l-zn+1\n else:\n ti=l\n ans+=ti*p1[q]\n ans%=mod\n\nprint(ans%mod)\n\n", "def bin_pow(n, s):\n if s == 0:\n return 1\n else:\n if s % 2 == 0:\n t = bin_pow(n, s / 2) % 998244353\n return (t * t) % 998244353\n else:\n return ((bin_pow(n, s - 1) % 998244353) * n) % 998244353\ntr, tl = list(map(int, input().split()))\na = input()\nb = input()\n\nans = 0\nansd = 0\nfor i in range(tl):\n if tr - i - 1 > -1 and a[tr - i - 1] == \"1\":\n ansd += bin_pow(2, i)\n ansd %= 998244353\n if b[tl - i - 1] == \"1\":\n ans += ansd\n ans %= 998244353\nprint(ans % 998244353)\n", "def get_input_list():\n\treturn list(map(int, input().split()))\nn, m = get_input_list()\na = input()\nb = input()\nl = 0\nq = 1\nv = 0\ni = n-1\nj = m-1\nr = 0\nmod = 998244353\nwhile j >= 0:\n\tif i>=0 and a[i] == '1':\n\t\tv = (v+q)%mod\n\tif b[j] == '1':\n\t\tr = (r+v)%mod\n\ti -= 1\n\tq = (q << 1)%mod\n\tj -= 1\nprint(r)\n", "n,m = list(map(int,input().split()))\ns1 = input();\ns2 = input();\nif m < n:\n\ts2 = \"0\"*(n-m) + s2;\n\tm = n;\nelse:\n\ts1 = \"0\"*(m-n) + s1;\n\tn = m;\n\n#print(s1,s2)\n#count1 = s1.count(\"1\");\n#count2 = s2.count(\"1\");\nans = [0]*n;\nfor i in range(n):\n\tif s2[i] == \"1\":\n\t\tans[i] =1;\nfor i in range(1,n):\n\tans[i] += ans[i-1];\n\n\nmod = 998244353;\nfinal = 0;\nn -= 1;\n#print(s1)\n#print(*ans)\nfor i in range(m):\n\tif s1[i] == \"1\":\n\t\t#print(i)\n\t\tfinal += ( pow(2,n-i,mod) * ans[i] )%mod\n\t\tfinal %= mod;\nprint(final)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "n,m = list(map(int,input().split()))\na = input()\nb = input()\nif n < m:\n a = \"0\"*(m-n)+a\nelif m < n:\n b = \"0\"*(n-m)+b\nn = max(n,m)\ntot = 0\nsm = 0\nfor i in range(n):\n if b[i] == '1':\n tot += 1\n if a[i] == '1':\n sm = (sm+tot*int(pow(2,(n-i-1),998244353)))%998244353\nprint(sm)\n", "#!/usr/bin/env python3\nimport sys\n\ndef rint():\n return list(map(int, sys.stdin.readline().split()))\n#lines = stdin.readlines()\n\n\nn, m = rint()\n\na = list(map(int, input()))\nb = list(map(int, input()))\na = a[::-1]\nb = b[::-1]\ndiv = 998244353\n\nmod_bit = [0]*(2*10**5+1)\nmod_asum = [0]*(2*10**5+1)\n\nmod_bit[0] = 1%div\nfor i in range(1, n):\n mod_bit[i] = mod_bit[i-1]*2%div\nmod_asum[0] = a[0]\nfor i in range(1, n):\n mod_asum[i] = (mod_asum[i-1] + a[i]*mod_bit[i])%div\n\nans = 0\nfor i in range(m):\n ans += b[i]*mod_asum[min(i, n-1)]\n ans %= div\n\nprint(ans)\n\n\n\n"] | {
"inputs": [
"4 4\n1010\n1101\n",
"4 5\n1001\n10101\n",
"5 5\n11111\n11111\n"
],
"outputs": [
"12\n",
"11\n",
"57\n"
]
} | INTRODUCTORY | PYTHON3 | CODEFORCES | 12,067 |
Subsets and Splits