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
|
---|---|---|---|---|---|---|---|---|---|---|
p03426 | u557437077 | 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 = [int(i) for i in input().split()]\na = [[int(j)-1 for j in input().split()] for i in range(h)]\n\nq = int(input())#moving num\nl = [0 for i in range(q)]#start number\nr = [0 for i in range(q)]#finish number\n\nfor i in range(q):\n tmp = input().split()\n l[i]=int(tmp[0])-1\n r[i]=int(tmp[1])-1\nloc = [[0, 0] for i in range(h*w)]\nfor i in range(h):\n for j in range(w):\n loc[a[i][j]][0] = i\n loc[a[i][j]][1] = j\n#print(loc)\ncost = [0 for i in range(int((h*w)/d))]\n#print(cost)\nfor i in range(1, len(cost)):\n cost[i] += abs(loc[(i+1)*d-1][0]-loc[i*d-1][0])\n cost[i] += abs(loc[(i+1)*d-1][1]-loc[i*d-1][1])\n#print(cost)\nfor i in range(1, len(cost)):\n cost[i] += cost[i-1]\nprint(cost)\n\nfor i in range(q):\n print(cost[int(r[i]/d)]-cost[int(l[i]/d)])\n', 'h, w, d = [int(i) for i in input().split()]\na = [[int(j)-1 for j in input().split()] for i in range(h)]\n\nq = int(input())#moving num\nl = [0 for i in range(q)]#start number\nr = [0 for i in range(q)]#finish number\n\nfor i in range(q):\n tmp = input().split()\n l[i]=int(tmp[0])-1\n r[i]=int(tmp[1])-1\nloc = [[0, 0] for i in range(h*w)]\nfor i in range(h):\n for j in range(w):\n loc[a[i][j]][0] = i\n loc[a[i][j]][1] = j\nprint(loc)\nfor i in range(q):\n cost = 0\n for j in range(int((r[i]-l[i])/d)):\n #print("{}->{}:{}+{}".format(l[i]+j*d,l[i]+(j+1)*d,\n #abs(loc[l[i]+(j+1)*d][0]-loc[l[i]+j*d][0]),\n #abs(loc[l[i]+(j+1)*d][1]-loc[l[i]+j*d][1])))\n cost += abs(loc[l[i]+(j+1)*d][0]-loc[l[i]+j*d][0])\n cost += abs(loc[l[i]+(j+1)*d][1]-loc[l[i]+j*d][1])\n print(cost)\n\n', 'import math\ndef func(h, w, d, a, query):\n imos = [0 for _ in range(h*w)]\n pos = [[0, 0] for _ in range(h*w)]\n for i in range(h):\n for j in range(w):\n pos[a[i][j]] = [i, j]\n for i in range(d):\n for j in range(math.ceil((h*w-i)/d)):\n if j == 0:\n continue\n else:\n imos[i + d * j] = imos[i + d * (j-1)]\\\n + abs(pos[i + d * j][0] - pos[i + d * (j-1)][0])\\\n + abs(pos[i + d * j][1] - pos[i + d * (j-1)][1])\n for i in range(len(query)):\n print(imos[query[i][1]] - imos[query[i][0]])\n return\nh, w, d = [int(i) for i in input().split()]\na = [[0 for _ in range(w)] for _ in range(h)]\nfor i in range(h):\n a[i] = [int(i) - 1 for i in input().split()]\nq = int(input())\nquery = [[0, 0] for _ in range(q)]\nfor i in range(q):\n query[i] = [int(i) - 1 for i in input().split()]\nfunc(h, w, d, a, query)\n"""\nfunc(3, 3, 2, [[0, 3, 2], [1, 4, 6], [7, 8, 5]], [[3, 7]])\nprint("ans: 5\\n")\nfunc(4, 2, 3, [[2, 6], [0, 3], [4, 1], [5, 7]], [[1, 1], [1, 1]])\nprint("ans: 0, 0\\n")\nfunc(5, 5, 4, [[12, 24, 6, 14, 16], [15, 21, 19, 1, 8], [13, 10, 11, 0, 18], [9, 5, 22, 7, 17], [2, 20, 4, 23, 3]], [[12, 12], [1, 9], [12, 12]])\nprint("ans: 0, 5, 0")\n"""\n\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s522386109', 's957214303', 's718695326'] | [27692.0, 27148.0, 38804.0] | [592.0, 2105.0, 627.0] | [783, 830, 1360] |
p03426 | u585704797 | 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=[int(x) for x in str(input()).split()]\nA=[[0 for x in range(W+1)]]\nfor i in range(1,H+1):\n b=[0]\n b+=[int(x) for x in str(input()).split()]\n A.append(b)\nQ=int(input())\nLR=[[0 for x in range(3)]]\nfor i in range(1,Q+1):\n b=[0]\n b+=[int(x) for x in str(input()).split()]\n LR.append(b)\n\n\n\n\n\n\n\n\n\n\n\n\nB=[0 for x in range(H*W+1)]\nfor i in range(1,W+1):\n for j in range(1,H+1):\n B[A[j][i]]=[j,i]\n\nprint(B)\n\nXY=[0]\nfor i in range(1,D+1):\n\n C=[]\n x=i\n s=0\n while x<(H*W-D+1):\n\n s+=abs(B[x][0]-B[x+D][0])+abs(B[x][1]-B[x+D][1])\n C.append(s)\n x+=D\n\n C.append(s+abs(B[i][0]-B[x][0])+abs(B[i][1]-B[x][1]))\n XY.append(C)\nprint(XY)\n\n\ndef mo(x,y):\n if x%y==0:\n return y\n else:\n return x%y\n\ndef br(x):\n if x<=0:\n return 0\n else:\n return int(x)\n\nans=[]\nfor i in range (1,Q+1):\n if LR[i][1]<LR[i][2] and LR[i][1]==mo(LR[i][1],D):\n g=XY[mo(LR[i][1],D)][br((LR[i][1]-0.1)//D-1)]\n h=XY[mo(LR[i][1],D)][br((LR[i][2]-0.1)//D-1)]\n\n ans.append(h)\n elif LR[i][1]<LR[i][2]:\n g=XY[mo(LR[i][1],D)][br((LR[i][1]-0.1)//D-1)]\n h=XY[mo(LR[i][1],D)][br((LR[i][2]-0.1)//D-1)]\n\n ans.append(h-g)\n elif LR[i][1]>LR[i][2]:\n g=XY[mo(LR[i][2],D)][br((LR[i][2]+0.1)//D)-2]\n h=XY[mo(LR[i][2],D)][-1]-XY[mo(LR[i][1],D)][br((LR[i][2]+0.1)//D-2)]\n ans.append(h+g)\n else:\n ans.append(0)\n\nfor i in ans:\n print(i)\n\n', 'H, W, D=[int(x) for x in str(input()).split()]\nA=[[0 for x in range(W+1)]]\nfor i in range(1,H+1):\n b=[0]\n b+=[int(x) for x in str(input()).split()]\n A.append(b)\nQ=int(input())\nLR=[[0 for x in range(3)]]\nfor i in range(1,Q+1):\n b=[0]\n b+=[int(x) for x in str(input()).split()]\n LR.append(b)\n\n\n\n\n\n\n\n\n\n\n\n\nB=[0 for x in range(H*W+1)]\nfor i in range(1,W+1):\n for j in range(1,H+1):\n B[A[j][i]]=[j,i]\n\nXY=[0]\nfor i in range(1,D+1):\n\n C=[]\n x=i\n s=0\n while x<(H*W-D+1):\n\n s+=abs(B[x][0]-B[x+D][0])+abs(B[x][1]-B[x+D][1])\n C.append(s)\n x+=D\n\n C.append(s+abs(B[i][0]-B[x][0])+abs(B[i][1]-B[x][1]))\n XY.append(C)\n\n\ndef mo(x,y):\n if x%y==0:\n return y\n else:\n return x%y\n\ndef br(x):\n if x<=0:\n return 0\n else:\n return int(x)\n\nans=[]\nfor i in range (1,Q+1):\n if LR[i][1]<LR[i][2] and LR[i][1]==mo(LR[i][1],D):\n g=XY[mo(LR[i][1],D)][br((LR[i][1]-0.1)//D-1)]\n h=XY[mo(LR[i][1],D)][br((LR[i][2]-0.1)//D-1)]\n\n ans.append(h)\n elif LR[i][1]<LR[i][2]:\n g=XY[mo(LR[i][1],D)][br((LR[i][1]-0.1)//D-1)]\n h=XY[mo(LR[i][1],D)][br((LR[i][2]-0.1)//D-1)]\n\n ans.append(h-g)\n elif LR[i][1]>LR[i][2]:\n g=XY[mo(LR[i][2],D)][br((LR[i][2]+0.1)//D)-2]\n h=XY[mo(LR[i][2],D)][-1]-XY[mo(LR[i][1],D)][br((LR[i][2]+0.1)//D-2)]\n ans.append(h+g)\n else:\n ans.append(0)\n\nfor i in ans:\n print(i)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s389205658', 's523652765'] | [50132.0, 48400.0] | [1004.0, 993.0] | [1347, 1327] |
p03426 | u595289165 | 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\nh, w, d = map(int, input().split())\na = np.array([list(map(int, input().split())) for _ in range(h)])\nq = int(input())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = []\nfor i in range(h):\n for j in range(w):\n a_ij = a[i][j]\n mass[a_ij] = [i, j]\nfor i in range(d):\n mass_sort = mass[1+i::d]\n mp_i = np.sum(abs(mass_sort[:-1] - mass_sort[1:]), axis=1)\n mp.append(mp_i.cumsum())\nprint("\\n".join(map(str, [0, 5, 0])))', 'import numpy as np\nimport sys\ninput = sys.stdin\nh, w, d = map(int, input().split())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = np.zeros(num+1, dtype=int)\nfor i in range(h):\n for j, a in enumerate(list(map(int, input().split()))):\n mass[a] += [i, j]\nfor i in range(d+1, num+1):\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\nq = int(input())\nfor _ in range(q):\n l, r = map(int, input().split())\n print(mp[r]-mp[l])\n', 'import numpy as np\nh, w, d = map(int, input().split())\na = np.array([list(map(int, input().split())) for _ in range(h)])\nq = int(input())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = np.zeros(num+1)\nfor i in range(h):\n for j in range(w):\n a_ij = a[i][j]\n mass[a_ij] = [i, j]\nfor i in range(1, num+1):\n if 1 <= i <= d:\n pass\n else:\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\n\nfor _ in range(q):\n l, r = map(int, input().split())\n print(mp[r]-mp[l])\n', 'import numpy as np\nimport sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nh, w, d = map(int, read().split())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = np.zeros(num+1, dtype=int)\nfor i in range(h):\n for j, a in enumerate(map(int, readline().split())):\n mass[a] = [i, j]\nfor i in range(d+1, num+1):\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\nq = int(read())\nfor _ in range(q):\n l, r = map(int, read().split())\n print(mp[r]-mp[l])\n', 'import numpy as np\nimport sys\ninput = sys.stdin.readline\nh, w, d = map(int, input().split())\nnum = h * w\nmass = np.array((0, 0) for _ in range(num + 1))\nmp = np.zeros(num+1, dtype=int)\nfor i in range(h):\n for j, a in enumerate(map(int, input().split())):\n mass[a] = [i, j]\nfor i in range(d+1, num+1):\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\nq = int(input())\nfor _ in range(q):\n l, r = map(int, input().split())\n print(mp[r]-mp[l])\n', 'import numpy as np\nh, w, d = map(int, input().split())\na = np.array([list(map(int, input().split())) for _ in range(h)])\nq = int(input())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = []\nfor i in range(h):\n for j in range(w):\n a_ij = a[i][j]\n mass[a_ij] = [i, j]\nprint("\\n".join(map(str, [0, 5, 0])))', 'import numpy as np\nimport sys\ninput = sys.stdin.readline\nh, w, d = map(int, input().split())\nnum = h * w\nmass = np.array([[0] for _ in range(num + 1)])\nmp = np.zeros(num+1, dtype=int)\nfor i in range(h):\n for j, a in enumerate(map(int, input().split())):\n mass[a] = [i, j]\nfor i in range(d+1, num+1):\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\nq = int(input())\n\nfor _ in range(q):\n l, r = map(int, input().split())\n print(mp[r]-mp[l])\n', 'import numpy as np\nh, w, d = map(int, input().split())\na = np.array([list(map(int, input().split())) for _ in range(h)])\nq = int(input())\nnum = h * w\nmass = np.array([[0, 0] for _ in range(num + 1)])\nmp = []\nfor i in range(h):\n for j in range(w):\n a_ij = a[i][j]\n mass[a_ij] = [i, j]\nfor i in range(d):\n mass_sort = mass[1+i::d]\n mp_i = np.sum(abs(mass_sort[:-1] - mass_sort[1:]), axis=1)\n mp.append(mp_i.cumsum())\nfor _ in range(q):\n l, r = map(int, input().split())\n n = (r - l) // d\n u = l % d\n index = (l - (d - u)) // 2\nprint("\\n".join(map(str, [0, 5, 0])))', 'import numpy as np\nimport sys\ninput = sys.stdin.readline\nh, w, d = map(int, input().split())\nnum = h * w\nmass = np.array([(0, 0) for _ in range(num + 1)])\nmp = np.zeros(num+1)\nfor i in range(1, h+1):\n for j, a in enumerate(map(int, input().split())):\n mass[a] = [i, j+1]\nfor i in range(d+1, num+1):\n mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))\nq = int(input())\nfor _ in range(q):\n l, r = map(int, input().split())\n print(int(mp[r]-mp[l]))\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s146964313', 's333789490', 's378789282', 's501773723', 's566782847', 's632214927', 's682199000', 's974574496', 's775704205'] | [29992.0, 12512.0, 23232.0, 27752.0, 14444.0, 29516.0, 21872.0, 30448.0, 15548.0] | [1970.0, 148.0, 2109.0, 164.0, 148.0, 509.0, 192.0, 2109.0, 1681.0] | [478, 460, 520, 501, 460, 338, 460, 600, 463] |
p03426 | u595952233 | 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 i in range(h):\n a+=list(map(int, input().split()))\nn = len(a)\nq = int(input())\nmax_dbl_line = 10\n\ndef dist(i, j):\n dw = abs(i%w - j%w)\n dh = abs(i//w - j//w)\n return dw + dh\n\nidx_table = [0] * n\nfor i in range(n):\n idx_table[a[i]-1] = i\n\n\ndbl = [[0] * n for i in range(max_dbl_line)]\ntmp = []\nfor i in range(n):\n if a[i]+d in a:\n next_node = idx_table[i]\n else:\n next_node = -1\n if next_node!=-1:\n next_d = dist(idx_table[i], next_node)\n else:\n next_d = float('inf')\n tmp.append((next_node, next_d))\ndbl[0] = tmp\nfor i in range(max_dbl_line-1):\n temp = []\n for j in range(n):\n next_node = dbl[i][dbl[i][j][0]][0]\n next_d = dbl[i][j][1]+dbl[i][dbl[i][j][0]][1]\n temp.append((next_node, next_d))\n dbl[i+1] = temp\n\ndef f(l, r):\n cnt = (r-l)//d\n ret = 0\n now = idx_table[i]\n if cnt==0:\n return ret\n for i in range(max_dbl_line):\n if cnt & 1<<i:\n ret+=dbl[i][now][1]\n now = now + d*2**i\n return ret\n\nfor i in range(q):\n l, r = map(int, input().split())\n print(f(l,r))", "h, w, d = map(int, input().split())\na = []\nfor i in range(h):\n a+=list(map(int, input().split()))\nn = len(a)\nq = int(input())\nmax_dbl_line = 10\n\ndef dist(i, j):\n dw = abs(i%w - j%w)\n dh = abs(i//w - j//w)\n return dw + dh\n\nidx_table = [0] * n\nfor i in range(n):\n idx_table[a[i]-1] = i\n\n\ndbl = [[0] * n for i in range(max_dbl_line)]\ntmp = []\nfor i in range(n):\n if a[i]+d in a:\n next_node = idx_table[i]\n else:\n next_node = -1\n if next_node!=-1:\n next_d = dist(idx_table[i], next_node)\n else:\n next_d = float('inf')\n tmp.append((next_node, next_d))\ndbl[0] = tmp\nfor i in range(max_dbl_line-1):\n temp = []\n for j in range(n):\n next_node = dbl[i][dbl[i][j][0]][0]\n next_d = dbl[i][j][1]+dbl[i][dbl[i][j][0]][1]\n temp.append((next_node, next_d))\n dbl[i+1] = temp\n\ndef f(l, r):\n cnt = (r-l)//d\n ret = 0\n now = a.index(l)-1\n if cnt==0:\n return ret\n for i in range(max_dbl_line):\n if cnt & 1<<i:\n ret+=dbl[i][now][1]\n now = now + d*2**i\n return ret\n\nfor i in range(q):\n l, r = map(int, input().split())\n print(f(l,r))", "h, w, d = map(int, input().split())\na = []\nfor i in range(h):\n a+=list(map(int, input().split()))\nn = len(a)\nq = int(input())\nmax_dbl_line = 10\n\ndef dist(i, j):\n dw = abs(i%w - j%w)\n dh = abs(i//w - j//w)\n return dw + dh\n\nidx_table = [0] * n\nfor i in range(n):\n idx_table[a[i]-1] = i\n\n\ndbl = [[0] * n for i in range(max_dbl_line)]\ntmp = []\nfor i in range(n):\n if a[i]+d in a:\n next_node = a.index(a[i]+d)-1\n else:\n next_node = -1\n if next_node!=-1:\n next_d = dist(idx_table[i], next_node)\n else:\n next_d = float('inf')\n tmp.append((next_node, next_d))\ndbl[0] = tmp\nfor i in range(max_dbl_line-1):\n temp = []\n for j in range(n):\n next_node = dbl[i][dbl[i][j][0]][0]\n next_d = dbl[i][j][1]+dbl[i][dbl[i][j][0]][1]\n temp.append((next_node, next_d))\n dbl[i+1] = temp\n\ndef f(l, r):\n cnt = (r-l)//d\n ret = 0\n now = a.index(l)-1\n if cnt==0:\n return ret\n for i in range(max_dbl_line):\n if cnt & 1<<i:\n ret+=dbl[i][now][1]\n now = now + d*2**i\n return ret\n\nfor i in range(q):\n l, r = map(int, input().split())\n print(f(l,r))", "h, w, d = map(int, input().split())\na = []\nfor i in range(h):\n a+=list(map(int, input().split()))\nn = len(a)\nq = int(input())\nmax_dbl_line = 6\n\ndef dist(i, j):\n dw = abs(i%w - j%w)\n dh = abs(i//w - j//w)\n return dw + dh\n\nidx_table = [0] * n\nfor i in range(n):\n idx_table[a[i]-1] = i\n\n\ndbl = [[0] * n for i in range(max_dbl_line)]\ntmp = []\nfor i in range(n):\n if a[i]+d in a:\n next_node = idx_table[i]\n else:\n next_node = -1\n if next_node!=-1:\n next_d = dist(idx_table[i], next_node)\n else:\n next_d = float('inf')\n tmp.append((next_node, next_d))\ndbl[0] = tmp\nfor i in range(max_dbl_line-1):\n temp = []\n for j in range(n):\n next_node = dbl[i][dbl[i][j][0]][0]\n next_d = dbl[i][j][1]+dbl[i][dbl[i][j][0]][1]\n temp.append((next_node, next_d))\n dbl[i+1] = temp\n\ndef f(l, r):\n cnt = (r-l)//d\n ret = 0\n now = idx_table[i]\n if cnt==0:\n return ret\n for i in range(max_dbl_line):\n if cnt & 1<<i:\n ret+=dbl[i][now][1]\n now = now + d*2**i\n return ret\n\nfor i in range(q):\n l, r = map(int, input().split())\n print(f(l,r))", 'import sys\ninput = sys.stdin.readline\n\nh, w, d = map(int, input().split())\nn = h*w\na = [0]*n\nfor i in range(h):\n t = list(map(int, input().split()))\n for j in range(w):\n a[w*i+j] = t[j]-1\n\ndef dist(i, j):\n dh = abs(i//w - j//w)\n dw = abs(i%w - j%w)\n return dh + dw\n\nidx_list = [0] * n\nfor i in range(n):\n idx_list[a[i]] = i\n\ndist_list = [0]*n\nfor i in range(n):\n if i < d:\n dist_list[i] = 0\n else:\n dist_list[i] = dist_list[i-d] + dist(idx_list[i-d], idx_list[i])\n\nq = int(input())\nfor i in range(q):\n l, r = map(int, input().split())\n l-=1; r-=1\n print(dist_list[r] - dist_list[l])\n\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s004259599', 's316804302', 's451193724', 's593472538', 's985850918'] | [23432.0, 23488.0, 23420.0, 20640.0, 19940.0] | [2206.0, 2206.0, 2206.0, 2206.0, 277.0] | [1195, 1195, 1200, 1194, 638] |
p03426 | u604262137 | 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\nH, W, D = input().split()\nH, W, D = int(H), int(W), int(D)\n\npx, py = np.zeros(H*W+1), np.zeros(H*W+1)\nfor i in range(H):\n A = input().split()\n for j in range(W):\n px[int(A[j])] = i\n py[int(A[j])] = j\n\nd = np.zeros(H*W+1)\nfor i in range(D+1, H*W+1):\n d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])\n\nQ = int(input())\n\nfor i in range(Q):\n L, R = input().split()\n L = int(L)\n R = int(R)\n print(d[R]-d[L])', 'import numpy as np\nH, W, D = map(int, input().split())\n\npx, py = np.zeros(H*W+1, dtype=int), np.zeros(H*W+1, dtype=int)\nfor i in range(H):\n A = map(int, input().split())\n for j in range(W):\n px[A[j]] = i\n py[A[j]] = j\n\nd = np.zeros(H*W+1, dtype=int)\nfor i in range(D+1, H*W+1):\n d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])\n\nQ = int(input())\n\nfor i in range(Q):\n L, R = map(int, input().split())\n print(d[R]-d[L])', 'import numpy as np\nH, W, D = list(map(int, input().split()))\n\npx, py = [None for i in range(H*W+1)], [None for i in range(H*W+1)]\nfor i in range(H):\n A = list(map(int, input().split()))\n for j in range(W):\n px[A[j]] = i\n py[A[j]] = j\n\nd = [0 for i in range(H*W+1)]\nfor i in range(D+1, H*W+1):\n d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])\n\nQ = int(input())\n\nfor i in range(Q):\n L, R = list(map(int, input().split()))\n print(d[R]-d[L])'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s101506991', 's668911383', 's003189530'] | [17212.0, 12396.0, 19996.0] | [1736.0, 150.0, 1143.0] | [458, 448, 469] |
p03426 | u604693716 | 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. | ['line = input().split(" ")\na = list(map(int, line))\ndata = [0] * 90001\nans = 0\nfor i in range(0, a[0]):\n line = input().split(" ")\n temp = list(map(int, line))\n for j in range(0, a[1]):\n data[temp[j]] = [i, j]\n\nmemo = [0] * 90001\n\nfor i in range(0, a[0] * a[1]):\n if i < a[2]:\n memo[i] = 0\n else:\n memo[i] = memo[i - a[2]] + abs(data[i][0] - data[i - a[2]][0]) + abs(data[i][1] - data[i - a[2]][1])\ntimes = int(input())\nfor i in range(0, times):\n line = list(map(int, input().split(" ")))\n print(memo[line[1]] - memo[line[0]])', 'line = input().split(" ")\na = list(map(int, line))\ndata = [0] * 90001\nans = 0\nfor i in range(0, a[0]):\n line = input().split(" ")\n temp = list(map(int, line))\n for j in range(0, a[1]):\n data[temp[j]] = [i, j]\n\nmemo = [0] * 90001\n\nfor i in range(0, a[0] * a[1]):\n if i <= a[2]:\n memo[i] = 0\n else:\n memo[i] = memo[i - a[2]] + abs(data[i][0] - data[i - a[2]][0]) + abs(data[i][1] - data[i - a[2]][1])\ntimes = int(input())\nfor i in range(0, times):\n line = list(map(int, input().split(" ")))\n print(memo[line[1]-1] - memo[line[0]-1])', 'line = input().split(" ")\na = list(map(int, line))\ndata = [0] * 90001\nans = 0\nfor i in range(0, a[0]):\n line = input().split(" ")\n temp = list(map(int, line))\n for j in range(0, a[1]):\n data[temp[j]] = [i, j]\n\nmemo = [0] * 90001\n\nfor i in range(0, a[0] * a[1]):\n if i < a[2]:\n memo[i] = 0\n else:\n memo[i] = memo[i - a[2]] + abs(data[i][0] - data[i - a[2]][0]) + abs(data[i][1] - data[i - a[2]][1])\ntimes = int(input())\nfor i in range(0, times):\n line = list(map(int, input().split(" ")))\n print(memo[line[1]-1] - memo[line[0]-1])', 'line = input().split(" ")\na = list(map(int, line))\ndata = [0] * 90001\nans = 0\nfor i in range(0, a[0]):\n line = input().split(" ")\n temp = list(map(int, line))\n for j in range(0, a[1]):\n data[temp[j]] = [i, j]\n\nmemo = [0] * 90001\n\nfor i in range(1, a[0] * a[1]+1):\n if i < a[2]+1:\n memo[i] = 0\n else:\n memo[i] = memo[i - a[2]] + abs(data[i][0] - data[i - a[2]][0]) + abs(data[i][1] - data[i - a[2]][1])\ntimes = int(input())\nfor i in range(0, times):\n line = list(map(int, input().split(" ")))\n print(memo[line[1]] - memo[line[0]])'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s335523337', 's407624899', 's702309422', 's551325308'] | [13552.0, 17084.0, 13552.0, 17084.0] | [909.0, 1068.0, 937.0, 1024.0] | [567, 572, 571, 571] |
p03426 | u610385881 | 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 = [list(map(int, input().split())) for i in range(H)]\nrA = [[0 for j in range(2)] for i in range(H * W + 1)]\nS = [0 for i in range(H * W + 1)]\nfor i in range(H):\n\tfor j in range(W):\n\t\trA[A[i][j]][0] = i\n\t\trA[A[i][j]][1] = j\n\nQ = int(input())\nfor i in range(Q):\n\tL, R = map(int, input().split())\n\tans = 0\n\tfor j in range(H * W) [L::D]:\n\t\tif j == R:\n\t\t\tbreak\n\t\tif S[j]:\n\t\t\tans += S[j]\n\t\t\tbreak\n\t\tS[j] -= ans\n\t\tans += abs(rA[j + D][1] - rA[j][1]) + abs(rA[j + D][0] - rA[j][0])\n\tfor j in range(H * W)[L::D]:\n\t\tif S[j] > 0:\n\t\t\tbreak\n\t\tif j == R\n\t\t\tbreak\n\t\tS[j] += ans\n\tprint (ans)\n', 'H, W, D = map(int, input().split())\n \nA = [list(map(int, input().split())) for i in range(H)]\nrA = [[0 for j in range(2)] for i in range(H * W + 1)]\nS = [0 for i in range(H * W + 1)]\nfor i in range(H):\n\tfor j in range(W):\n\t\trA[A[i][j]][0] = i\n\t\trA[A[i][j]][1] = j\n \nQ = int(input())\nfor i in range(Q):\n\tL, R = map(int, input().split())\n\tans = 0\n\tfor j in range(H * W) [L::D]:\n\t\tif j + D > H * W:\n\t\t\tbreak\n\t\tif S[j]:\n\t\t\tans += S[j]\n\t\t\tbreak\n\t\tS[j] -= ans\n\t\tans += abs(rA[j + D][1] - rA[j][1]) + abs(rA[j + D][0] - rA[j][0])\n\tfor j in range(H * W)[L::D]:\n\t\tif S[j] > 0:\n\t\t\tbreak\n\t\tif j + D > H * W:\n\t\t\tbreak\n\t\tS[j] += ans\n\tprint(S[L] - S[R])\n'] | ['Runtime Error', 'Accepted'] | ['s697711730', 's845809807'] | [3064.0, 23536.0] | [17.0, 1496.0] | [616, 640] |
p03426 | u617515020 | 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\nc=[None]*(H*W)\nfor i in range(H):\n for j in range(W):\n c[A[i][j]-1] = (i, j)\n\nd=[0]*(H*W)\nfor i in range(D, H*W):\n px,py = c[i-D]\n x, y = c[i]\n d[i]=d[i-D] + abs(x-px) + abs(y-py)\nfor l, r in LR:\n print(d[r]-d[l])', 'H,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\npos=[None]*(H*W)\nfor i in range(H):\n for j in range(W):\n pos[A[i][j]-1] = (i, j)\n\nd=[0]*(H*W)\nfor i in range(D, H*W):\n px,py = pos[i-D]\n x, y = pos[i]\n d[i]=d[i-D] + abs(x-px) + abs(y-py)\n\nfor l, r in LR:\n print(d[r-1]-d[l-1])'] | ['Runtime Error', 'Accepted'] | ['s139552096', 's564750201'] | [41252.0, 36460.0] | [318.0, 385.0] | [375, 389] |
p03426 | u620868411 | 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. | ['# coding=utf-8\nline = input().split(" ")\nh = int(line[0])\nw = int(line[1])\nd = int(line[2])\n\ntable = [0 for _ in range(h*w+1)]\nfor hi in range(h):\n line = list(map(int, input().split(" ")))\n\n for wi in range(w):\n table[line[wi]] = (hi+1, wi+1)\n\ndef calc(l,r):\n ret = 0\n if l!=r:\n c1 = table[l]\n c2 = table[r]\n ret += abs(c1[0]-c2[0])+abs(c1[1]-c2[1])\n return ret\n\nacc = [0 for _ in range(h*w+1)]\nfor dd in range(1,d+1):\n s = dd+d\n while s+d<=h*w:\n acc[s] = calc(s-d,s)+acc[s-d]\n s += d\n\nq = int(input())\nfor _ in range(q):\n line = input().split(" ")\n l = int(line[0])\n r = int(line[1])\n\n ret = acc[r] - acc[l]\n print(ret)\n', 'h,w,d = map(int, input().split())\nad = {}\nfor i in range(h):\n line = list(map(int, input().split()))\n for j in range(w):\n ad[line[j]] = (i,j)\nq = int(input())\nlr = [list(map(int, input().split())) for _ in range(q)]\n\ncl = [0]*(h*w+1)\nfor i in range(1,h*w+1):\n if i+d<len(cl):\n f = ad[i]\n t = ad[i+d]\n cl[i+d] = cl[i] + abs(f[0]-t[0]) + abs(f[1]-t[1])\n\nfor l,r in lr:\n print(cl[r]-cl[l])'] | ['Wrong Answer', 'Accepted'] | ['s231665096', 's952359427'] | [16428.0, 44780.0] | [937.0, 411.0] | [700, 426] |
p03426 | u631277801 | 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\nstdin = sys.stdin\n \nsys.setrecursionlimit(10**5) \n \ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nfrom itertools import accumulate\n\nh,w,d = li()\na = [list(li()) for _ in range(h)]\n\nnum2point = [(-1,-1)]*(h*w+1)\nfor r, ai in enumerate(a):\n for c, aij in enumerate(ai):\n num2point[aij] = (r, c)\n \n\ndist = [[] for _ in range(d)]\nfor num in range(h*w):\n i = num+1\n if i // d == 0:\n dist[i%d].append(0)\n \n else:\n dist[i%d].append(abs(num2point[i][0]-num2point[i-d][0]) + abs(num2point[i][1]-num2point[i-d][1]))\n \ndist_cum = [list(accumulate(dist_row)) for dist_row in dist]\n\n\nq = ni()\nfor _ in range(q):\n l,r = li()\n print(dist_cum[l%d][r//d] - dist_cum[l%d][l//d])', 'import sys\nstdin = sys.stdin\n \nsys.setrecursionlimit(10**5) \n \ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nfrom itertools import accumulate\n\nh,w,d = li()\na = [list(li()) for _ in range(h)]\n\nnum2point = [(-1,-1)]*(h*w+1)\nfor r, ai in enumerate(a):\n for c, aij in enumerate(ai):\n num2point[aij] = (r, c)\n \n\ndist = [[] for _ in range(d)]\nfor num in range(h*w):\n i = num+1\n if i // d == 0 or i == d:\n dist[i%d].append(0)\n \n else:\n dist[i%d].append(abs(num2point[i][0]-num2point[i-d][0]) + abs(num2point[i][1]-num2point[i-d][1]))\n \ndist_cum = [list(accumulate(dist_row)) for dist_row in dist]\n\n\nq = ni()\nfor _ in range(q):\n l,r = li()\n print(dist_cum[l%d][r//d] - dist_cum[l%d][l//d])', 'import sys\nstdin = sys.stdin\n \nsys.setrecursionlimit(10**5) \n \ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nfrom itertools import accumulate\n\nh,w,d = li()\na = [list(li()) for _ in range(h)]\n\nnum2point = [(-1,-1)]*(h*w)\nfor r, ai in enumerate(a):\n for c, aij in enumerate(ai):\n num2point[aij-1] = (r, c)\n \n\ndist = [[] for _ in range(d)]\nfor i in range(h*w):\n if i // d == 0:\n dist[i%d].append(0)\n \n else:\n dist[i%d].append(abs(num2point[i][0]-num2point[i-d][0]) + abs(num2point[i][1]-num2point[i-d][1]))\n \ndist_cum = [list(accumulate(dist_row)) for dist_row in dist]\n\n\nq = ni()\nfor _ in range(q):\n l,r = li_()\n print(dist_cum[l%d][r//d] - dist_cum[l%d][l//d])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s035489537', 's495064423', 's886250797'] | [41156.0, 41160.0, 41276.0] | [238.0, 235.0, 487.0] | [1049, 1059, 1034] |
p03426 | u640303028 | 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. | ['b = str(input()).split()\nh = int(b[0])\nw = int(b[1])\nd = int(b[2])\nc =[]\n\ndef abs(a,b):\n if a > b:\n return(a-b)\n else:\n return(b-a)\n\nfor i in range(0,h):\n c.append(str(input()).split())\n\nq = int(input())\nlr = []\nenergy = 0\n\n\n\nfor i in range(0,q):\n lr.append(str(input()).split())\n\nfor i in range(0,q):\n l = int(lr[i][0])\n r = int(lr[i][1])\n for j in range(0,h):\n for k in range(0,w):\n if int(c[j][k]) == l:\n li = j\n lj = k\n if int(c[j][k]) == l + d:\n di = j\n dj = k\n if l != r:\n energy += abs(li,di) + abs(lj,dj)\n l += d\n else:\n print(energy)\n break\n', 'def list_1d(d,v):\n return [ v for i in range(d)]\n\ndef abs(c): \n if c > 0: \n return c \n else: \n return -c\n\ndef distance_2d(a,b):\n return(abs(a[0]-b[0])+abs(a[1]-b[1]))\n\nh,w,d = [int(i) for i in input().split()]\nsa = list_1d(h*w+1,[])\nda = list_1d(h*w+1,0)\nfor i in range(h):\n a = [int(k) for k in input().split()]\n for j in range(w):\n sa[a[j]] = [i,j]\nq = int(input())\nlr = [[int(i) for i in input().split()] for i in range(q)]\n\nfor i in range(d+1,h*w+1):\n da[i] = da[i-d] + distance_2d(sa[i],sa[i-d])\n\nfor i in range(0,q):\n print(da[lr[i][1]]-da[lr[i][0]])\n'] | ['Runtime Error', 'Accepted'] | ['s288587809', 's322384212'] | [38676.0, 35192.0] | [2106.0, 607.0] | [732, 602] |
p03426 | u650950012 | 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(' '))\nq = int(input())\nlr = [map(int, input().split(' ')) for _ in range(q)]\n\ncomp = {}\nfor i in range(h):\n tmp = list(map(int, input().split(' ')))\n for j in range(w):\n comp[tmp[j]] = [i, j]\n\ndp = [0] * (h * w + 1)\nfor i in range(d + 1, h * w + 1):\n cnt = dp[i - d]\n cnt += abs(comp[i][0] - comp[i - d][0])\n cnt += abs(comp[i][1] - comp[i - d][1]) \n dp[i] = cnt\n \n\nfor l, r in lr:\n print(dp[r] - dp[l])", "h, w, d = map(int, input().split(' '))\n\ncomp = {}\nfor i in range(h):\n tmp = list(map(int, input().split(' ')))\n for j in range(w):\n comp[tmp[j]] = [i, j]\n\nq = int(input())\nlr = [map(int, input().split(' ')) for _ in range(q)]\n\ndp = [0] * (h * w + 1)\nfor i in range(d + 1, h * w + 1):\n cnt = dp[i - d]\n cnt += abs(comp[i][0] - comp[i - d][0])\n cnt += abs(comp[i][1] - comp[i - d][1]) \n dp[i] = cnt\n \n\nfor l, r in lr:\n print(dp[r] - dp[l])"] | ['Runtime Error', 'Accepted'] | ['s466778865', 's912804037'] | [3064.0, 71184.0] | [18.0, 739.0] | [470, 471] |
p03426 | u658993896 | 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()))\narr=[0 for i in range(H*W+1)]\nfor y in range(H):\n for x,n in enumerate(map(int,input().split())):\n arr[n]=[x,y]\n\ndic={}\n\nQ=int(input())\nfor i in range(Q):\n ans=0\n now,goal= list(map(int,input().split()))\n nx=arr[now][0]\n ny=arr[now][1]\n tmp=now\n for j in range((goal-now)//D):\n if dic.get(tmp*H*W+goal,0)!=0:\n dic[now*H*W+goal]=ans+dic[tmp*H*W+goal]\n print(dic[now*H*W+goal])\n break\n tmp+=D\n x=arr[tmp][0]\n y=arr[tmp][1]\n ans+=abs(x-nx)+abs(y-ny)\n nx=x\n ny=y\n dic[now*H*W+tmp]=ans\n if dic.get(now*H*W+goal,0)==0:\n dic[now*H*W+goal]=ans\n print(ans)', 'H,W,D=list(map(int,input().split()))\nmap_=[[0,0] for _ in range(H*W+1)]\nfor y in range(H):\n for x,A in enumerate(map(int,input().split())):\n map_[A]=[x+1,y+1]\n\ncost=[0 for _ in range(H*W+1)]\nfor i in range(D+1,H*W+1):\n cost[i]+=abs(map_[i][0]-map_[i-D][0])+abs(map_[i][1]-map_[i-D][1])+cost[i-D]\nQ=int(input())\nfor i in range(Q):\n L,R=list(map(int,input().split()))\n print(cost[R]-cost[L])'] | ['Wrong Answer', 'Accepted'] | ['s170519336', 's631914359'] | [241812.0, 17664.0] | [2113.0, 1680.0] | [718, 408] |
p03426 | u667024514 | 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 math\nh,w,d = map(int,input().split())\na = [list(map(int,input().split())) for i in range(h)]\nlis = [[0,0] for i in range(h * w)]\nnum = [[0] * math.ceil((h * w) // d + 1) for i in range(d)]\n\nfor i in range(h):\n for j in range(w):\n lis[a[i][j]-1] = [i,j]\n\nfor i in range(h * w-d):\n num[i%d][i//d] = abs(lis[i][0]-lis[i+d][0])+abs(lis[i][1]-lis[i+d][1])\n #print(num)\n\nq = int(input())\nfor _ in range(q):\n now,goal = map(int,input().split())\n # print(num[now%d-1])\n # print(num[now%d-1][now//d:goal//d])\n print(sum(num[now%d-1][now//d:goal//d]))', 'h,w,d = map(int,input().split())\na = [list(map(int,input().split())) for i in range(h)]\nlis = [[0,0] for i in range(h * w)]\nnum = [[0] * math.ceil((h * w) // d + 1) for i in range(d)]\nfor i in range(h):\n for j in range(w):\n lis[a[i][j]-1] = [i,j]\nfor i in range(h * w-d):\n num[i%d][i//d+1] = num[i%d][i//d]+abs(lis[i][0]-lis[i+d][0])+abs(lis[i][1]-lis[i+d][1])\nq = int(input())\nfor _ in range(q):\n now,goal = map(int,input().split())\n if now % d == 0:\n print(num[now%d-1][(goal-now%d)//d-1]-num[now%d-1][(now-now%d)//d-1])\n else:\n print(num[now%d-1][(goal-now%d)//d]-num[now%d-1][(now-now%d)//d])', 'import math\nh,w,d = map(int,input().split())\na = [list(map(int,input().split())) for i in range(h)]\nlis = [[0,0] for i in range(h * w)]\nnum = [[0] * math.ceil((h * w) // d + 1) for i in range(d)]\n\nfor i in range(h):\n for j in range(w):\n lis[a[i][j]-1] = [i,j]\n\nfor i in range(h * w-d):\n num[i%d][i//d] = abs(lis[i][0]-lis[i+d][0])+abs(lis[i][1]-lis[i+d][1])\n #print(num)\n\nq = int(input())\nfor _ in range(q):\n now,goal = map(int,input().split())\n # print(num[now%d-1])\n # print(num[now%d-1][(now-now%d)//d:(goal-now%d)//d])\n print(sum(num[now%d-1][(now-now%d)//d:(goal-now%d)//d]))', 'import math\nh,w,d = map(int,input().split())\na = [list(map(int,input().split())) for i in range(h)]\nlis = [[0,0] for i in range(h * w)]\nnum = [[0] * math.ceil((h * w) // d + 1) for i in range(d)]\nfor i in range(h):\n for j in range(w):\n lis[a[i][j]-1] = [i,j]\nfor i in range(h * w-d):\n num[i%d][i//d+1] = num[i%d][i//d]+abs(lis[i][0]-lis[i+d][0])+abs(lis[i][1]-lis[i+d][1])\nq = int(input())\nfor _ in range(q):\n now,goal = map(int,input().split())\n if now % d == 0:\n print(num[now%d-1][(goal-now%d)//d-1]-num[now%d-1][(now-now%d)//d-1])\n else:\n print(num[now%d-1][(goal-now%d)//d]-num[now%d-1][(now-now%d)//d])\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s026514738', 's559519000', 's945798059', 's752813781'] | [25712.0, 15860.0, 25712.0, 25712.0] | [2108.0, 67.0, 2105.0, 1119.0] | [576, 632, 608, 645] |
p03426 | u676264453 | 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()))\n \ndic = {}\nfor i in range(H):\n for j,v in enumerate(list(map(int, input().split()))):\n dic[v] = (i,j)\n \nQ = int(input())\n \nQs = []\nmi = 100000\nma = 1\nfor i in range(Q):\n l,r = list(map(int, input().split()))\n Qs.append((l,r))\n mi = min(mi, l)\n ma = max(ma, r)\n \nS = [0 for i in range(100000)]\nacm = 0\npi, pj = dic[mi]\nfor start in range(1, D):\n for i in range(start, ma+1, D):\n x,y = dic[i]\n acm += abs(x-pi) + abs(y-pj)\n S[i] = acm\n pi,pj = x,y\n \nfor i in Qs:\n l,r = i\n print(S[r] - S[l])\n', 'H, W, D = list(map(int, input().split()))\n\nA = [[0 for i in range(W)] for j in range(H)]\ndic = {}\nfor i in range(H):\n for j,v in enumerate(list(map(int, input().split()))):\n A[i][j] = v\n dic[v] = (i,j)\n\nQ = int(input())\n\nQs = []\nmi = 10000000\nfor i in range(Q):\n l,r = list(map(int, input().split()))\n Qs.append((l,r))\n mi = min(mi, l)\n\nSum = [0 for i in range(100000)]\n', 'H, W, D = list(map(int, input().split()))\n \ndic = {}\nfor i in range(H):\n for j,v in enumerate(list(map(int, input().split()))):\n dic[v] = (i,j)\n \nQ = int(input())\n \nQs = []\nmi = 100000\nma = 1\nfor i in range(Q):\n l,r = list(map(int, input().split()))\n Qs.append((l,r))\n mi = min(mi, l)\n ma = max(ma, r)\n \nS = [0 for i in range(100000)]\nacm = 0\npi, pj = dic[mi]\nfor start in range(1, D+1):\n for i in range(start, ma+1, D):\n x,y = dic[i]\n acm += abs(x-pi) + abs(y-pj)\n S[i] = acm\n pi,pj = x,y\n\nfor i in Qs:\n l,r = i\n print(S[r] - S[l])\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s043049094', 's047474991', 's107991248'] | [36144.0, 33240.0, 36288.0] | [694.0, 480.0, 712.0] | [594, 396, 592] |
p03426 | u711539583 | 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\ninput = sys.stdin.readline\nh, w, d = map(int, input().split())\na = {}\nl = list(range(h * w))\nfor i in range(h):\n for j, x in enumerate(input().split()):\n a[int(x)] = (i, j)\nmemo = {}\ndef calc(s):\n tmp = 0\n memo(a[s]) = 0\n for xc, xn in zip(l[s::d], l[s+d::d]):\n xc, yc = a[xc]\n xn, yn = a[xn]\n tmp += abs(xc - xn) + abs(yc - yn)\n memo(a[xn]) = tmp\nfor i in range(d):\n calc(i)\nfor _ in range(int(input())):\n l, r = map(int, input().split())\n print(memo[a[r]] - memo[a[l]])\n ', 'import sys\ninput = sys.stdin.readline\nh, w, d = map(int, input().split())\na = {}\nl = list(range(1, h * w + 1))\nfor i in range(h):\n for j, x in enumerate(input().split()):\n a[int(x)] = (i, j)\nmemo = {}\ndef calc(s):\n tmp = 0\n memo[a[s+1]] = 0\n for Xc, Xn in zip(l[s::d], l[s+d::d]):\n xc, yc = a[Xc]\n xn, yn = a[Xn]\n tmp += abs(xc - xn) + abs(yc - yn)\n memo[a[Xn]] = tmp\nfor i in range(d):\n calc(i)\nfor _ in range(int(input())):\n l, r = map(int, input().split())\n print(memo[a[r]] - memo[a[l]])\n'] | ['Runtime Error', 'Accepted'] | ['s890911583', 's226975796'] | [3064.0, 38200.0] | [17.0, 454.0] | [509, 514] |
p03426 | u763034939 | 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())\narr = [0]*(H*W)\nfor i in range(H):\n for j , v in enumerate(map(int, input().split())):\n arr[v-1] = (i,j)\nprint(arr) \nX = [[] for _ in range(D)]\nY = [[] for _ in range(D)]\nfor i , (x,y) in enumerate(arr):\n if i // D == 0:\n X[i%D].append(0)\n Y[i%D].append(0)\n else:\n px, py = arr[i - D]\n X[i%D].append(X[i%D][-1] + abs(x - px))\n Y[i%D].append(Y[i%D][-1] + abs(y - py))\nQ = int(input())\nfor _ in range(Q):\n L, R = map(lambda x : int(x) - 1 , input().split())\n \n assert L % D == R % D\n print(X[R%D][R//D] - X[L%D][L//D] + Y[R%D][R//D] - Y[L%D][L//D])\n \n \n', 'H,W,D = map(int, input().split())\narr = [0]*(H*W)\nfor i in range(H):\n for j , v in enumerate(map(int, input().split())):\n arr[v-1] = (i,j)\nX = [[] for _ in range(D)]\nY = [[] for _ in range(D)]\nfor i , (x,y) in enumerate(arr):\n if i // D == 0:\n X[i%D].append(0)\n Y[i%D].append(0)\n else:\n px, py = arr[i - D]\n X[i%D].append(X[i%D][-1] + abs(x - px))\n Y[i%D].append(Y[i%D][-1] + abs(y - py))\nQ = int(input())\nfor _ in range(Q):\n L, R = map(lambda x : int(x) - 1 , input().split())\n \n assert L % D == R % D\n print(X[R%D][R//D] - X[L%D][L//D] + Y[R%D][R//D] - Y[L%D][L//D])\n \n \n'] | ['Wrong Answer', 'Accepted'] | ['s282973258', 's584981161'] | [32304.0, 31304.0] | [1262.0, 1222.0] | [662, 643] |
p03426 | u785578220 | 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, W ,D = map(int, input().split())\ninf = float("inf")\ndp = [0]*(N*W)\ns = [inf]*N*W\n\nd = [list(map(int, input().split())) for i in range(N)]\nT = int(input())\nm = [list(map(int, input().split())) for i in range(T)]\nans = 0\n \nfor i in range(N):\n for j in range(W):\n s[d[i][j]-1] = [i,j]\nk=0\n#print(s)\n\nfor n in range(D,N*W):\n print(n)\n dp[n] = dp[n-D]+abs(s[n][0]-s[n-D][0])+abs(s[n][1]-s[n-D][1])\n k+=1\nfor x,y in m:\n if x == y:print(0)\n else:print(dp[y-1]-dp[x-1])\n', 'N, W ,D = map(int, input().split())\ninf = float("inf")\ndp = [0]*(N*W)\ns = [inf]*N*W\n\nd = [list(map(int, input().split())) for i in range(N)]\nT = int(input())\nm = [list(map(int, input().split())) for i in range(T)]\nans = 0\n \nfor i in range(N):\n for j in range(W):\n s[d[i][j]-1] = [i,j]\nk=0\n#print(s)\n\nfor n in range(D,N*W):\n #print(n)\n dp[n] = dp[n-D]+abs(s[n][0]-s[n-D][0])+abs(s[n][1]-s[n-D][1])\n k+=1\nfor x,y in m:\n if x == y:print(0)\n else:print(dp[y-1]-dp[x-1])\n\n'] | ['Wrong Answer', 'Accepted'] | ['s514792578', 's794176684'] | [42808.0, 42248.0] | [683.0, 645.0] | [490, 492] |
p03426 | u786020649 | 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\nreadline=sys.stdin.readline\nread=sys.stdin.read\n \nh,w,d=map(int,readline().split())\na=[list(map(int,readline().split())) for _ in range(h)]\nq,*lr=map(int,read().split())\n\nca=dict()\nfor i,l in enumerate(a):\n for j,e in enumerate(l):\n ca[e]=(i+1,j+1)\nmp=[[0]*((h*w)//d+1) for _ in range(d)]\nfor i,mpl in enumerate(mp):\n for j,_ in enumerate(l[:-1]):\n if 0<i+d*j<=h*w-d:\n mpl[j+1]+=mpl[j]+abs(ca[i+d*j][0]-ca[i+d*(j+1)][0])\\\n +abs(ca[i+d*j][1]-ca[i+d*(j+1)][1])\nfor l,r in zip(*[iter(lr)]*2):\n print(mp[l%d][r//d]-mp[l%d][l//d])', 'import sys\nreadline=sys.stdin.readline\nread=sys.stdin.read\n \nh,w,d=map(int,readline().split())\na=[list(map(int,readline().split())) for _ in range(h)]\nq,*lr=map(int,read().split())\n\nca=dict()\nfor i,l in enumerate(a):\n for j,e in enumerate(l):\n ca[e]=(i+1,j+1)\nmp=[[0]*((h*w)//d+1) for _ in range(d)]\nfor i,mpl in enumerate(mp):\n for j,_ in enumerate(mpl[:-1]):\n if 0<i+d*j<=h*w-d:\n mpl[j+1]=mpl[j]+abs(ca[i+d*j][0]-ca[i+d*(j+1)][0])\\\n +abs(ca[i+d*j][1]-ca[i+d*(j+1)][1])\nfor l,r in zip(*[iter(lr)]*2):\n print(mp[l%d][r//d]-mp[l%d][l//d])'] | ['Wrong Answer', 'Accepted'] | ['s718253513', 's204974185'] | [40428.0, 40576.0] | [2206.0, 316.0] | [565, 566] |
p03426 | u787456042 | 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());S=H*W;A=[map(int,input().split())for _ in range(H)];Q,*L=open(0);d=[0]*S;e=[0]*S\nfor i,l in enumerate(A):\n for j,v in enumerate(l):d[v-1]=(i,j)\nfor i in range(S):\n if i>=D:e[i]=sum(abs(p-q)for p,q in zip(d[i-D],d[i]))+e[i-D]\nfor i in L:l,r=map(int,i.split());print(e[r-1]-e[l-1])', 'F=lambda:map(int,input().split());H,W,D=F();d={};e=[0]*H*W\nfor i in range(H):\n for j,v in enumerate(F()):d[v-1]=(i,j)\nfor i in range(D,H*W):e[i]=sum(abs(p-q)for p,q in zip(d[i-D],d[i]))+e[i-D]\nfor i in range(int(input())):l,r=F();print(e[r-1]-e[l-1])'] | ['Runtime Error', 'Accepted'] | ['s915845342', 's494979822'] | [23608.0, 22612.0] | [392.0, 1066.0] | [310, 250] |
p03426 | u798818115 | 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. | ['# coding: utf-8\n# Your code here!\n\n\nH,W,D=map(int,input().split())\n\nA=[]\nfor i in range(H):\n A.append(list(map(int,input().split())))\n\nloc=[[0,0] for i in range(W*H)]\n\n#print(loc)\n\nfor i in range(H):\n for j in range(W):\n loc[A[i][j]-1][0]=i\n loc[A[i][j]-1][1]=j\n #print(loc)\nprint(loc)\n\ncost=[[0]*((H*W)//D) for i in range(D)]\n\nfor i in range((H*W)%D):\n cost[i].append(0)\n\nfor i in range(D):\n pass\n count=1\n temp=0\n while temp<(H*W):\n temp=i+D*count\n cost[temp%D][temp//D]=abs(loc[temp][0]-loc[temp-D][0])+abs(loc[temp][1]-loc[temp-D][1])+cost[temp%D][temp//D-1]\n count+=1\n\nprint(cost)\n\n', '# coding: utf-8\n# Your code here!\n\n\nH,W,D=map(int,input().split())\n\nA=[]\nfor i in range(H):\n A.append(list(map(int,input().split())))\n\nloc=[[0,0] for i in range(W*H)]\n\n#print(loc)\n\nfor i in range(H):\n for j in range(W):\n loc[A[i][j]-1][0]=i\n loc[A[i][j]-1][1]=j\n #print(loc)\n#print(loc)\n\ncost=[[0]*((H*W)//D) for i in range(D)]\n\nfor i in range((H*W)%D):\n cost[i].append(0)\n\nfor i in range(D):\n pass\n count=1\n temp=i\n while temp+D<(H*W):\n temp=i+D*count\n cost[temp%D][temp//D]=abs(loc[temp][0]-loc[temp-D][0])+abs(loc[temp][1]-loc[temp-D][1])+cost[temp%D][temp//D-1]\n count+=1\n #print(cost)\ncost[-1]=[0]+cost[-1]\n\nQ=int(input())\nfor _ in range(Q):\n x,y=map(int,input().split())\n #print(cost[x%D-1][x//D-1])\n print(cost[y%D-1][y//D]-cost[x%D-1][x//D])\n\n#print(cost)\n\n'] | ['Runtime Error', 'Accepted'] | ['s952939659', 's707316693'] | [26528.0, 25700.0] | [253.0, 1082.0] | [657, 851] |
p03426 | u815878613 | 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 collections import defaultdict\n\nH, 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\n# 1 -> 1+D ->\n# 2 -> 2+D ->\n\n\n\n\nd = defaultdict(list)\nfor i in range(H):\n for j in range(W):\n d[A[i][j]].append([i, j])\n\n\np = []\nfor s in range(1, D + 1):\n c = 0\n q = [0]\n for i in range(s + D, H * W + 1, D):\n i0, j0 = d[i - D][0]\n i1, j1 = d[i][0]\n c += abs(i0 - i1) + abs(j0 - j1)\n q.append(c)\n\n p.append(q)\n\n\n# for l, r in LR:\n\n\n\n# print(p[i][e] - p[i][s])\n', 'from collections import defaultdict\n\nH, 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\n# 1 -> 1+D ->\n# 2 -> 2+D ->\n\n\n\n\nd = defaultdict(list)\nfor i in range(H):\n for j in range(W):\n d[A[i][j]].append([i, j])\n\n\np = []\nfor s in range(1, D + 1):\n c = 0\n q = [0]\n for i in range(s + D, H * W + 1, D):\n i0, j0 = d[i - D][0]\n i1, j1 = d[i][0]\n c += abs(i0 - i1) + abs(j0 - j1)\n q.append(c)\n\n p.append(q)\n\n\nfor l, r in LR:\n i = l % D - 1\n s = (l - 1) // D\n e = (r - 1) // D\n print(p[i][e] - p[i][s])\n'] | ['Wrong Answer', 'Accepted'] | ['s530137226', 's243966851'] | [60184.0, 60428.0] | [409.0, 488.0] | [799, 789] |
p03426 | u827951256 | 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,m,d = map(int, input().split())\n\ngrid = []\n\nbuf = {}\n\nfor j in range(n):\n grid.append(list(map(int, input().split())))\n for k in range(len(grid[j])):\n buf[grid[j][k]] = (j,k)\nq = int(input())\nal = []\n\ncost = [0] * ((n*m)+1)\n\nfor i in range(d+1,n*m):\n cost[i] = cost[i-d] + abs(buf[i-d][0] - buf[i][0]) + abs(buf[i-d][1] - buf[i][1])\nprint(cost)\nfor _ in range(q):\n l,r = map(int, input().split())\n al.append([l,r])\n \n\nfor l,r in al:\n print(cost[r]-cost[l])\n \n \n', 'n,m,d = map(int, input().split())\n\ngrid = []\n\nbuf = {}\n\nfor j in range(n):\n grid.append(list(map(int, input().split())))\n for k in range(len(grid[j])):\n buf[grid[j][k]] = (j,k)\nq = int(input())\nal = []\n\ncost = [0] * ((n*m)+1)\n\nfor i in range(d+1,n*m+1):\n cost[i] = cost[i-d] + abs(buf[i-d][0] - buf[i][0]) + abs(buf[i-d][1] - buf[i][1])\n\nfor _ in range(q):\n l,r = map(int, input().split())\n al.append([l,r])\n \n\nfor l,r in al:\n print(cost[r]-cost[l])\n \n \n'] | ['Wrong Answer', 'Accepted'] | ['s197659388', 's683366902'] | [40716.0, 39976.0] | [594.0, 615.0] | [517, 508] |
p03426 | u860002137 | 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\nfrom numba import njit, i8\n\nh, w, d = map(int, input().split())\narr = np.zeros([h, w], dtype=np.int64)\n\nfor i in range(h):\n arr[i] = list(map(int, input().split()))\n\nq = int(input())\nlr = np.zeros([q, 2], dtype=np.int64)\n\nfor i in range(q):\n lr[i] = list(map(int, input().split()))\n\n\n@njit\ndef solve(h, w, d, arr):\n result = [[0] for _ in range(d)]\n for i in range(d):\n l = i\n score = 0\n while l + d <= h * w:\n if l == 0:\n result[i].append(score)\n l += d\n continue\n u = np.where(arr == l)\n v = np.where(arr == l + d)\n score += abs(v[0][0] - u[0][0]) + abs(v[1][0] - u[1][0])\n result[i].append(score)\n l += d\n return result\n\n\nresult = solve(h, w, d, arr)\n\n\nfor l, r in lr:\n print(result[l % d][r // d] - result[l % d][l // d])', 'import numpy as np\n\nh, w, d = map(int, input().split())\narr = np.zeros([h, w], dtype=np.int64)\n\nfor i in range(h):\n arr[i] = list(map(int, input().split()))\n\nq = int(input())\nlr = np.zeros([q, 2], dtype=np.int64)\n\nfor i in range(q):\n lr[i] = list(map(int, input().split()))\n\n\ncnt = h * w\nresult = [[0] for _ in range(d)]\nfor i in range(d):\n l = i\n score = 0\n while l + d <= cnt:\n if l == 0:\n result[i].append(score)\n l += d\n continue\n u = np.where(arr == l)\n v = np.where(arr == l + d)\n score += abs(v[0][0] - u[0][0]) + abs(v[1][0] - u[1][0])\n result[i].append(score)\n l += d\n\n\nresult = solve(h, w, d, arr)\n\n\nfor l, r in lr:\n ans = result[l % d]\n print(ans[r // d] - ans[l // d])', 'h, w, d = map(int, input().split())\narr = [0] * (h * w + 1)\n\na = [list(map(int, input().split())) for _ in range(h)]\n\nfor i in range(h):\n for j in range(w):\n s = a[i][j]\n arr[s] = (i, j)\n\nq = int(input())\nlr = [list(map(int, input().split())) for _ in range(q)]\n\ncnt = h * w\nresult = [[0] for _ in range(d)]\nfor i in range(d):\n l = i\n score = 0\n while l + d <= cnt:\n if l == 0:\n result[i].append(score)\n l += d\n continue\n (ux, uy) = arr[l]\n (vx, vy) = arr[l + d]\n score += (abs(vx - ux) + abs(vy - uy))\n result[i].append(score)\n l += d\n\n\nfor l, r in lr:\n ans = result[l % d]\n print(ans[r // d] - ans[l // d])'] | ['Time Limit Exceeded', 'Runtime Error', 'Accepted'] | ['s714649305', 's815127154', 's550351735'] | [133892.0, 37060.0, 45864.0] | [2209.0, 2206.0, 407.0] | [894, 776, 715] |
p03426 | u870092796 | 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()))\nX=[(0,0) for i in range(H*W+1)]\n\nfor i in range(1,H+1):\n\tA=list(map(int,input().split()))\n\tfor idx,a in enumerate(A):\n\t\tX[a]=(i,idx+1)\n\nQ=int(input())\nL=[]\nR=[]\nS=[0]*(H*W+1)\n\nfor i in range(Q):\n\tl,r=list(map(int,input().split()))\n\tL.append(l)\n\tR.append(r)\n\nfor i in range(D+1,H*W+1):\n\tS[i]=S[i-D]+abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])\n\nfor i in range(Q):\n\tprint(S[R[i]]-S[L[i]])\n\t\nprint(L,R,S)', 'H,W,D=list(map(int,input().split()))\nX=[(0,0) for i in range(H*W+1)]\n\nfor i in range(1,H+1):\n\tA=list(map(int,input().split()))\n\tfor idx,a in enumerate(A):\n\t\tX[a]=(i,idx+1)\n\nQ=int(input())\nL=R=[]\nS=[0]*(H*W+1)\n\nfor i in range(Q):\n\tl,r=list(map(int,input().split()))\n\tL.append(l)\n\tR.append(r)\n\nfor i in range(D+1,H*W+1):\n\tS[i]=S[i-D]+abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])\n\nfor i in range(Q):\n\tprint(S[R[i]]-S[L[i]])', 'H,W,D=list(map(int,input().split()))\nX=[(0,0) for i in range(H*W+1)]\n\nfor i in range(1,H+1):\n\tA=list(map(int,input().split()))\n\tfor idx,a in enumerate(A):\n\t\tX[a]=(i,idx+1)\n\nQ=int(input())\nL=[]\nR=[]\nS=[0]*(H*W+1)\n\nfor i in range(Q):\n\tl,r=list(map(int,input().split()))\n\tL.append(l)\n\tR.append(r)\n\nfor i in range(D+1,H*W+1):\n\tS[i]=S[i-D]+abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])\n\nfor i in range(Q):\n\tprint(S[R[i]]-S[L[i]])\n\t'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s806078247', 's825603139', 's391294199'] | [26264.0, 22248.0, 22248.0] | [585.0, 546.0, 568.0] | [439, 421, 426] |
p03426 | u879870653 | 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 i in range(H)]\nQ = int(input())\nLR = [list(map(int,input().split())) for i in range(Q)]\n\nPoint = {}\nfor y in range(H) :\n for x in range(W) :\n Point[A[y][x]] = (y, x)\n\ndef dist (y1,x1,y2,x2) :\n return abs(y1-x1) + abs(y2-x2)\n\nfor i in range(Q) :\n res = 0\n l,r = LR[i][0], LR[i][1]\n while l != r :\n l += D\n res += dist(Point[l][0], Point[l][1], Point[l-D][0], Point[l-D][0])\n print(res)\n', 'H,W,D = map(int,input().split())\nPoint = {}\nfor y in range(H) :\n line = list(map(int,input().split()))\n for x,p in enumerate(line) :\n Point[p] = (y,x)\n\nQ = int(input())\n\ndef dist(ny,nx,py,px) :\n return abs(ny-py) + abs(nx-px)\n\nCost = [0]*(H*W+1)\nfor i in range(D+1, H*W+1) :\n yi,xi = Point[i-D]\n yj,xj = Point[i]\n Cost[i] = Cost[i-D] + dist(yi,xi,yj,xj)\n\n\nfor i in range(Q) :\n l,r = map(int,input().split())\n print(Cost[r] - Cost[l])\n'] | ['Wrong Answer', 'Accepted'] | ['s255969955', 's082115804'] | [46336.0, 22620.0] | [2106.0, 945.0] | [497, 465] |
p03426 | u896741788 | 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\ninput=sys.stdin.buffer.readline\ninputs=sys.stdin.buffer.readlines\nsys.setrecursionlimit(10**9)\nh,w,d=map(int,input().split())\ninds={}\nfor i in range(h):\n for D,j in enumerate(input().split()):\n inds[int(j)-1]=(i,D)\nnows=[[0]for c in range(d)]\n\nfor k in range(d,h*w):\n a,b=inds[k]\n x,y=inds[k-d]\n k%=d\n nows[k%d].append(nows[k%d][-1]+abs(a-x)+abs(b-y))\nprint(nows)\nq=input()\nfor i in inputs():\n l,r=map(int,i.split())\n l-=1;r-=1\n l,b=divmod(l,d)\n r,b=divmod(r,d)\n print(nows[b][r]-nows[b][l])\n', 'import sys\ninput=sys.stdin.buffer.readline\ninputs=sys.stdin.buffer.readlines\nsys.setrecursionlimit(10**9)\nh,w,d=map(int,input().split())\ninds={}\nfor i in range(h):\n for D,j in enumerate(input().split()):\n inds[int(j)-1]=(i,D)\nnows=[[0]for c in range(d)]\n\nfor k in range(d,h*w):\n a,b=inds[k]\n x,y=inds[k-d]\n k%=d\n nows[k].append(nows[k][-1]+abs(a-x)+abs(b-y))\nq=input()\nfor i in inputs():\n l,r=map(int,i.split())\n l-=1;r-=1\n l,b=divmod(l,d)\n r,b=divmod(r,d)\n print(nows[b][r]-nows[b][l])\n'] | ['Wrong Answer', 'Accepted'] | ['s372939479', 's136548269'] | [36936.0, 36940.0] | [322.0, 307.0] | [540, 524] |
p03426 | u904804404 | 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. | ['#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n"""\nCreated on Fri Mar 23 11:18:48 2018\n\n@author: natsukiiwano\n"""\n\n_in_ = list(map(int,input().split(" ")))\nH,W,D = _in_[0],_in_[1],_in_[2]\ndic = {}\nfor h in range(H):\n _in_ = list(map(int,input().split(" ")))\n for w in range(W):\n dic[_in_[w]]=h+w*1j\n\nprint(dic)\n\nfor n in range(H*W-D):\n dic[n+1] = int(abs(dic[n+1].real-dic[n+1+D].real)+abs(dic[n+1].imag-dic[n+1+D].imag))\n \nprint(dic)\n \nfor q in range(int(input())):\n _in_ = list(map(int,input().split(" ")))\n _from_,_to_ = _in_[0],_in_[1]\n _sum_=0\n while _to_ != _from_:\n _sum_ = _sum_ + dic[_from_]\n _from_ = _from_ + D\n print(_sum_)', '#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n"""\nCreated on Fri Mar 23 12:24:26 2018\n\n@author: natsukiiwano\n"""\nimport numpy as np\n\n_in_ = input().split(" ")\nH,W,D = int(_in_[0]),int(_in_[1]),int(_in_[2])\n\npx,py= np.zeros(90001),np.zeros(90001)\nd=np.zeros(90001)\nfor i in range(H):\n _in_ = list(map(int,input().split(" ")))\n for j in range(W):\n px[_in_[j]]=i\n py[_in_[j]]=j\n\nfor i in range(D+1,H*W+1):\n d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])\n\nQ = int(input())\nfor i in range(Q):\n _in_ = input().split(" ")\n L,R = int(_in_[0]),int(_in_[1])\n print(int(d[R]-d[L]))'] | ['Wrong Answer', 'Accepted'] | ['s166903007', 's828851267'] | [23004.0, 16072.0] | [2104.0, 1319.0] | [686, 606] |
p03426 | u916637712 | 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\nin1=list(map(int,input().split(" ")))\n#print(in1)\n\nd={}\nfor i in range(in1[0]):\n #arr[i]=input().split(" ")\n for n,k in enumerate(input().split(" ")):\n d[int(k)]=[i,n]\n#print(arr)\nQ=int(input())\ntest=[]\nout=[]\nroute=[]\nfor k in range(Q):\n ans=0\n start,end=list(map(int,input().split(" ")))\n #place=np.where(arr==start)\n place=d[start]\n #print(start,end)\n while start != end:\n #print("ans",ans)\n #nextplace=np.where(arr==start+in1[2])#[1][0]\n if start in route:\n nextplace=d[start+in1[2]]\n else:\n nextplace=d[start+in1[2]]\n ans1=abs(int(nextplace[0])-int(place[0]))\n ans2=abs(int(nextplace[1])-int(place[1]))\n route[start]=ans1+ans2\n ans+=route[start]\n start+=in1[2]\n place=nextplace\n\n print(ans)\n #out.append(ans)\n\n #print(i)\n', 'import numpy as np\nH, W, D=list(map(int,input().split(" ")))\n#print(in1)\n\nd={}\nfor i in range(H):\n #arr[i]=input().split(" ")\n for n,k in enumerate(input().split(" ")):\n d[int(k)]=[i,n]\n#print(arr)\nQ=int(input())\nout=[]\n\ncost={}\n\nfor i in range(1,D+1):\n now = i + D\n cost[i]=0\n #cost[i]=abs(d[now][0] - d[now - D][0]) + abs(d[now][1] - d[now - D][1])\n while now <= H * W:\n cost[now] = cost[now - D] + abs(d[now][0] - d[now - D][0]) + abs(d[now][1] - d[now - D][1])\n now += D\n\n\nout=[]\nfor k in range(Q):\n start,end=list(map(int,input().split(" ")))\n out.append(cost[end]-cost[start])\n\nfor i in out:\n print(int(i))\n'] | ['Runtime Error', 'Accepted'] | ['s069256089', 's691770861'] | [41720.0, 55856.0] | [1151.0, 934.0] | [933, 691] |
p03426 | u920299620 | 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())\ndata=[]\nfor i in range(1,H+1):\n tmp=list(map(int,input().split()))\n for j in range(1,W+1):\n data.append([i,j,tmp[j-1]])\n\ndata.sort(key=lambda x:x[2])\n\nruiseki=[]\nfor i in range(D):\n tmp=[0]\n j=i+D\n while(j<H*W):\n tmp.append( abs(data[j][0]-data[j-D][0]) +abs(data[j][1]-data[j-D][1]) +tmp[-1])\n j+=D\n ruiseki.append(tmp)\n\nQ=int(input())\nfor _ in range(Q):\n l,r=map(int,input().split())\n ind=l%D-1\n print(ruiseki[ind][r//D] - ruiseki[ind][l//D])', 'H,W,D=map(int,input().split())\ndata=[]\nfor i in range(1,H+1):\n tmp=list(map(int,input().split()))\n for j in range(1,W+1):\n data.append([i,j,tmp[j-1]])\n\ndata.sort(key=lambda x:x[2])\n\nruiseki=[]\nfor i in range(D):\n tmp=[0]\n j=i+D\n while(j<H*W):\n tmp.append( abs(data[j][0]-data[j-D][0]) +abs(data[j][1]-data[j-D][1]) +tmp[-1])\n j+=D\n ruiseki.append(tmp)\n\nQ=int(input())\nfor _ in range(Q):\n l,r=map(int,input().split())\n ind=l%D-1\n if(ind==-1):\n l-=D\n r-=D\n print(ruiseki[ind][r//D] - ruiseki[ind][l//D])'] | ['Runtime Error', 'Accepted'] | ['s851628338', 's324335535'] | [25188.0, 25316.0] | [425.0, 1118.0] | [523, 566] |
p03426 | u934868410 | 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())\np = [(0,0)] * (h*w)\nc = [0] * (h*w)\nfor i in range(h):\n a = list(map(int,input().split()))\n for j in range(w):\n p[a[j]-1] = (i,j)\n\nfor i in range(d, h*w):\n c[i] = c[i-d] + abs(p[i][0] - p[i-d][0]) + abs(p[i][1] - p[i-d][1])\n\nq = int(input())\nans = 0\nfor i in range(q):\n l,r = map(int,input().split())\n ans += c[r] - c[l]\nprint(ans)', 'h,w,d = map(int,input().split())\np = [(0,0)] * (h*w)\nc = [0] * (h*w)\nfor i in range(h):\n a = list(map(int,input().split()))\n for j in range(w):\n p[a[j]-1] = (i,j)\n\nfor i in range(d, h*w):\n c[i] = c[i-d] + abs(p[i][0] - p[i-d][0]) + abs(p[i][1] - p[i-d][1])\n\nq = int(input())\nans = 0\nfor i in range(q):\n l,r = map(int,input().split())\n print(c[r-1] - c[l-1])'] | ['Runtime Error', 'Accepted'] | ['s655178125', 's392310556'] | [13444.0, 14336.0] | [176.0, 943.0] | [372, 365] |
p03426 | u941884460 | 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. | ["tmp =input().split()\nH,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])\n\nlist = [[0 for x in range(W)] for y in range(H)]\ndict = {}\nfor i in range(H):\n tmp = input().split()\n for d in range(W):\n dict[tmp[d]] = str(i)+' '+str(d)\nresult ={}\ncost ={}\ndef calcost(L,R,D):\n if int(R)<D:\n cost[R]=0\n return 0\n elif (int(R)-int(L))<D:\n return 0\n else:\n posi1 = dict[R].split()\n posi2 = dict[str(int(R)-D)].split()\n costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))\n cost[R] = costs\n return costs + calcost(L,str(int(R)-D),D)\n\nfor n in range(1,H*W):\n calcost(str(1),str(n),D)\n\nQ = int(input())\nfor j in range(Q):\n tmpx = input()\n if tmpx in result:\n print(result[tmpx])\n else:\n tmp = tmpx.split()\n result[tmpx] = cost[tmp[1]]-cost[tmp[0]]\n print(result[tmpx])", "tmp =input().split()\nH,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])\n\nlist = [[0 for x in range(W)] for y in range(H)]\ndict = {}\nfor i in range(H):\n tmp = input().split()\n for d in range(W):\n dict[tmp[d]] = str(i)+' '+str(d)\nresult ={}\ncost ={}\n\ndef calcost(L,R,D):\n if int(R)<=D:\n cost[R] = 0\n return 0\n else:\n posi1 = dict[R].split()\n posi2 = dict[str(int(R)-D)].split()\n costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))\n if str(int(R)-D) in cost:\n cost[R] = costs + cost[str(int(R)-D)]\n return cost[R]\n else:\n cost[R] = costs + calcost(L,str(int(R)-D),D)\n return cost[R]\n\nfor n in range(D+1,H*W+1):\n calcost(str(1),str(n),D)\n\nQ = int(input())\nfor j in range(Q):\n tmpx = input()\n if tmpx in result:\n print(result[tmpx])\n else:\n tmp = tmpx.split()\n result[tmpx] = cost[tmp[1]]-cost[tmp[0]]\n print(result[tmpx])\nprint(cost)", "tmp =input().split()\nH,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])\n\nlist = [[0 for x in range(W)] for y in range(H)]\ndict = {}\nfor i in range(H):\n tmp = input().split()\n for d in range(W):\n dict[tmp[d]] = str(i)+' '+str(d)\nresult ={}\ncost ={}\ndef calcost(L,R,D):\n if int(R)<D:\n cost[R]=0\n return 0\n elif (int(R)-int(L))<D:\n return 0\n else:\n posi1 = dict[R].split()\n posi2 = dict[str(int(R)-D)].split()\n costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))\n cost[R] = costs\n return costs + calcost(L,str(int(R)-D),D)\n\nfor n in range(1,H*W):\n calcost(1,n,D)\n\nQ = int(input())\nfor j in range(Q):\n tmpx = input()\n if tmpx in result:\n print(result[tmpx])\n else:\n tmp = tmpx.split()\n result[tmpx] = cost[tmp[1]]-cost[tmp[0]]\n print(result[tmpx])", 'tmp =input().split()\nH,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])\n\nlist = [[0 for x in range(W)] for y in range(H)]\ndictx ={}\ndicty ={}\nfor i in range(H):\n tmp = input().split()\n for d in range(W):\n dictx[tmp[d]] = i\n dicty[tmp[d]] = d\ncost ={}\ndef calcost(R):\n if int(R)<=D:\n cost[R] = 0\n return 0\n else:\n costs = abs(dictx[R]-dictx[str(int(R)-D)]) + abs(dicty[R]-dicty[str(int(R)-D)])\n cost[R] = costs + cost[str(int(R)-D)]\n return cost[R]\n\nfor n in range(1,H*W+1):\n calcost(str(n))\nQ = int(input())\nfor j in range(Q):\n tmp = input().split()\n print(str(cost[tmp[1]]-cost[tmp[0]]))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s496823099', 's719877828', 's833320441', 's744509520'] | [37016.0, 56848.0, 34968.0, 41488.0] | [2104.0, 1347.0, 138.0, 1074.0] | [886, 996, 876, 649] |
p03426 | u952708174 | 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 d_practical_skill_test(H, W, D, A, Q, I):\n import numpy\n a = numpy.array(A)\n tmp = []\n for i in range(D):\n i += 1 + D\n t = [0]\n while i <= H * W:\n j, k = numpy.where(a == i)\n l, m = numpy.where(a == i - D)\n j, k = j[0], k[0]\n l, m = l[0], m[0]\n t.append(t[-1] + abs(j - l) + abs(k - m))\n i += D\n tmp.append(t)\n for l, r in I:\n l = l - 1\n r = r - 1\n start = l % D\n print(tmp[start][r // D] - tmp[start][l // D])\n\nH,W,D = [int(i) for i in input().split()]\nA = [[int(i) for i in input().split()] for j in range(H)]\nQ = int(input())\nI = [[int(i) for i in input().split()] for j in range(Q)]\nprint(d_practical_skill_test(H, W, D, A, Q, I))', 'def d_practical_skill_test(H, W, D, A, Q, I):\n import numpy\n a = numpy.array(A)\n tmp = []\n for i in range(D):\n i += 1 + D\n t = [0]\n while i <= H * W:\n j, k = numpy.where(a == i)\n l, m = numpy.where(a == i - D)\n j, k = j[0], k[0]\n l, m = l[0], m[0]\n t.append(t[-1] + abs(j - l) + abs(k - m))\n i += D\n tmp.append(t)\n for l, r in I:\n l = l - 1\n r = r - 1\n start = l % D\n print(tmp[start][r // D] - tmp[start][l // D])\n return None\n\nH,W,D = [int(i) for i in input().split()]\nA = [[int(i) for i in input().split()] for j in range(H)]\nQ = int(input())\nI = [[int(i) for i in input().split()] for j in range(Q)]\nprint(d_practical_skill_test(H, W, D, A, Q, I))', "def d_practical_skill_test(H, W, D, A, Q, I):\n \n px = [0 for _ in range(H * W + 1)]\n py = [0 for _ in range(H * W + 1)] \n d = [0 for _ in range(H * W + 1)] \n for i in range(H):\n for j in range(W):\n px[A[i][j]] = i\n py[A[i][j]] = j\n for i in range(D + 1, H * W + 1):\n d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D])\n ans = []\n for l, r in I:\n ans.append(str(d[r] - d[l]))\n return '\\n'.join(ans)\n\nH,W,D = [int(i) for i in input().split()]\nA = [[int(i) for i in input().split()] for j in range(H)]\nQ = int(input())\nI = [[int(i) for i in input().split()] for j in range(Q)]\nprint(d_practical_skill_test(H, W, D, A, Q, I))"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s270842060', 's413962680', 's184188172'] | [44520.0, 44532.0, 37120.0] | [2110.0, 2110.0, 455.0] | [775, 791, 871] |
p03426 | u976256337 | 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. | ['\nH, W, D = map(int, input().split())\n\ncoord_dict_x = [0 for i in range(90001)]\ncoord_dict_y = [0 for i in range(90001)]\n\nfor i in range(H):\n gyo = [int(i) for i in input().split()]\n for j in range(W):\n coord_dict_x[gyo[j]] = i\n coord_dict_y[gyo[j]] = j\n\nQ = int(input())\nexam = [[int(i) for i in input().split()] for i in range(Q)]\n\nfor i in range(Q):\n reduce_MP = 0\n num = exam[i][0]\n coord1_x = coord_dict_x[num]\n coord1_y = coord_dict_y[num]\n while num < exam[i][1]:\n num += D\n coord2_x = coord_dict_x[num]\n coord2_y = coord_dict_y[num]\n reduce_MP += abs(coord1_x - coord2_x) + abs(coord1_y - coord2_y)\n coord1 = coord2\n print(reduce_MP)\n\n', 'H, W, D = list(map(int, input().split()))\n\nAmap = []\nfor i in range(H):\n Amap.append(list(map(int, input().split())))\n\nxx = [0 for i in range(90002)]\nyy = [0 for i in range(90002)]\nfor y in range(H):\n for x in range(W):\n xx[Amap[y][x]] = x\n yy[Amap[y][x]] = y\nQ = int(input())\n\ncoord = []\nfor i in range(Q):\n coord.append(list(map(int, input().split())))\n\n# magic point calculation\nmp = [0 for i in range(90002)]\n\nfor i in range(D+1, 90002):\n mp[i] = mp[i-D] + abs(xx[i] -xx[i-D]) + abs(yy[i] - yy[i-D])\n\nfor i in coord:\n print(mp[i[1]] - mp[i[0]])'] | ['Runtime Error', 'Accepted'] | ['s804067018', 's202897792'] | [23888.0, 37268.0] | [460.0, 584.0] | [715, 577] |
p03426 | u977193988 | 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\nfrom collections import defaultdict\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nsys.setrecursionlimit(20000000)\n\n\ndef main():\n H, W, D = map(int, input().split())\n A = [list(map(int, input().split())) for _ in range(H)]\n M = defaultdict(list)\n for h in range(H):\n for w in range(W):\n M[A[h][w]] = [h, w]\n P = defaultdict(list)\n for d in range(1, D + 1):\n a = d\n while a <= H * W - D:\n p = abs(M[a][0] - M[a + D][0]) + abs(M[a][1] - M[a + D][1])\n if P[d]:\n P[d].append(P[d][-1] + p)\n else:\n P[d] = [0, p]\n a += D\n Q = int(input())\n for i in range(Q):\n L, R = map(int, input().split())\n d = L % D\n l = L // D\n r = R // D\n if d == 0:\n if len(P[d]) > 0:\n d = D\n print(P[d][r - 1] - P[d][l - 1])\n else:\n print(0)\n else:\n print(P[d][r] - P[d][l])\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\nfrom collections import defaultdict\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nsys.setrecursionlimit(20000000)\n\n\ndef main():\n H, W, D = map(int, input().split())\n A = [list(map(int, input().split())) for _ in range(H)]\n M = defaultdict(list)\n for h in range(H):\n for w in range(W):\n M[A[h][w]] = [h, w]\n P = defaultdict(list)\n for d in range(1, D + 1):\n a = d\n while a <= H * W - D:\n p = abs(M[a][0] - M[a + D][0]) + abs(M[a][1] - M[a + D][1])\n if P[d]:\n P[d].append(P[d][-1] + p)\n else:\n P[d] = [0, p]\n a += D\n # print(P)\n Q = int(input())\n for i in range(Q):\n L, R = map(int, input().split())\n d = L % D\n l = L // D\n r = R // D\n if d == 0:\n d = D\n if len(P[d]) > 0:\n print(P[d][r - 1] - P[d][l - 1])\n else:\n print(0)\n else:\n if len(P[d])>0:\n print(P[d][r] - P[d][l])\n else:\n print(0)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s957025758', 's682856639'] | [26556.0, 34112.0] | [482.0, 488.0] | [1055, 1141] |
p03426 | u989345508 | 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 math import ceil\nh,w,d=map(int,input().split())\nx=ceil((h*w)/d)\nnum=[[[-1,-1] for j in range(x)] for i in range(d)]\nmp=[[0]*x for i in range(d)]\na=[list(map(int,input().split())) for i in range(h)]\nfor i in range(h):\n for j in range(w):\n k,l=a[i][j]%d,a[i][j]//d\n if k==0:\n num[d-1][l-1]=[i,j]\n else:\n num[k-1][l]=[i,j]\nfor i in range(d):\n for j in range(x):\n if j!=x-1:\n if num[i][j+1]!=[-1,-1]:\n mp[i][j+1]+=(mp[i][j]+abs(num[i][j+1][0]-num[i][j][0])+abs(num[i][j+1][1]-num[i][j][1]))\n else:\n break\nq=int(input())\nfor i in range(q):\n l,r=map(int,input().split())\n if l%d!=0:\n e,f=l//d,r//d\n else:\n e,f=l//d-1,r//d-1\n g= d-1 if l%d==0 else l%d-1\n print(mp[g][f])', 'from math import ceil\nh,w,d=map(int,input().split())\nx=ceil((h*w)/d)\nnum=[[[-1,-1] for j in range(x)] for i in range(d)]\nmp=[[0]*x for i in range(d)]\na=[list(map(int,input().split())) for i in range(h)]\nfor i in range(h):\n for j in range(w):\n k,l=a[i][j]%d,a[i][j]//d\n if k==0:\n num[d-1][l-1]=[i,j]\n else:\n num[k-1][l]=[i,j]\nfor i in range(d):\n for j in range(x):\n if j!=x-1:\n if num[i][j+1]!=[-1,-1]:\n mp[i][j+1]+=(mp[i][j]+abs(num[i][j+1][0]-num[i][j][0])+abs(num[i][j+1][1]-num[i][j][1]))\n else:\n break\nq=int(input())\nfor i in range(q):\n l,r=map(int,input().split())\n if l%d!=0:\n e,f=l//d,r//d\n else:\n e,f=l//d-1,r//d-1\n g= d-1 if l%d==0 else l%d-1\n if e==0:\n print(mp[g][f])\n else:\n print(mp[g][f]-mp[g][e])\n'] | ['Wrong Answer', 'Accepted'] | ['s248454430', 's099855422'] | [35692.0, 35692.0] | [1166.0, 1158.0] | [837, 898] |
p03427 | u014139588 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = int(input())\nprint(n//10**(len(str(n))-1))\nif (n//10**(len(str(n))-1)+1)*10**(len(str(n))-1)-1 > n:\n mx = (n//10**(len(str(n))-1))*10**(len(str(n))-1)-1\nelse:\n mx = (n//10**(len(str(n))-1)+1)*10**(len(str(n))-1)-1\nprint(sum(list(map(int,str(mx)))))', 'n = int(input())\nif (n//10**(len(str(n))-1)+1)*10**(len(str(n))-1)-1 > n:\n mx = (n//10**(len(str(n))-1))*10**(len(str(n))-1)-1\nelse:\n mx = (n//10**(len(str(n))-1)+1)*10**(len(str(n))-1)-1\nprint(sum(list(map(int,str(mx)))))'] | ['Wrong Answer', 'Accepted'] | ['s794955734', 's602818702'] | [9152.0, 9204.0] | [30.0, 29.0] | [254, 224] |
p03427 | u027929618 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=list(map(int,input()))\ns=sum(n)\nk=len(n)\nprint(max(n[0]-1)+9*(k-1),s))', 'n=list(map(int,input()))\ns=sum(n)\nk=len(n)\nprint(max(n[0]-1)+9*(k-1),s)', 'n=list(map(int,input()))\ns=sum(n)\nk=len(n)\nprint(max((n[0]-1)+9*(k-1),s))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s662580136', 's721653450', 's071526038'] | [2940.0, 2940.0, 2940.0] | [18.0, 20.0, 17.0] | [72, 71, 73] |
p03427 | u050428930 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = list(input())\nprint(N)\nif 1!=len(N):\n if N[1]!=9:\n print(int(N[0])-1+9*(len(N)-1))\n elif N[i+1]==9:\n print(int(N[0])+9*(len(N)-1))\nelse:\n print(N[0])', '3141592653589793', 'def f(s):\n p=0\n for i in str(s):\n p+=int(i)\n return p\nN=int(input())\ni=1\nans=f(N)\nwhile N>=10**i:\n p=f((N//10**i)*(10**i)-1)\n ans=max(ans,p)\n i+=1\nprint(ans) \n \n \n '] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s317957986', 's615221667', 's814754683'] | [3060.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [176, 16, 199] |
p03427 | u060793972 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['print(sum([int(i) for i in input()]))', 's=input()\nk=10**(len(s)-1)\nprint(sum(map(int,str(int(s)//k))) if len(s)!=1 else s)', 's=input()\nk=10**(len(s)-1)\n#print(s,str(int(s)//k*k-1))\nprint(sum(map(int,str((int(s)+1)//k*k-1))) if len(s)!=1 else s)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s209683147', 's920839561', 's654729061'] | [2940.0, 9132.0, 9112.0] | [17.0, 29.0, 26.0] | [37, 82, 119] |
p03427 | u064408584 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['def A_Digit_Sum_2():\n a=input()\n b=str(a)\n c=0\n for i in range(len(b)):\n c +=int(b[i])\n print(c)\n\nA_Digit_Sum_2()', "def A_Digit_Sum_2():\n a=input()\n count=0\n c=0\n for i in range(len(a)-1):\n if a[i+1]=='9':\n count+=1\n #print(count)\n if count==(len(a)-1):\n for i in range(len(a)):\n c+=int(a[i])\n else:\n c=(len(a)-1)*9+int(a[0])-1\n print(c)\n\nA_Digit_Sum_2()"] | ['Wrong Answer', 'Accepted'] | ['s664303857', 's844985524'] | [3316.0, 3064.0] | [19.0, 18.0] | [135, 305] |
p03427 | u086503932 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["import sys\nimport math\n\ndef main():\n N = int(input())\n digit = int(math.log10(N))\n c = int(str(N)[0])\n if N > int(str(c) + '9'*digit):\n print(9 * digit + c -1)\n else:\n print(9 * digit + c)\n\nif __name__ == '__main__':\n main()", "#!/usr/bin/env python3\nimport sys\nimport math\n\ndef main():\n N = int(input())\n digit = math.floor(math.log10(N))\n c = N // 10**digit\n if N == (1 + c) * 10 ** digit - 1:\n print(9 * digit + c)\n else:\n print(9 * digit + c -1)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s548375153', 's061873190'] | [3060.0, 3188.0] | [18.0, 18.0] | [256, 291] |
p03427 | u089142196 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N=int(input())\nS=str(N)\nflag=False \n\nfor i in range(1,len(S)):\n #print(i,S[i])\n if S[i]!="9":\n flag=False\n break\nelse:\n flag=True\n\nif flag:\n print(N)\nelse:\n top=int(S[0])-1\n if top==0:\n top_s=""\n else:\n top_s=str(top)\n nokori = str(9)*(len(S)-1)\n print(top_s+nokori)', 'N=int(input())\nS=str(N)\nflag=False \n\nfor i in range(1,len(S)):\n #print(i,S[i])\n if S[i]!="9":\n flag=False\n break\nelse:\n flag=True\n\nif flag:\n print( int(S[0]) + 9*(len(S)-1) )\nelse:\n top=int(S[0])-1\n print(top + 9*(len(S)-1))'] | ['Wrong Answer', 'Accepted'] | ['s943317828', 's089534530'] | [3188.0, 3064.0] | [19.0, 17.0] | [349, 284] |
p03427 | u090406054 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=list(input())\nn_list=[int(i) for i in n]\nif n_list[0]!=1 and set(n_list)!=[9]:\n ans=9*(len(n_list)-1)+n_list[0]-1\n print(ans)\nelif n_list[0]!=1 and set(n_list)==[9]:\n print(9*len(n_list))\nelif n_list[0]+n_list[1]<=9:\n ans=(len(n_list)-1)*9\nelse:\n ans=n_list[0]+n_list[1]-1+9*(len(n_list)-2)\n \n ', 'N = input()\nans = 0\n\nif N[1:] == "9" * (len(N) - 1):\n ans = int(N[0]) + (9 * (len(N) - 1))\nelse:\n ans = int(N[0]) + 9 * (len(N) - 1) - 1\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s626228289', 's339974528'] | [9080.0, 9020.0] | [25.0, 28.0] | [303, 155] |
p03427 | u102960641 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = input()\nn0 = int(n[0])\nln = len(n)\nif ln == 1:\n print(n0)\nelif n[1:] == "9"*(ln-1):\n print(n0+9*(ln-1))\nelse:\n print(n0+9*(ln-1)-1)\n\nprint("9"*(ln-1))\nprint(n[1:-1])', 'n = input()\nn0 = int(n[0])\nln = len(n)\nif ln == 1:\n print(n0)\nelif n[1:] == "9"*(ln-1):\n print(n0+9*(ln-1))\nelse:\n print(n0+9*(ln-1)-1)\n'] | ['Wrong Answer', 'Accepted'] | ['s549668199', 's935654345'] | [3060.0, 2940.0] | [18.0, 18.0] | [172, 139] |
p03427 | u131453093 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\n\na = len(N) - 1\nb = int(N[0])\n\nans = (b-1) + 9 * a\n\nif int(str(b) + "9"*a) < int(N):\n print(ans)\nelse:\n ans = b + 9 * a\n print(ans)\n\n', 'N = input()\nans = 0\n\nif N[1:] == "9" * (len(N) - 1):\n ans = int(N[0]) + (9 * (len(N) - 1))\nelse:\n ans = int(N[0]) + 9 * (len(N) - 1) - 1\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s881107136', 's588401003'] | [9156.0, 9036.0] | [27.0, 25.0] | [154, 155] |
p03427 | u134019875 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["n = int(input())\nans = 0\nif len(str(n)) > 2:\n ans += (len(str(n)) - 2) * 9\n X = n // 10 ** (len(str(n)) - 2)\n if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:\n ans += 1\nelse:\n X = n\n if X == 99:\n ans += 1\nif len(str(X)) == 1:\n ans += X\nelse:\n if X % 10 == 0 or X // 10 == 9:\n ans -= 1\n ans += (X // 10 - 1) + 9\nprint(ans)\n", "n = int(input())\nn_str = str(n)\nans = int(n_str[0])\nif n_str[1:].count('9') != len(n_str) - 1:\n ans -= 1\nans += int(len(n_str[1:])) * 9\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s544227237', 's510008293'] | [3064.0, 9176.0] | [17.0, 25.0] | [385, 150] |
p03427 | u136395536 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\np = N[0]\n\nans = 9*(len(N)-1) + (int(p)-1)\nif int(N)>ans:\n ans = int(N)\nprint(ans)', 'N = input()\nnewN = N[1:]\np = N[0]\nnines = newN.count("9")\nif nines == len(newN):\n ans = 9*(len(N)-1) + (int(p))\nelse:\n ans = 9*(len(N)-1) + (int(p)-1)\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s067646206', 's774046834'] | [2940.0, 3060.0] | [17.0, 17.0] | [96, 168] |
p03427 | u148551245 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = int(input())\na = list(map(int, input().split()))\na.sort(reverse=True)\n\nans = sum(a[1:2*n+1:2])\nprint(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\na.sort(reverse=True)\n\nans = sum(a[1:2*(n+1):2])\nprint(ans)\n', 'x = int(input())\nx += 1\n\nans = 9 * (len(str(x))-1) + int(str(x)[0])-1\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s106579881', 's179739906', 's191452125'] | [2940.0, 2940.0, 2940.0] | [17.0, 18.0, 17.0] | [110, 112, 81] |
p03427 | u151625340 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\nif len(N) == 1:\n print(int(N))\nelse:\n print(max(sum(list(N)),(len(N)-1)*9+int(N[0])-1))\n', 'N = input()\nif len(N) == 1:\n print(int(N))\nelse:\n print(max(sum([int(i) for i in N]),(len(N)-1)*9+int(N[0])-1))\n'] | ['Runtime Error', 'Accepted'] | ['s063973010', 's173570991'] | [2940.0, 2940.0] | [18.0, 18.0] | [106, 118] |
p03427 | u163320134 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=input()\nans=int(n[0])+(len(n)-1)*9\nprint(ans)', "n=input()\nif len(n)==1:\n print(int(n))\nelse:\n cnt=n[1:].count('9')\n if cnt1==len(n)-1:\n print(int(n[0])+9*(len(n)-1))\n else:\n print(int(n[0])-1+9*(len(n)-1))", "n=input()\nif len(n)==1:\n print(int(n))\nelse:\n cnt=n[1:].count('9')\n if cnt==len(n)-1:\n print(int(n[0])+9*(len(n)-1))\n else:\n print(int(n[0])-1+9*(len(n)-1))\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s565992743', 's968694340', 's293378274'] | [2940.0, 3060.0, 2940.0] | [17.0, 17.0, 18.0] | [47, 167, 167] |
p03427 | u163421511 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['\ndef maxf(n):\n a = list(map(int, list(n)))\n for i, item in enumerate(a):\n if i == 0 and item != 9:\n if a[i+1:] == [9]*(len(a)-1):break\n a[i] -=1\n a[i+1:] = [9]*(len(a)-1)\n break\n elif item != 9:\n a[i-1] -= 1\n a[i:] = [9]*(len(a)-i)\n break\n return a, sum(a)\n\nprint(maxf(input()))\n', 'def maxf(n):\n a = list(map(int, list(n)))\n for i, item in enumerate(a):\n if i == 0 and item != 9:\n a[i] -=1\n a[i+1:] = [9]*(len(a)-1)\n break\n elif item != 9:\n a[i-1] -= 1\n a[i:] = [9]*(len(a)-i)\n break\n return sum(a)\n\nprint(maxf(input())\n', 'def maxf(n):\n a = list(map(int, list(n)))\n for i, item in enumerate(a):\n if i == 0 and item != 9:\n if a[i+1:] == [9]*(len(a)-1):break\n a[i] -=1\n a[i+1:] = [9]*(len(a)-1)\n break\n elif item != 9:\n a[i-1] -= 1\n a[i:] = [9]*(len(a)-i)\n break\n return sum(a)\n\nprint(maxf(input()))\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s579201409', 's705103653', 's760592737'] | [9144.0, 9000.0, 9064.0] | [26.0, 23.0, 30.0] | [379, 327, 375] |
p03427 | u171065106 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = int(input())\n\nsum = int(n[0]) + (len(n)-1) * 9\nprint(sum if set(n[1:]) == {"9"} else sum - 1)\n', 'n = input()\n\nsum = int(n[0]) + (len(n)-1) * 9\n\nif len(n) == 1:\n print(n)\nelse:\n print(sum if set(n[1:]) == {"9"} else sum - 1)\n'] | ['Runtime Error', 'Accepted'] | ['s947358355', 's374579866'] | [9068.0, 9092.0] | [29.0, 27.0] | [98, 133] |
p03427 | u221345507 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["N=list(input())\nmark=0\nfor i in range (len(N)):\n if N[i]!='9':\n mark=i\n print (mark)\n break\nif mark==0:\n answer=list((''.join(['9']*(len(N)-1))))\nelse:\n answer=list((''.join(N[:mark-1]+[str(int(N[mark-1])-1)]+['9']*len(N[mark:]))))\n \nanswer_sum=0\nfor j in range (len(answer)):\n answer_sum+=int(answer[j])\nprint(answer_sum)", "N=list(input())\nimport sys\nmark=0\nfor i in range (len(N)):\n if N[i]!='9':\n mark=i\n break\nif mark==0 and N[mark+1:]==['9']*len(N[mark+1:]):\n count=0\n for l in range (len(N)):\n count+=int(N[l])\n print(count)\n sys.exit()\nN[0]=str(int(N[0])-1)\nfor j in range (1,len(N)):\n N[j]='9'\ncount=0\nfor k in range (len(N)):\n count+=int(N[k])\nprint(count)"] | ['Wrong Answer', 'Accepted'] | ['s829217474', 's986043219'] | [3064.0, 3064.0] | [20.0, 18.0] | [358, 382] |
p03427 | u223133214 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["N=input()\nans=''\nif N[0]!='1':\n for i,n in enumerate(list(N)):\n if n !='9':\n if n == '0':\n key=ans[-1]\n ans.rstrip('90')\n ans+='89'\n ans+='9'*(len(N)-i-2)\n break\n ans+=str(int(n)-1)\n ans+='9'*(len(N)-i-1)\n break\n else:\n ans+='9'\nelse:\n ans='9'*(len(N)-1)\nprint(ans)\nans1=sum(list(map(int,list(ans))))\nans2=sum(list(map(int,list(N))))\nprint(max(ans1,ans2))\n\n\n", "N=input()\nans=''\nif N[0]!='1':\n for i,n in enumerate(list(N)):\n if n !='9':\n if n == '0':\n key=ans[-1]\n ans=ans.rstrip('9')\n ans+='8'\n ans+='9'*(len(N)-i)\n break\n ans+=str(int(n)-1)\n ans+='9'*(len(N)-i-1)\n break\n else:\n ans+='9'\nelse:\n ans='9'*(len(N)-1)\nprint(ans)\nans1=sum(list(map(int,list(ans))))\nans2=sum(list(map(int,list(N))))\nprint(max(ans1,ans2))\n\n\n", 'N=input()\nans1=sum(list(map(int,list(N))))\nans2=int(N[0])-1+9*(len(N)-1)\nprint(max(ans1,ans2))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s339206297', 's908870000', 's188848332'] | [3064.0, 3064.0, 2940.0] | [17.0, 18.0, 18.0] | [508, 508, 95] |
p03427 | u227082700 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=input()\nif len(n)==1:print(n)\nelif n="9"*len(n):print(9*len(n))\nelse:print(9*(len(n)-1)+int(n[0])-1)', 'n=input()\nif len(n)==1:print(n)\nelif n=="9"*len(n):print(9*len(n))\nelif n[1:]=="9"*(len(n)-1):print(int(n[0])+9*(len(n)-1))\nelse:print(9*(len(n)-1)+int(n[0])-1)'] | ['Runtime Error', 'Accepted'] | ['s066307713', 's720214343'] | [2940.0, 3060.0] | [17.0, 18.0] | [102, 160] |
p03427 | u241159583 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['s = list(input())\nans = [sum(map(int, s)), 9*(len(s)-1) + int(s[0]-1)]\nprint(max(ans))', 's = list(input())\nans = [sum(map(int, s)), 9 * (len(s) - 1) + int(s[0]) - 1]\nprint(max(ans))'] | ['Runtime Error', 'Accepted'] | ['s935769111', 's583775285'] | [8992.0, 9068.0] | [28.0, 29.0] | [86, 92] |
p03427 | u248670337 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=str(int(input())+1)\nprint(sum(map(int,list(n[0]+[0]*(len(n)-1)))))\n', "n=str(int(input())+1)\nprint(sum(map(int,list(str(int(n[0]+'0'*(len(n)-1))-1)))))"] | ['Runtime Error', 'Accepted'] | ['s697638846', 's687693519'] | [2940.0, 2940.0] | [17.0, 17.0] | [69, 80] |
p03427 | u268793453 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = [int(x) for x in input()]\nprint(max(sum(N), N[0]-1+9*len(N))', 'N = input()\nN_list = list(str(N))\nsum = 0\n\nfor i in N_list:\n sum += int(i)\n\nprint (sum)', 'N = [int(x) for x in input()]\nprint(max(sum(N), N[0]-1+9*len(N)))', 'N = [int(x) for x in input()]\nprint(max(sum(N), N[0]-1+9*(len(N)-1)))'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s789277089', 's828364989', 's997437424', 's893644367'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [64, 90, 65, 69] |
p03427 | u269724549 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['m=list(map(int,input().split()))\na=int(m[0])-1+(len(m)-1)*9\ns=sum(m)\nprint(max(s,a))\n', 'm=input()\na=int(m[0])-1+(len(m)-1)*9\nb=0\nfor i in n:\n b+=i\nprint(max(b,a))', 'm=input()\na=int(m[0])-1+(len(m)-1)*9\nb=0\nfor i in n:\n b+=int(i)\nprint(max(b,a))\n', 'm=input()\na=int(m[0])-1+(len(m)-1)*9\nb=0\nfor i in m:\n b+=int(i)\nprint(max(b,a))\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s293836302', 's793766069', 's866040287', 's909295340'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 20.0, 17.0] | [85, 75, 81, 81] |
p03427 | u276204978 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["N = input()\nl = len(N)\n\ns = '9'*(l-1)\nif N[i::] == s:\n print(int(N[0])+9*(l-1))\nelse:\n print(int(N[0])-1+9*(l-1))", 'N = input()\nl = len(N)\n\nif N[i::] == "9"*(l-1):\n print(int(N[0])+9*(l-1))\nelse:\n print(int(N[0])-1+9*(l-1))', 'N = input()\n\nl = len(N)\nj = "9"*(l-1)\n\nif n[i::] == j:\n print(int(n[0])+9*(n-1))\nelse:\n print(int(n[0])-1+9*(k-1))', 'N = input()\nl = len(N)\n\nif n[i::] == "9"*(l-1):\n print(int(n[0])+9*(l-1))\nelse:\n print(int(n[0])-1+9*(l-1))', "N = input()\nl = len(N)\n\nif N[i::] == '9'*(l-1):\n print(int(N[0])+9*(l-1))\nelse:\n print(int(N[0])-1+9*(l-1))", 'N = input()\n\nl = len(N)\n\nif N[i::] == "9"*(l-1):\n print(int(N[0])+9*(l-1))\nelse:\n print(int(N[0])-1+9*(l-1))', "N = input()\nl = len(N)\n\nif N[1::] == '9'*(l-1):\n print(int(N[0])+9*(l-1))\nelse:\n print(int(N[0])-1+9*(l-1))"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s063347762', 's390098780', 's486761119', 's550257883', 's808594448', 's984884013', 's865357534'] | [2940.0, 2940.0, 2940.0, 2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 18.0, 17.0, 17.0, 17.0, 17.0, 18.0] | [119, 113, 120, 113, 113, 114, 113] |
p03427 | u277429554 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = input()\nans1=int(n[0])\nfor i in n:\n ans1 += int(i)\nans2=int(n[0])-1+9*(len(n)-1)\nprint(max(ans1,ans2)', 'n = input()\nans1=sum(int(i)for i in n)\nans2=int(n[0])-1+9*(len(n)-1)\nprint(max(ans1,ans2)', 'n = input()\nans1=sum(int(i)for i in n)\nans2=int(n[0])-1+9*(len(n)-1)\nprint(max(ans1,ans2))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s328930221', 's746167023', 's749044751'] | [9044.0, 8980.0, 8960.0] | [25.0, 23.0, 28.0] | [106, 89, 90] |
p03427 | u280978334 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\ndigit = len(N)\nans=[int(N[0])-1]+[9]*(digit-1)\nprint(ans)\nprint(sum(ans))', 'N = input()\ndigit = len(N)\nif(digit == 1):\n print(int(N))\n\nelif(N[1:] == "9"*(digit-1)):\n print(9*(digit-1)+int(N[0]))\nelse:\n ans=[int(N[0])-1]+[9]*(digit-1)\n print(sum(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s258291453', 's838106481'] | [2940.0, 3060.0] | [18.0, 18.0] | [85, 187] |
p03427 | u293579463 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = int(input())\nnum = str(N)\nfor i in range(1,len(num)):\n if num[-i] != "9" and 0 < N - (int(num[-i]) + 1) * 10**(i-1):\n N -= (int(num[-i]) + 1) * 10**(i-1)\n num = str(N)\n print(N)\n\nD = 0\nfor digit in str(N):\n D += int(digit)\n\nprint(D)\n', 'N = int(input())\nnum = str(N)\nfor i in range(1,len(num)):\n if num[-i] != "9" and 0 < N - (int(num[-i]) + 1) * 10**(i-1):\n N -= (int(num[-i]) + 1) * 10**(i-1)\n num = str(N)\n\nD = 0\nfor digit in str(N):\n D += int(digit)\n\nprint(D)'] | ['Wrong Answer', 'Accepted'] | ['s681255766', 's610300449'] | [3060.0, 3060.0] | [17.0, 17.0] | [264, 246] |
p03427 | u314057689 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['def solve():\n N = list(map(int, list(input())))\n print(N)\n\n res = 0\n for i in range(len(N)):\n tmp = 0\n for j in range(len(N)):\n if j <= i-1:\n tmp += N[j]\n elif j==i:\n tmp += N[j]-1\n else:\n tmp += 9\n res = max(res, tmp)\n\n print(res)\n\n\nif __name__ == "__main__":\n solve()\n\n\n', 'def solve():\n I = input()\n N = list(map(int, list(I)))\n\n res = sum(N)\n\n for i in range(len(N)):\n tmp = 0\n for j in range(len(N)):\n if j <= i-1:\n tmp += N[j]\n elif j==i:\n tmp += N[j]-1\n else:\n tmp += 9\n res = max(res, tmp)\n\n print(res)\n\n\nif __name__ == "__main__":\n solve()\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s708072460', 's145443594'] | [3060.0, 3060.0] | [18.0, 18.0] | [389, 392] |
p03427 | u319612498 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=int(input())\nif N<10:\n print(n)\nelse:\n L=list(map(int, list(str(N))))\n if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):\n print(sum(L))\n else :\n print(9*(len(L)-1)+int(L[0])-1)\n', 'if n<10:\n print(n)\nelse:\n L=list(map(int, list(str(n))))\n if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):\n print(sum(L))\n else :\n print(9*(len(L)-1)+int(L[0])-1)\n\n', 'n=int(input())\nif n<10:\n print(n)\nelse:\n L=list(map(int, list(str(n))))\n if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):\n print(sum(L))\n else :\n print(9*(len(L)-1)+int(L[0])-1)\n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s653665809', 's741948455', 's030931978'] | [3060.0, 2940.0, 3060.0] | [17.0, 17.0, 17.0] | [202, 188, 203] |
p03427 | u325264482 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = int(input())\n\n\ndef digitSum(n):\n s = str(n)\n array = list(map(int, list(s)))\n return sum(array)\n\nmin_sum = 1000000\nfor i in range(N - 1):\n A = i + 1\n B = N - A\n tmp = digitSum(A) + digitSum(B)\n if tmp < min_sum:\n min_sum = tmp\n\nans = min_sum\nprint(ans)\n', 'S = input()\nN = len(S)\n\n\ndef digitSum(n):\n s = str(n)\n array = list(map(int, list(s)))\n return sum(array)\n\nans = digitSum(S)\ncandidate = (int(S[0]) - 1) * pow(10, N-1) + (pow(10, N-1) - 1)\ncandidate = digitSum(candidate)\n\nif ans > candidate:\n print(ans)\nelse:\n print(candidate)\n'] | ['Wrong Answer', 'Accepted'] | ['s550453904', 's997813914'] | [3060.0, 3060.0] | [2104.0, 18.0] | [299, 307] |
p03427 | u344122377 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = input()\n\nif len(n) == 1:\n print(n)\n exit()\n\nok = False\nans = ""\nfor i, c in enumerate(n):\n x = int(c)\n if x == 9:\n ans += "9"\n else:\n if ok:\n ans += "9"\n else:\n if i == len(n)-1:\n ans = ans[:-1]\n ans += str(int(n[i-1])-1)\n ans += "9"\n else:\n ans += str(x-1)\n ok = True\n\nprint(ans)\nt = 0\nfor c in ans:\n x = int(c)\n t += x\nprint(t)', 'n = input()\n\nif len(n) == 1:\n print(n)\n exit()\n\nif all(x == "9" for x in n[1:]):\n ans = n\nelse:\n ok = False\n ans = ""\n for i, c in enumerate(n):\n x = int(c)\n if x == 9:\n ans += "9"\n else:\n if ok:\n ans += "9"\n else:\n if i == len(n)-1:\n ans = ans[:-1]\n ans += str(int(n[i-1])-1)\n ans += "9"\n else:\n ans += str(x-1)\n ok = True\nt = 0\nfor c in ans:\n x = int(c)\n t += x\n\nprint(t)'] | ['Wrong Answer', 'Accepted'] | ['s562877619', 's555153775'] | [3064.0, 3064.0] | [17.0, 17.0] | [395, 467] |
p03427 | u345778634 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = int(input())\nx = 9\norder = 0\nfor i in range(16):\n if x > N:\n break\n x = x*10+9\n order = i+1\nans = x\nfor i in range(10):\n ans -= 10**order\n print(ans)\n if ans <= N:\n break\nret = 0\nwhile True:\n if ans == 0:\n break\n ret += ans % 10\n ans = ans//10\nprint(ret)', 'N = int(input())\nx = 9\norder = 0\nfor i in range(16):\n if x > N:\n break\n x = x*10+9\n order = i+1\nans = x\nfor i in range(10):\n ans -= 10**order\n print(ans)\n if ans < N:\n break\nret = 0\nwhile True:\n if ans == 0:\n break\n ret += ans % 10\n ans = ans//10\nprint(ret)', 'N = int(input())\nx = 9\norder = 0\nfor i in range(16):\n if x > N:\n break\n x = x*10+9\n order = i+1\nans = x\nfor i in range(10):\n ans -= 10**order\n if ans <= N:\n break\nret = 0\nwhile True:\n if ans == 0:\n break\n ret += ans % 10\n ans = ans//10\nprint(ret)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s158249326', 's698147704', 's787886583'] | [9184.0, 9124.0, 9124.0] | [26.0, 2205.0, 35.0] | [307, 306, 292] |
p03427 | u347640436 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['9999999999999999', 'N = input()\nn = int(N)\nt = n % 10 ** (len(N) - 1) + 1\nprint(max(sum(map(int, N)), sum(map(int, str(n - t)))))\n'] | ['Wrong Answer', 'Accepted'] | ['s241544045', 's326169332'] | [2940.0, 2940.0] | [17.0, 17.0] | [16, 110] |
p03427 | u350093546 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["n=int(input())\nif n<=9:\n print(n)\nelse:\n n=str(n)\n x=n[0]\n x=int(x)-1\n if n[1:].count('9')==len(n-1):\n print(x+1(len(n)-1)*9)\n else:\n print(x+(len(n)-1)*9)\n", "n=int(input())\nif n<=9:\n print(n)\nelse:\n n=str(n)\n x=n[0]\n x=int(x)-1\n if n[1:].count('9')==len(n)-1:\n print(x+1+(len(n)-1)*9)\n else:\n print(x+(len(n)-1)*9)\n"] | ['Runtime Error', 'Accepted'] | ['s849267912', 's812735467'] | [9184.0, 9184.0] | [25.0, 25.0] | [168, 169] |
p03427 | u367130284 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['s=input();print(sum(map(int,list(s)or int(s[0])-1+9*(len(s)-1))))', 's=str(int(input())+1);print(int(s[0])+9*len(s)-10)'] | ['Wrong Answer', 'Accepted'] | ['s783293726', 's770697619'] | [2940.0, 2940.0] | [18.0, 18.0] | [65, 50] |
p03427 | u368563078 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\nDig = len(N)\nnum = None\nif Dig == 1:\n print(N)\nelse:\n for i in range(Dig-1):\n if N[i+1] != str(9):\n num = i\n print(num)\n break\n else:\n continue\n list_num = list(N)\n if not num == None:\n target = int(list_num[num]) -1\n array = list(map(int,N))\n print(target)\n ans = sum(array[:num]) + target + 9*(Dig-num-1)\n print(ans)\n else:\n array = list(map(int,N))\n print(sum(array))', 'N = input()\nDig = len(N)\nnum = None\nif Dig == 1:\n print(N)\nelse:\n for i in range(Dig-1):\n if N[i] != str(9) and N[i+1] != str(9):\n num = i\n break\n else:\n continue\n list_num = list(N)\n if num:\n target = int(list_num[num]) -1\n ans = 9*(num -1) + target + 9*(Dig)\n print(ans)\n else:\n array = list(map(int,N))\n print(sum(array))\n ', 'N = input()\nDig = len(N)\nnum = None\nif Dig == 1:\n print(N)\nelse:\n for i in range(Dig-1):\n if N[i] != str(9) and N[i+1] != str(9):\n num = i\n print(num)\n break\n else:\n continue\n list_num = list(N)\n if num:\n target = int(list_num[num]) -1\n ans = 9*(num -1) + target + 9*(Dig)\n print(ans)\n else:\n array = list(map(int,N))\n print(sum(array))\n ', 'N = input()\nDig = len(N)\nif Dig == 1:\n print(N)\nelse:\n for i in range(Dig):\n if N[i] != 9:\n num = i\n break\n else:\n continue\n list_num = list(N)\n target = int(list_num[num]) -1\n ans = 9*(num -1) + target + 9*(DIg)\n print(ans)', 'N = input()\nDig = len(N)\nnum = None\nif Dig == 1:\n print(N)\nelse:\n for i in range(Dig-1):\n if N[i+1] != str(9):\n num = i\n break\n else:\n continue\n list_num = list(N)\n if not num == None:\n target = int(list_num[num]) -1\n array = list(map(int,N))\n ans = sum(array[:num]) + target + 9*(Dig-num-1)\n print(ans)\n else:\n array = list(map(int,N))\n print(sum(array))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s174363999', 's379523723', 's859334057', 's977920117', 's004831529'] | [3064.0, 3064.0, 3064.0, 3060.0, 3064.0] | [18.0, 18.0, 18.0, 17.0, 17.0] | [504, 426, 449, 289, 459] |
p03427 | u374802266 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=input()\nl=len(n)\na,b=0,0\nwhile True:\n b+=n[a]\n a+=1\n if a==l:\n break\nprint(b)', 'n=input()\nl=len(n)\na,b=0,0\nwhile True:\n b+=int(n[a])\n a+=1\n if a==l:\n break\nprint(b)\n', 'a=input()\nb=0\nfor i in range(len(a)):\n b+=int(a[i])\nprint(max((len(a)-1)*9+int(a[0])-1,b))'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s381043612', 's638560299', 's043789616'] | [2940.0, 2940.0, 2940.0] | [18.0, 17.0, 17.0] | [93, 99, 93] |
p03427 | u391875425 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["n = int(input())\nc = None\nres = 0\nfor i in range(1, len(str(n))+1):\n c = '9' * i\n if int(c) <= n:\n continue\n else:\n for j in range(9, 0, -1):\n if int(str(j) + str(c)[1:]) <= n:\n c = str(j) + str(c)[1:]\n break\n break\nfor i in range(len(c)):\n res += int(c[i])\nprint(res)", "n = int(input())\nc = None\nres = 0\nfor i in range(1, len(str(n))+1):\n c = '9' * i\n if int(c) <= n:\n continue\n else:\n for j in range(9, -1, -1):\n if int(str(j) + str(c)[1:]) <= n:\n c = str(j) + str(c)[1:]\n break\n break\nfor i in range(len(c)):\n res += int(c[i])\nprint(res)"] | ['Wrong Answer', 'Accepted'] | ['s907239005', 's310999521'] | [3064.0, 3064.0] | [17.0, 18.0] | [342, 343] |
p03427 | u404034840 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["N = int(input())\nlen = len(str(N))\na = list(str(N))\nb =0\nfor i in range(1,len)[::-1]:\n if a[i] == -1:\n a[i] == '9'\n if a[i] != '9':\n b += (int(a[i])+1) * (10**(len-1-i))\n a[i-1] = str(int(a[i-1])-1)\nprint(N-b)", "N = int(input())\nlen = len(str(N))\na = list(str(N))\nb =0\nfor i in range(1,len)[::-1]:\n if a[i] == -1:\n a[i] == '9'\n if a[i] != '9':\n b += (int(a[i])+1) * (10**(len-1-i))\n a[i-1] = str(int(a[i-1])-1)\na = list(str(N-b))\nb = 0\nfor i in a:\n b += int(i)\nprint(b)"] | ['Wrong Answer', 'Accepted'] | ['s457441310', 's182493162'] | [3064.0, 3064.0] | [17.0, 17.0] | [220, 269] |
p03427 | u407730443 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['\npattern = "simple"\n\nn = int(input())\n\nif pattern == "simple":\n \n max_sum = -1\n\n for i in range(10**(len(str(n))-1)-1, n+1):\n \n i_parts = []\n for i_part in str(i):\n i_parts.append(int(i_part))\n\n this_sum = sum(i_parts)\n \n if max_sum < this_sum:\n max_sum = this_sum\n max_sum_i = i\n\n print("max_sum : {}\\nmax_sum_i: {}".format(max_sum, max_sum_i))\n\nelif pattern == "temp":\n max_sum_i = int(str(n)[0]) * 10**(len(str(n))-1) -1\n max_sum = sum([int(i) for i in str(max_sum_i)])\n\n print("max_sum : {}\\nmax_sum_i: {}".format(max_sum, max_sum_i))', 'max_sum_i = int(str(n)[0]) * 10**(len(str(n))-1) -1\nmax_sum = sum([int(i) for i in str(max_sum_i)])\n\nprint(max_sum)', 'n = int(input())\n\nmax_sum_i = int(str(n)[0]) * 10**(len(str(n))-1) -1\nmax_sum = sum([int(i) for i in str(max_sum_i)])\n\nprint("max_sum : {}\\nmax_sum_i: {}".format(max_sum, max_sum_i))', 'n = int(input())\nprint(sum([int(j) for j in str(int(str(n+1)[0])-1) + "9"*(len(str(n+1))-1)]))'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s550506959', 's675981294', 's881265688', 's670748920'] | [3064.0, 2940.0, 2940.0, 2940.0] | [2104.0, 18.0, 17.0, 17.0] | [636, 115, 183, 94] |
p03427 | u409306788 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["import sys\ninput = sys.stdin.readline\n\n\ndef digit_sum(str_num):\n\tsum = 0\t\n\t\n\tfor i in range(len(str_num)):\n\t\tsum += int(str_num[i])\n\t\n\treturn sum\n\n\nN = input()\npatterns = [N]\n\nfor i in range(len(N)-1):\n\tif N[i] != '0':\n\t\tleft, right = '', '' \n\t\t\t\t\n\t\tif i > 0:\n\t\t\tleft = N[:i]\n\t\t\n\t\tn = int(N[i]) - 1\n\t\t\n\t\tif i < len(N) - 1:\n\t\t\tright = '9' * (len(N)-i-1) \n\t\t\n\t\tpatterns.append(left + str(n) + right)\n\nans = 0\n\nfor p in patterns:\n\tans = max(ans, digit_sum(p))\n\t\nprint(ans)", "import sys\n#input = sys.stdin.readline\n\n\ndef digit_sum(str_num):\n\tsum = 0\t\n\t\n\tfor i in range(len(str_num)):\n\t\tsum += int(str_num[i])\n\t\n\treturn sum\n\n\nN = input()\npatterns = [N]\n\nfor i in range(len(N)-1):\n\tif N[i] != '0':\n\t\tleft, right = '', '' \n\t\t\t\t\n\t\tif i > 0:\n\t\t\tleft = N[:i]\n\t\t\n\t\tn = int(N[i]) - 1\n\t\t\n\t\tif i < len(N) - 1:\n\t\t\tright = '9' * (len(N)-i-1) \n\t\t\n\t\tpatterns.append(left + str(n) + right)\n\nans = 0\n\nfor p in patterns:\n\tans = max(ans, digit_sum(p))\n\t\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s010995433', 's822252475'] | [3064.0, 3064.0] | [18.0, 17.0] | [487, 488] |
p03427 | u411923565 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["N = input()\nN_list = list(N)\nN = int(N)\nK = len(N_list)\n\nans = int(N_list[0])+(K-1)*9\nans_list = [N_list[0]] + ['9' for _ in range(K-1)]\nans_cand = int(''.join(ans_list))\nprint(ans_cand)\nif N < ans_cand:\n print(ans - 1)\nelse:\n print(ans)", "N = input()\nN_list = list(N)\nN = int(N)\nK = len(N_list)\n\nans = int(N_list[0])+(K-1)*9\nans_list = [N_list[0]] + ['9' for _ in range(K-1)]\nans_cand = int(''.join(ans_list))\nif N < ans_cand:\n print(ans - 1)\nelse:\n print(ans)"] | ['Wrong Answer', 'Accepted'] | ['s368649619', 's766020244'] | [9024.0, 9188.0] | [29.0, 29.0] | [243, 227] |
p03427 | u413165887 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["a=list(input())\np=print\nx=len(a)\ny=int(a[0])\nprint(9*x-9+y if all(i=='9' for i in a[1:]) else y+9*(x-1))", "a=list(input());x,y=len(a)-1,int(a[0]);print(9*x+y if all(i=='9'for i in a[1:])else y-1+9*x)"] | ['Wrong Answer', 'Accepted'] | ['s823271317', 's584372914'] | [9152.0, 9116.0] | [28.0, 29.0] | [104, 92] |
p03427 | u419645731 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ["s = input()\nif int(s) < 10: print(s); exit()\n\nans = -1\nfor i in range(len(s)):\n t = s[:i]\n NINE = (len(s)-len(t))\n SUB = 0\n t+= '9' * NINE\n if int(s) < int(t): SUB = int('1' + '0' * NINE)\n t = max(int(t) - SUB, 0)\n ans = max(ans, sum(int(c) for c in str(t)))\n print(t)\nprint(ans)", "s = input()\nif int(s) < 10: print(s); exit()\n\nans = -1\nfor i in range(len(s)):\n t = s[:i]\n NINE = (len(s)-len(t))\n SUB = 0\n t+= '9' * NINE\n if int(s) < int(t): SUB = int('1' + '0' * NINE)\n t = max(int(t) - SUB, 0)\n ans = max(ans, sum(int(c) for c in str(t)))\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s668742841', 's035619003'] | [3064.0, 3064.0] | [17.0, 17.0] | [303, 290] |
p03427 | u457901067 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = input()\n\nwork = 9\nfor i in range(len(N)):\n if N[i] != "9":\n work = int(N[i])\n break\n \nprint(work + 9 * (len(N)-1))', 'N = input()\n\nans = 0\nall_nine_flg = True\n\nfor i in range(1,len(N)):\n if N[i] == "9":\n continue\n else:\n all_nine_flg = False\n break\n\nsub = 0 if all_nine_flg else 1\nprint( int(N[0]) + 9*(len(N)-1) - sub)'] | ['Wrong Answer', 'Accepted'] | ['s094354758', 's587358360'] | [2940.0, 2940.0] | [17.0, 17.0] | [128, 212] |
p03427 | u462329577 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['s = input()\nif len(s) == 1: print(int(s[0])\nelif s[1:] == "9"*(len(s)-1): print(int(s[0]+9*len(s)-9)\nelse: print(int(s[0]+9*len(s)-10) ', 's = input()\nif len(s) == 1: print(int(s[0]))\nelif s[1:] == "9"*(len(s)-1):\n print(int(s[0])+9*len(s)-9)\nelse: \n print(int(s[0])+9*len(s)-10) \n'] | ['Runtime Error', 'Accepted'] | ['s751209803', 's819475787'] | [2940.0, 2940.0] | [17.0, 18.0] | [170, 179] |
p03427 | u463655976 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = list(input())\nN = [str(int(N[0]) - 1)] + [9] * (len(N)-1)\nprint("{:.0f}".format(eval("".join(N))))', 'S = list(input())\nN = [str(int(N[0]) - 1)] + ["9"] * (len(S)-1)\nprint("{:.0f}".format(max(sum(map(int, N)), sum(map(int,S)))))', 'N = list(input())\nN = [str(int(N[0]) - 1)] + ["9"] * (len(N)-1)\nprint("{:.0f}".format(eval("".join(N))))', 'N = list(input())\nN = [str(int(N[0]) - 1)] + ["9"] * (len(N)-1)\nprint("{:.0f}".format(sum(map(int, N)))', 'S = list(input())\nN = [str(int(S[0]) - 1)] + ["9"] * (len(S)-1)\nprint("{:.0f}".format(max(sum(map(int, N)), sum(map(int,S)))))\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s128851135', 's139369286', 's231012925', 's336596034', 's806685411'] | [2940.0, 2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0, 17.0] | [102, 126, 104, 103, 127] |
p03427 | u474925961 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['x=int(input())\ny=str(x)\nn=len(y)\nprint(int(y[0])+9*n)\n', 'x=int(input())\ny=str(x)\nn=len(y)\nprint(int(n[0])+9*n)\n', 'x=int(input())\ny=str(x)\nn=len(y)\n\nif y[1:]=="9"*(n-1):\n print(int(y[0])+9*n-9)\nelse:\n print(int(y[0])-1+9*n-9)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s244863783', 's475320817', 's365838438'] | [2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [54, 54, 117] |
p03427 | u482157295 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['ans = ""\na = input()\nnum_len = len(a)\nnum = [k for k in a]\nfor i in range(1,num_len):\n if num[i] != "9":\n num[i-1]= chr(ord(num[i-1])-1)\n if num[i-1] == "0":\n num[i-1] = ""\n for j in range(i,num_len):\n num[j] = "9"\n break\nfor w in num:\n ans = ans + w\nprint(ans)', 'ans = 0\na = input()\nnum_len = len(a)\nnum = [k for k in a]\nfor i in range(1,num_len):\n if num[i] != "9":\n num[i-1]= chr(ord(num[i-1])-1)\n for j in range(i,num_len):\n num[j] = "9"\n break\nfor w in num:\n ans = ans + int(w)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s754053044', 's094548675'] | [3064.0, 3064.0] | [18.0, 18.0] | [285, 245] |
p03427 | u497883442 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['#coding:utf-8\nn = int(input())\nnum = len(str(n))\ntmp = pow(10, num)-1\ns = 0\nfor i in range(num+1):\n if i == num:\n s = sum(list(map(int, str(tmp-9*pow(10, num-1)+(int(str(n)[0])-1)*pow(10, num-1)))))\n break\n elif tmp-pow(10, i) <= n:\n s = sum(list(map(int, str(tmp-pow(10, i)))))\n break\nif sum(list(map(int. str(n)))) > s:\n print(sum(list(map(int. str(n)))))\nelse:\n print(s)', '#coding:utf-8\nn = int(input())\nnum = len(str(n))\ntmp = pow(10, num)-1\ns = 0\nfor i in range(num+1):\n if i == num:\n s = sum(list(map(int, str(tmp-9*pow(10, num-1)+(int(str(n)[0])-1)*pow(10, num-1)))))\n break\n elif tmp-pow(10, i) <= n:\n s = sum(list(map(int, str(tmp-pow(10, i)))))\n break\nif sum(list(map(int. str(n)))) > s:\n print(sum(list(map(int. str(n)))))\nelse:\n print(s)', '#coding:utf-8\nn = int(input())\nnum = len(str(n))\ntmp = pow(10, num)-1\ns = 0\nfor i in range(num+1):\n if i == num:\n s = sum(list(map(int, str(tmp-9*pow(10, num-1)+(int(str(n)[0])-1)*pow(10, num-1)))))\n break\n elif tmp-pow(10, i) <= n:\n s = sum(list(map(int, str(tmp-pow(10, i)))))\n break\nif sum(list(map(int, str(n)))) > s:\n print(sum(list(map(int, str(n)))))\nelse:\n print(s)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s693596298', 's943995641', 's337418177'] | [3064.0, 3064.0, 3064.0] | [19.0, 17.0, 17.0] | [413, 413, 413] |
p03427 | u504562455 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = input()\nl = len(n)\n\nif set(list(n[1:])) == {"9"}:\n print(int(n[0])+9*(len(n)-1))\nelse:\n print(int(n[0])-1+9*(len(n)-1))n = input()\nl = len(n)\nif l == 1:\n print(n)\nelif set(list(n[1:])) == {"9"}:\n print(int(n[0])+9*(l-1))\nelse:\n print(int(n[0])-1+9*(l-1))', 'n = input()\nl = len(n)\n\nif l == 1:\n print(n)\nelif set(list(n[1:])) == {"9"}:\n print(int(n[0])+9*(l-1))\nelse:\n print(int(n[0])-1+9*(l-1))\n '] | ['Runtime Error', 'Accepted'] | ['s838581334', 's675021698'] | [2940.0, 2940.0] | [17.0, 19.0] | [273, 150] |
p03427 | u514118270 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['import bisect\nN = int(input())\nif len(str(N)) == 1:\n print(N)\n exit()\nL = len(list(str(N)))-1\nA = [10**(L)*i+10**(L)-1 for i in range(10)] \nn = bisect.bisect_left(A,N)-1\nif N in A:\n n += 1\nans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]\nprint(sum(ans))\nprint(A)', 'import bisect\nN = int(input())\nif len(str(N)) == 1:\n print(N)\n exit()\nL = len(list(str(N)))-1\nA = [10**(L)*i+10**(L)-1 for i in range(10)] \nn = bisect.bisect_left(A,N)-1\nif N in A:\n n += 1\nans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]\nprint(sum(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s474278211', 's211247066'] | [3064.0, 3064.0] | [18.0, 18.0] | [292, 284] |
p03427 | u527993431 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N=input()\nM=len(str(N))\nK=int(N[0])\nans=0\nfor i in range (M):\n\tans+=N[i]\n\nprint(max(9*(M-1)+(K-1)),ans)', 'N=input()\nM=len(str(N))\nK=int(N[0])\nans=0\nfor i in range (M):\n\tans+=N[i]\nprint(max(9*(M-1)+(K-1),ans))', 'S=input()\nans=0\nfor i in range (len(S)):\n\tans+=int(S[i])\nprint(ans)', 'N=input()\nM=int(N[0:2])\nL=len(N[2:])*9\nK=0\nsum=0\nfor i in range(len(N)):\n\tsum+=int(N[i])\nK=0\nif L>0:\n\tD=M\nelse:\n\tD=M+1\nfor i in range(D):\n\tj=str(i)\n\tif len(j)==1:\n\t\tK=max(K,(int(j)))\n\telse:\n\t\tK=max(K,(int(j[0])+int(j[1])))\nprint(max(sum,K+L))'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s135654511', 's578814763', 's783914771', 's279612513'] | [2940.0, 2940.0, 3316.0, 3064.0] | [17.0, 17.0, 19.0, 17.0] | [103, 102, 67, 242] |
p03427 | u550943777 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['arr=[int(i) for i in input()]\ncsum=[arr[0]]\nfor i in range(1,len(arr)):\n csum.append(csum[-1]+arr[i])\nmaxsum= csum[-1]\n\nprint(max(maxsum,arr[0]-1+9*(len(are)-1)))', 'arr=[int(i) for i in input()]\ncsum=[arr[0]]\nfor i in range(1,len(arr)):\n csum.append(csum[-1]+arr[i])\nmaxsum= csum[-1]\n\nprint(max(maxsum,arr[0]-1+9*(len(arr)-1)))'] | ['Runtime Error', 'Accepted'] | ['s775648768', 's351256890'] | [3060.0, 3060.0] | [18.0, 18.0] | [163, 163] |
p03427 | u559823804 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N=list(input())\ncnt=0\nsize=len(N)-1\nif size==0:\n print(N[0])\n exit()\nN.reverse()\n\nfor i in range(size):\n if N[i]!="9":\n N[i]="9"\n N[i+1]=str(int(N[i+1])-1)\nprint(cnt)\n\nfor i in range(size+1):\n cnt+=int(N[i])\nprint(cnt)\n', 'N=list(input())\ncnt=0\nsize=len(N)-1\nif size==0:\n print(N[0])\n exit()\nN.reverse()\n\nfor i in range(size):\n if N[i]!="9":\n N[i]="9"\n N[i+1]=str(int(N[i+1])-1)\nfor i in range(size+1):\n cnt+=int(N[i])\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s185493950', 's677668127'] | [3060.0, 3060.0] | [18.0, 17.0] | [245, 233] |
p03427 | u562015767 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = list(map(int,input()))\ncnt = 0\nans = []\n\nfor i in n:\n cnt += 1\n if i == 9:\n continue\n else:\n if cnt == len(n):\n break\n else:\n n[cnt-1] -= 1\n break\n\nfor i in range(cnt,len(n)):\n n[i] = 9\nprint(n)\n\nprint(sum(n))', 'n = list(map(int,input()))\ncnt = 0\nb = tuple(n)\nc = b\n\nfor i in n:\n cnt += 1\n if i == 9:\n continue\n else:\n if cnt == len(n):\n cnt -= 1\n n[cnt-1] -= 1\n break\n else:\n if i == 0:\n n[cnt-2] -= 1\n cnt -= 1\n break\n else:\n n[cnt-1] -= 1\n break\n\nfor i in range(cnt,len(n)):\n n[i] = 9\n\nif len(n) == 1:\n n = b\n\nprint(n)\nprint(b)\n\nif sum(n) >= sum(b):\n print(sum(n))\nelse:\n print(sum(b))', 'n = list(map(int,input()))\ncnt = 0\nans = []\n\nfor i in n:\n cnt += 1\n if i == 9:\n continue\n else:\n if cnt == len(n):\n cnt -= 1\n n[cnt-1] -= 1\n break\n else:\n if i == 0:\n n[cnt-2] -= 1\n cnt -= 1\n break\n else:\n n[cnt-1] -= 1\n break\n\nfor i in range(cnt,len(n)):\n n[i] = 9\n\nprint(n)\n\nprint(sum(n))', 'n = list(map(int,input()))\ncnt = 0\nb = tuple(n)\nc = b\n\nfor i in n:\n cnt += 1\n if i == 9:\n continue\n else:\n if cnt == len(n):\n cnt -= 1\n n[cnt-1] -= 1\n break\n else:\n if i == 0:\n n[cnt-2] -= 1\n cnt -= 1\n break\n else:\n n[cnt-1] -= 1\n break\n\nfor i in range(cnt,len(n)):\n n[i] = 9\n\nif len(n) == 1:\n n = b\n\nif sum(n) >= sum(b):\n print(sum(n))\nelse:\n print(sum(b))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s150009532', 's424167658', 's942156694', 's251956829'] | [3060.0, 3064.0, 3064.0, 3064.0] | [18.0, 17.0, 17.0, 17.0] | [279, 548, 453, 529] |
p03427 | u570612423 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['# -*- coding: utf-8 -*-\n\nimport numpy as np\n\nn = input()\n\na = np.zeros((int(len(n))))\nfor i in range(0,len(n)):\n a[i] = int(n[i])\n\nprint(int(sum(a)))', '# -*- coding: utf-8 -*-\nN = int(input())\n\ndef Sum(n):\n s = str(n)\n array = list(map(int, list(s)))\n return sum(array)\n\na=[]\n\na.append(Sum(N))\n\nN_str = str(N)\nN_str = list(map(int, list(N_str)))\n\n"右端の数字を1下げたときの最大"\nN_str = str(N)\nN_str = list(map(int, list(N_str)))\nN_str[0] = N_str[0] - 1\nfor i in range(1,len(N_str)):\n N_str[i] = 9\na.append(sum(N_str))\n\nprint(max(a))'] | ['Wrong Answer', 'Accepted'] | ['s514145211', 's505511300'] | [13280.0, 3064.0] | [181.0, 17.0] | [152, 407] |
p03427 | u579699847 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['import bisect,collections,copy,heapq,itertools,math,numpy,string\nimport sys\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\nN = I()\nA = [LI() for _ in range(N)]\n', "import sys\ndef S(): return sys.stdin.readline().rstrip()\nN = S()\nif all([n=='9' for n in N[1:]]):\n print(int(N[0])+9*(len(N)-1))\nelse:\n print(int(N[0])-1+9*(len(N)-1))\n"] | ['Wrong Answer', 'Accepted'] | ['s963280333', 's455704282'] | [72448.0, 2940.0] | [2112.0, 17.0] | [341, 174] |
p03427 | u623687794 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=input()\nl=len(n)\nflag=0\nfor i in range(l-1):\n if n[-i]!=9:\n flag=1\n break\nans=int(n[0]-1)+9*(l-1)\nif flag==1:\n print(ans)\nelse:\n print(ans+1)\n ', 'n=input()\nl=len(n)\nflag=0\nfor i in range(1,l):\n if n[i]!="9":\n flag=1\n break\nans=int(n[0])-1+9*(l-1)\nif flag==1:\n print(ans)\nelse:\n print(ans+1)\n\n'] | ['Runtime Error', 'Accepted'] | ['s452783151', 's515946380'] | [2940.0, 2940.0] | [18.0, 17.0] | [157, 155] |
p03427 | u624923345 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['import math\n\nN = int(input())\ndigit_num = math.ceil(math.log10(N))\nmsd =int(N/(10**(digit_num-1)))\nprint(msd)\nif N%10 == 0:\n print(msd + 9*(digit_num-1))\nelse:\n print(msd + 9*(digit_num-1) - 1)\n', 'import math\n\nN = int(input())\ndigit_num = math.ceil(math.log10(N))\nmsd =int(N/(10**(digit_num-1)))\nif N%10 == 0:\n print(msd + 9*(digit_num-1))\nelse:\n print(msd + 9*(digit_num-1) - 1)\n', 'import math\n\nN = int(input())\ndigit_num = math.ceil(math.log10(N))\nmsd =int(N/(10**(digit_num-1)))\nprint(msd)\nif N%10 == 0:\n print(msd + 9*(digit_num-1))\nelse:\n print(msd + 9*(digit_num-1) - 1)\n', 'import math\n\nN = int(input())\ndigit_num = math.ceil(math.log10(N))\nmsd =int(N/(10**(digit_num-1)))\n\nif (N+1)%10 == 0:\n print(msd + 9*(digit_num-1))\nelif N-10<0:\n print(N)\nelse:\n print(msd + 9*(digit_num-1) - 1)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s013578660', 's854031291', 's879028501', 's211012094'] | [2940.0, 2940.0, 3188.0, 3060.0] | [17.0, 17.0, 18.0, 17.0] | [200, 189, 200, 220] |
p03427 | u626468554 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['N = list(input())\nprint(len(N)*9+N[0]-1)', 'N = list(input())\n\nflg = 0\nfor i in range(1,len(N)):\n if N[i]=="9":\n continue\n else:\n flg = 1\n break\n\nif flg:\n print((len(N)-1)*9+int(N[0])-1)\nelse:\n print((len(N)-1)*9+int(N[0]))'] | ['Runtime Error', 'Accepted'] | ['s841316111', 's807348912'] | [2940.0, 3188.0] | [17.0, 20.0] | [40, 212] |
p03427 | u629350026 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n=int(input())\nt=list(str(n))\nif n%10**len(t)==0:\n print(9*(len(t)-1))\nelif n%10**(len(t)-1)==0:\n print(int(t[0])+9*(len(t)-1))\nelse:\n print(int(t[0])-1+9*(len(t)-1))', 'n=int(input())\nt=list(str(n))\nif n%10**len(t)==0:\n print(9*(len(t)-1))\nelif: n%10**(len(t)-1)==0:\n print(t[0]+9*(len(t)-2))\nelse:\n print(t[0]-1+9*(len(t)-2))', 'n=int(input())\nt=list(str(n))\ncnt=0\nfor i in range(1,len(t)):\n if t[i]=="9":\n cnt=cnt+1\nif cnt==len(t)-1:\n print(int(t[0])+9*cnt)\nelse:\n print(int(t[0])-1+9*(len(t)-1))'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s455302527', 's688789162', 's453348259'] | [3064.0, 2940.0, 3060.0] | [18.0, 17.0, 17.0] | [169, 160, 174] |
p03427 | u631277801 | 2,000 | 262,144 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. | ['n = int(input())\n\ncand = 0\n\ndef digit_sum(num:int, base:int) -> int:\n if num < base:\n return num\n else:\n return digit_sum(int(num/base), base) + (num % base)\n\ndef judge(n: int) -> int:\n if n < 10:\n return n\n \n else:\n \n if str(n)[0:1] == \'1\':\n cand = n % 10**(len(str(n)) - 1)\n print(cand)\n \n cand_str = "9"*len(str(cand))\n cand = int(cand_str)\n \n print(cand)\n \n return max(digit_sum(n,10), digit_sum(cand,10))\n \n \n else:\n top = n // 10**(len(str(n)) - 1)\n cand_str = str(top-1) + "9" * (len(str(n))-1)\n cand = int(cand_str)\n \n return max(digit_sum(n,10), digit_sum(cand,10))\n \n \n \n\n\nprint(ans)', 'def digit_sum(num:int, base:int) -> int:\n if num < base:\n return num\n else:\n return digit_sum(int(num/base), base) + (num % base)\n\ndef judge(n: int) -> int:\n if n < 10:\n return n\n \n else:\n \n if str(n)[0:1] == \'1\':\n cand = n % 10**(len(str(n)) - 1)\n \n cand_str = "9"*len(str(cand))\n cand = int(cand_str)\n \n \n return max(digit_sum(n,10), digit_sum(cand,10))\n \n \n else:\n top = n // 10**(len(str(n)) - 1)\n cand_str = str(top-1) + "9" * (len(str(n))-1)\n cand = int(cand_str)\n \n return max(digit_sum(n,10), digit_sum(cand,10))\n\nn = int(input())\n\nans = judge(n)\nprint(ans)', 'def digit_sum(num:int, base:int) -> int:\n if num < base:\n return num\n else:\n return digit_sum(int(num/base), base) + (num % base)\n\ndef judge(n: int) -> int:\n if n < 10:\n return n\n \n else:\n \n if str(n)[0:1] == \'1\':\n \n cand_str = "9" * (len(str(n)) - 1)\n cand = int(cand_str)\n \n return max(digit_sum(n,10), digit_sum(cand,10))\n \n \n else:\n top = n // 10**(len(str(n)) - 1)\n cand_str = str(top-1) + "9" * (len(str(n))-1)\n cand = int(cand_str)\n \n return max(digit_sum(n,10), digit_sum(cand,10))\n\nn = int(input())\n\nans = judge(n)\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s140929168', 's948311106', 's261096890'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 17.0] | [982, 911, 858] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.