problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03425
u478462004
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['h,w,d = map(int,input().split(" "))\nboard = [input().split(" ") for i in range(h)]\n\nq = int(input())\nfor i in range(q):\n l,r = map(int,input().split(" "))\n n = int((r-l)/d)\n count = 0\n x = []\n y = []\n for k in range(h):\n if str(l) in board[k]:\n x.append(board[k].index(str(l)))\n y.append(k)\n for j in range(n):\n for k in range(h):\n if str(l+(j+1)*d) in board[k]:\n x.append(board[k].index(str(l+(j+1)*d)))\n y.append(k)\n count = count + abs(int(x[j+1])-int(x[j])) + abs(y[j+1]-y[j])\n print(count)', 'n = int(input())\nm=0\na=0\nr=0\nc=0\nh=0\nname = [list(str(input().split())) for i in range(n)]\nfor i in range(n):\n if name[i][2] == "M":\n m = m+1\n elif name[i][2] == "A":\n a = a+1\n elif name[i][2] == "R":\n r = r+1\n elif name[i][2] == "C":\n c = c+1\n elif name[i][2] == "H":\n h = h+1\nprint(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)']
['Runtime Error', 'Accepted']
['s923682046', 's240206111']
[3064.0, 25208.0]
[18.0, 391.0]
[602, 412]
p03425
u488497128
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import sys\nimport numpy as np\nimport itertools\n\nN = int(sys.stdin.readline().strip())\ndct = {}\ndct["M"] = 0\ndct["A"] = 0\ndct["R"] = 0\ndct["C"] = 0\ndct["H"] = 0\nchar_list = ["M", "A", "R", "C", "H"]\n\nfor _ in range(N):\n name = sys.stdin.readline().strip()\n first = name[0]\n dct[first] += 1\n\ncount = 0\nfor a, b, c in list(itertools.combinations(char_list, 3)):\n count += dct[a] * dct[b] * dct[c]\nprint(count)\n', 'import sys\nimport numpy as np\nimport itertools\n\nN = int(sys.stdin.readline().strip())\ndct = {}\ndct["M"] = 0\ndct["A"] = 0\ndct["R"] = 0\ndct["C"] = 0\ndct["H"] = 0\nchar_list = ["M", "A", "R", "C", "H"]\n\nfor _ in range(N):\n name = sys.stdin.readline().strip()\n first = name[0]\n if first not in dct:\n continue\n dct[first] += 1\n\ncount = 0\nfor a, b, c in list(itertools.combinations(char_list, 3)):\n count += dct[a] * dct[b] * dct[c]\nprint(count)\n']
['Runtime Error', 'Accepted']
['s111183614', 's789963108']
[12420.0, 12392.0]
[198.0, 215.0]
[419, 461]
p03425
u502486340
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
[' n = int(input())\n \n M = 0\n A = 0\n R = 0\n C = 0\n H = 0\n \n res = 0\n \n for i in range(n):\n char = input()[0]\n if char == "M":\n M += 1\n elif char == "A":\n A += 1\n elif char == "R":\n R += 1\n elif char == "C":\n C += 1\n elif char == "H":\n H += 1\n \n res += M * A * R;\n res += M * A * C;\n res += M * A * H;\n res += M * R * C;\n res += M * R * H;\n res += M * C * H;\n \n res += A * R * C;\n res += A * R * H;\n res += A * C * H;\n \n res += R * C * H;\n \n print(res)', 'n = int(input())\n \nM = 0\nA = 0\nR = 0\nC = 0\nH = 0\n \nres = 0\n \nfor i in range(n):\n char = input()[0]\n if char == "M":\n M += 1\n elif char == "A":\n A += 1\n elif char == "R":\n R += 1\n elif char == "C":\n C += 1\n elif char == "H":\n H += 1\n\nres += M * A * R;\nres += M * A * C;\nres += M * A * H;\nres += M * R * C;\nres += M * R * H;\nres += M * C * H;\n \nres += A * R * C;\nres += A * R * H;\nres += A * C * H;\n \nres += R * C * H;\n \nprint(res)']
['Runtime Error', 'Accepted']
['s637927854', 's041301566']
[2940.0, 3188.0]
[17.0, 160.0]
[631, 482]
p03425
u513081876
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import itertools\nN = int(input())\nMARCH = [0, 0, 0, 0, 0]\nfinal_ans = 0\nfor i in range(N):\n a = input()\n if a[0] =='M':\n MARCH[0] += 1\n elif a[0] =='A':\n MARCH[1] += 1\n elif a[0] =='R':\n MARCH[2] += 1\n elif a[0] =='C':\n MARCH[3] += 1\n elif a[0] =='H':\n MARCH[4] += 1\n\nMARCH = list(itertools.combinations(MARCH,3))\n\nfor i in ans:\n final_ans += i[0]*i[1]*i[2]\nprint(final_ans)", "import itertools\n\nN = int(input())\nS = [0] * N\nans = 0\nfor i in range(N):\n s = input()\n if s[0] in ['M', 'A', 'R', 'C', 'H']:\n S[i] = s\nS = list(set(S))\nif 0 in S:\n S.remove(0)\nmarch = [0] * 5\nfor i in S:\n if i[0] == 'M':\n march[0] += 1\n elif i[0] == 'A':\n march[1] += 1\n elif i[0] == 'R':\n march[2] += 1\n elif i[0] == 'C':\n march[3] += 1\n else:\n march[4] += 1\n\nfor i, j, k in list(itertools.combinations([0, 1, 2, 3, 4], 3)):\n ans += march[i] * march[j] * march[k]\nprint(ans)"]
['Runtime Error', 'Accepted']
['s103750412', 's393960985']
[3064.0, 15852.0]
[181.0, 204.0]
[430, 545]
p03425
u539517139
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\nl=[0]*5\nm='MARCH'\nfor i in range(n):\n s=input()\n f=s[0]\n for i in range(5):\n if f==m[i]:\n l[i]+=1\n break\nx=0\nfor i in range(3):\n for j in range(i+1,4):\n for k in range(j+1,5):\n x+=a[i]*a[j]*a[k]\nprint(x)", "n=int(input())\nl=[0]*5\nm='MARCH'\nfor i in range(n):\n s=input()\n f=s[0]\n for i in range(5):\n if f==m[i]:\n l[i]+=1\n break\nx=0\nfor i in range(3):\n for j in range(i+1,4):\n for k in range(j+1,5):\n x+=l[i]*l[j]*l[k]\nprint(x)"]
['Runtime Error', 'Accepted']
['s441359218', 's022437646']
[3064.0, 3060.0]
[252.0, 257.0]
[243, 243]
p03425
u547167033
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\ns=[input() for i in range(n)]\ncnt=[0]*5\nfor t in s:\n if t[0]=='M':\n cnt[0]+=1\n elif t[0]=='A':\n cnt[1]+=1\n elif t[0]=='R':\n cnt[2]+=1\n elif t[0]=='C':\n cnt[3]+=1\n elif t[0]=='H':\n cnt[4]+=1\nans=0\nfor v in itertools.combinations([0,1,2,3,4],3):\n ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]\nprint(ans)", "import itertools\nn=int(input())\ns=[input() for i in range(n)]\ncnt=[0]*5\nfor t in s:\n if t[0]=='M':\n cnt[0]+=1\n elif t[0]=='A':\n cnt[1]+=1\n elif t[0]=='R':\n cnt[2]+=1\n elif t[0]=='C':\n cnt[3]+=1\n elif t[0]=='H':\n cnt[4]+=1\nans=0\nfor v in itertools.combinations([0,1,2,3,4],3):\n ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]\nprint(ans)"]
['Runtime Error', 'Accepted']
['s733067528', 's358506644']
[9772.0, 9776.0]
[172.0, 167.0]
[326, 343]
p03425
u562015767
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import numpy as np\nfrom scipy.special import comb\n\nn = int(input())\na = []\nfor _ in range(n):\n b = list(map(str,input()))\n a.append(b)\n\nans = [0]*5\n\nfor i in range(n):\n tmp = a[i][0]\n if tmp == "M":\n ans[0] += 1\n elif tmp == "A":\n ans[1] += 1\n elif tmp == "R":\n ans[2] += 1\n elif tmp == "C":\n ans[3] += 1\n elif tmp == "H":\n ans[4] += 1\n else:\n continue\n\ncnt = []\nfor j in range(len(ans)):\n if ans[j] == 0:\n continue\n else:\n cnt.append(ans[j])\nl = 0\nfor k in range(len(cnt)):\n if cnt[k] > 1:\n l += cnt[k] - 1\n\ncnt.sort()\nprint(cnt)\nif len(cnt) <= 2:\n print(0)\nelif len(cnt) == 3:\n print(np.prod(cnt))\nelif len(cnt) == 4:\n print((cnt[0]*cnt[1]*cnt[2])+(3*cnt[3]))\nelse:\n print((cnt[0]*cnt[1]*cnt[2])+(3*cnt[3])+(6*cnt[4]))', 'import itertools\n\nn = int(input())\na = []\nfor _ in range(n):\n b = list(map(str,input()))\n a.append(b)\n\nans = [0]*5\n\nfor i in range(n):\n tmp = a[i][0]\n if tmp == "M":\n ans[0] += 1\n elif tmp == "A":\n ans[1] += 1\n elif tmp == "R":\n ans[2] += 1\n elif tmp == "C":\n ans[3] += 1\n elif tmp == "H":\n ans[4] += 1\n else:\n continue\n\ncnt = 0\nfor l in itertools.combinations(ans,3):\n cnt += l[0]*l[1]*l[2]\n\nprint(cnt)']
['Runtime Error', 'Accepted']
['s344761792', 's637295427']
[14492.0, 21068.0]
[188.0, 362.0]
[831, 475]
p03425
u583507988
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ns = [list(input()) for i in range(n)]\n\n\nans = 0\nfor i in range(n):\n for j in range(i+1,n):\n for k in range(j+1,n):\n p = s[i][0]\n q = s[j][0]\n r = s[k][0]\n if (p=='M'or'A'or'C'or'R'or'H') and (q=='M'or'A'or'C'or'R'or'H') and (r=='M'or'A'or'C'or'R'or'H') and (p!=q) and (q!=r) and (r!=p):\n ans += 1\n \nprint(ans)", "n=int(input())\ndict={'M':0,'A':0,'R':0,'C':0,'H':0}\nfor i in range(n):\n s=input()\n if s[0] in dict:\n dict[s[0]]+=1\ndata=['M','A','R','C','H']\nans=0\nfor i in range(3):\n for j in range(i+1,4):\n for k in range(j+1,5):\n ans+=dict[data[i]]*dict[data[j]]*dict[data[k]]\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s270847142', 's049788309']
[22336.0, 9096.0]
[2206.0, 147.0]
[365, 287]
p03425
u594956556
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N = int(input())\n\nmarch = 'MARCH'\nmdict = {s:0 for s in march}\n\nfor i in range(N):\n S = input()\n mdict[S[0]] += 1\n \nlst = [mdict[key] for key in mdict]\nans = 0\nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+1, 5):\n ans += lst[i] * lst[j] * lst[k]\n \nprint(ans)\n", "N = int(input())\n\nmarch = 'MARCH'\nmdict = {s:0 for s in march}\n\nfor i in range(N):\n S = input()\n if S[0] in march:\n mdict[S[0]] += 1\n \nlst = [mdict[key] for key in mdict]\nans = 0\nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+1, 5):\n ans += lst[i] * lst[j] * lst[k]\n \nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s060151743', 's131139393']
[3064.0, 3064.0]
[162.0, 175.0]
[292, 314]
p03425
u595289165
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import Counter\nmarch = "MARCH"\nn = int(input())\ninitial = Counter([input()[0] for _ in range(n)])\nans = []\nfor i, num in initial.items():\n if i in march:\n ans.append(num)\n\nx = len(ans)\nif x < 3:\n print(0)\nelif x >= 3:\n y = 0\n for i in range(1, x-1):\n for j in range(i+1, x):\n for k in range(j+1, x+1):\n y += ans[i] * ans[j] * ans[k]\n print(y)\n\n\n', 'from collections import Counter\nmarch = "MARCH"\nn = int(input())\ninitial = Counter([input()[0] for _ in range(n)])\nans = []\nfor i, num in initial.items():\n if i in march:\n ans.append(num)\n\nx = len(ans)\nif x < 3:\n print(0)\nelif x >= 3:\n y = 0\n for i in range(0, x-2):\n for j in range(i+1, x-1):\n for k in range(j+1, x):\n y += ans[i] * ans[j] * ans[k]\n print(y)\n']
['Runtime Error', 'Accepted']
['s612609160', 's146344713']
[4224.0, 4224.0]
[141.0, 141.0]
[417, 415]
p03425
u597436499
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ns = []\nfor i in range(n):\n s.append(input()[0])\n\ndef qwe(y):\n m = 0\n a = 0\n r = 0\n c = 0\n h = 0\n for i in y:\n if i == 'M':\n m += 1\n elif i == 'A':\n a += 1\n elif i == 'R':\n r += 1\n elif i == 'C':\n c += 1\n elif i == 'H':\n h += 1\n else:\n pass\n q = [m,a,r,c,h]\n return q\n\ndef qwer(arr):\n count = 0\n coun = 0\n for j in arr:\n if j == 0:\n count += 1\n else:\n coun += 1\n if count == 5:\n return 0\n else:\n if arr[0] == 0:\n arr[0] = 1\n if arr[1] == 0:\n arr[1] = 1\n if arr[2] == 0:\n arr[2] = 1\n if arr[3] == 0:\n arr[3] = 1\n if arr[4] == 0:\n arr[4] = 1\n if coun == 4:\n asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*4 - 1\n return asd\n if coun == 5:\n asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*10 - 4\n return asd\nv = qwe(s)\nprint(qwer(v))\n", "n = int(input())\ns = []\nfor i in range(n):\n s.append(input()[0])\n\ndef qwe(y):\n m = 0\n a = 0\n r = 0\n c = 0\n h = 0\n for i in y:\n if i == 'M':\n m += 1\n elif i == 'A':\n a += 1\n elif i == 'R':\n r += 1\n elif i == 'C':\n c += 1\n elif i == 'H':\n h += 1\n else:\n pass\n q = [m,a,r,c,h]\n return q\n\ndef qwer(arr):\n count = 0\n coun = 0\n for j in range(len(arr)):\n if arr[j] == 0:\n count += 1\n arr.pop(j)\n else:\n coun += 1\n if count == 5:\n return 0\n if coun == 4:\n asd_1 = arr[0]*arr[1]*arr[2]\n asd_2 = arr[0]*arr[1]*arr[3]\n asd_3 = arr[0]*arr[2]*arr[3]\n asd_4 = arr[1]*arr[2]*arr[3]\n return (asd_1 + asd_2 + asd_3 + asd_4)\n if coun == 5:\n asf_1 = arr[0]*arr[1]*arr[2]\n asf_2 = arr[0]*arr[1]*arr[3]\n asf_3 = arr[0]*arr[1]*arr[4]\n asf_4 = arr[0]*arr[2]*arr[3]\n asf_5 = arr[0]*arr[2]*arr[4]\n asf_6 = arr[0]*arr[3]*arr[4]\n asf_7 = arr[1]*arr[2]*arr[3]\n asf_8 = arr[1]*arr[2]*arr[4]\n asf_9 = arr[1]*arr[3]*arr[4]\n asf_10 = arr[2]*arr[3]*arr[4]\n return (asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10)\nv = qwe(s)\nprint(qwer(v))\n", 'n = int(input())\ns = []\nfor i in range(n):\n s.append(input()[0])\n\ndef qwe(y):\n m = 0\n a = 0\n r = 0\n c = 0\n h = 0\n for i in y:\n if i == \'M\':\n m += 1\n elif i == \'A\':\n a += 1\n elif i == \'R\':\n r += 1\n elif i == \'C\':\n c += 1\n elif i == \'H\':\n h += 1\n else:\n pass\n q = [m,a,r,c,h]\n return q\n\ndef qwer(arr):\n count = 0\n for j in range(len(arr)):\n if arr[j] == 0:\n count += 1\n arr[j] = "D"\n arr.remove("D")\n if count == 5:\n return 0\n if count == 4:\n return 0\n if count == 3:\n return 0\n if count == 2:\n wer = arr[0] * arr[1] * arr[2]\n return wer\n if count == 1:\n asd_1 = arr[0]*arr[1]*arr[2]\n asd_2 = arr[0]*arr[1]*arr[3]\n asd_3 = arr[0]*arr[2]*arr[3]\n asd_4 = arr[1]*arr[2]*arr[3]\n asde = asd_1 + asd_2 + asd_3 + asd_4\n return asde\n if count == 0:\n asf_1 = arr[0]*arr[1]*arr[2]\n asf_2 = arr[0]*arr[1]*arr[3]\n asf_3 = arr[0]*arr[1]*arr[4]\n asf_4 = arr[0]*arr[2]*arr[3]\n asf_5 = arr[0]*arr[2]*arr[4]\n asf_6 = arr[0]*arr[3]*arr[4]\n asf_7 = arr[1]*arr[2]*arr[3]\n asf_8 = arr[1]*arr[2]*arr[4]\n asf_9 = arr[1]*arr[3]*arr[4]\n asf_10 = arr[2]*arr[3]*arr[4]\n asdf = asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10\n return asdf\nv = qwe(s)\nprint(qwer(v))\n', "n = int(input())\ns = []\nfor i in range(n):\n s.append(input()[0])\n\ndef qwe(y):\n m = 0\n a = 0\n r = 0\n c = 0\n h = 0\n for i in y:\n if i == 'M':\n m += 1\n elif i == 'A':\n a += 1\n elif i == 'R':\n r += 1\n elif i == 'C':\n c += 1\n elif i == 'H':\n h += 1\n else:\n pass\n q = [m,a,r,c,h]\n return q\n\ndef qwer(arr):\n count = 0\n for j in range(len(arr)):\n if arr[j] == 0:\n count += 1\n arr.pop(j)\n if count == 5:\n return 0\n if count == 4:\n return 0\n if count == 3:\n return 0\n if count == 2:\n wer = arr[0] * arr[1] * arr[2]\n return wer\n if count == 1:\n asd_1 = arr[0]*arr[1]*arr[2]\n asd_2 = arr[0]*arr[1]*arr[3]\n asd_3 = arr[0]*arr[2]*arr[3]\n asd_4 = arr[1]*arr[2]*arr[3]\n asde = asd_1 + asd_2 + asd_3 + asd_4\n return asde\n if count == 0:\n asf_1 = arr[0]*arr[1]*arr[2]\n asf_2 = arr[0]*arr[1]*arr[3]\n asf_3 = arr[0]*arr[1]*arr[4]\n asf_4 = arr[0]*arr[2]*arr[3]\n asf_5 = arr[0]*arr[2]*arr[4]\n asf_6 = arr[0]*arr[3]*arr[4]\n asf_7 = arr[1]*arr[2]*arr[3]\n asf_8 = arr[1]*arr[2]*arr[4]\n asf_9 = arr[1]*arr[3]*arr[4]\n asf_10 = arr[2]*arr[3]*arr[4]\n asdf = asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10\n return asdf\nv = qwe(s)\nprint(qwer(v))\n", 'n = int(input())\ns = []\nfor i in range(n):\n s.append(input()[0])\n\ndef qwe(y):\n m = 0\n a = 0\n r = 0\n c = 0\n h = 0\n for i in y:\n if i == \'M\':\n m += 1\n elif i == \'A\':\n a += 1\n elif i == \'R\':\n r += 1\n elif i == \'C\':\n c += 1\n elif i == \'H\':\n h += 1\n else:\n pass\n q = [m,a,r,c,h]\n return q\n\ndef qwer(arr):\n count = 0\n for j in range(len(arr)):\n if arr[j] == 0:\n count += 1\n arr[j] = "D"\n while "D" in arr:\n arr.remove("D")\n if count == 5:\n return 0\n if count == 4:\n return 0\n if count == 3:\n return 0\n if count == 2:\n wer = arr[0] * arr[1] * arr[2]\n return wer\n if count == 1:\n asd_1 = arr[0]*arr[1]*arr[2]\n asd_2 = arr[0]*arr[1]*arr[3]\n asd_3 = arr[0]*arr[2]*arr[3]\n asd_4 = arr[1]*arr[2]*arr[3]\n asde = asd_1 + asd_2 + asd_3 + asd_4\n return asde\n if count == 0:\n asf_1 = arr[0]*arr[1]*arr[2]\n asf_2 = arr[0]*arr[1]*arr[3]\n asf_3 = arr[0]*arr[1]*arr[4]\n asf_4 = arr[0]*arr[2]*arr[3]\n asf_5 = arr[0]*arr[2]*arr[4]\n asf_6 = arr[0]*arr[3]*arr[4]\n asf_7 = arr[1]*arr[2]*arr[3]\n asf_8 = arr[1]*arr[2]*arr[4]\n asf_9 = arr[1]*arr[3]*arr[4]\n asf_10 = arr[2]*arr[3]*arr[4]\n asdf = asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10\n return asdf\nv = qwe(s)\nprint(qwer(v))\n']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s059347086', 's382252839', 's607568420', 's965624997', 's315655829']
[4016.0, 4064.0, 4040.0, 4076.0, 4040.0]
[160.0, 156.0, 161.0, 146.0, 154.0]
[1074, 1358, 1519, 1497, 1545]
p03425
u597455618
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import sys\nimport itertools\n\nn = int(input())\na = [i.rstrip() for i in sys.stdin.readlines() if i.rstrip()[0] in ['M','A','R','C','H'] ]\n\nprint(len(list(itertools.combinations(a, 3))))\n", "import sys\nimport itertools\n\nn = int(input())\nl = {}\nfor i in sys.stdin.readlines():\n i = i.rstrip()\n if i[0] in ['M','A','R','C','H']:\n l.setdefault(i[0], []).append(i)\n\ns = list(itertools.combinations(l.keys(), 3))\nans = 0\nfor v in s:\n tmp = 1\n for k in v:\n tmp *= len(l[k])\n ans += tmp\nprint(ans)\n"]
['Wrong Answer', 'Accepted']
['s139557484', 's671895210']
[1964704.0, 16936.0]
[2226.0, 84.0]
[185, 329]
p03425
u604262137
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import numpy as np\nN = int(input())\nS = [None]*5\nfor i in range(N):\n S[i] = input()\n\nS_M = [S[i] for i in range(N) if S[i][0] == 'M']\nS_A = [S[i] for i in range(N) if S[i][0] == 'A']\nS_R = [S[i] for i in range(N) if S[i][0] == 'R']\nS_C = [S[i] for i in range(N) if S[i][0] == 'C']\nS_H = [S[i] for i in range(N) if S[i][0] == 'H']\n\nsouwa = 0\nkahi = [0]*5\nkahi[0] = len(S_M)\nkahi[1] = len(S_A)\nkahi[2] = len(S_R)\nkahi[3] = len(S_C)\nkahi[4] = len(S_H)\n\nkahi_not0 = kahi[kahi != 0]\nif len(kahi_not0) <= 2:\n print(0)\nelse:\n for i in range(len(kahi_not0)-2):\n for j in range(i+1, len(kahi_not0)-1):\n for k in range(j+1, len(kahi_not0)):\n souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]\n\n if souwa >= 2**32:\n print(souwa/(2**32), end='')\n print(souwa-(souwa/(2**32))*(2**32))\n else:\n print(souwa)", "import numpy as np\nN = int(input())\nS = [None]*5\nfor i in range(N):\n S[i] = input()\n\nS_M = [S[i] for i in range(N) if S[i][0] == 'M']\nS_A = [S[i] for i in range(N) if S[i][0] == 'A']\nS_R = [S[i] for i in range(N) if S[i][0] == 'R']\nS_C = [S[i] for i in range(N) if S[i][0] == 'C']\nS_H = [S[i] for i in range(N) if S[i][0] == 'H']\n\nsouwa = 0\nkahi = [0]*5\nkahi[0] = len(S_M)\nkahi[1] = len(S_A)\nkahi[2] = len(S_R)\nkahi[3] = len(S_C)\nkahi[4] = len(S_H)\n\nkahi_not0 = kahi[kahi != 0]\nif len(kahi_not0) <= 2:\n print(0)\nelse:\n for i in range(len(kahi_not0)-2):\n for j in range(i+1, len(kahi_not0)-1):\n for k in range(j+1, len(kahi_not0)):\n souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]\n\n print(souwa)", "import numpy as np\nN = int(input())\nS = [None]*N\nfor i in range(N):\n S[i] = input()\n\nS_M = [S[i] for i in range(N) if S[i][0] == 'M']\nS_A = [S[i] for i in range(N) if S[i][0] == 'A']\nS_R = [S[i] for i in range(N) if S[i][0] == 'R']\nS_C = [S[i] for i in range(N) if S[i][0] == 'C']\nS_H = [S[i] for i in range(N) if S[i][0] == 'H']\n\nsouwa = 0\nkahi = [0]*5\nkahi[0] = len(S_M)\nkahi[1] = len(S_A)\nkahi[2] = len(S_R)\nkahi[3] = len(S_C)\nkahi[4] = len(S_H)\n\nfor i in range(len(kahi)-2):\n for j in range(i+1, len(kahi)-1):\n for k in range(j+1, len(kahi)):\n souwa += kahi[i]*kahi[j]*kahi[k]\nprint(souwa)"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s243733460', 's795927986', 's298460627']
[12524.0, 12060.0, 28588.0]
[152.0, 150.0, 499.0]
[858, 739, 617]
p03425
u614875193
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N=int(input())\nM,A,R,C,H=0,0,0,0,0\nfor i in range(N):\n s=input()[0]\n if s=='M':\n M+=1\n elif s=='A':\n A+=1\n elif s=='R':\n R+=1\n elif s=='C':\n C+=1\n elif s=='H':\n H+=1\n\nprint(M,A,R,C,H)\n\nprint(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + \\\n M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)", "N=int(input())\nM,A,R,C,H=0,0,0,0,0\nfor i in range(N):\n s=input()[0]\n if s=='M':\n M+=1\n elif s=='A':\n A+=1\n elif s=='R':\n R+=1\n elif s=='C':\n C+=1\n elif s=='H':\n H+=1\n\nprint(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + \\\n M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)"]
['Wrong Answer', 'Accepted']
['s130500132', 's134645824']
[3064.0, 3064.0]
[170.0, 161.0]
[330, 312]
p03425
u617116410
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import re\nfrom itertools import groupby\n\ndef nCr(n, r):\n """\n Calculate the number of combination (nCr = nPr/r!).\n The parameters need to meet the condition of n >= r >= 0.\n It returns 1 if r == 0, which means there is one pattern\n to choice 0 items out of the number of n.\n """\n\n # 10C7 = 10C3\n r = min(r, n-r)\n\n # Calculate the numerator.\n numerator = 1\n for i in range(n, n-r, -1):\n numerator *= i\n\n # Calculate the denominator. Should use math.factorial?\n denominator = 1\n for i in range(r, 1, -1):\n denominator *= i\n\n return numerator // denominator\n\npattern = r"^(M|A|R|C|H).*"\nchecker = re.compile(pattern)\n\nN = int(input())\nnames = [None]*N\nhasMarch = [None]*N\nfor i in range(N):\n name = input()\n if checker.match(name):\n names[i] = name\n \ngroups = [n for n in groupby(names, lambda x:x[0] if x is not None else 0)]\nn_groups = len(groups) - 1\ncomb = nCr(n_groups, 3) if n_groups >=3 else 0\nprint(comb)', 'import re\nfrom itertools import groupby\nfrom itertools import groupby, combinations\nimport functools\nimport operator\n\npattern = r"^(M|A|R|C|H).*"\nchecker = re.compile(pattern)\n\nN = int(input())\nnames = []\nfor i in range(N):\n name = input()\n if checker.match(name):\n names.append(name)\n \ncounts = {}\nfor group, item in groupby(names, lambda x:x[0]):\n counts[group] = counts[group]+(len(list(item))) if group in counts.keys() else (len(list(item)))\n# print(counts)\ntotal = 0\nfor comb in combinations(counts.keys(), 3):\n tmp = []\n for letter in comb:\n tmp.append(counts[letter])\n# print(comb)\n n_comb = functools.reduce(operator.mul, tmp)\n total += n_comb\n \nprint(total)']
['Wrong Answer', 'Accepted']
['s630806986', 's810021288']
[20976.0, 11260.0]
[292.0, 301.0]
[988, 716]
p03425
u618512227
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['N = int(input())\nmember = [0,0,0,0,0]\nans = 0\nfor _ in range(N):\n a = input().split()\n if a[0] == "M":\n member[0] += 1\n elif a[1] == "A":\n member[1] += 1\n elif a[2] == "R":\n member[2] += 1\n elif a[3] == "C":\n member[3] += 1\n elif a[4] == "H":\n member[4] += 1\n \nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(i+2, 5):\n ans += member[i]*member[j]*member[k]\n\nprint(ans)\n\n', 'N = int(input())\nmember = [0,0,0,0,0]\nans = 0\nfor _ in range(N):\n a = input().split()\n if a[0] == "M":\n member[0] += 1\n elif a[0] == "A":\n member[1] += 1\n elif a[0] == "R":\n member[2] += 1\n elif a[0] == "C":\n member[3] += 1\n elif a[0] == "H":\n member[4] += 1\n \nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+1, 5):\n ans += member[i]*member[j]*member[k]\n\nprint(ans)\n\n', 'N = int(input())\nmember = [0,0,0,0,0]\nans = 0\nfor _ in range(N):\n a = input().split()\n if a[0] == "M":\n member[0] += 1\n elif a[1] == "A":\n member[1] += 1\n elif a[2] == "R":\n member[2] += 1\n elif a[3] == "C":\n member[3] += 1\n elif a[4] == "H":\n member[4] += 1\n \nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+2, 5):\n ans += member[i]*member[j]*member[k]\n\nprint(ans)\n\n', 'N = int(input())\nmember = [0,0,0,0,0]\nans = 0\nfor _ in range(N):\n a = input().split()\n if a[0] == "M":\n member[0] += 1\n elif a[0] == "A":\n member[1] += 1\n elif a[0] == "R":\n member[2] += 1\n elif a[0] == "C":\n member[3] += 1\n elif a[0] == "H":\n member[4] += 1\n \nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+2, 5):\n ans += member[i]*member[j]*member[k]\n\nprint(ans)\n\n', 'N = int(input())\nmember = [0,0,0,0,0]\nans = 0\nfor _ in range(N):\n a = list(input())\n if a[0] == "M":\n member[0] += 1\n elif a[0] == "A":\n member[1] += 1\n elif a[0] == "R":\n member[2] += 1\n elif a[0] == "C":\n member[3] += 1\n elif a[0] == "H":\n member[4] += 1\n \nfor i in range(3):\n for j in range(i+1, 4):\n for k in range(j+1, 5):\n ans += member[i]*member[j]*member[k]\n\nprint(ans)\n\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s460516600', 's814448614', 's861673512', 's900279578', 's099491684']
[3064.0, 3064.0, 3064.0, 3064.0, 3064.0]
[17.0, 191.0, 18.0, 190.0, 236.0]
[455, 455, 455, 455, 453]
p03425
u620846115
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n = int(input())\nMnum = 0\nAnum = 0\nRnum = 0\nCnum = 0\nHnum = 0\nfor i in range(n):\n a = input()\n if a[0] == "M":\n Mnum+=1\n elif a[0] == "A":\n Anum+=1\n elif a[0] == "R":\n Rnum+=1\n elif a[0] == "C":\n Cnum+=1\n elif a[0] == "H":\n Hnum+=1\nalist = []\nalist.append(Mnum)\nalist.append(Anum)\nalist.append(Rnum)\nalist.append(Cnum)\nalist.append(Hnum)\nfrom itertools import combinations\nblist =list(combinations(alist,3))\nfrom functools import reduce\nsum = 0\nfor i in range(len(blist)):\n sum+=reduce(mul,blist[i])\nprint(sum)', 'for i in range(n):\n a = input()\n if a[0] == "M":Mnum+=1\n elif a[0] == "A":Anum+=1\n elif a[0] == "R":Rnum+=1\n elif a[0] == "C":Cnum+=1\n elif a[0] == "H":Hnum+=1\nalist = []\nalist.append(Mnum)\nalist.append(Anum)\nalist.append(Rnum)\nalist.append(Cnum)\nalist.append(Hnum)\nfrom itertools import combinations\nblist =list(combinations(alist,3))\nfrom functools import reduce\nsum = 0\nfor i in range(len(blist)):\n sum+=reduce(mul,blist)\nprint(sum)', 'n = int(input())\nMnum = 0\nAnum = 0\nRnum = 0\nCnum = 0\nHnum = 0\nfor i in range(n):\n a = input()\n if a[0] == "M":Mnum+=1\n elif a[0] == "A":Anum+=1\n elif a[0] == "R":Rnum+=1\n elif a[0] == "C":Cnum+=1\n elif a[0] == "H":Hnum+=1\nalist = [Mnum,Anum,Rnum,Cnum,Hnum]\nfrom itertools import combinations\nblist =list(combinations(alist,3))\nfrom functools import reduce\nsum = 0\nfor i in range(len(blist)):\n sum+=reduce(mul,blist)\nprint(sum)', 'n = int(input())\nMnum = 0\nAnum = 0\nRnum = 0\nCnum = 0\nHnum = 0\nfor i in range(n):\n a = input()\n if a[0] == "M":Mnum+=1\n elif a[0] == "A":Anum+=1\n elif a[0] == "R":Rnum+=1\n elif a[0] == "C":Cnum+=1\n elif a[0] == "H":Hnum+=1\nalist = []\nalist.append(Mnum)\nalist.append(Anum)\nalist.append(Rnum)\nalist.append(Cnum)\nalist.append(Hnum)\nfrom itertools import combinations\nblist =list(combinations(alist,3))\nfrom functools import reduce\nsum = 0\nfor i in range(len(blist)):\n sum+=reduce(mul,blist)\nprint(sum)', 'n = int(input())\nMnum = 0\nAnum = 0\nRnum = 0\nCnum = 0\nHnum = 0\nfor i in range(n):\n a = input()\n if a[0] == "M":\n Mnum+=1\n elif a[0] == "A":\n Anum+=1\n elif a[0] == "R":\n Rnum+=1\n elif a[0] == "C":\n Cnum+=1\n elif a[0] == "H":\n Hnum+=1\nalist = []\nalist.append(Mnum)\nalist.append(Anum)\nalist.append(Rnum)\nalist.append(Cnum)\nalist.append(Hnum)\nfrom itertools import combinations\nblist =list(combinations(alist,3))\nfrom functools import reduce\nsum = 0\nfor i in range(len(blist)):\n sum+=reduce(mul,blist)\nprint(sum)', 'from itertools import combinations\nfrom collections import Counter\nN = int(input())\nS = Counter()\nfor i in range(N):\n S[input()[0]]+=1\nprint(sum([S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)]))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s175413295', 's191340947', 's551710493', 's704115403', 's763899631', 's467512794']
[9540.0, 8976.0, 9424.0, 9528.0, 9452.0, 9420.0]
[152.0, 21.0, 152.0, 157.0, 153.0, 155.0]
[532, 442, 433, 504, 529, 201]
p03425
u620945921
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import itertools\n\nn=int(input())\nlist1=[]\nss=['M', 'A', 'R', 'C', 'H']\n\nfor j in range(n):\n s=input()\n for k in range(5):\n if s[0]==ss[k]:\n list1.append(s[0])\n\n#list1.sort()\n\nlist2=list(itertools.combinations(list1, 3))\n\ncnt=0\n#for j in range(len(list2)):\n# if len(list2[j])==len(set(list2[j])):\n# cnt+=1\n\nprint(cnt)\n\n", "import itertools\n\nn=int(input())\nlist1=[]\nfor j in range(n):\n s=input()\n if s[0]=='M' or s[0]=='A' or s[0]=='R' or s[0]=='C' or s[0]=='H':\n list1.append(s[0])\n\nlist1.sort()\n\nlist2=list(itertools.combinations(list1, 3))\n\ncnt=0\n#for j in range(len(list2)):\n# if len(list2[j])==len(set(list2[j])):\n# cnt+=1\n\nprint(cnt)\n\n", "import itertools\n\nn=int(input())\nlist1=[]\nss=['M', 'A', 'R', 'C', 'H']\n\nfor j in range(n):\n s=input()\n for k in range(5):\n if s[0]==ss[k]:\n list1.append(s[0])\n\n#list1.sort()\n\nlist2=list(itertools.combinations(list1, 3))\n\ncnt=0\n#for j in range(len(list2)):\n# if len(list2[j])==len(set(list2[j])):\n# cnt+=1\n\nprint(cnt)\n\n", "import itertools\n\nn=int(input())\nlist1=[]\nss=['M', 'A', 'R', 'C', 'H']\n\nfor j in range(n):\n s=input()\n for k in range(5):\n if s[0]==ss[k]:\n list1.append(s[0])\n\n#list1.sort()\n\n#list2=list(itertools.combinations(list1, 3))\n\ncnt=0\n#for j in range(len(list2)):\n# if len(list2[j])==len(set(list2[j])):\n# cnt+=1\n\nprint(cnt)\n\n", "n=int(input())\n\nm=0;a=0;r=0;c=0;h=0\n\nfor i in range(n):\n s=input()\n if s[0]=='M':\n m+=1\n elif s[0]=='A':\n a+=1\n elif s[0]=='R':\n r+=1 \n elif s[0]=='C':\n c+=1 \n elif s[0]=='H':\n h+=1\n\n#print(m,a,r,c,h)\nans=0\nans+=m*a*r\nans+=m*a*c\nans+=m*a*h\nans+=m*r*c\nans+=m*r*h\nans+=m*c*h\nans+=a*r*c\nans+=a*r*h\nans+=a*c*h\nans+=r*c*h\n\nprint(ans)\n\n"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s058588225', 's585414039', 's875939784', 's944209976', 's472983922']
[1816760.0, 1950964.0, 1824696.0, 3892.0, 3064.0]
[2218.0, 2236.0, 2219.0, 265.0, 170.0]
[332, 326, 332, 333, 361]
p03425
u626228246
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools\nfrom collections import Counter\nn = int(input())\ns = [input()[0] for _ in range(n)]\ncnt = Counter(s)\nprint(cnt)\n\nans = 0\nfor x,y,z in itertools.combinations("MARCH",3):\n # print(x,y,z)\n ans += cnt[x]*cnt[y]*cnt[z]\n #print(cnt[x],cnt[y],cnt[z])\n \nprint(ans)', "import sys\nimport math\nn = int(input())\ns = [input() for m in range(n)]\nmarch = ['M','A','R','C','H']\nans = []\n\nfor i in range(n):\n\tif s[i][0] in march:\n\t\tans.append(s[i][0])\ns_set = set(ans)\nsl = len(s_set)\nif sl == 0:\n\tprint(0)\n\tsys.exit()\ndouble_num = len(ans) - len(s_set)\nfactorial_num = math.factorial(sl) // (math.factorial(sl - 3) * math.factorial(3))\nif sl <= 2:\n\tprint(0)\n\tsys.exit()\nelif sl == 3:\n\tprint(factorial_num + 2*double_num)\n\tsys.exit()\nelif sl == 4:\n\tprint(factorial_num + 2*(double_num) -(1*double_num))\n\tsys.exit()\nelse:\n\tprint(factorial_num + 2*double_num -(4 *double_num))\n\tsys.exit()", 'import itertools\nfrom collections import Counter\nn = int(input())\ns = [input()[0] for _ in range(n)]\ncnt = Counter(s)\n#print(cnt)\n\nans = 0\nfor x,y,z in itertools.combinations("MARCH",3):\n # print(x,y,z)\n ans += cnt[x]*cnt[y]*cnt[z]\n #print(cnt[x],cnt[y],cnt[z])\n \nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s273154212', 's413767234', 's356884211']
[10256.0, 16760.0, 10068.0]
[135.0, 158.0, 137.0]
[282, 609, 283]
p03425
u626337957
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N = int(input())\nnames_dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}\nFIRST = ('M', 'A', 'R', 'C', 'H')\nfor _ in range(N):\n nams = input()\n if name[0] in FIRST:\n names_dic[name[0]] += 1\nans = 0\nfor i in range(5):\n for j in range(i+1, 5):\n for k in range(j+1, 5):\n ans += names_dic[FIRST[i]]*names_dic[FIRST[j]]*names_dic[FIRST[k]]\nprint(ans)", "N = int(input())\nnames = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}\nFIRST = ('M', 'A', 'R', 'C', 'H')\nfor _ in range(N):\n name = input()\n if name[0] in FIRST:\n names[name[0]] += 1\nans = 0\nfor i in range(5):\n for j in range(i+1, 5):\n for k in range(j+1, 5):\n ans += names[FIRST[i]]*names[FIRST[j]]*names[FIRST[k]]\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s257585384', 's805780125']
[3064.0, 3064.0]
[17.0, 172.0]
[350, 331]
p03425
u627530854
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import Counter\nfrom itertools import combinations, reduce\n\nimport operator\n\nGOOD_LETTERS = "MARCH"\nPEOPLE = 3\n\nn = int(input())\nc = Counter()\n\nfor _ in range(n):\n first = input()[0]\n if first in GOOD_LETTERS:\n c.update(first)\n \nways = 0\nfor tup in combinations(GOOD_LETTERS, PEOPLE):\n ways += reduce(operator.mul, [c[ch] for ch in tup], 1)\n\nprint(ways)', 'from collections import Counter\nfrom functools import reduce\nfrom itertools import combinations\n\nimport operator\n\nGOOD_LETTERS = "MARCH"\nPEOPLE = 3\n\nn = int(input())\nc = Counter()\n\nfor _ in range(n):\n first = input()[0]\n if first in GOOD_LETTERS:\n c.update(first)\n\nways = 0\nfor tup in combinations(GOOD_LETTERS, PEOPLE):\n ways += reduce(operator.mul, [c[ch] for ch in tup], 1)\n\nprint(ways)\n']
['Runtime Error', 'Accepted']
['s649287443', 's798340276']
[3316.0, 3572.0]
[21.0, 550.0]
[378, 396]
p03425
u635974378
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import itertools as it\n\ndef c(n,k):\n if k>n:\n return 0\n ret = 1\n for i in range(n, n-k, -1):\n ret *= i\n for i in range(k, 1, -1):\n ret /= i\n return ret\n\n\nn = int(input())\ndic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}\nfor person in range(n):\n name = input()\n if name[0] in 'MARCH':\n dic[name[0]] += 1\n\nanswer = 0\nfor a,b,c = it.combinations('MARCH', 3):\n answer += dic[a] * dic[b] * dic[c]\nprint(answer)", "import itertools as it\n\ndef c(n,k):\n if k>n:\n return 0\n ret = 1\n for i in range(n, n-k, -1):\n ret *= i\n for i in range(k, 1, -1):\n ret /= i\n return ret\n\n\nn = int(input())\ndic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}\nfor person in range(n):\n name = input()\n if name[0] in 'MARCH':\n dic[name[0]] += 1\n\nanswer = 0\nfor a,b,c in it.combinations('MARCH', 3):\n answer += dic[a] * dic[b] * dic[c]\nprint(answer)\n"]
['Runtime Error', 'Accepted']
['s361694075', 's032748425']
[3064.0, 3064.0]
[17.0, 175.0]
[418, 420]
p03425
u637551956
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from itertools import combinations\nN=int(input())\nL = [str(input()) for i in range(N)]\ncount_M=0\ncount_A=0\ncount_R=0\ncount_C=0\ncount_H=0\nfor i in L:\n if i[0]=='M':count_M+=1\n elif i[0]=='A':count_A+=1\n elif i[0]=='R':count_R+=1\n elif i[0]=='C':count_C+=1\n elif i[0]=='H':count_H+=1\nname_list=[count_M,count_A,count_R,count_C,count_H]\nsum_list=list(combinations(name_list,3))\ns_list=[i[0]*i[1]*i[2] for i in sum_list]\nsum(s_list)", "from itertools import combinations\nN=int(input())\nL = [str(input()) for i in range(N)]\ncount_M=0\ncount_A=0\ncount_R=0\ncount_C=0\ncount_H=0\nfor i in L:\n if i[0]=='M':count_M+=1\n elif i[0]=='A':count_A+=1\n elif i[0]=='R':count_R+=1\n elif i[0]=='C':count_C+=1\n elif i[0]=='H':count_H+=1\nname_list=[count_M,count_A,count_R,count_C,count_H]\nsum_list=list(combinations(name_list,3))\ns_list=[i[0]*i[1]*i[2] for i in sum_list]\nprint(sum(s_list))"]
['Wrong Answer', 'Accepted']
['s040918354', 's056088247']
[9776.0, 9776.0]
[181.0, 185.0]
[443, 450]
p03425
u639691968
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N = int(input())\nnum = [0,0,0,0,0]\nfor i in range(N):\n a = input()\n if a[0]=='M':\n num[0] += 1\n if a[0]=='A':\n num[1] += 1\n if a[0]=='R':\n\tnum[2] += 1\n if a[0]=='C':\n\tnum[3] += 1\n if a[0]=='H':\n\tnum[4] += 1\n\n\nnum_1 = num[0]*num[1]*num[2]\nnum_2 = num[0]*num[1]*num[3]\nnum_3 = num[0]*num[1]*num[4]\nnum_4 = num[1]*num[2]*num[3]\nnum_5 = num[1]*num[2]*num[4]\nnum_6 = num[2]*num[3]*num[4]\nnum_7 = num[0]*num[2]*num[3]\nnum_8 = num[0]*num[2]*num[4]\nnum_9 = num[0]*num[3]*num[4]\nnum_10 = num[1]*num[3]*num[4]\n\nanswer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10\n\nprint(answer)", "N = int(input())\nnum = [0,0,0,0,0]\nanswer = 0\nfor i in range(N):\n\ta = input()\n\tif a[0]=='M':\n\t\tnum[0] += 1\n\tif a[0]=='A':\n\t\tnum[1] += 1\n\tif a[0]=='R':\n\t\tnum[2] += 1\n\tif a[0]=='C':\n\t\tnum[3] += 1\n\tif a[0]=='H':\n\t\tnum[4] += 1\n\nfor i in range(3):\n\tfor j in range(i+1, 4):\n\t\tfor k in range(j+1, 5):\n\t\t\tanswer += num[i]*num[j]*num[k]\n\nprint(answer)"]
['Runtime Error', 'Accepted']
['s866945781', 's920835114']
[2940.0, 3064.0]
[17.0, 198.0]
[615, 342]
p03425
u644778646
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['N = int(input())\nSdic = {}\nL = ["M","A","R","C","H"]\nfor i in L:\n Sdic[i] = []\n\ntN = N\nfor i in range(N):\n s = input()\n if s[0] in L:\n Sdic[s[0]].append(s)\n else:\n tN -= 1\n\ncnt = 0\nfor val in Sdic.values():\n if len(val) == 0:\n cnt += 1\nif cnt >=3:\n print(0)\n exit()\n\nzen = tN*(tN-1)*(tN-2) / 6\n\none = 0\nfor i in ["M","A","R","C","H"]:\n c = len(Sdic[i])\n if c >= 3:\n one += c * (c-1) * (c-2) / 6\n\n\nlis = []\nfor i in range(len(L)):\n for j in range(len(L)):\n if i < j:\n lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))\n\ntwo = 0\nfor c in lis:\n if c >= 3:\n two += c * (c-1) * (c-2) / 6\nprint(zen , one , two)\nprint(int(zen - one - two))\n', 'N = int(input())\nd = {}\nfor i in range(N):\n s = input()[0]\n if s not in d.keys():\n d[s] = 0\n d[s] += 1\nmarch = ["M","A","R","C","H"]\nlis = []\nfor a in d.keys():\n if a in march:\n lis.append(a)\nimport itertools\nans = 0\nfor l in list(itertools.combinations(lis,3)):\n ans += d[l[0]]*d[l[1]]*d[l[2]]\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s425968666', 's814403155']
[10152.0, 3064.0]
[174.0, 181.0]
[717, 335]
p03425
u659753499
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from itertools import combinations\nN = int(input())\nS = Counter()\nfor _ in range(N):\n S[input()[0]] += 1\nprint(sum([S[p0]*S[p1]*S[p2] for p0,p1,p2 in combinations('MARCH', 3)]))", "from itertools import combinations\nN = int(input())\nd = [0]*128\nfor _ in range(N): dic[ord(input()[0])] += 1\nprint(sum([d[ord(p0)]*d[ord(p1)]*d[ord(p2)] for p0,p1,p2 in combinations('MARCH', 3)]))\n", "N = int(input())\ndic = [0]*128\nfor _ in range(N): dic[ord(input()[0])] += 1\nM,A,R,C,H = [dic[ord(x)] for x in list('MARCH')]\nprint(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s243827065', 's504982879', 's363143623']
[3060.0, 3060.0, 3060.0]
[18.0, 18.0, 159.0]
[178, 197, 210]
p03425
u663710122
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['m,a,r,c,h = [0,0,0,0,0]\nN = int(input())\n\nfor i in range(N):\n', "m, a, r, c, h = [0] * 5\n\nN = int(input())\n\nfor _ in range(N):\n s = input()[0]\n\n if s == 'M':\n m += 1\n elif s == 'A':\n a += 1\n elif s == 'R':\n r += 1\n elif s == 'C':\n c += 1\n elif s == 'H':\n h += 1\nprint(m * a * r + \n m * a * c +\n m * a * h + \n m * r * c + \n m * r * h + \n m * c * h + \n a * r * c + \n a * r * h +\n a * c * h +\n r * c * h)\n"]
['Runtime Error', 'Accepted']
['s686094722', 's429639575']
[2940.0, 3060.0]
[17.0, 162.0]
[61, 435]
p03425
u671252250
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['# coding: utf-8\n# Your code here!\nimport math\nfrom collections import Counter\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r)\n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nN = int(input())\narr = [input() for i in range(N)]\nmar_arr = [j for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]\nini_arr = [k[0] for k in mar_arr]\ndic = Counter(ini_arr)\nkey_num = len(dic)\nval_num = sum(v for v in dic.values())\nif key_num <= 3:\n print(0)\nelse:\n total = C(len(ini_arr), 3)\n for i in dic.values():\n if i == 2:\n total -= C(num - i, 1)\n elif i >= 3:\n total -= C(i, 2) * C(num - i, 1) + C(i, 3)\n print(total)', '# coding: utf-8\n# Your code here!\nimport math\nfrom collections import Counter\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r)\n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nN = int(input())\narr = [input() for i in range(N)]\nmar_arr = [j for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]\nini_arr = [k[0] for k in mar_arr]\ndic = Counter(ini_arr)\nkey_num = len(dic)\nval_num = sum(v for v in dic.values())\nif key_num < 3:\n print(0)\nelse:\n total = C(len(ini_arr), 3)\n for i in dic.values():\n if i == 2:\n total -= C(num - i, 1)\n elif i >= 3:\n total -= C(i, 2) * C(num - i, 1) + C(i, 3)\n print(total)', '# coding: utf-8\n# Your code here!\nimport sys\ninput = sys.stdin.readline\n\nn = int(input())\nt = [0] * n\nfor i in range(n):\n t[i] =input()[0]\nt2 = [t.count(i) for i in ["M","A","R","C","H"]]\nans = 0\nfor i in range(5):\n for j in range(5):\n if j == i:\n break\n for k in range(5):\n if k == j:\n break\n ans += t2[i] * t2[j] * t2[k]\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s126820227', 's490877129', 's816673160']
[12932.0, 12944.0, 3828.0]
[613.0, 614.0, 47.0]
[704, 703, 401]
p03425
u680851063
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\n\nl=[]\nfor i in range(n):\n l+=[input()[0]]\n\nmarch=[0]*5\nfor j in range(n):\n if l[j]=='M':\n march[0]+=1\n elif l[j]=='A':\n march[1]+=1\n elif l[j]=='R':\n march[2]+=1\n elif l[j]=='C':\n march[3]+=1\n elif l[j]=='H':\n march[4]+=1\nprint(march)\n\nfrom itertools import combinations\nans=0\nfor x,y,z in combinations(march, 3):\n ans+=x*y*z\n\nprint(ans)\n\n", "n=int(input())\n\nl=[]\nfor i in range(n):\n l+=[input()[0]]\n\nmarch=[0]*5\nfor j in range(n):\n if l[j]=='M':\n march[0]+=1\n elif l[j]=='A':\n march[1]+=1\n elif l[j]=='R':\n march[2]+=1\n elif l[j]=='C':\n march[3]+=1\n elif l[j]=='H':\n march[4]+=1\n\nfrom itertools import combinations\nans=0\nfor x,y,z in combinations(march, 3):\n ans+=x*y*z\n\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s034401773', 's234701186']
[3888.0, 3992.0]
[193.0, 198.0]
[410, 395]
p03425
u686036872
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from itertools import combinations\nimport collections\n\nN = int(input()) \n\nA = []\nfor i in range(N):\n A.append(input()[0])\n\nAA = set(A)\nC = collections.Counter(A)\nprint(sum(C[a]*C[b]*C[c] for a, b, c combinations(AA, 3)))', 'from itertools import combinations\nimport collections\n\nN = int(input()) \n\nA = []\nfor i in range(N):\n A.append(input()[0])\n\nAA = set(A)\nC = collections.Counter(A)\nprint(sum(C[a]*C[b]*C[c] for a, b, c in combinations(AA, 3)))', 'from itertools import combinations\nimport collections\n\nN = int(input()) \n\nA = []\nfor i in range(N):\n A.append(input()[0])\n\nC = collections.Counter(A)\nprint(sum(C[a]*C[b]*C[c] for a, b, c in combinations("MARCH", 3)))']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s334828320', 's853813100', 's718929777']
[2940.0, 4224.0, 4232.0]
[17.0, 162.0, 146.0]
[223, 226, 219]
p03425
u687044304
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['#-*- coding:utf-8 -*-\n\ndef _is_march(c):\n if (c == "M") or (c == "A") or (c == "R") or (c == "C") or (c == "H"):\n return True\n return False\n\nif __name__ == "__main__":\n N = int(input())\n march = []\n for i in range(N):\n name = input()\n if _is_march(name[0]):\n march.append(name)\n n = len(march)\n\n bunsi = n * (n-1) * (n-2)\n bunbo = 3 * 2 * 1\n print(int(bunsi/bunbo))\n', '#-*- coding:utf-8 -*-\n\nif __name__ == "__main__":\n\tN = int(input())\n\tm = 0\n\ta = 0\n\tr = 0\n\tc = 0\n\th = 0\n\tfor i in range(N):\n\t\tname = input()\n\t\tif name[0] == "M":\n\t\t\tm += 1\n\t\telif name[0] == "A":\n\t\t\ta += 1\n\t\telif name[0] == "R":\n\t\t\tr += 1\n\t\telif name[0] == "C":\n\t\t\tc += 1\n\t\telif name[0] == "H":\n\t\t\th += 1\n\t\n\tans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h\n\tans += a*r*c + a*r*h + a*c*h\n\tans += r*c*h\n\tprint(ans)\n']
['Wrong Answer', 'Accepted']
['s752133260', 's918618938']
[9752.0, 3064.0]
[175.0, 168.0]
[425, 454]
p03425
u691018832
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\nfrom collections import Counter\nfrom scipy.misc import comb\n\nn = int(readline())\ns = [input()[0] for i in range(n)]\nmemo = list(Counter(s).items())\ncheck = ['M', 'A', 'R', 'C', 'H']\ncnt = 0\nans = 0\nfor x, y in memo:\n if x in check:\n ans += y\n if y > 1:\n cnt += n - y\nprint(comb(ans, 3) - cnt)\n", "import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\nfrom collections import Counter\nfrom scipy.special import comb\n\nn = int(readline())\ns = [input()[0] for i in range(n)]\nmemo = list(Counter(s).items())\ncheck = ['M', 'A', 'R', 'C', 'H']\ncnt = 0\nans = 0\nfor x, y in memo:\n if x in check:\n ans += y\n if y > 1:\n cnt += n - y\nprint(comb(ans, 3, exact=True) - cnt)\n", "import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\nfrom collections import Counter\nfrom operator import mul\nfrom functools import reduce\n\n\ndef cmb(n, r):\n r = min(n - r, r)\n if r == 0:\n return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1, r + 1))\n return over // under\n\n\nn = int(readline())\ns = []\ncheck = ['M', 'A', 'R', 'C', 'H']\nfor i in range(n):\n ss = readline().rstrip().decode()\n if ss[0] in check:\n s.append(ss[0])\ncounter = list(Counter(s).values())\nif len(counter) < 3:\n print(0)\n exit()\nans = cmb(sum(counter), 3)\nfor v in counter:\n if v >= 2:\n ans -= cmb(v, 2) * (len(s) - v)\n if v >= 3:\n ans -= cmb(v, 3)\nprint(ans)\n"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s547192239', 's616767269', 's889638688']
[23484.0, 14320.0, 4524.0]
[521.0, 174.0, 89.0]
[469, 484, 822]
p03425
u691896522
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ndata = [0 for i in range(5)]\nfor i in range(n):\n k = input()\n if k[0] == 'M':\n data[0] += 1\n elif k[0] == 'A':\n data[1] += 1\n elif k[0] == 'R':\n data[2] += 1\n elif k[0] == 'C':\n data[3] += 1\n elif k[0] == 'H':\n data[4] += 1\ntotal = 0\nprint(data)\nfor i in range(5):\n for j in range(i+1,5):\n for k in range(j+1,5):\n total += data[i] * data[j] * data[k]\nprint(total)\n", "n = int(input())\ndata = [0 for i in range(5)]\nfor i in range(n):\n k = input()\n if k[0] == 'M':\n data[0] += 1\n elif k[0] == 'A':\n data[1] += 1\n elif k[0] == 'R':\n data[2] += 1\n elif k[0] == 'C':\n data[3] += 1\n elif k[0] == 'H':\n data[4] += 1\ntotal = 0\nfor i in range(5):\n for j in range(i+1,5):\n for k in range(j+1,5):\n total += data[i] * data[j] * data[k]\nprint(total)\n"]
['Wrong Answer', 'Accepted']
['s574226668', 's703547528']
[3064.0, 3064.0]
[167.0, 168.0]
[455, 443]
p03425
u694810977
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import Counter\nfrom itertools import combinations\n\nn = int(input())\nl = [input()[0] for _ in range(n)]\nlc = Counter(l)\nprint(lc)\n\ncon = []\nfor c in "MARCH":\n if c in lc:\n con.append(lc[c])\nans = 0\nfor a, b, c in combinations(con, 3):\n ans += a * b * c\nprint(ans)\n', 'from collections import Counter\nfrom itertools import combinations\n\nn = int(input())\nl = [input()[0] for _ in range(n)]\nlc = Counter(l)\n\ncon = []\nfor c in "MARCH":\n if c in lc:\n con.append(lc[c])\nans = 0\nfor a, b, c in combinations(con, 3):\n ans += a * b * c\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s447906357', 's536404375']
[4224.0, 4224.0]
[139.0, 141.0]
[293, 283]
p03425
u698771758
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools as ite\nN=int(input())\nC=[0]*N\nJ="MARCH"\nfor i in range(N):\n C[J.find(input()[0])]+=1\nans=0\nfor i,j,k in list(ite.combinations(range(5),3)):\n ans+=C[i]*C[j]*C[k]\nprint(ans)\n', 'import itertools as ite\nN=int(input())\nC=[0]*6\nJ="MARCH"\nfor i in range(N):\n C[J.find(input()[0])]+=1\nans=0\nfor i,j,k in list(ite.combinations(range(5),3)):\n ans+=C[i]*C[j]*C[k]\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s941879160', 's005063931']
[3828.0, 3060.0]
[203.0, 192.0]
[195, 195]
p03425
u698919163
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N = int(input())\nS = [input() for i in range(N)]\n\nS_first = [S[i][0] for i in range(N)]\nmarch = ['M','A','R','C','H']\nmarch_number = [0]*5\n\nfor i in range(N):\n march_number[i] = S.count(march[i])\n\nimport itertools\nptr = list(itertools.combinations(march_number,3))\n\nans = 0\nseki = 1\n\nfor i in range(len(ptr)):\n for j in range(3):\n seki *= ptr[i][j]\n ans += seki\n seki = 1\n\nprint(ans)", "N = int(input())\nS = [input() for i in range(N)]\n\nS_first = [S[i][0] for i in range(N)]\nmarch = ['M','A','R','C','H']\nmarch_number = [0]*5\n\nfor i in range(5):\n march_number[i] = S_first.count(march[i])\n\nimport itertools\nans = 0\nfor v in itertools.combinations(march_number,3):\n ans += v[0]*v[1]*v[2]\nprint(ans)"]
['Runtime Error', 'Accepted']
['s792144930', 's834428846']
[10520.0, 10648.0]
[155.0, 163.0]
[402, 316]
p03425
u711768617
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools\nn = int(input())\nnames = [input() for i in range(n)]\nnames = [i for i in names if i[0] in "MARCH"]\n\n\nprint(len(list(itertools.combinations(seq,3))))', 'import itertools\nn = int(input())\ncounters = {"M":0,"A":0,"R":0,"C":0,"H":0}\n\nfor _ in range(n):\n s = input()[0]\n \n if s in "MARCH":\n \tcounters[s] += 1\nres = 0\nfor i in list(itertools.combinations(["M","A","R","C","H"],3)):\n res += counters[i[0]] * counters[i[1]] * counters[i[2]]\n\nprint(res)']
['Runtime Error', 'Accepted']
['s772228175', 's080140629']
[16756.0, 9116.0]
[141.0, 145.0]
[165, 297]
p03425
u716043626
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ncnt = [0,0,0,0,0]\ncomp = 'MARCH'\nans = 0\n\nfor i in range(N):\n word = input()\n for j in range(len(comp)):\n if word[0] == comp[j]:\n cnt[j] += 1\n\nfor i in range(len(cnt)):\n for j in range(i+1,len(cnt)):\n for k in range(j+1,len(cnt)):\n ans += cnt[i] * cnt[j] * cnt[k]\nprint(ans)", "comp='MARCH'\ncnt=[0,0,0,0,0]\n\nn=int(input())\nfor i in range(n):\n word=input()\n for j in range(len(comp)):\n if word[0]==comp[j]: cnt[j]+=1\n\nans = 0\nfor i in range(len(cnt)):\n for j in range(i+1, len(cnt)):\n for k in range(j+1, len(cnt)):\n ans += cnt[i]*cnt[j]*cnt[k]\n \nprint(ans)"]
['Runtime Error', 'Accepted']
['s291209112', 's557278960']
[3064.0, 3064.0]
[18.0, 292.0]
[336, 319]
p03425
u729133443
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from itertools import*;d={}\nfor t in open(0).read().split():d[t]=d.get(t,0)+1\ng=d.get;print(sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3)))", "from itertools import*;d={};g=d.get\nfor t in open(0).read().split():d[t]=g(t,0)+1\nprint(sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3)))", "from itertools import*;s,*_=zip(*open(0));print(sum(p*q*r for p,q,r in combinations(map(s.count,'MARCH'),3)))"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s496014535', 's739922864', 's437144013']
[20664.0, 20664.0, 17832.0]
[65.0, 60.0, 53.0]
[154, 150, 109]
p03425
u760961723
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['N = int(input())\ns = [input() for _ in range(N)]\n\nprint(s)\n\nMx,Ax,Rx,Cx,Hx=0,0,0,0,0\n\nfor n in range(N):\n if s[n][0] =="M":\n Mx += 1\n elif s[n][0] =="A":\n Ax += 1\n elif s[n][0] =="R":\n Rx += 1\n elif s[n][0] =="C":\n Cx += 1\n elif s[n][0] =="H":\n Hx += 1\n\nMAR = Mx * Ax * Rx\nMAC = Mx * Ax * Cx\nMAH = Mx * Ax * Hx\nMRC = Mx * Rx * Cx\nMRH = Mx * Rx * Hx\nMCH = Mx * Cx * Hx\n\nARC = Ax * Rx * Cx\nARH = Ax * Rx * Hx\nACH = Ax * Cx * Hx\n\nRCH = Rx * Cx * Hx\n\nprint(MAR+MAC+MAH+MRC+MRH+MCH+ARC+ARH+ACH+RCH)', 'N = int(input())\ns = [input() for _ in range(N)]\n\nMx,Ax,Rx,Cx,Hx=0,0,0,0,0\n\nfor n in range(N):\n if s[n][0] =="M":\n Mx += 1\n elif s[n][0] =="A":\n Ax += 1\n elif s[n][0] =="R":\n Rx += 1\n elif s[n][0] =="C":\n Cx += 1\n elif s[n][0] =="H":\n Hx += 1\n\nMAR = Mx * Ax * Rx\nMAC = Mx * Ax * Cx\nMAH = Mx * Ax * Hx\nMRC = Mx * Rx * Cx\nMRH = Mx * Rx * Hx\nMCH = Mx * Cx * Hx\n\nARC = Ax * Rx * Cx\nARH = Ax * Rx * Hx\nACH = Ax * Cx * Hx\n\nRCH = Rx * Cx * Hx\n\nprint(MAR+MAC+MAH+MRC+MRH+MCH+ARC+ARH+ACH+RCH)']
['Wrong Answer', 'Accepted']
['s950325042', 's350631764']
[13076.0, 9776.0]
[186.0, 176.0]
[515, 505]
p03425
u773686010
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['N = int(input())\nM_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}\nfor i in range(N):\n moji = str(input())\n if moji[0] in M_Dict.keys():\n M_Dict[moji[0]] += 1\nM_Dict = {k: v for k, v in M_Dict.items() if v != 0} \nif len(M_Dict) < 3:\n ans = 0\nelse:\n ans = 0\n for k in itertools.combinations(list(M_Dict.keys()),3):\n ans += M_Dict[k[0]]*M_Dict[k[1]]*M_Dict[[2]]\n \nprint(ans) ', 'import itertools\nN = int(input())\nM_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}\nfor i in range(N):\n moji = str(input())\n if moji[0] in M_Dict.keys():\n M_Dict[moji[0]] += 1\nM_Dict = {k: v for k, v in M_Dict.items() if v != 0} \nif len(M_Dict) < 3:\n ans = 0\nelse:\n ans = 0\n for k in itertools.combinations(list(M_Dict.keys()),3):\n ans += int(M_Dict[k[0]]) * int(M_Dict[k[1]]) * int(M_Dict[k[2]])\n \nprint(ans) ']
['Runtime Error', 'Accepted']
['s857530612', 's213055840']
[9240.0, 9228.0]
[162.0, 166.0]
[402, 439]
p03425
u781262926
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from itertools import combinations\nn, *S = open(0).read().split()\nn = int(n)\nmarch = []\nfor c in 'MARCH':\n march.append(len([s for s in S if s[0] == c]))\nprint(march)\nans = 0\nfor a, b, c in combinations(march, 3):\n if a*b*c != 0:\n print(a,b,c)\n ans += a*b*c\nprint(ans)", "from itertools import combinations\nn, *S = open(0).read().split()\nn = int(n)\nmarch = []\nfor c in 'MARCH':\n march.append(len([s for s in S if s[0] == c]))\nprint(march)\nans = 0\nfor a, b, c in combinations(march, 3):\n ans += a*b*c\nprint(ans)", "from itertools import combinations\nn, *S = open(0).read().split()\nn = int(n)\nmarch = []\nfor c in 'MARCH':\n march.append(len([s for s in S if s[0] == c]))\nans = 0\nfor a, b, c in combinations(march, 3):\n ans += a*b*c\nprint(ans)"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s119215918', 's743496385', 's226540974']
[10864.0, 10988.0, 10864.0]
[59.0, 62.0, 59.0]
[284, 244, 231]
p03425
u787456042
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations(sum(1for s in S if s[0]==c)for c in"MARCH",3)))', 'from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations(sum(1for s in S if s[0]==c)for c in"MARCH",3)))', 'from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations([sum(1for s in S if s[0]==c)for c in"MARCH"],3)))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s340392411', 's538617656', 's791786418']
[2940.0, 2940.0, 9896.0]
[17.0, 17.0, 57.0]
[125, 125, 127]
p03425
u798731634
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ns = [input() for i in range(n)]\n\nf = [a for a in s if s.startswith('M')]\ng = [b for b in s if s.startswith('A')]\nh = [c for c in s if s.startswith('R')]\ni = [d for d in s if s.startswith('C')]\nj = [e for e in s if s.startswith('H')]\n\nk = len(f)*len(g)*len(h)\nl = len(f)*len(g)*len(i)\nm = len(f)*len(g)*len(j)\nn = len(f)*len(h)*len(i)\no = len(f)*len(h)*len(j)\np = len(f)*len(i)*len(j)\nq = len(g)*len(h)*len(i)\nr = len(g)*len(h)*len(j)\ns = len(g)*len(i)*len(j)\nt = len(h)*len(i)*len(j)\n\nsum = k+l+m+n+o+p+q+r+s+t\nprint(sum)", "n = int(input())\ns = [input() for i in range(n)]\n\nf = [a for a in s if a.startswith('M')]\ng = [b for b in s if b.startswith('A')]\nh = [c for c in s if c.startswith('R')]\ni = [d for d in s if d.startswith('C')]\nj = [e for e in s if e.startswith('H')]\n\nk = len(f)*len(g)*len(h)\nl = len(f)*len(g)*len(i)\nm = len(f)*len(g)*len(j)\nn = len(f)*len(h)*len(i)\no = len(f)*len(h)*len(j)\np = len(f)*len(i)*len(j)\nq = len(g)*len(h)*len(i)\nr = len(g)*len(h)*len(j)\ns = len(g)*len(i)*len(j)\nt = len(h)*len(i)*len(j)\n\nsum = k+l+m+n+o+p+q+r+s+t\nprint(sum)"]
['Runtime Error', 'Accepted']
['s432011850', 's588984201']
[9776.0, 10540.0]
[132.0, 204.0]
[538, 538]
p03425
u802963389
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import collections\nimport itertools\n\nN = int(input())\ns = [input()[0] for _ in range(N)]\nc = collections.Counter(s)\n\n# print(c)\n\nl = list(itertools.combinations(c,3))\n\n# print(l)\n\nans = sum([c[i[0]] * c[i[1]] * c[i[2]] for i in l])\n\nprint(ans)', 'from collections import Counter\nfrom itertools import combinations\nfrom functools import reduce\nfrom operator import mul\nn = int(input())\nS = [input()[0] for _ in range(n)]\nS = [s for s in S if s in {"M","A","R","C","H"}]\ncs = Counter(S)\nptn = combinations(cs.keys(), 3)\n\nans = 0\nfor p in ptn:\n arr = [cs[i] for i in p]\n ans += reduce(mul, arr)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s738987533', 's358294203']
[4476.0, 5252.0]
[145.0, 149.0]
[243, 357]
p03425
u812137330
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n = int(input())\n\nd = {"M":0,"R":0,"A":0,"C":0,"H":0}\nS = []\nnum = 0\n\nfor i in range(n):\n S.append(input())\n\n\nfor s in S:\n \n if s[0] in list(d.keys()):\n d[s[0]] += 1\n\n\n\nfor al1 in list(d.keys()):\n for al2 in list(d.keys()):\n for al3 in list(d.keys()):\n if al1 != al2 and al1 != al3 and al2 != al3:\n print(al1,al2,al3)\n num += d[al1]*d[al2]*d[al3]\n\nprint(int(num/6))\n ', 'n = int(input())\n\nd = {"M":0,"R":0,"A":0,"C":0,"H":0}\nS = []\nnum = 0\n\nfor i in range(n):\n S.append(input())\n\n\nfor s in S:\n \n if s[0] in list(d.keys()):\n d[s[0]] += 1\n\n\n\nfor al1 in list(d.keys()):\n for al2 in list(d.keys()):\n for al3 in list(d.keys()):\n if al1 != al2 and al1 != al3 and al2 != al3:\n num += d[al1]*d[al2]*d[al3]\n\nprint(int(num/6))\n ']
['Wrong Answer', 'Accepted']
['s645870429', 's234852482']
[9752.0, 9760.0]
[202.0, 209.0]
[491, 456]
p03425
u813102292
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n = int(input())\ns = []\nfor i in range(n):\n s.append(input())\ntmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}\nfor i in range(n):\n tmp_nums[s[i][0]] += 1\nnums=[]\nfor i in tmp_nums.values():\n nums.append(i)\np = [0,0,0,0,0,0,1,1,1,2]\nq = [1,1,1,2,2,3,2,2,3,3]\nr = [2,3,4,3,4,4,3,4,4,4]\nsum = 0\nfor i in range(10):\n sum += nums[p[i]]*nums[q[i]]*nums[r[i]]\nprint(sum)\n', 'n = int(input())\ns = []\nfor i in range(n):\n s.append(input())\ntmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}\nfor i in range(n):\n if s[i][0] in tmp_nums.keys():\n tmp_nums[s[i][0]] += 1\nnums=[]\nfor i in tmp_nums.values():\n nums.append(i)\np = [0,0,0,0,0,0,1,1,1,2]\nq = [1,1,1,2,2,3,2,2,3,3]\nr = [2,3,4,3,4,4,3,4,4,4]\nsum = 0\nfor i in range(10):\n sum += nums[p[i]]*nums[q[i]]*nums[r[i]]\nprint(sum)\n']
['Runtime Error', 'Accepted']
['s948775274', 's891376817']
[9776.0, 9772.0]
[166.0, 185.0]
[374, 413]
p03425
u814781830
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['N = int(input())\nS = []\nfor i in range(N):\n s = input()\n if s[0] in [ \'M\',\'A\',\'R\',\'C\',\'H\' ]:\n S.append(s)\n\nS = list(set(S))\n\nN = len(S)\nselected = [""] * 2\ncnt = 0\nfor i in range(N-2):\n selected = [""] * 2\n selected[0] = S[i][0]\n for k in range(i+1, N-1):\n if S[k][0] in selected:\n continue\n selected[1] = S[k][0]\n for t in range(k+1, N):\n if S[t][0] in selected:\n continue\n cnt += 1\nprint(cnt)', "import numpy as np\nimport itertools\ncnt = 0\nN = int(input())\nS = {'M':0,'A':0,'R':0,'C':0,'H':0}\nmarch = ['M','A','R','C','H']\nfor i in range(N):\n s = input()[0]\n if s in march:\n S[s] += 1\nseq = S.values()\nfor i in list(itertools.combinations(seq, 3)):\n i = np.array(i)\n cnt += np.prod(i)\n\nprint(cnt)"]
['Wrong Answer', 'Accepted']
['s474426853', 's091880585']
[15908.0, 12504.0]
[2104.0, 309.0]
[485, 319]
p03425
u815878613
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools\n\nN = int(input())\nS = [input() for _ in range(N)]\n\ncnt = [0 for _ in range(5)]\nfor s in S:\n if s[0] == "M":\n cnt[0] += 1\n elif s[1] == "A":\n cnt[1] += 1\n elif s[2] == "R":\n cnt[2] += 1\n elif s[3] == "C":\n cnt[3] += 1\n elif s[4] == "H":\n cnt[4] += 1\n\nans = 0\nfor i, j, k in itertools.permutations(cnt, r=3):\n ans += i * j * k\n\nprint(ans)\n', 'import itertools\n\nN = int(input())\nS = [input() for _ in range(N)]\n\ncnt = [0 for _ in range(5)]\nfor s in S:\n if s[0] == "M":\n cnt[0] += 1\n elif s[0] == "A":\n cnt[1] += 1\n elif s[0] == "R":\n cnt[2] += 1\n elif s[0] == "C":\n cnt[3] += 1\n elif s[0] == "H":\n cnt[4] += 1\n\nans = 0\nfor i, j, k in itertools.combinations(cnt, r=3):\n ans += i * j * k\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s925647334', 's634706671']
[15968.0, 16112.0]
[137.0, 149.0]
[407, 407]
p03425
u836737505
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import defaultdict\nfrom scipy.misc import comb\n#ID\nb = defaultdict(lambda: len(b))\nn = int(input())\nhed = ["M","A","R","C","H"]\nfor i in hed:\n b[i] \nli = [0]*5\nfor _ in range(n):\n a = input()\n if a[0] in hed:\n li[b[a[0]]] += 1\n\nc = [i for i in li if i != 0]\nprint(int(comb(len(c),3))*2 -int(comb(len(c)-1,3)))', 'import itertools\nn = int(input())\na = ["M","A","R","C","H"]\nb = [0]*5\nfor i in range(n):\n s = input()\n for j in range(5):\n if a[j] == s[0]:\n b[j] += 1\nans = 0\nfor k in itertools.combinations(b,3):\n ans += k[0]*k[1]*k[2]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s179373763', 's379065085']
[15956.0, 3064.0]
[372.0, 265.0]
[342, 257]
p03425
u839509562
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["import sys\nfrom itertools import combinations\nfrom collections import Counter\ninput = sys.stdin.readline\n\n\ndef log(*args):\n print(*args, file=sys.stderr)\n\n\ndef main():\n n = int(input().rstrip())\n s = [input()[0] for _ in range(n)]\n s = [v for v in range(n)]\n c = Counter(s)\n ans = 0\n for x, y, z in combinations('MARCH', 3):\n ans += c[x] * c[y] * c[z]\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom itertools import combinations\nfrom collections import Counter\ninput = sys.stdin.readline\n\n\ndef log(*args):\n print(*args, file=sys.stderr)\n\n\ndef main():\n n = int(input().rstrip())\n s = [input()[0] for _ in range(n)]\n c = Counter(s)\n ans = 0\n for x, y, z in combinations('MARCH', 3):\n ans += c[x] * c[y] * c[z]\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s933534711', 's804698655']
[21752.0, 10140.0]
[57.0, 47.0]
[435, 405]
p03425
u842230338
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import Counter\nfrom math import factorial\nN = int(input())\nS = [input()[0:1:] for i in range(N)]\n\nmarch = ["M","A","R","C","H"]\nlist = []\nc = Counter(S)\nfor k,v in c.items():\n if k in march:\n list.append(v)\n\nans = 0\nif len(list) >= 3:\n for i in range(len(list)):\n for j in range(len(list)-1):\n for k in range(len(list)-2):\n if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):\n ans += list[i] * list[j+1] * list[k+2]\n print(ans,i,j+1,k+2)\n\nprint(ans)\n', 'from collections import Counter\nfrom math import factorial\nN = int(input())\nS = [input()[0:1:] for i in range(N)]\n\nmarch = ["M","A","R","C","H"]\nlist = []\nc = Counter(S)\nfor k,v in c.items():\n if k in march:\n list.append(v)\n\nans = 0\nif len(list) >= 3:\n for i in range(len(list)):\n for j in range(len(list)-1):\n for k in range(len(list)-2):\n if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):\n ans += list[i] * list[j+1] * list[k+2]\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s293573900', 's052984056']
[4464.0, 4348.0]
[254.0, 246.0]
[570, 529]
p03425
u844005364
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['from collections import combinations\n\nn = int(input())\n\ncount = {x:0 for x in "MARCH"}\n\nfor _ in range(n):\n s = input()[0]\n if s in count:\n count[s] += 1\n\nsum_count = 0\nfor a, b, c in combinations("MARCH", 3):\n sum_count += count[a] * count[b] * count[c]\n\nprint(sum_count)', 'from itertools import combinations\n \nn = int(input())\n \ncount = {x:0 for x in "MARCH"}\n \nfor _ in range(n):\n s = input()[0]\n if s in count:\n count[s] += 1\n \nsum_count = 0\nfor a, b, c in combinations("MARCH", 3):\n sum_count += count[a] * count[b] * count[c]\n \nprint(sum_count)']
['Runtime Error', 'Accepted']
['s495372380', 's054630206']
[3316.0, 3060.0]
[21.0, 172.0]
[278, 281]
p03425
u845333844
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\nl=[0]*10\nfor i in range(n):\n x=input()\n y=x[0]\n if y=='M':\n l[0]+=1\n elif y=='A':\n l[1]+=1\n elif y=='R':\n l[2]+=1\n elif y=='C':\n l[3]+=1\n elif y=='H':\n l[4]+=1\nans=0\nfor i in range(3):\n for j in range(i+1,i+4):\n for k in range(j+1,j+4):\n sum+=l[i]*l[j]*l[k]\nprint(sum)\n", "n=int(input())\nl=[0]*5\nfor i in range(n):\n x=input()\n y=x[0]\n if y=='M':\n l[0]+=1\n elif y=='A':\n l[1]+=1\n elif y=='R':\n l[2]+=1\n elif y=='C':\n l[3]+=1\n elif y=='H':\n l[4]+=1\nans=l[0]*l[1]*l[2]\nprint(ans)", "n=int(input())\nl=[0]*10\nfor i in range(n):\n x=input()\n y=x[0]\n if y=='M':\n l[0]+=1\n elif y=='A':\n l[1]+=1\n elif y=='R':\n l[2]+=1\n elif y=='C':\n l[3]+=1\n elif y=='H':\n l[4]+=1\nans=0\nfor i in range(3):\n for j in range(i+1,i+4):\n for k in range(j+1,j+4):\n ans+=l[i]*l[j]*l[k]\nprint(ans)"]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s293266189', 's860262088', 's458520308']
[3064.0, 3060.0, 3064.0]
[170.0, 171.0, 172.0]
[315, 225, 314]
p03425
u853900545
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\nm,a,r,c,h=0,0,0,0,0\nfor i in range(n):\n s=input()\n if s[0]=='M':\n m+=1\n elif s[0]=='A':\n a+=1\n elif s[0]=='R':\n r+=1\n elif s[0]=='C':\n c+=1\n elif s[0]=='H':\n h+=1\nx=del ([m,a,r,c,h],0)\nx.sort()\nl=len(x)\nif l<3:\n print(0)\nelif l==3:\n print(x[0]*x[1]*x[2])\nelif l==4:\n print()\nelse:\n print()", "n=int(input())\nm,a,r,c,h=0,0,0,0,0\nfor i in range(n):\n s=input()\n if s[0]=='M':\n m+=1\n elif s[0]=='A':\n a+=1\n elif s[0]=='R':\n r+=1\n elif s[0]=='C':\n c+=1\n elif s[0]=='H':\n h+=1\nx=[m,a,r,c,h]\ncnt=x.count(0)\nfor i in range(cnt):\n x.remove(0)\n\nl=len(x)\nif l<3:\n print(0)\nelif l==3:\n print(x[0]*x[1]*x[2])\nelif l==4:\n a,b,c,d=x[0],x[1],x[2],x[3]\n print(a*b*c+a*b*d+a*c*d+b*c*d)\nelse:\n a,b,c,d,e=x[0],x[1],x[2],x[3],x[4]\n print(a*b*c+a*b*d+a*c*d+b*c*d\\\n +e*a*b+e*a*c+e*a*d+e*b*c+e*b*d\\\n +e*c*d)\n"]
['Runtime Error', 'Accepted']
['s117634450', 's327571607']
[3060.0, 3064.0]
[17.0, 165.0]
[369, 581]
p03425
u856555908
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["x = input()\ncount = [0 for i in range(5)]\nfor i in x:\n name = input()\n if name[0] == 'M':\n count[0] += 1\n elif name[0] == 'A':\n count[1] += 1\n elif name[0] == 'R':\n count[2] += 1\n elif name[0] == 'C':\n count[3] += 1\n elif name[0] == 'H':\n count[4] += 1\n\np = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]\nq = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]\nr = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]\nres = 0\nfor i in range(10):\n res += count[p[i]]*count[q[i]]*count[r[i]]\n\nprint(res)", "x = int(input())\ncount = [0 for i in range(5)]\nfor i in range(x):\n name = input()\n if name[0] == 'M':\n count[0] += 1\n elif name[0] == 'A':\n count[1] += 1\n elif name[0] == 'R':\n count[2] += 1\n elif name[0] == 'C':\n count[3] += 1\n elif name[0] == 'H':\n count[4] += 1\n\np = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]\nq = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]\nr = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]\nres = 0\nfor i in range(10):\n res += count[p[i]]*count[q[i]]*count[r[i]]\n\nprint(res)"]
['Wrong Answer', 'Accepted']
['s360120285', 's928857553']
[3188.0, 3064.0]
[17.0, 163.0]
[498, 510]
p03425
u859897687
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n=int(input())\nm=[0,0,0,0,0]\nfor i in range(n):\n s=input()\n if s[0]=="M":\n m[0]+=1\n elif s[0]=="A":\n m[1]+=1\n elif s[0]=="R":\n m[2]+=1\n elif s[0]=="C":\n m[3]+=1\n elif s[0]=="H":\n m[4]+=1\nans=0\nfor i in range(3):\n for j in range(i,4):\n for k in range(j,5):\n ans+=m[i]*m[j]*m[k]\nprint(ans)', 'n=int(input())\nm=[0,0,0,0,0]\nfor i in range(n):\n s=input()\n if s[0]=="M":\n m[0]+=1\n if s[0]=="A":\n m[1]+=1\n if s[0]=="R":\n m[2]+=1\n if s[0]=="C":\n m[3]+=1\n if s[0]=="H":\n m[4]+=1\nans=0\nfor i in range(3):\n for j in range(i+1,4):\n for k in range(j+1,5):\n ans+=m[i]*m[j]*m[k]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s713092749', 's250128843']
[3064.0, 3064.0]
[177.0, 182.0]
[317, 313]
p03425
u863442865
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["\ndef main():\n import sys\n #input = sys.stdin.readline\n sys.setrecursionlimit(10000000)\n from collections import Counter, deque\n #from collections import defaultdict\n from itertools import combinations, permutations\n #from itertools import accumulate, product\n from bisect import bisect_left,bisect_right\n from math import floor, ceil\n #from operator import itemgetter\n\n #mod = 1000000007\n\n N = int(input())\n M = 0\n A = 0\n R = 0\n C = 0\n H = 0\n for _ in range(N):\n s = input().rstrip()\n if s[0]=='M':\n M += 1\n elif s[0]=='A':\n A += 1\n elif s[0]=='R':\n R += 1\n elif s[0]=='C':\n C += 1\n else:\n H += 1\n res = 0\n l = [M, A, R, C, H]\n for a, b, c in combinations(l, 3):\n res += a*b*c\n print(res)\n\nif __name__ == '__main__':\n main()", "\ndef main():\n import sys\n #input = sys.stdin.readline\n sys.setrecursionlimit(10000000)\n from collections import Counter, deque\n #from collections import defaultdict\n from itertools import combinations, permutations\n #from itertools import accumulate, product\n from bisect import bisect_left,bisect_right\n from math import floor, ceil\n #from operator import itemgetter\n\n #mod = 1000000007\n\n N = int(input())\n M = 0\n A = 0\n R = 0\n C = 0\n H = 0\n for _ in range(N):\n s = input().rstrip()\n if s[0]=='M':\n M += 1\n if s[0]=='A':\n A += 1\n if s[0]=='R':\n R += 1\n if s[0]=='C':\n C += 1\n if s[0]=='H':\n H += 1\n res = 0\n l = [M, A, R, C, H]\n for a, b, c in combinations(l, 3):\n res += a*b*c\n print(res)\n \nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s272387822', 's810687576']
[3316.0, 3316.0]
[177.0, 184.0]
[929, 935]
p03425
u884982181
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n = int(input())\nm = 0\na = 0\nr = 0\nc = 0\nh = 0\nfor i in range(n):\n s = input()\n if s[0] == "M":\n m += 1\n if s[0] == "A":\n a += 1\n if s[0] == "R":\n r += 1\n if s[0] == "C":\n c += 1\n if s[0] == "H":\n H += 1\nans = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h\nprint(ans)', 'n = int(input())\nm = 0\na = 0\nr = 0\nc = 0\nh = 0\nfor i in range(n):\n s = input()\n if s[0] == "M":\n m += 1\n if s[0] == "A":\n a += 1\n if s[0] == "R":\n r += 1\n if s[0] == "C":\n c += 1\n if s[0] == "H":\n h += 1\nans = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h\nprint(ans)']
['Runtime Error', 'Accepted']
['s419478113', 's870713907']
[3064.0, 3064.0]
[181.0, 188.0]
[306, 306]
p03425
u887207211
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["N = int(input())\nname = {}\nfor i in range(N):\n S = input()\n if(S[0] in ['M', 'A', 'R', 'C', 'H']):\n if(S[0] not in name):\n name[S[0]] = 1\n else:\n name[S[0]] += 1\nans = 1\ncnt = 0\nfor k, v in name.items():\n k,v\n if(v >= 2):\n ans *= v\n else:\n cnt += 1\nprint(ans*cnt+cnt//3)", 'from collections import Counter\nfrom itertools import combinations\nN = int(input())\nS = Counter(input()[0] for _ in range(N))\n\nans = 0\nfor i, j, k in combinations("MARCH", 3):\n ans += S[i]*S[j]*S[k]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s333496058', 's411581361']
[3188.0, 3316.0]
[184.0, 161.0]
[297, 210]
p03425
u893063840
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['n = int(input())\ns = [input()[0] for _ in range(n)]\n\nfrom collections import Counter\n\nc = Counter(s)\n\nc = list(c.values())\n\nc_len = len(c)\n\nans = 0\nfor i in range(c_len):\n for j in range(i+1, c_len):\n for k in range(j+1, c_len):\n ans += c[i] * c[j] * c[k]\n\nprint(ans)\n', 'n = int(input())\ns = [input()[0] for _ in range(n)]\n\nc = []\nc.append(s.count("M"))\nc.append(s.count("A"))\nc.append(s.count("R"))\nc.append(s.count("C"))\nc.append(s.count("H"))\nc_len = len(c)\nans = 0\nfor i in range(c_len):\n for j in range(i+1, c_len):\n for k in range(j+1, c_len):\n ans += c[i] * c[j] * c[k]\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s975072003', 's203620681']
[4120.0, 3864.0]
[142.0, 140.0]
[289, 339]
p03425
u896726004
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from itertools import (\n accumulate, \n groupby, \n permutations, \n combinations, \n product, \n)\n\nn = int(input())\nSm, Sa, Sr, Sc, Sh = set(), set(), set(), set(), set()\nfor _ in range(n):\n s = input()\n if s[0]=='M':\n Sm.add(s)\n elif s[0]=='A':\n Sa.add(s)\n elif s[0]=='R':\n Sr.add(s)\n elif s[0]=='C':\n Sc.add(s)\n elif s[0]=='H':\n Sh.add(s)\n\nans = 0\nS = [len(Sm), len(Sa), len(Sr), len(Sc), len(Sh)]\n\nfor v1, v2, v3 in combinations(S, 3):\n print(v1, v2, v3)\n ans += v1*v2*v3\n\nprint(ans)", "from itertools import (\n accumulate, \n groupby, \n permutations, \n combinations, \n product, \n)\n\nn = int(input())\nSm, Sa, Sr, Sc, Sh = set(), set(), set(), set(), set()\nfor _ in range(n):\n s = input()\n if s[0]=='M':\n Sm.add(s)\n elif s[0]=='A':\n Sa.add(s)\n elif s[0]=='R':\n Sr.add(s)\n elif s[0]=='C':\n Sc.add(s)\n elif s[0]=='H':\n Sh.add(s)\n\nans = 0\nS = [len(Sm), len(Sa), len(Sr), len(Sc), len(Sh)]\n\nfor v1, v2, v3 in combinations(S, 3):\n ans += v1*v2*v3\n\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s683893761', 's671932462']
[14316.0, 14316.0]
[195.0, 184.0]
[688, 666]
p03425
u916637712
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import numpy as np\nnum=int(input())\n#valid=["M","A","R","C","H"]\narr=np.zeros(5)\n#print(arr)\n\nfor i in range(num):\n chara=list(input())[0]\n if chara == "M":\n arr[0]+=1\n if chara == "A":\n arr[1]+=1\n if chara == "R":\n arr[2]+=1\n if chara == "C":\n arr[3]+=1\n if chara == "H":\n arr[4]+=1\n\nans=0\nfor i in range(3):\n for k in range(3-i):\n for j in range(3-k-i):\n ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]\n print(arr[i]*arr[1+i+k]*arr[2+i+k+j])\nprint(int(ans))\n', 'import numpy as np\nnum=int(input())\n#valid=["M","A","R","C","H"]\narr=np.zeros(5)\n#print(arr)\n\nfor i in range(num):\n chara=list(input())[0]\n if chara == "M":\n arr[0]+=1\n if chara == "A":\n arr[1]+=1\n if chara == "R":\n arr[2]+=1\n if chara == "C":\n arr[3]+=1\n if chara == "H":\n arr[4]+=1\n\nans=0\nfor i in range(3):\n for k in range(3-i):\n for j in range(3-k-i):\n ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]\n #print(arr[i]*arr[1+i+k]*arr[2+i+k+j])\nprint(int(ans))\n']
['Wrong Answer', 'Accepted']
['s937956419', 's877506982']
[21380.0, 21504.0]
[1744.0, 1458.0]
[533, 534]
p03425
u922449550
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from collections import defaultdict\nimport itertools\n\nd = defaultdict(int)\nN = int(input())\nfor i in range(N):\n s = input()[0].lower()\n d[s] += 1\n\nn = [d['m'], d['a'], d['r'], d['r'], d['h']]\nans = 0\n\na = itertools.combinations(n, 3)\nfor aa in a:\n t = 1\n for aaa in aa:\n t *= aaa\n ans += t\n\nprint(ans)", "from collections import defaultdict\nimport itertools\n\nd = defaultdict(int)\nN = int(input())\nfor i in range(N):\n s = input()[0].lower()\n d[s] += 1\n\nn = [d['m'], d['a'], d['r'], d['c'], d['h']]\nans = 0\n\na = itertools.combinations(n, 3)\nfor aa in a:\n t = 1\n for aaa in aa:\n t *= aaa\n ans += t\n\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s646601820', 's003390169']
[3316.0, 3444.0]
[193.0, 186.0]
[309, 309]
p03425
u923659712
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['m=0\na=0 \nr=0\nc=0\nh=0\nfor j in range(n):\n if s[j][0]=="M":\n m+=1\n elif s[j][0]=="A":\n a+=1\n elif s[j][0]=="R":\n r+=1\n elif s[j][0]=="C":\n c+=1\n elif s[j][0]=="H":\n h+=1\n \nans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+a*r*h+r*c*h\n\nprint(ans)', 'n=int(input())\ns=[]\nfor i in range(n):\n s.append(input())\nm=0\na=0 \nr=0\nc=0\nh=0\nfor j in range(n):\n if s[j][0]=="M":\n m+=1\n elif s[j][0]=="A":\n a+=1\n elif s[j][0]=="R":\n r+=1\n elif s[j][0]=="C":\n c+=1\n elif s[j][0]=="H":\n h+=1\n \nans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+a*r*h+r*c*h\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s307248772', 's120644592']
[3064.0, 9772.0]
[18.0, 190.0]
[268, 327]
p03425
u934868410
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n = int(input())\ncount = [0]*5\nd = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}\n\nfor i in range(n):\n s = input()\n if s[0] in 'MARCH':\n count[d[s[0]]] += 1\n\nans = 0\nfor i in range(5):\n for j in range(i+1, 5):\n for k in range(j+1, 5):\n ans += count[i] * count[j] * count[k]]\nprint(ans)", "n = int(input())\ncount = [0]*5\nd = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}\n\nfor i in range(n):\n s = input()\n if s[0] in 'MARCH':\n count[d[s[0]]] += 1\n\nans = 0\nfor i in range(5):\n for j in range(i+1, 5):\n for k in range(j+1, 5):\n ans += count[i] * count[j] * count[k]\nprint(ans)"]
['Runtime Error', 'Accepted']
['s418523965', 's122948316']
[3064.0, 3064.0]
[18.0, 171.0]
[292, 291]
p03425
u948521599
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools\nN = int(input())\nSK = {"M":0,"A":1,"R":2,"C":3,"H":4}\nSD = [0]*5\ndel_list = []\nA = ["M","A","R","C","H"]\nfor x in range(N):\n tmp = str(input())\n if tmp[0] in A:\n SD[SK[tmp[0]]] +=1\nC = 0\nfor x in range(5)\n if SD[x] == 0 :\n del_list.append(x)\n C +=1\ndel_list.reverse()\nfor x in del_list:\n SD.pop(x)\n \nif C >2:\n print(0)\nelse:\n Z = 5-C\n k = itertools.combinations(range(Z), 3)\n ans = 0\n for x in k:\n ans += SD[x[0]]*SD[x[1]]*SD[x[2]]\n print(ans)', 'import itertools\nN = int(input())\nSK = {"M":0,"A":1,"R":2,"C":3,"H":4}\nSD = [0]*5\ndel_list = []\nA = ["M","A","R","C","H"]\nfor x in range(N):\n tmp = str(input())\n if tmp[0] in A:\n SD[SK[tmp[0]]] +=1\nC = 0\nfor x in range(5):\n if SD[x] == 0 :\n del_list.append(x)\n C +=1\ndel_list.reverse()\nfor x in del_list:\n SD.pop(x)\n \nif C >2:\n print(0)\nelse:\n Z = 5-C\n k = itertools.combinations(range(Z), 3)\n ans = 0\n for x in k:\n ans += SD[x[0]]*SD[x[1]]*SD[x[2]]\n print(ans)']
['Runtime Error', 'Accepted']
['s516722740', 's179807128']
[3064.0, 3064.0]
[17.0, 206.0]
[521, 522]
p03425
u955125992
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["from collections import Counter\nimport itertools\n\nn = int(input())\n\ns = [str(input()) for _ in range(n)]\ninitial = [''] * n\n\nfor i in range(n):\n initial[i] = s[i][0]\n\nreg = Counter(initial)\nele = []\n\nfor i, j in reg.items():\n ele.append(i)\nans = 0\nfor A in itertools.combinations(ele, 3):\n #print(A)\n cnt = 1\n for s in A:\n cnt *= reg[s]\n ans += cnt\n\nprint(ans)", "from collections import Counter\nimport itertools\n\nn = int(input())\n\ns = [str(input()) for _ in range(n)]\ninitial = []\nd = ['M', 'A', 'R', 'C', 'H']\n\nfor i in range(n):\n if s[i][0] in d:\n initial.append(s[i][0])\n\nreg = Counter(initial)\nele = []\n\nfor i, j in reg.items():\n ele.append(i)\nans = 0\nfor A in itertools.combinations(ele, 3):\n #print(A)\n cnt = 1\n for s in A:\n cnt *= reg[s]\n ans += cnt\n\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s204327366', 's275031895']
[10880.0, 10880.0]
[191.0, 185.0]
[385, 437]
p03425
u969211566
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
['import itertools \nn = int(input())\ns = [input() for _ in range(n)]\n\nmarch = [0]*5\nans = 0\nfor i in range(n):\n if s[i][0] == "M":\n march[0] += 1\n elif s[i][0] == "A":\n march[1] += 1\n elif s[i][0] == "R":\n march[2] += 1\n elif s[i][0] == "C":\n march[3] += 1\n elif s[i][0] == "H":\n march[4] += 1\nprint(march)\n\nfor j in itertools.combinations(march,3):\n comb_multi = 1\n for k in range(3):\n comb_multi *= j[k]\n ans += comb_multi\nprint(ans)', 'import itertools \nn = int(input())\ns = [input() for _ in range(n)]\n\nmarch = [0]*5\nans = 0\nfor i in range(n):\n if s[i][0] == "M":\n march[0] += 1\n elif s[i][0] == "A":\n march[1] += 1\n elif s[i][0] == "R":\n march[2] += 1\n elif s[i][0] == "C":\n march[3] += 1\n elif s[i][0] == "H":\n march[4] += 1\n\nfor j in itertools.combinations(march,3):\n comb_multi = 1\n for k in range(3):\n comb_multi *= j[k]\n ans += comb_multi\nprint(ans)']
['Wrong Answer', 'Accepted']
['s617175278', 's688374725']
[9776.0, 9776.0]
[172.0, 181.0]
[467, 454]
p03425
u970197315
2,000
262,144
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type.
["n=int(input())\nc=0\nd=set()\nfor i in range(n):\n s=input()\n if s[0]==('M' or 'A' or 'C' or 'R' or 'H'):\n if s not in d:\n c+=1\n d.add(s)\nans=0\nif c<3:\n print(ans)\nelse:\n ans=(c*(c-1)*(c-2))//6\n", 'n = int(input())\nfrom collections import Counter\nc = Counter()\nfor _ in range(n):\n s = input()[0]\n c[s] += 1\n\nans = 0\nans += c["M"]*c["A"]*c["R"]\nans += c["M"]*c["A"]*c["C"]\nans += c["M"]*c["A"]*c["H"]\nans += c["M"]*c["R"]*c["C"]\nans += c["M"]*c["R"]*c["H"]\nans += c["M"]*c["C"]*c["H"]\nans += c["A"]*c["R"]*c["C"]\nans += c["A"]*c["R"]*c["H"]\nans += c["A"]*c["C"]*c["H"]\nans += c["R"]*c["C"]*c["H"]\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s419976918', 's705308768']
[14316.0, 9476.0]
[202.0, 158.0]
[231, 415]
p03426
u017810624
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d=map(int,input().split())\nl=[list(map(int,input().split())) for i in range(h)]\nL=[0 for i in range(h*w)]\nfor i in range(h):\n for j in range(w):\n L[l[i][j]-1]=[i,j]\n\nsumL=[0 for i in range(h*w+1)]\nfor i in range(h*w):\n if i>=d:\n sumL[i+1]=sumL[i+1-d]+abs(L[i][0]-L[i-d][0])+abs(L[i][1]-L[i-d][1])\nprint(sumL)\nq=int(input())\nQL=[list(map(int,input().split())) for i in range(q)]\nfor i in range(q):\n print(sumL[QL[i][1]]-sumL[QL[i][0]])', 'h,w,d=map(int,input().split())\nl=[list(map(int,input().split())) for i in range(h)]\nL=[0 for i in range(h*w)]\nfor i in range(h):\n for j in range(w):\n L[l[i][j]-1]=[i,j]\n\nsumL=[0 for i in range(h*w+1)]\nfor i in range(h*w):\n if i>=d:\n sumL[i+1]=sumL[i+1-d]+abs(L[i][0]-L[i-d][0])+abs(L[i][1]-L[i-d][1])\n\nq=int(input())\nQL=[list(map(int,input().split())) for i in range(q)]\nfor i in range(q):\n print(sumL[QL[i][1]]-sumL[QL[i][0]])']
['Wrong Answer', 'Accepted']
['s406316860', 's492218982']
[45780.0, 45080.0]
[623.0, 629.0]
[447, 436]
p03426
u037430802
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d = map(int, input().split())\n\na = [[0 for _ in range(w)] for _ in range(h)]\nmasu = {}\nfor i in range(h):\n a[i] = list(map(int, input().split())\n for j in range(w):\n masu[a[i][j]] = (i,j)\n"""\nmasu = {}\nfor i in range(h):\n for j in range(w):\n masu[a[i][j]] = (i,j)\n"""\npoint = [0] * (h*w)\nfor i in range(1,h*w-d+1):\n point[i] = abs(masu[i][0] - masu[i+d][0]) + abs(masu[i][1] - masu[i+d][1])\n\n\nq = int(input())\nans = [0] * q\nfor i in range(q):\n l, r = map(int, input().split())\n if l == r:\n ans[i] = 0\n else:\n ans[i] = sum(point[l:r:d])\n \nfor i in range(q):\n print(ans[i])\n', '\n\n\nH,W,D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [tuple(map(int, input().split())) for _ in range(Q)]\n\nnum = [None] * (H*W)\nfor i in range(H):\n for j in range(W):\n num[A[i][j] - 1] = (i,j)\n\n\naccum = [0] * (H*W)\n\nfor i in range(D):\n j = 0\n while i + j*D <= (H*W) - 1:\n if j == 0:\n accum[i + j*D] = 0\n else:\n curr = i + j*D\n prev = i + (j-1)*D\n accum[curr] = accum[prev] + abs(num[prev][0] - num[curr][0]) + abs(num[prev][1] - num[curr][1])\n\n j += 1\n\nfor l,r in LR:\n print(accum[r-1] - accum[l-1])\n\n ']
['Runtime Error', 'Accepted']
['s850874797', 's975327346']
[2940.0, 31396.0]
[17.0, 568.0]
[628, 651]
p03426
u046187684
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['from itertools import product\n\n\ndef solve(string):\n h, w, d, *a = map(int, string.split())\n a, q, lr = a[:h * w], a[h * w], a[h * w + 1:]\n n = h * w\n index = [a.index(i + 1) for i in range(h * w)]\n costs = [\n [0 if j <= i or (j - i) % d != 0 else n * (j - i) // d for j in range(n)] for i in range(n)\n ]\n for s, g in product(range(n), repeat=2):\n if costs[s][g] == 0:\n continue\n if s - d >= 0:\n costs[s][g] = costs[s - d][g] - costs[s - d][s]\n continue\n before = 0 if g - d < 0 else costs[s][g - d]\n costs[s][g] = abs(index[g - d] // w - index[g] // w) + abs(index[g - d] % w -\n index[g] % w) + before\n print(costs)\n return "\\n".join([str(costs[l - 1][r - 1]) for l, r in zip(lr[::2], lr[1::2])])\n\n\nif __name__ == \'__main__\':\n n, m, d = map(int, input().split())\n ins = \'{} {} {}\\n\'.format(n, m, d) + \'\\n\'.join([input() for _ in range(n)])\n n = int(input())\n print(solve(ins + \'\\n{}\\n\'.format(n) + \'\\n\'.join([input() for _ in range(n)])))\n', 'from functools import partial\nfrom itertools import islice\n\n\ndef take(n, iterable):\n return list(islice(iterable, n))\n\n\ndef chunked(iterable, n):\n return iter(partial(take, n, iter(iterable)), [])\n\n\ndef distance(x, y):\n return abs(x[0] - y[0]) + abs(x[1] - y[1])\n\n\ndef solve(s):\n h, w, d, *aqlr = map(int, s.split())\n n = h * w\n pos = [(i // w, i % w) for i, _a in enumerate(aqlr[:n])]\n cost = [0] * (n + 1)\n for i in range(d + 1, n + 1):\n cost[i] = cost[i - d] + distance(pos[i - d], pos[i])\n return "\\n".join(["%d" % (cost[r] - cost[l]) for l, r in chunked(aqlr[n + 1:], 2)])\n\n\nn, m, d = map(int, input().split())\nl = \'{} {} {}\\n\'.format(n, m, d) + \'\\n\'.join([input() for _ in range(n)])\nq, = map(int, input().split())\nl += \'\\n{}\\n\'.format(q) + \'\\n\'.join([input() for _ in range(q)])\nprint(solve(l))\n', 'def solve(string):\n h, w, d, *a = map(int, string.split())\n a, q, lr = a[:h * w], a[h * w], a[h * w + 1:]\n n = h * w\n index = [a.index(i + 1) for i in range(h * w)]\n # costs = [\n # [0 if j <= i or (j - i) % d != 0 else n * (j - i) // d for j in range(n)] for i in range(n)\n # ]\n diff = [abs(i0 // w - i1 // w) + abs(i0 % w - i1 % w) for i0, i1 in zip(index, index[d:])]\n """\n for s in range(n):\n if sum(costs[s]) == 0:\n continue\n for g in range(n):\n if costs[s][g] == 0:\n continue\n if s - d >= 0:\n costs[s][g] = costs[s - d][g] - costs[s - d][s]\n continue\n before = 0 if g - d < 0 else costs[s][g - d]\n costs[s][g] = +before\n return "\\n".join([str(costs[l - 1][r - 1]) for l, r in zip(lr[::2], lr[1::2])])\n """\n print(diff)\n return "\\n".join([str(sum(diff[l - 1:r - 1:d])) for l, r in zip(lr[::2], lr[1::2])])\n\n\nif __name__ == \'__main__\':\n n, m, d = map(int, input().split())\n ins = \'{} {} {}\\n\'.format(n, m, d) + \'\\n\'.join([input() for _ in range(n)])\n n = int(input())\n print(solve(ins + \'\\n{}\\n\'.format(n) + \'\\n\'.join([input() for _ in range(n)])))\n', 'from functools import partial\nfrom itertools import islice\n\n\ndef take(n, iterable):\n return list(islice(iterable, n))\n\n\ndef chunked(iterable, n):\n return iter(partial(take, n, iter(iterable)), [])\n\n\ndef distance(x, y):\n return abs(x[0] - y[0]) + abs(x[1] - y[1])\n\n\ndef solve(s):\n h, w, d, *aqlr = map(int, s.split())\n a, q, lr = aqlr[:h * w], aqlr[h * w], aqlr[h * w + 1:]\n n = h * w\n pos = [0] * (n + 1)\n for i, _a in enumerate(a):\n pos[_a] = (i // w, i % w)\n cost = [0] * (n + 1)\n for i in range(d + 1, n + 1):\n cost[i] = cost[i - d] + distance(pos[i - d], pos[i])\n return "\\n".join(["%d" % (cost[r] - cost[l]) for l, r in chunked(lr, 2)])\n\n\nn, m, d = map(int, input().split())\nl = \'{} {} {}\\n\'.format(n, m, d) + \'\\n\'.join([input() for _ in range(n)])\nq, = map(int, input().split())\nl += \'\\n{}\\n\'.format(q) + \'\\n\'.join([input() for _ in range(q)])\nprint(solve(l))\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s199675626', 's236417550', 's789855164', 's954794831']
[36748.0, 36940.0, 37004.0, 37112.0]
[2105.0, 330.0, 2105.0, 417.0]
[1112, 836, 1220, 913]
p03426
u146597538
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d= map(int, input().split())\na = {}\nfor y in range(h):\n line = list(map(int, input().split()))\n for x in range(len(line)):\n a[line[x]-1] = (y,x)\n\n\n\n\n# 1,2,3,4,5,6,7,8,9\n\n\n\n\nnum = len(a)\ndp = [0]*num\nfor i in range(num-1, -1, -1):\n print(i)\n if i+d <= num-1:\n x, y = a[i]\n px, py = a[i+d]\n dp[i] = dp[i+d] + abs(x-px) + abs(y-py)\n\nq = int(input())\nfor _ in range(q):\n l, r = map(int, input().split())\n l -= 1\n r -= 1\n print(dp[l]-dp[r])', 'h,w,d= map(int, input().split())\na = {}\nfor y in range(h):\n line = list(map(int, input().split()))\n for x in range(len(line)):\n a[line[x]-1] = (y,x)\n\n\n\n\n# 1,2,3,4,5,6,7,8,9\n\n\n\n\nnum = len(a)\ndp = [0]*num\nfor i in range(num-1, -1, -1):\n if i+d <= num-1:\n x, y = a[i]\n px, py = a[i+d]\n dp[i] = dp[i+d] + abs(x-px) + abs(y-py)\n\nq = int(input())\nfor _ in range(q):\n l, r = map(int, input().split())\n l -= 1\n r -= 1\n print(dp[l]-dp[r])']
['Wrong Answer', 'Accepted']
['s146504612', 's668651296']
[26416.0, 26480.0]
[600.0, 579.0]
[1219, 1206]
p03426
u163320134
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,k=map(int,input().split())\npos=[0]*(h*w+1)\nfor _ in range(h):\n tmp=list(map(int,input().split()))\n for i in range(w):\n pos[tmp[w]]=[i+1,w+1]\nprint(pos)h,w,k=map(int,input().split())\npos=[0]*(h*w+1)\nfor i in range(h):\n tmp=list(map(int,input().split()))\n for j in range(w):\n pos[tmp[j]]=[i+1,j+1]\ncs=[[0] for _ in range(k+1)]\nfor i in range(1,k+1):\n for j in range(1,(h*w-i)//k+1):\n x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]\n x2,y2=pos[i+k*j][1],pos[i+k*j][0]\n cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])\nq=int(input())\nfor i in range(q):\n l,r=map(int,input().split())\n tmp=l%k\n if tmp==0:\n tmp=k\n l,r=(l-tmp)//k,(r-tmp)//k\n print(cs[tmp][r]-cs[tmp][l])', 'h,w,k=map(int,input().split())\npos=[0]*(h*w+1)\nfor i in range(h):\n tmp=list(map(int,input().split()))\n for j in range(w):\n pos[tmp[j]]=[i+1,j+1]\ncs=[[0] for _ in range(k+1)]\nfor i in range(1,k+1):\n for j in range(1,(h*w-i)//k+1):\n x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]\n x2,y2=pos[i+k*j][1],pos[i+k*j][0]\n cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])\nq=int(input())\nfor i in range(q):\n l,r=map(int,input().split())\n tmp=l%k\n if tmp==0:\n tmp=k\n l,r=(l-tmp)//k,(r-tmp)//k\n print(cs[tmp][r]-cs[tmp][l])']
['Runtime Error', 'Accepted']
['s111220558', 's900189079']
[2940.0, 22440.0]
[18.0, 1108.0]
[687, 527]
p03426
u175034939
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d = map(int,input().split())\nhw = [[] for _ in range(h*w+1)]\nhw[0] = [0,0]\nfor i in range(h):\n row = list(map(int,input().split()))\n for j in range(w):\n hw[row[j]] = [i,j]\nprint(hw)\n\na = [0 for _ in range(h*w+1)]\nfor i in range(d+1,h*w+1):\n a[i] = a[i-d] + abs(hw[i][0] - hw[i-d][0]) + abs(hw[i][1] - hw[i-d][1])\n\nq = int(input())\nfor i in range(q):\n L,R = map(int,input().split())\n print(a[R] - a[L])', 'h,w,d = map(int,input().split())\nhw = [[] for _ in range(h*w+1)]\nfor i in range(h):\n row = list(map(int,input().split()))\n for j in range(w):\n hw[row[j]] = [i,j]\n \na = [0 for _ in range(h*w+1)]\nfor i in range(d+1,h*w+1):\n a[i] = a[i-d] + abs(hw[i][0] - hw[i-d][0]) + abs(hw[i][1] - hw[i-d][1])\n \nq = int(input())\nfor i in range(q):\n L,R = map(int,input().split())\n print(a[R] - a[L])']
['Wrong Answer', 'Accepted']
['s949235588', 's456877562']
[18084.0, 17188.0]
[1035.0, 996.0]
[427, 405]
p03426
u187205913
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d = map(int,input().split())\na = [list(map(int,input().split())) for _ in range(h)]\nq = int(input())\nl = [list(map(int,input().split())) for _ in range(q)]\ndic = {0:[0]}\nfor i in range(1,d+1):\n list = []\n for j in range(i,h*w,d):\n for y in range(len(a)):\n if j in a[y]:\n for x in range(len(a[y])):\n if a[y][x]==j:\n if i==j:\n list.append(0)\n x_ = x\n y_ = y\n k = 0\n else:\n k += abs(x-x_)+abs(y-y_)\n list.append(k)\n x_ = x\n y_ = y\n dic[i] = list\nprint(dic)\nfor l_ in l:\n if l_[0]%d==0:\n print(dic[d][(l_[1]-l_[0])//d])\n else:\n print(dic[l_[0]%d][(l_[1]-l_[0])//d])', 'h,w,d = map(int,input().split())\na = [list(map(int,input().split())) for _ in range(h)]\nq = int(input())\nl = [list(map(int,input().split())) for _ in range(q)]\ndic = {}\nfor i in range(len(a)):\n for j in range(len(a[i])):\n dic[a[i][j]] = (i,j)\nsum = [0]*(h*w+1)\nfor i in range(d+1,h*w+1):\n sum[i] = sum[i-d]+abs(dic[i][0]-dic[i-d][0])+abs(dic[i][1]-dic[i-d][1])\nfor l_ in l:\n print(sum[l_[1]]-sum[l_[0]])']
['Runtime Error', 'Accepted']
['s615862802', 's967305686']
[31376.0, 47728.0]
[2105.0, 567.0]
[908, 419]
p03426
u210827208
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H,W,D=map(int,input().split())\nA=[list(map(int,input().split())) for _ in range(H)]\nQ=int(input())\nX=[[0,0] for _ in range(H*W)]\nfor i in range(H):\n for j in range(W):\n X[A[i][j]][0]=i\n X[A[i][j]][1]=j\nM=[0]*(H*W+1)\nfor d in range(D+1,H*W+1):\n M[d]=abs(X[d][0]-X[d-D][0])+abs(X[d][1]-X[d-D][1])+M[d-D]\n\nfor i in range(Q):\n L,R=map(int,input().split())\n print(M[R]-M[L])', 'H,W,D=map(int,input().split())\nA=[list(map(int,input().split())) for _ in range(H)]\nQ=int(input())\nX=[[0,0] for _ in range(H*W+1)]\nfor i in range(H):\n for j in range(W):\n X[A[i][j]][0]=i\n X[A[i][j]][1]=j\nM=[0]*(H*W+1)\nfor d in range(D+1,H*W+1):\n M[d]=abs(X[d][0]-X[d-D][0])+abs(X[d][1]-X[d-D][1])+M[d-D]\n\nfor i in range(Q):\n L,R=map(int,input().split())\n print(M[R]-M[L])']
['Runtime Error', 'Accepted']
['s726626662', 's076806757']
[16116.0, 20712.0]
[95.0, 957.0]
[399, 401]
p03426
u232852711
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
["h, w, d = list(map(int, input().split()))\na = [list(map(int, input().split())) for _ in range(h)]\nq = int(input())\nlr = [list(map(int, input().split())) for _ in range(q)]\n\na_and_pos = {}\nfor i in range(h):\n for j in range(w):\n a_and_pos[a[i][j]] = (i, j)\n\npaths = {}\nfor rem in range(1, d+1):\n path = [0]*(h*w+1)\n i, j = a_and_pos[rem]\n for x in range(rem+d, h*w+1, d):\n i_next, j_next = a_and_pos[x]\n path[x] = path[x-d] + abs(i_next-i) + abs(j_next-j)\n i, j = i_next, j_next\n paths[rem] = path\n\n# for k, v in paths.items(): print(f'{k} : {v}')\nfor l, r in lr:\n rem = l%d if l%d != 0 else l%d+1\n path = paths[rem]\n print(path[r] - path[l])\n", 'h, w, d = list(map(int, input().split()))\na = [list(map(int, input().split())) for _ in range(h)]\nq = int(input())\nlr = [list(map(int, input().split())) for _ in range(q)]\n\na_and_pos = {}\nfor i in range(h):\n for j in range(w):\n a_and_pos[a[i][j]] = (i, j)\n\ncosts = [0]*(h*w+1)\nfor x in range(d+1, h*w+1):\n i_prev, j_prev = a_and_pos[x-d]\n i, j = a_and_pos[x]\n costs[x] = costs[x-d] + abs(i-i_prev) + abs(j-j_prev)\n# print(costs)\n\nfor l, r in lr:\n print(costs[r] - costs[l])\n']
['Wrong Answer', 'Accepted']
['s793134612', 's079373556']
[1889396.0, 47720.0]
[2232.0, 595.0]
[694, 496]
p03426
u255001744
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
["def calc(prepoint, nextpoint):\n return abs(nextpoint[0]-prepoint[0]) + abs(nextpoint[1]-prepoint[1])\n\ndef search(i,A):\n for h in range(H):\n if L in A[h]:\n return (h,A[h].index(L))\ndef main():\n H,W,D = map(int,input().split())\n A = [list(map(int, input().split())) for i in range(H)]\n Q = int(input())\n L_R_List = [list(map(int, input().split())) for i in range(Q)]\n\n temp = [(0,0) for i in range(H*W)]\n for L_R in L_R_List:\n L = L_R[0]\n R = L_R[1]\n ans = 0\n if temp[L] == (0,0):\n temp[L] = search(L,A)\n prepoint = temp[L]\n else:\n prepoint = temp[L]\n while(L != R):\n L += D\n if temp[L] == (0,0):\n temp[L] = search(L,A)\n nextpoint = temp[L]\n else:\n nextpoint = temp[L]\n ans += calc(prepoint, nextpoint)\n prepoint = nextpoint\n print(ans)\nif __name__ == '__main__':\n main()\n", "def calc(prepoint, nextpoint):\n return abs(nextpoint[0]-prepoint[0]) + abs(nextpoint[1]-prepoint[1])\n\ndef main():\n H,W,D = map(int,input().split())\n index = [(0,0) for i in range(H*W+1)]\n A = []\n for i in range(H):\n temp = list(map(int, input().split()))\n for t in temp:\n index[t] = (i,temp.index(t))\n A.append(temp)\n Q = int(input())\n L_R_List = [list(map(int, input().split())) for i in range(Q)]\n\n dp = [0 for i in range(H*W+1)]\n for i in range(D, H*W+1):\n dp[i] = dp[i-D] + calc(index[i], index[i-D])\n for L_R in L_R_List:\n L = L_R[0]\n R = L_R[1]\n print(dp[R]-dp[L])\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s864934209', 's810609600']
[31884.0, 42320.0]
[375.0, 714.0]
[997, 701]
p03426
u267325300
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D = map(int, input().split())\nA = [0] * H * W\nfor i in range(H):\n temp = list(map(int, input().split()))\n for j in range(len(temp)):\n A[temp[j] - 1] = (i + 1, j + 1)\n\nQ = int(input())\nL = []\nR = []\nfor _ in range(Q):\n l, r = map(int, input().split())\n L.append(l)\n R.append(r)\n\n\ndef consumption(point_A, point_B):\n return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])\n\n\nprint(A)\nfor i in range(Q):\n power = 0\n for j in range(int((R[i] - L[i]) / D)):\n power += consumption(A[L[i] + j * D - 1], A[L[i] + (j + 1) * D - 1])\n #print("{}->{}".format(A[L[i] + j * D - 1], A[L[i] + (j + 1) * D - 1]))\n print(power)\n', 'H, W, D = map(int, input().split())\nA = [0] * H * W\nfor i in range(H):\n temp = list(map(int, input().split()))\n for j in range(len(temp)):\n A[temp[j] - 1] = (i + 1, j + 1)\n\nQ = int(input())\nL = []\nR = []\nfor _ in range(Q):\n l, r = map(int, input().split())\n L.append(l)\n R.append(r)\n\n\ndef consumption(point_A, point_B):\n return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])\n\n\nprint(A)\nassert len(A) == H * W\nfor i in range(Q):\n power = 0\n for j in range(int((R[i] - L[i]) / D)):\n power += consumption(A[L[i] + j * D - 1], A[L[i] + (j + 1) * D - 1])\n #print("{}->{}".format(A[L[i] + j * D - 1], A[L[i] + (j + 1) * D - 1]))\n print(power)\n', 'H, W, D = map(int, input().split())\nA = [0] * H * W\nfor i in range(H):\n temp = list(map(int, input().split()))\n for j in range(len(temp)):\n A[temp[j] - 1] = (i + 1, j + 1)\n\nQ = int(input())\nL = []\nR = []\nfor _ in range(Q):\n l, r = map(int, input().split())\n L.append(l)\n R.append(r)\n\n\ndef consumption(point_A, point_B):\n return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])\n\n\nX = []\nfor i in [D] + list(range(1, D)):\n power = 0\n x = [0]\n for j in range(int((H * W - i) / D)):\n power += consumption(A[i - 1 + j * D], A[i - 1 + (j + 1) * D])\n x.append(power)\n #print("{}->{}".format(A[i - 1], A[i - 1 + (j + 1) * D]))\n X.append(x)\n# print(X)\nfor i in range(Q):\n l = int(L[i] / D)\n r = int(R[i] / D)\n #print(X[L[i] % D], l, r)\n print(X[L[i] % D][r] - X[L[i] % D][l])\n', 'H, W, D = map(int, input().split())\nA = [0] * H * W\nfor i in range(H):\n temp = list(map(int, input().split()))\n for j in range(len(temp)):\n A[temp[j] - 1] = (i + 1, j + 1)\n\nQ = int(input())\nL = []\nR = []\nfor _ in range(Q):\n l, r = map(int, input().split())\n L.append(l)\n R.append(r)\n\n\ndef consumption(point_A, point_B):\n return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])\n\n\nX = []\nfor i in [D] + list(range(1, D)):\n power = 0\n x = [0]\n for j in range(int((H * W - i) / D)):\n power += consumption(A[i - 1 + j * D], A[i - 1 + (j + 1) * D])\n x.append(power)\n #print("{}->{}".format(A[i - 1], A[i - 1 + (j + 1) * D]))\n X.append(x)\n# print(X)\nfor i in range(Q):\n k = L[i] % D\n if k == 0:\n l = int((L[i] - D) / D)\n r = int((R[i] - D) / D)\n else:\n l = int((L[i] - k) / D)\n r = int((R[i] - k) / D)\n #print(X[k], l, r)\n print(X[k][r] - X[k][l])\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s123647011', 's721217892', 's807859337', 's996668782']
[21284.0, 21284.0, 31328.0, 30888.0]
[2105.0, 2105.0, 482.0, 639.0]
[675, 698, 848, 953]
p03426
u272557899
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d = map(int, input().split())\na = []\n\nPY = [list(map(int, input().split())) + [i] for i in range(h)]\nfor i in range(h):\n a.append([int(m) for m in input().split()])\n\nq = int(input())\nlr = []\nfor i in range(q):\n lr.append([int(m) for m in input().split()])\n\nrea = []\nfor i in range(h * w):\n rea.append([])\nfor i in range(h):\n for j in range(w):\n rea[i].append([])\n\n\nfor i in range(h):\n for j in range(w):\n rea[w*i+j].append(a[i][j])\n rea[w*i+j].append(i)\n rea[w*i+j].append(j)\n\nrea.sort()\n\npre = []\nfor i in range(h*w):\n pre.append([])\n\nfor i in range(h):\n for j in range(w):\n lmn = 0\n pre[w * i + j].append(lmn)\n for k in range(i, h*w,d):\n lmn += abs(rea[w*i+j + k][1] - rea[w*i+j+d + k][1]) + abs(rea[w*i+j + k][2]- rea[w*i+j+d + k][2])\n pre[w*i+j].append(lmn)\n\nfor i in range(q):\n print(pre[lr[i][0] - 1][(lr[i][1]-lr[i][0])//d - 1])', 'h,w,d = map(int, input().split())\na = []\n\nfor i in range(h):\n a.append([int(m) for m in input().split()])\n\nq = int(input())\nlr = []\nfor i in range(q):\n lr.append([int(m) for m in input().split()])\n\nrea = []\nfor i in range(h * w):\n rea.append([])\n\n\nfor i in range(h):\n for j in range(w):\n rea[w*i+j].append(a[i][j])\n rea[w*i+j].append(i)\n rea[w*i+j].append(j)\n\nrea.sort()\n\npre = []\nfor i in range(h*w):\n pre.append([])\np = 0\nfor i in range(h):\n if p == 1:\n break\n for j in range(w):\n if w * i + j + 1 <= d:\n lmn = 0\n pre[w * i + j].append(lmn)\n\n for k in range(0,h*w,d):\n if w*i+j + d + k < h*w:\n lmn += abs(rea[w*i+j + k][1] - rea[w*i+j+d + k][1]) + abs(rea[w*i+j + k][2]- rea[w*i+j+d + k][2])\n pre[w*i+j].append(lmn)\n else:\n break\n else:\n p = 1\n break\n\nfor i in range(q):\n print(pre[(lr[i][0] - 1) % d][(lr[i][1] - 1)//d] - pre[(lr[i][0] - 1) % d][(lr[i][0] - 1)//d])']
['Runtime Error', 'Accepted']
['s108181350', 's328086607']
[6644.0, 47332.0]
[39.0, 901.0]
[952, 1094]
p03426
u273201018
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['import cython\n\n\nH, W, D = map(int, input().split())\n\nA = [False] * (H * W + 1)\n\nfor i in range(H):\n l = list(map(int, input().split()))\n for j in range(W):\n A[l[j]] = (i, j)\n\nQ = int(input())\n\nfor i in range(Q):\n L, R = map(int, input().split())\n cost = 0\n while L != R:\n start = A[L]\n stop = A[L+D]\n cost += abs(start[0] - stop[0]) + abs(start[1] - stop[1])\n start = stop\n L += D\n print(cost, flush=True)\n', 'H, W, D = map(int, input().split())\n\nA = []\n\nfor i in range(H):\n l = list(map(int, input().split()))\n for j in range(W):\n A[l[j]] = (i, j)\n\nQ = int(input())\n\nfor i in range(Q):\n L, R = map(int, input().split())\n cost = 0\n while L != R:\n start = A[L]\n stop = A[L+D]\n cost += abs(start[0] - stop[0]) + abs(start[1] - stop[1])\n start = stop\n L += D\n print(cost, flush=True)', 'def func():\n H, W, D = map(int, input().split())\n\n MAP = [None] * (H*W+1)\n COST = {}\n\n for i in range(H):\n for j, str_l in enumerate(input().split()):\n MAP[int(str_l)] = (i, j)\n\n Q = int(input())\n\n for i in range(Q):\n L, R = map(int, input().split())\n cost = 0\n keys = COST.keys()\n for j in range(int((R-L)/D)):\n try:\n cost += COST[L+D*j]\n except:\n COST[L+D*j] = abs(MAP[L][0] - MAP[L+D*j][0]) + abs(MAP[L][1] - MAP[L+D*j][1])\n cost += COST[L+D*j]\n print(cost)\n\nfunc()', '# speed-test\n\n\nh,w,d = map(int,input().split())\n \ndic = {}\nfor i in range(h):\n a = input().split()\n for j in range(w):\n dic[int(a[j])] = (i+1,j+1)\n \nq = int(input())\nc = [0]*(h*w+1)\nfor i in range(d+1,h*w+1):\n pi,pj = dic[i]; qi,qj = dic[i-d]\n c[i] = c[i-d] + abs(pi-qi) + abs(pj-qj)\n \nfor i in range(q):\n l,r = map(int,input().split())\n print(c[r]-c[l])\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s015576435', 's454302877', 's999566190', 's607266068']
[3064.0, 3064.0, 22780.0, 24512.0]
[18.0, 18.0, 2105.0, 970.0]
[467, 431, 607, 445]
p03426
u285891772
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
["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\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 fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10**9 + 7\n#from decimal import *\n\nH, W, D = MAP()\nA = [LIST() for _ in range(H)]\n\ndic = defaultdict(tuple)\n\nfor y in range(H):\n\tfor x in range(W):\n\t\tdic[A[y][x]] = (y+1, x+1)\n\npower = [[] for _ in range(D)]\nfor i in range(H*W):\n\tif i <= D:\n\t\tpower[i%D].append(0)\n\telse:\n\t\tidx = i%D\n\t\ttmp = abs(dic[i][0]-dic[i-D][0]) + abs(dic[i][1]-dic[i-D][1])\n\t\tpower[i%D].append(tmp)\n\npower_acc = []\nfor x in power:\n\tpower_acc.append(list(accumulate(x)))\n\nQ = INT()\nfor _ in range(Q):\n\tL, R = MAP()\n\tprint(power_acc[L%D][R//D] - power_acc[R%D][L//D])", "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\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 fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10**9 + 7\n#from decimal import *\n\nH, W, D = MAP()\nA = [LIST() for _ in range(H)]\n\ndic = defaultdict(tuple)\n\nfor y in range(H):\n\tfor x in range(W):\n\t\tdic[A[y][x]] = (y+1, x+1)\n\npower = [[] for _ in range(D)]\nfor i in range(1, H*W+1):\n\tif i <= D:\n\t\tpower[i%D].append(0)\n\telse:\n\t\tidx = i%D\n\t\ttmp = abs(dic[i][0]-dic[i-D][0]) + abs(dic[i][1]-dic[i-D][1])\n\t\tpower[i%D].append(tmp)\n\n#print(power)\npower_acc = []\nfor x in power:\n\tpower_acc.append(list(accumulate(x)))\npower_acc[0].insert(0, 0)\n#print(power_acc)\n\nQ = INT()\nfor _ in range(Q):\n\tL, R = MAP()\n\tprint(power_acc[R%D][R//D-1] - power_acc[L%D][L//D-1])", "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\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 fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10**9 + 7\n#from decimal import *\n\nH, W, D = MAP()\nA = [LIST() for _ in range(H)]\n\ndic = defaultdict(tuple)\n\nfor y in range(H):\n\tfor x in range(W):\n\t\tdic[A[y][x]] = (y+1, x+1)\n\npower = [[] for _ in range(D)]\nfor i in range(1, H*W+1):\n\tif i <= D:\n\t\tpower[i%D].append(0)\n\telse:\n\t\tidx = i%D\n\t\ttmp = abs(dic[i][0]-dic[i-D][0]) + abs(dic[i][1]-dic[i-D][1])\n\t\tpower[i%D].append(tmp)\n\npower_acc = []\nfor x in power:\n\tpower_acc.append(list(accumulate(x)))\n\nQ = INT()\nfor _ in range(Q):\n\tL, R = MAP()\n\tprint(power_acc[R%D][R//D] - power_acc[L%D][L//D])", "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\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7 \n#mod = 998244353\nfrom decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nH, W, D = MAP()\nA = [LIST() for _ in range(H)]\nQ = INT()\nLR = [LIST() for _ in range(Q)]\n\ndic = [[] for _ in range(D)]\n\nfor y in range(H):\n\tfor x in range(W):\n\t\t#print(dic)\n\t\tdic[A[y][x]%D].append([A[y][x], y, x])\n\nfor lis in dic:\n\tlis.sort(key = lambda x:x[0])\n\nfor lis in dic:\n\tlis[0][0] = 0\n\tfor i in range(len(lis)):\n\t\tif i == len(lis)-1:\n\t\t\tbreak\n\t\tpoint = (lis[i][1], lis[i][2])\n\t\tdist_point = (lis[i+1][1], lis[i+1][2])\n\t\tlis[i+1][0] = lis[i][0] + abs(point[0] - dist_point[0]) + abs(point[1]-dist_point[1])\n\nprint(dic)\nfor L, R in LR:\n\tprint(dic[R%D][ceil(R/D)-1][0] - dic[R%D][ceil(L/D)-1][0])\n\n", "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\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7 \n#mod = 998244353\nfrom decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nH, W, D = MAP()\nA = [LIST() for _ in range(H)]\nQ = INT()\nLR = [LIST() for _ in range(Q)]\n\ndic = [[] for _ in range(D)]\n\nfor y in range(H):\n\tfor x in range(W):\n\t\t#print(dic)\n\t\tdic[A[y][x]%D].append([A[y][x], y, x])\n\nfor lis in dic:\n\tlis.sort(key = lambda x:x[0])\n\nfor lis in dic:\n\tlis[0][0] = 0\n\tfor i in range(len(lis)):\n\t\tif i == len(lis)-1:\n\t\t\tbreak\n\t\tpoint = (lis[i][1], lis[i][2])\n\t\tdist_point = (lis[i+1][1], lis[i+1][2])\n\t\tlis[i+1][0] = lis[i][0] + abs(point[0] - dist_point[0]) + abs(point[1]-dist_point[1])\n\n#print(dic)\nfor L, R in LR:\n\tprint(dic[R%D][ceil(R/D)-1][0] - dic[R%D][ceil(L/D)-1][0])\n\n"]
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s138074478', 's391228105', 's927882198', 's934045385', 's619980032']
[45064.0, 44904.0, 44944.0, 53184.0, 50768.0]
[205.0, 344.0, 206.0, 617.0, 519.0]
[1378, 1445, 1383, 1528, 1529]
p03426
u309977459
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\npos = [None]*(H*W+1)\nfor i, elem in enumerate(A):\n for j, a in enumerate(elem):\n pos[a] = (i, j)\nacc = [[] for _ in range(D+1)]\nfor i in range(1, D+1):\n tmp = i\n s = 0\n acc[i].append(s)\n while tmp <= H*W-D:\n s += abs(pos[tmp][0]-pos[tmp+D][0])+abs(pos[tmp][1]-pos[tmp+D][1])\n acc[i].append(s)\n tmp += D\n\nfor _ in range(Q):\n L, R = map(int, input().split())\n print(acc[(R-1) % D+1][(R-R % D-1)//D+1] -\n acc[(R-1) % D+1][(L-L % D-1)//D+1])\n', 'H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\npos = [None]*(H*W+1)\nfor i, elem in enumerate(A):\n for j, a in enumerate(elem):\n pos[a] = (i, j)\nacc = [[] for _ in range(D+1)]\nfor i in range(1, D+1):\n tmp = i\n s = 0\n acc[i].append(s)\n while tmp <= H*W-D:\n s += abs(pos[tmp][0]-pos[tmp+D][0])+abs(pos[tmp][1]-pos[tmp+D][1])\n acc[i].append(s)\n tmp += D\n\nfor _ in range(Q):\n L, R = map(int, input().split())\n print(acc[(R-1) % D+1][(R-R % D)//D-(R % D == 0)] -\n acc[(R-1) % D+1][(L-L % D)//D-(L % D == 0)])\n']
['Runtime Error', 'Accepted']
['s952482209', 's290205753']
[24112.0, 24240.0]
[323.0, 1091.0]
[605, 623]
p03426
u343523393
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
["import sys\nimport math\nimport numpy as np\nstdin = sys.stdin\n \nni = lambda: int(ns())\nna = lambda: list(map(int, input().split()))\nns = lambda: input()\nH,W,D = na()\nf= [list(map(int,input().split())) for i in range(H)]\n#print(f)\nf = np.array(f)\nQ=int(input())\n'''\nli = [0]*(H*W+2)\nfor i in range(1,D+1):\n li[i]=0\n h_=int(np.where(f==i)[0])\n w_=int(np.where(f==i)[1])\n for j in range(i+D,H*W+1,D):\n h_n=int(np.where(f==j)[0])\n w_n=int(np.where(f==j)[1])\n li[j] = li[j-D]+abs(h_ - h_n)+abs(w_ - w_n)\n h_ = h_n\n w_ = w_n\nfor i in range(Q):\n L,R = na()\n print(li[R]-li[L])\n'''\n\nli ={}\nfor i in range(H):\n for j in range(W):\n li[f[i][j]]=[i,j]\nres=[0]*(H*W+1)\nfor i in range(1,D+1):\n for j in range(i+D,W*H+1,D):\n res[j] += abs(li[j-D][0]-li[j][0]) + abs(li[j-D][1]-li[j][1])\n\nfor i in range(Q):\n L,R = na()\n print(res[R]-res[L])\n", 'import sys\nimport math\nimport numpy as np\nstdin = sys.stdin\n \nni = lambda: int(ns())\nna = lambda: list(map(int, input().split()))\nns = lambda: input()\nH,W,D = na()\nf= [list(map(int,input().split())) for i in range(H)]\n#print(f)\nf = np.array(f)\nQ=int(input())\n\'\'\'\nli = [0]*(H*W+2)\nfor i in range(1,D+1):\n li[i]=0\n h_=int(np.where(f==i)[0])\n w_=int(np.where(f==i)[1])\n for j in range(i+D,H*W+1,D):\n h_n=int(np.where(f==j)[0])\n w_n=int(np.where(f==j)[1])\n li[j] = li[j-D]+abs(h_ - h_n)+abs(w_ - w_n)\n h_ = h_n\n w_ = w_n\nfor i in range(Q):\n L,R = na()\n print(li[R]-li[L])\n\'\'\'\n\nli ={}\nfor i in range(H):\n for j in range(W):\n li[f[i][j]]=[i+1,j+1]\nres=[0]*(H*W+1)\nfor i in range(1,D+1):\n for j in range(i+D,W*H+1,D):\n #print("j",j)\n #print(li[j][0],li[j][1])\n res[j] = res[j-D] +abs(li[j-D][0]-li[j][0]) + abs(li[j-D][1]-li[j][1])\n#print(res)\nfor i in range(Q):\n L,R = na()\n print(res[R]-res[L])\n']
['Wrong Answer', 'Accepted']
['s908288778', 's565238338']
[33320.0, 35560.0]
[1523.0, 1546.0]
[903, 983]
p03426
u346308892
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['\n#import numpy as np\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\nH, W, D = acinput()\n# Ad={}\nAd = [0]*(H*W+1)\nfor i in range(H):\n ar = acinput()\n for j, sar in enumerate(ar):\n # Ad[sar]=np.array((i,j))\n Ad[sar] = (i, j)\n\n#dp = [[0 for j in range(H*W+1)]for i in range(H*W+1)]\nd = [0]*(H*W+1)\n\n# for x in range(1, H*W+1):\n# dp[x][x]=0\n\ny = D+1\nwhile True:\n if y > H*W:\n break\n # print(x,y)\n #tmp = Ad[y]-Ad[y-D]\n #S = np.sum(np.abs(tmp[0])+abs(tmp[1]))\n #tmp = Ad[y]-Ad[y-D]\n S = abs(Ad[y][0]-Ad[y-D][0])+abs(Ad[y][1]-Ad[y-D][1])\n\n # dp[x][y]=dp[x][y-D]+S\n d[y] = d[y-D]+S\n y += 1\n\n\n# print(np.array(dp))\n\nQ = int(input())\nfor i in range(Q):\n l, r = acinput()\n print(d[r]-d[l])\n\n\n# print(Ad)\n# print(np.array(dp))\nprint(d)', '\n#import numpy as np\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\nH, W, D = acinput()\n# Ad={}\nAd = [0]*(H*W+1)\nfor i in range(H):\n ar = acinput()\n for j, sar in enumerate(ar):\n # Ad[sar]=np.array((i,j))\n Ad[sar] = (i, j)\n\n#dp = [[0 for j in range(H*W+1)]for i in range(H*W+1)]\nd = [0]*(H*W+1)\n\n# for x in range(1, H*W+1):\n# dp[x][x]=0\n\ny = D+1\nwhile True:\n if y > H*W:\n break\n # print(x,y)\n #tmp = Ad[y]-Ad[y-D]\n #S = np.sum(np.abs(tmp[0])+abs(tmp[1]))\n #tmp = Ad[y]-Ad[y-D]\n S = abs(Ad[y][0]-Ad[y-D][0])+abs(Ad[y][1]-Ad[y-D][1])\n\n # dp[x][y]=dp[x][y-D]+S\n d[y] = d[y-D]+S\n y += 1\n\n\n# print(np.array(dp))\n\nQ = int(input())\nfor i in range(Q):\n l, r = acinput()\n print(d[r]-d[l])\n\n\n# print(Ad)\n# print(np.array(dp))\n#print(d)']
['Wrong Answer', 'Accepted']
['s920811703', 's416240908']
[16888.0, 14396.0]
[1038.0, 1009.0]
[970, 971]
p03426
u347640436
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\n\nd = {}\nfor y in range(H):\n for x in range(W):\n d[A[y][x]] = (y, x)\n\nt = [[0] * (H * W // D + 1) for _ in range(D)]\nfor i in range(D):\n j = 0\n if i == 0:\n j = 1\n while i + (j + 1) * D <= H * W:\n y1, x1 = d[i + j * D]\n y2, x2 = d[i + (j + 1) * D]\n t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)\n j += 1\n for j in range(len(H * W // D + 1) - 1):\n t[i][j + 1] += t[i][j]\n\nQ = int(input())\nfor _ in range(Q):\n L, R = map(int, input().split())\n i = L % D\n print(t[i][(R - i) // D] - t[i][(L - i) // D])\n', "H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\n\nd = {}\nfor y in range(H):\n for x in range(W):\n d[A[y][x]] = (y, x)\n\nt = [[0] * (H * W // D + 1) for _ in range(D)]\nfor i in range(D):\n j = 0\n if i == 0:\n j = 1\n while i + (j + 1) * D <= H * W:\n y1, x1 = d[i + j * D]\n y2, x2 = d[i + (j + 1) * D]\n t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)\n j += 1\n for j in range(H * W // D):\n t[i][j + 1] += t[i][j]\n\nQ = int(input())\nresult = []\nfor _ in range(Q):\n L, R = map(int, input().split())\n i = L % D\n result.append(t[i][(R - i) // D] - t[i][(L - i) // D])\n\nprint(*result, sep='\\n')\n"]
['Runtime Error', 'Accepted']
['s565873746', 's534134760']
[28136.0, 34964.0]
[200.0, 388.0]
[658, 732]
p03426
u350997995
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['#19:38\n#20:19\n\nH,W,D = map(int,input().split())\nMAX = H*W\nA = [list(map(int,input().split())) for i in range(H)]\nPoint = [0]*(MAX+1)\nfor h in range(H):\n for w in range(W):\n Point[A[h][w]] = (h,w)\nK = []\nfor i in range(1,D+1):\n List = []\n n = i\n h,w = Point[n]\n cost = 0\n while n<=MAX:\n y,x = Point[n]\n cost += abs(h-y)+abs(w-x)\n List.append(cost)\n h,w = y,x\n n+=D\n K.append(List)\nQ = int(input())\nfor k in K:print(k)\nfor i in range(Q):\n L,R = map(int,input().split())\n a,l,r = (L-1)%D,L//D,R//D\n try:\n print(K[a][r]-K[a][l])\n except:\n print(K[a][r-1]-K[a][l-1])', '#19:38\n#20:19\n\nH,W,D = map(int,input().split())\nMAX = H*W\nA = [list(map(int,input().split())) for i in range(H)]\nPoint = [0]*(MAX+1)\nfor h in range(H):\n for w in range(W):\n Point[A[h][w]] = (h,w)\nK = []\nfor i in range(1,D+1):\n List = []\n n = i\n h,w = Point[n]\n cost = 0\n while n<=MAX:\n y,x = Point[n]\n cost += abs(h-y)+abs(w-x)\n List.append(cost)\n h,w = y,x\n n+=D\n K.append(List)\nQ = int(input())\nfor i in range(Q):\n L,R = map(int,input().split())\n a,l,r = (L-1)%D,(L-1)//D,(R-1)//D\n print(K[a][r]-K[a][l])']
['Wrong Answer', 'Accepted']
['s409104936', 's291754700']
[25252.0, 24304.0]
[1118.0, 1022.0]
[650, 578]
p03426
u365364616
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h, w, d = map(int, input().split())\nx = []\nz = [[0, 0] for i in range(h * w)]\nfor i in range(h):\n x.append(list(map(int, input().split())))\n for j in range(w):\n z[x[i][j] - 1] = [i + 1, j + 1]\nprint(z)\ns = [0 for _ in range(d)]\nfor i in range(d):\n a = z[max(0, i - 1)]\n b = z[d + i - 1]\n s[i] = [abs(a[0] - b[0]) + abs(a[1] - b[1])]\n j = 1\n while(True):\n if d * (j + 1) + i <= h * w:\n a = z[d * j + i - 1]\n b = z[d * (j + 1) + i - 1]\n s[i].append(s[i][-1] + abs(a[0] - b[0]) + abs(a[1] - b[1]))\n j += 1\n else:\n break\n\nQ = int(input())\nans = [0 for _ in range(Q)]\nfor i in range(Q):\n L, R = map(int, input().split())\n if L == R:\n ans[i] = 0\n elif L // d - 1 < 0:\n ans[i] = s[R % d][R // d - 1]\n else:\n ans[i] = s[R % d][R // d - 1] - s[L % d][L // d - 1]\nfor i in range(Q):\n print(ans[i])', 'h, w, d = map(int, input().split())\nx = []\nz = [None for i in range(h * w)]\nfor i in range(h):\n x.append(list(map(int, input().split())))\n for j in range(w):\n z[x[i][j] - 1] = [i + 1, j + 1]\n\ns = [None for _ in range(d)]\nfor i in range(min(d, h * w - d + 1)):\n a = z[max(0, i - 1)]\n b = z[d + i - 1]\n s[i] = [abs(a[0] - b[0]) + abs(a[1] - b[1])]\n j = 1\n while(True):\n if d * (j + 1) + i <= h * w:\n a = z[d * j + i - 1]\n b = z[d * (j + 1) + i - 1]\n s[i].append(s[i][-1] + abs(a[0] - b[0]) + abs(a[1] - b[1]))\n j += 1\n else:\n break\n\nQ = int(input())\nans = [None for _ in range(Q)]\nfor i in range(Q):\n L, R = map(int, input().split())\n if L == R:\n ans[i] = 0\n elif L // d - 1 < 0:\n ans[i] = s[R % d][R // d - 1]\n else:\n ans[i] = s[R % d][R // d - 1] - s[L % d][L // d - 1]\nfor i in range(Q):\n print(ans[i])']
['Runtime Error', 'Accepted']
['s152479360', 's558015132']
[26388.0, 25372.0]
[721.0, 656.0]
[920, 936]
p03426
u391475811
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H,W,D=map(int,input().split())\nd=[[0,0] for i in range(H*W+1)]\nd2=[0 for i in range(H*W+1)]\nfor j in range(H):\n a=[int(x) for x in input().split()]\n for k in range(W):\n d[a[k]]=[j+1,k+1]\nfor l in range(D+1,H*W+1-D):\n d2[l]=abs(d[l][0]-d[l-D][0])+abs(d[l][1]-d[l-D][1])\nfor m in range(D+1,H*W+1-D):\n d2[m]+=d2[m-D]\nQ=int(input())\nfor i in range(Q):\n a,b=map(int,input().split())\n if a==b:\n print(0)\n else:\n ans=d2[b]-d2[a]\n print(ans)', 'H,W,D=map(int,input().split())\nd=[[0,0] for i in range(H*W+1)]\nd2=[0 for i in range(H*W+1)]\nfor j in range(H):\n a=[int(x) for x in input().split()]\n for k in range(W):\n d[a[k]]=[j+1,k+1]\nfor l in range(D+1,H*W+1):\n d2[l]=abs(d[l][0]-d[l-D][0])+abs(d[l][1]-d[l-D][1])\nfor m in range(D+1,H*W+1):\n d2[m]+=d2[m-D]\nQ=int(input())\nfor i in range(Q):\n a,b=map(int,input().split())\n if a==b:\n print(0)\n else:\n ans=d2[b]-d2[a]\n print(ans)']
['Wrong Answer', 'Accepted']
['s638877875', 's186221910']
[17552.0, 17680.0]
[1003.0, 1024.0]
[452, 448]
p03426
u411537765
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D = map(int, input().split())\nA = []\nC = [0 for _ in range(H * W + 1)]\nfor h in range(H):\n A.append(list(map(int, input().split())))\nfor i in range(H):\n for j in range(W):\n C[A[i][j]] = (i, j)\nh = [0 for _ in range(H * W + 1)]\nfor i in range(D):\n s = 0\n for j in range(i, H * W, D):\n if j != i:\n print(j)\n n = (C[j + 1][0], C[j + 1][1])\n p = (C[j + 1 - D][0], C[j + 1 - D][1])\n s += abs(n[0] - p[0]) + abs(n[1] - p[1])\n h[j + 1] = s\nQ = int(input())\nfor _ in range(Q):\n l, r = map(int, input().split())\n print(h[r] - h[l])\n', 'H, W, D = map(int, input().split())\nA = []\nC = [0 for _ in range(H * W + 1)]\nfor h in range(H):\n A.append(list(map(int, input().split())))\nfor i in range(H):\n for j in range(W):\n C[A[i][j]] = (i, j)\nprint(A)\nprint(C)\nh = [0 for _ in range(H * W + 1)]\nfor i in range(D):\n s = 0\n for j in range(i, H * W, D):\n if j != i:\n print(j)\n n = (C[j + 1][0], C[j + 1][1])\n p = (C[j + 1 - D][0], C[j + 1 - D][1])\n s += abs(n[0] - p[0]) + abs(n[1] - p[1])\n h[j + 1] = s\nQ = int(input())\nfor _ in range(Q):\n l, r = map(int, input().split())\n print(h[r] - h[l])\n', 'H, W, D = map(int, input().split())\nA = []\nC = [0 for _ in range(H * W + 1)]\nfor h in range(H):\n A.append(list(map(lambda x: int(x) - 1, input().split())))\nfor i in range(H):\n for j in range(W):\n C[A[i][j]] = (i, j)\nh = [0 for _ in range(H * W)]\nfor i in range(D):\n s = 0\n for j in range(i, H * W, D):\n if j != i:\n n = (C[j][0], C[j][1])\n p = (C[j - D][0], C[j - D][1])\n s += abs(n[0] - p[0]) + abs(n[1] - p[1])\n h[j] = s\nQ = int(input())\nfor _ in range(Q):\n l, r = map(lambda x: int(x) - 1, input().split())\n print(h[r] - h[l])\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s594317984', 's787246435', 's703281618']
[20232.0, 20372.0, 18096.0]
[1079.0, 1088.0, 1051.0]
[612, 630, 601]
p03426
u411858517
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [list(map(int, input().split())) for _ in range(Q)]\n\nres = 0\nfor i in range(10 **7):\n res += 1\n \n \nprint(res)', 'H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [list(map(int, input().split())) for _ in range(Q)]\n\nres = 0\nfor i in range(10 **8):\n res += 1\n \n \nprint(res)', 'H, W, D = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [list(map(int, input().split())) for _ in range(Q)]\n\nnumber_dict = {}\nfor h in range(H):\n for w in range(W):\n number_dict[A[h][w]] = (w+1, h+1)\n \n \nnumber = [0 for _ in range(H*W+1)]\nfor i in range(H*W):\n now = H * W - i\n \n if now + D > H * W:\n pass\n \n else:\n number[now] = number[now + D] + abs(number_dict[now+D][0] - number_dict[now][0]) + abs(number_dict[now+D][1] - number_dict[now][1])\n \n\nfor i in range(Q):\n res = number[LR[i][0]] - number[LR[i][1]]\n \n print(res)\n \n\n']
['Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s215500943', 's662803744', 's844719808']
[31052.0, 32464.0, 48176.0]
[1461.0, 2105.0, 633.0]
[226, 226, 671]
p03426
u437068347
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['import collections\nimport itertools\nfrom pprint import pprint as pp\n\nH,W,D = tuple(map(int, input().split()))\nA = [tuple(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [tuple(map(int, input().split())) for _ in range(Q)]\n\nArev = [None] * (H*W+1)\nfor h in range(H):\n for w in range(W):\n Arev[A[h][w]] = (h,w)\n\ntbl = []\nfor i in range(D):\n i += 1\n ary = []\n mp = 0\n start = Arev[i]\n for x in range(i, H*W, D):\n next_ = Arev[x]\n mp += abs(start[0]-next_[0]) + abs(start[1]-next_[1])\n ary.append((x,mp))\n start = next_\n tbl.append(ary)\npp(tbl)\nfor L,R in LR:\n col1, row = divmod(L, D)\n col2 = R // D\n if row == 0:\n col1 -= 1\n col2 -= 1\n row -= 1\n pp((row,col1,col2))\n print(tbl[row][col2][1] - tbl[row][col1][1])\n', 'import collections\nimport itertools\nfrom pprint import pprint as pp\n\nH,W,D = tuple(map(int, input().split()))\nA = [tuple(map(int, input().split())) for _ in range(H)]\nQ = int(input())\nLR = [tuple(map(int, input().split())) for _ in range(Q)]\n\nArev = [None] * (H*W+1)\nfor h in range(H):\n for w in range(W):\n Arev[A[h][w]] = (h,w)\n\ntbl = []\nfor i in range(D):\n ary = []\n mp = 0\n start = Arev[i+1]\n for x in range(i, H*W, D):\n next_ = Arev[x+1]\n mp += abs(start[0]-next_[0]) + abs(start[1]-next_[1])\n ary.append((x+1,mp))\n start = next_\n tbl.append(ary)\n#pp(A)\n#pp(tbl)\nfor L,R in LR:\n col1, row = divmod(L, D)\n col2 = R // D\n if row == 0:\n col1 -= 1\n col2 -= 1\n row -= 1\n #pp((row,col1,col2))\n print(tbl[row][col2][1] - tbl[row][col1][1])\n']
['Runtime Error', 'Accepted']
['s770489490', 's543131015']
[55580.0, 47544.0]
[2107.0, 695.0]
[764, 770]
p03426
u474270503
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H, W, D=map(int, input().split())\npos={}\nfor i in range(H):\n A=list(map(int, input().split()))\n for j in range(W):\n pos[A[j]]=(i, j)\np=[0]*(H*W)\nfor i in range(D+1,H*W+1):\n p[i]=p[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])\nQ=int(input())\nfor _ in range(Q):\n L, R=map(int, input().split())\n print(p[R]-p[L])\n', 'H, W, D=map(int, input().split())\npos={}\nfor i in range(H):\n A=list(map(int, input().split()))\n for j in range(W):\n pos[A[j]]=(i, j)\np=[0]*(H*W+1)\nfor i in range(D+1,H*W+1):\n p[i]=p[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])\nprint(p)\nQ=int(input())\nfor _ in range(Q):\n L, R=map(int, input().split())\n print(p[R]-p[L])\n', 'H, W, D=map(int, input().split())\npos={}\nfor i in range(H):\n A=list(map(int, input().split()))\n for j in range(W):\n pos[A[j]]=(i, j)\np=[0]*(H*W+1)\nfor i in range(D+1,H*W+1):\n p[i]=p[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])\nQ=int(input())\nfor _ in range(Q):\n L, R=map(int, input().split())\n print(p[R]-p[L])\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s259530157', 's792145498', 's267077622']
[21672.0, 24996.0, 22568.0]
[228.0, 977.0, 969.0]
[345, 356, 347]
p03426
u476604182
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
["H, W, D, *L = map(int, open('0').read().split())\nA = L[:W*H]\nQ = L[H*W]\ninf = []\nfor l,r in zip(*[iter(L[H*W+1:])]*2):\n inf += [(l,r)]\ndic = {A[i*W+j]:(i,j) for i in range(H) for j in range(W)}\nls = [[] for i in range(D)]\nfor i in range(D):\n s = i if i!=0 else D\n ls[i].append(0)\n m = s\n n = s\n while True:\n n += D\n if H*W<n:\n n = s\n px, py = dic[m]\n x, y = dic[n]\n ls[i].append(ls[i][-1]+abs(px-x)+abs(py-y))\n m = n\n if m==s:\n break\nfor l, r in inf:\n i = l%D\n if i==0:\n il = (l-D)//D\n ir = (r-D)//D\n else:\n il = (l-i)//D\n ir = (r-i)//D\n if l<r:\n print(ls[i][ir] - ls[i][il])\n elif l>r:\n print(ls[i][-1]-ls[i][il]+ls[i][ir])\n else:\n print(0)", 'H, W, D, *L = map(int, open(0).read().split())\nA = L[:W*H]\nQ = L[H*W]\ninf = []\nfor l,r in zip(*[iter(L[H*W+1:])]*2):\n inf += [(l,r)]\ndic = {A[i*W+j]:(i,j) for i in range(H) for j in range(W)}\nls = [[] for i in range(D)]\nfor i in range(D):\n s = i if i!=0 else D\n ls[i].append(0)\n m = s\n n = s\n while True:\n n += D\n if H*W<n:\n n = s\n px, py = dic[m]\n x, y = dic[n]\n ls[i].append(ls[i][-1]+abs(px-x)+abs(py-y))\n m = n\n if m==s:\n break\nfor l, r in inf:\n i = l%D\n if i==0:\n il = (l-D)//D\n ir = (r-D)//D\n else:\n il = (l-i)//D\n ir = (r-i)//D\n if l<r:\n print(ls[i][ir] - ls[i][il])\n elif l>r:\n print(ls[i][-1]-ls[i][il]+ls[i][ir])\n else:\n print(0)']
['Runtime Error', 'Accepted']
['s105676480', 's480635903']
[3064.0, 46104.0]
[17.0, 409.0]
[705, 703]
p03426
u497046426
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['import numpy as np\n\nH, W, D = map(int, input().split())\npos = [None]*(H*W)\n\nfor i in range(H):\n row = list(map(int, input().split()))\n for j in row:\n pos[row[j]] = (i, j)\n\nQ = int(input())\nfor _ in range(Q):\n L, R = map(int, input().split())\n if L == R:\n print(0)\n else:\n to_be_checked = [i for i in range(L, R+1, D)]\n moves = len(to_be_checked)\n pos_list = [tpl for tpl in to_be_checked]\n\n MP = sum([np.absolute(pos_list[i][0] - pos_list[i+1][0]) for i in range(moves-1)]) + sum([np.absolute(pos_list[i][1] - pos_list[i+1][1]) for i in range(moves-1)])\n\n print(MP)', 'H, W, D = map(int, input().split())\nposition = {}\n\nfor i in range(H):\n row = list(map(int, input().split()))\n for j, value in enumerate(row):\n position[value] = (i, j)\n\ncosts = {i: 0 for i in range(1, D+1)}\nfor i in range(1, D+1):\n current = i + D\n while current <= H*W:\n costs[current] = costs[current-D] + abs(position[current][0] - position[current-D][0]) + abs(position[current][1] - position[current-D][1])\n current += D\n\nQ = int(input())\nfor _ in range(Q):\n L, R = map(int, input().split())\n MP = costs[R] - costs[L]\n print(MP)']
['Runtime Error', 'Accepted']
['s804920073', 's829639581']
[13156.0, 35984.0]
[151.0, 1029.0]
[629, 575]
p03426
u518042385
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['h,w,d=map(int,input().split())\nl={}\nfor i in range(h):\n l1=list(map(int,input().split()))\n for j in l1:\n l[j]=[l1.index(j)+1,i+1]\nli=[]\nfor i in range(1,d+1):\n l11=[]\n c=0\n x=l[i][0]\n y=l[i][1]\n while i<=h*w:\n c+=abs(x-l[i][0])+abs(y-l[i][1])\n l11.append(c)\n x=l[i][0]\n y=l[i][1]\n i+=d\n li.append(l11)\nq=int(input())\nfor i in range(q):\n a,b=map(int,input().split())\n r=a%d\n if r==0:\n print(li[d][b//d-1]-li[d][a//d-1])\n else:\n print(li[r-1][b//d]-li[r-1][a//d])', 'h,w,d=map(int,input().split())\nl={}\nfor i in range(h):\n l1=list(map(int,input().split()))\n for j in l1:\n l[j]=[l1.index(j)+1,i+1]\nli=[]\nfor i in range(1,d+1):\n l11=[]\n c=0\n x=l[i][0]\n y=l[i][1]\n while i<=h*w:\n c+=abs(x-l[i][0])+abs(y-l[i][1])\n l11.append(c)\n x=l[i][0]\n y=l[i][1]\n i+=d\n li.append(l11)\nq=int(input())\nfor i in range(q):\n a,b=map(int,input().split())\n r=a%d\n if r==0:\n print(li[d-1][b//d-1]-li[d-1][a//d-1])\n else:\n print(li[r-1][b//d]-li[r-1][a//d])']
['Runtime Error', 'Accepted']
['s502022856', 's254872156']
[32032.0, 34208.0]
[600.0, 1263.0]
[497, 501]
p03426
u536113865
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['ai = lambda: list(map(int, input().split()))\n\nh,w,d = ai()\nph = [0 for _ in range(h*w + 1)]\npw = [0 for _ in range(h*w + 1)]\n\nfor i in range(h):\n a = ai()\n for j in range(w):\n ph[a[j]] = i\n pw[a[j]] = j\n\n\nscore = [0 for _ in range(h*w + 1)]\nfor i in range(d+1, h*w+1):\n score[i] = score[i-d] + abs(ph[i]-ph[i-d]) + abs(pw[i]-pw[i-d])\n\nprint(score)\n\nq = int(input())\nfor _ in range(q):\n l,r = ai()\n print(score[r]-score[l])', "ai = lambda: list(map(int, input().split()))\n\nh,w,d = ai()\nph = [0 for _ in range(h*w + 1)]\npw = [0 for _ in range(h*w + 1)]\n\nfor i in range(h):\n a = ai()\n for j in range(w):\n ph[a[j]] = i\n pw[a[j]] = j\n\n\nscore = [0 for _ in range(h*w + 1)]\nfor i in range(d+1, h*w+1):\n score[i] = score[i-d] + abs(ph[i]-ph[i-d]) + abs(pw[i]-pw[i-d])\n\n\nq = int(input())\nans = []\nfor _ in range(q):\n l,r = ai()\n ans.append(score[r]-score[l])\nprint(*ans, sep='\\n')\n"]
['Wrong Answer', 'Accepted']
['s343572949', 's656525684']
[10984.0, 15036.0]
[990.0, 497.0]
[451, 475]
p03426
u545368057
2,000
262,144
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
['H,W,D = map(int, input().split())\nfields = []\namaris = [[0] * (H*W) for i in range(D)] \nfor i in range(H):\n row = list(map(int, input().split()))\n がいくつかで分類\n for j,e in enumerate(row):\n n = (e-1) // D\n m = (e-1) % D\n amaris[m][n] = (i,j)\n\n# print(amaris[:10])\nごとに累積和を取っておく\nacc = [[0] * (H*W) for i in range(D)]\nfor i in range(D):\n cnt = 0\n x_pre, y_pre = amaris[i][0]\n for j in range(1,(H*W)//D+1):\n coords = amaris[i][j]\n if isinstance(coords,int): break\n x = coords[0]\n y = coords[1]\n cnt += abs(x-x_pre)+abs(y-y_pre)\n acc[i][j] = cnt\n x_pre = x\n y_pre = y\n\n\nQ = int(input())\nfor i in range(Q):\n l,r = map(int, input().split())\n m = (l-1) % D\n s = (l-1) // D\n g = (r-1) // D\n ans = acc[m][g] - acc[m][s]\n print(ans)\n\n', 'H,W,D = map(int, input().split())\nfields = []\namaris = [[0] * (H*W) for i in range(D)] \nfor i in range(H):\n row = list(map(int, input().split()))\n がいくつかで分類\n for j,e in enumerate(row):\n n = (e-1) // D\n m = (e-1) % D\n amaris[m][n] = (i,j)\n\n# print(amaris[:10])\n\nQ = int(input())\nfor i in range(Q):\n l,r = map(int, input().split())\n m = (l-1) % D\n s = (l-1) // D\n g = (r-1) // D\n coords = amaris[m][s:g+1]\n ans = 0\n x_pre,y_pre = coords[0]\n for x, y in coords[1:]:\n ans += abs(x-x_pre)+abs(y-y_pre) \n x_pre = x\n y_pre = y\n print(ans)\n', 'H, W , D = map(int, input().split())\nfields = []\nX = []\n\n\ndef calc_dist(a,b):\n return abs(a//W-b//W) + abs(a%W-b%W)\nfor i in range(H):\n # fields.append(list(map(int, input().split())))\n X.extend(list(map(int, input().split())))\npairs = [(x-1,i) for i,x in enumerate(X)]\npairs.sort()\nnumbers = [p[1] for p in pairs]\n\n# print(numbers)\nfrom itertools import accumulate\nfrom collections import defaultdict\n\n\nd = defaultdict(list)\nfor i in range(D):\n prev = numbers[i]\n acc = 0\n d[i] = [0]\n for num in numbers[i+D:len(numbers):D]:\n acc += calc_dist(prev,num)\n d[i].append(acc)\n prev = num\n# print(d) \n \n\n\nQ = int(input())\nfor i in range(Q):\n L1,R1 = map(int, input().split())\n L1 -= 1\n R1 -= 1\n acc = d[L1%D]\n # print("acc",acc)\n print(acc[R1//D]-acc[L1//D]) \n']
['Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s429972327', 's573104124', 's953227111']
[1818484.0, 1927924.0, 39880.0]
[2215.0, 2223.0, 1110.0]
[905, 655, 875]