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
p03329
u782098901
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['def calc(x, base):\n res = 0\n while x:\n x, m = divmod(x, base)\n res += m\n return res\n\nans = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))\n\nprint(ans)', 'N = int(input())\n\n\ndef f(x, base):\n ret = 0\n while x:\n x, m = divmod(x, base)\n ret += m\n return ret\n\nprint(min([f(i, 6) + f(N - i, 9) for i in range(N + 1)]))\n']
['Runtime Error', 'Accepted']
['s005652826', 's702925262']
[2940.0, 3864.0]
[17.0, 254.0]
[180, 182]
p03329
u787562674
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\n\ncount = 0\nnumbers = sorted([9**5, 9**4, 9**3, 9**2, 9, 6**6, 6**5, 6**4, 6**3, 6**2, 6], reverse=True)\n\ndef search(n):\n for i in numbers:\n if i <= n:\n return i\n\ndef search_max(n):\n mincount = 1000\n inp = n\n for i in range(3):\n n = inp\n n -= 9*i\n mincount = min((i + n // 6 + n % 6), mincount)\n print(mincount)\n return mincount\n\n\nfor i in range(100):\n if 1 <= N <= 5:\n count += N\n break\n elif N == 0:\n break\n elif 5 < N < 35:\n count += search_max(N)\n break\n else:\n count += N // search(N)\n N %= search(N)\n\nprint(count)', 'n = int(input())\nv = []\ni = 6\nwhile i<=n:\n v.append(i)\n i *= 6\ni=9\nwhile i <= n:\n v.append(i)\n i *= 9\nv.sort(reverse=True)\ndic = dict()\ndef dp(i, N):\n if i == len(v):\n return N\n if (i, N) not in dic:\n dic[(i, N)] = min(dp(i, N-v[i])+1, dp(i+1, N)) if N-v[i] >= 0 else dp(i+1, N)\n return dic[(i, N)]\nprint(dp(0, n))\n']
['Wrong Answer', 'Accepted']
['s624428296', 's381677422']
[3064.0, 13632.0]
[17.0, 102.0]
[653, 350]
p03329
u794173881
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n = int(input())\n\nyen9=[9**i for i in range(5)]\nyen6=[6**i for i in range(6)]\nyen1=[1]\n\ndef withdraw(n,count):\n if n ==0:\n return count\n\n maxmoney = 0\n for i in range(5):\n if yen9[i] <= n:\n maxmoney = max(yen9[i],maxmoney)\n \n for i in range(6):\n if yen6[i] <= n:\n maxmoney = max(yen6[i],maxmoney)\n \n if maxmoney ==0:\n maxmoney = 1\n print(maxmoney)\n return withdraw(n-maxmoney,count+1)\n\nprint(withdraw(n,0))', 'n = int(input())\nc = [1]\nfor i in range(6):\n c.append(6**(i+1))\nfor i in range(5):\n c.append(9**(i+1))\nINF = float("inf")\n \ndp = [INF]*(n+1)\ndp[0] = 0\n \nfor i in range(len(c)):\n for j in range(n+1):\n if j - c[i] < 0:\n continue\n else:\n dp[j] = min(dp[j], dp[j - c[i]] + 1)\n \nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s754420902', 's416553887']
[3064.0, 6900.0]
[18.0, 741.0]
[445, 331]
p03329
u798129018
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['from itertools import*\nfrom math import*\nfrom collections import*\nfrom heapq import*\nfrom bisect import bisect_left,bisect_right\nfrom copy import deepcopy\ninf = float("inf")\nmod = 10**9+7\nfrom functools import reduce\nimport sys\nsys.setrecursionlimit(10**7)\n\n\n\nN = int(input())\ndp=[inf]*(110000)\ndp[0]=0\nfor n in range(N):\n pow6,pow9 = 1,1\n while pow6<=n:\n dp[n+po6] = min(dp[n+pow6],dp[n]+1)\n pow6 *= 6\n while pow9 <=n:\n dp[n+pow9] = min(dp[n+pow9],dp[n]+1)\n pow9 *= 9\nprint(dp[N])', 'from itertools import*\nfrom math import*\nfrom collections import*\nfrom heapq import*\nfrom bisect import bisect_left,bisect_right\nfrom copy import deepcopy\ninf = float("inf")\nmod = 10**9+7\nfrom functools import reduce\nimport sys\nsys.setrecursionlimit(10**7)\n\n\n\nN = int(input())\ndp=[inf]*(110000)\nfor i in range(110000):\n dp[i] = N \ndp[0]=0\nfor n in range(N):\n pow6,pow9 = 1,1\n while n+pow6<=N:\n dp[n+pow6] = min(dp[n+pow6],dp[n]+1)\n pow6 *= 6\n while n+pow9 <=N:\n dp[n+pow9] = min(dp[n+pow9],dp[n]+1)\n pow9 *= 9\nprint(dp[N])']
['Runtime Error', 'Accepted']
['s915271574', 's025463363']
[4560.0, 4432.0]
[26.0, 803.0]
[1183, 1227]
p03329
u798818115
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['# coding: utf-8\n# Your code here!\nN=int(input())\n\nans=[]\n\ndef saiki(tgt,i,count):\n print(i)\n num=0\n if i==0:\n ans.append(tgt+count)\n print("終わり")\n return\n while tgt-num*temp[i]:\n count+=num\n saiki(tgt-num*temp[i],i-1,count)\n num+=1\n return\n\ntemp=[1]\nn=1\nwhile N>=6**n:\n temp.append(6**n)\n n+=1\n \nn=1\nwhile N>=9**n:\n temp.append(9**n)\n n+=1\n\ntemp.sort()\n\nsaiki(N,len(temp)-1,0)\n\nprint(ans)\n \n', '# coding: utf-8\n# Your code here!\nN=int(input())\nl=[1]\ncount=0\n\ndef cand(num):\n i=1\n while N>=num**i:\n l.append(num**i)\n i+=1\n\ndef sub(target,index):\n i=0\n if target==0:\n \n elif index==0:\n \n while target-l[index]>0:\n sub(target-l[index]**i,l[index-1])\n \n\ncand(6)\ncand(9)\n\nl.sort()\nprint(l)\n\n', '# coding: utf-8\n# Your code here!\nN=int(input())\n\nlis=[]\n\ntemp=6\nwhile temp<=N:\n lis.append(temp)\n temp*=6\n\ntemp=9\nwhile temp<=N:\n lis.append(temp)\n temp*=9\n\nlis.sort(reverse=True)\n\ndp=[10**9]*(N+1)\ndp[0]=0\n\nfor item in lis:\n for i in range(N+1):\n if dp[i]!=10**9:\n if i+item<=N:\n dp[i+item]=min(dp[i]+1,dp[i+item])\n \nans=10**10\nfor index,item in enumerate(dp):\n ans=min(ans,item+N-index)\nprint(ans)\n\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s346586322', 's689541791', 's963910884']
[72096.0, 3064.0, 3828.0]
[2108.0, 18.0, 182.0]
[482, 409, 463]
p03329
u811000506
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\nli=[6,9,36,81,216,729,1296,6561,7776,46656,59049]\ndp = [i for i in range(100010)]\nfor a in li:\n for x in range(a,N+1):\n print(dp[x],dp[x-a]+1)\n dp[x] = min(dp[x],dp[x-a]+1)\nprint(dp[N])', 'N = int(input())\nli=[6,9,36,81,216,729,1296,6561,7776,46656,59049]\ndp = [i for i in range(100010)]\nfor a in li:\n for x in range(a,N+1):\n dp[x] = min(dp[x],dp[x-a]+1)\nprint(dp[N])']
['Wrong Answer', 'Accepted']
['s579205424', 's805354609']
[12380.0, 7064.0]
[1702.0, 389.0]
[219, 188]
p03329
u816428863
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n=int(input())\nans=0\n\ndef solve(ans,n):\n sq_nine=1\n sq_six=1\n while n>=9**sq_nine:\n sq_nine+=1\n sq_nine-=1\n while n>=6**sq_six:\n sq_six+=1\n sq_six-=1\n if sq_nine==0 and sq_six==0:\n ans+=n\n return print(ans)\n else:\n n=n-max(9**sq_nine,6**sq_six)\n ans+=1\n print(max(9**sq_nine,6**sq_six),n)\n solve(ans,n)\n\nsolve(ans,n)', 'n=int(input())\nans=0\n\ndef solve(ans,n):\n sq_nine=1\n sq_six=1\n while n>=9**sq_nine:\n sq_nine+=1\n sq_nine-=1\n while n>=6**sq_six:\n sq_six+=1\n sq_six-=1\n if sq_nine==0 and sq_six==0:\n ans+=n\n return print(ans)\n else:\n n=n-max(9**sq_nine,6**sq_six)\n ans+=1\n print(max(9**sq_nine,6**sq_six),n)\n solve(ans,n)\n\nsolve(ans,n)', 'n=int(input())\ndp=[float("inf")]*100010\ndp[0]=0\n\nfor i in range(n+1):\n power = 1\n while i + power <= n:\n dp[i + power] = min(dp[i + power],dp[i] + 1)\n power *= 6\n power = 1\n while i + power <= n:\n dp[i + power] = min(dp[i + power],dp[i] + 1)\n power *= 9\n\nprint(dp[n])']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s594919994', 's946039080', 's553794162']
[3064.0, 3064.0, 3828.0]
[17.0, 17.0, 716.0]
[396, 396, 307]
p03329
u823458368
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n = int(input())\nimport math\n\nans = []\nfor i in range(n+1):\n cnt6 = i\n cnt9 = n - i\n\n ans6 = 0\n ans9 = 0\n \n list6 = [6, 36, 216, 1296, 7776, 46656]\n list9 = [9, 81, 729, 6561, 59049]\n \n while cnt6 > 0:\n if cnt6 in list6:\n ans6 = 1\n break\n else:\n sho = 6**math.floor(math.log(cnt6, 6))\n ans6 += cnt6//sho\n cnt6= cnt6%sho\n \n while cnt9 > 0:\n if cnt9 in list9:\n ans9 = 1\n break\n else:\n sho2 = 9**math.floor(math.log(cnt9, 9))\n ans9 += cnt9//sho2\n cnt9 = cnt9%sho2\n\n ans.append(ans6+ans9)\n\nprint(min(ans))', 'n = int(input())\n\nimport math\ndef bank2(n):\n ans = 1\n list_six = [6**i for i in range(math.floor(math.log(n, 6)+1))]\n list_nine = [9**i for i in range(math.floor(math.log(n, 9)+1))]\n \n if n in list_six or n in list_nine:\n pass\n elif n == 12 or n == 13 or n == 14:\n ans += bank(n-6)\n elif n > 1:\n ans += min(bank(n - list_six[-1]), bank(n - list_nine[-1]))\n \n return ans\n\nprint(bank2(n))', 'n = int(input())\nimport math\n\nans = []\nfor i in range(n+1):\n cnt6 = i\n cnt9 = n - i\n ans6 = 0\n ans9 = 0\n \n while cnt6 > 0:\n sho = 6**math.floor(math.log(cnt6, 6))\n ans6 += cnt6//sho\n cnt6= cnt6%sho\n \n while cnt9 > 0:\n if cnt9 != 59049:\n sho2 = 9**math.floor(math.log(cnt9, 9))\n else:\n sho2=59049\n ans9 += cnt9//sho2\n cnt9 = cnt9%sho2\n \n ans.append(ans6+ans9)\n sho, sho2 = 0, 0\n \nprint(min(ans))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s738022788', 's795254110', 's589592178']
[3992.0, 3064.0, 3864.0]
[1260.0, 18.0, 1159.0]
[679, 438, 513]
p03329
u825440127
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\ndp = [i for i in range(n+1)]\n\nyen = [6 ** i for i in range(1, 8) if 6 ** i <= n]\nyen += [9 ** i for i in range(1, 7) if 9 ** i <= n]\n\nfor i in range(n+1):\n for j in yen:\n if i - j >= 0:\n dp[i] = min(dp[i], dp[i - j] + 1)\n\ndp[-1]', 'import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\ndp = [i for i in range(n+1)]\n\nyen = [6 ** i for i in range(1, 8) if 6 ** i <= n]\nyen += [9 ** i for i in range(1, 7) if 9 ** i <= n]\n\nfor i in range(n+1):\n for j in yen:\n if i - j >= 0:\n dp[i] = min(dp[i], dp[i - j] + 1)\n\nprint(dp[-1])']
['Wrong Answer', 'Accepted']
['s287242097', 's615753272']
[7064.0, 7064.0]
[538.0, 483.0]
[306, 313]
p03329
u827202523
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import math\nfrom typing import List, Any\n\nN: int = 44852\n\ndef nsin(N, base):\n if N == 0: return [0]\n Nsin: List[Any] = []\n for i in range((int(math.log(N,base)//1)+1)):\n ithdigit = N%(base**(i+1)) // (base ** i)\n Nsin.append(ithdigit)\n Nsin.reverse()\n return Nsin\n\nans = N\nfor i in range(N):\n coins: int = sum(nsin(i,6)) + sum(nsin(N-i,9))\n if coins < ans: ans = coins\n\nprint(ans)', 'import math\nN = int(input())\n \ndef Nsinpou(x, base):\n \n if x == 0: return [0]\n Nsin = []\n for i in range((round(math.log(x,base))+1)):\n ithdigit = x%(base**(i+1)) // (base ** i)\n Nsin.append(ithdigit)\n Nsin.reverse()\n return Nsin\n \nans = N\nfor i in range(N+1):\n coins = sum(Nsinpou(i,6)) + sum(Nsinpou(N-i,9))\n if coins < ans:\n ans = coins\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s025856608', 's742208865']
[2940.0, 3064.0]
[17.0, 1159.0]
[415, 436]
p03329
u832039789
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\narr = [1]\nresult = 0\n\ni = 6\nwhile True:\n\tarr.append(i)\n\ti *= 6\n\tif i>N:\n\t\tbreak\n\ni = 9\nwhile True:\n\tarr.append(i)\n\ti *= 9\n\tif i>N:\n\t\tbreak\n\narr.sort()\narr.reverse()\n\nwhile N>14:\n\tfor i in arr:\n\t\tif i<=N:\n\t\t\tN -= i\n\t\t\tresult += 1\n\t\t\tbreak\nif N>=12:\n\tresult += 2\t\t\n\tN -= 12\nelif N>=6:\n\tresult += 1\t\t\n\tN -= 6\n\nprint(result + N)', 'n = int(input())\nsix = []\nfor i in range(20):\n six.append(6 ** i)\nnine = []\nfor i in range(20):\n nine.append(9 ** i)\n\nres = 10 ** 10\nfor i in range(n + 1):\n j = n - i\n k = i\n # print(i,j )\n cnt = 0\n\n #6\n piv = 19\n while k > 0 and piv >= 0:\n cnt += k // six[piv]\n k %= six[piv]\n piv -= 1\n\n #9\n piv = 19\n while j > 0 and piv >= 0:\n cnt += j // nine[piv]\n j %= nine[piv]\n piv -= 1\n\n res = min(res,cnt)\nprint(res)\n']
['Wrong Answer', 'Accepted']
['s886786341', 's659677472']
[3064.0, 3064.0]
[17.0, 1839.0]
[361, 491]
p03329
u841531687
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import sys\nsys.setrecursionlimit(10**7) \n\nN = int(input())\n\ndef ch(x, y):\n cnt = 0\n while x**cnt <= y:\n cnt += 1\n return cnt\n\ncoin = [1]\nfor i in range(1, ch(6, N)):\n coin.append(6**i)\n\nfor i in range(1, ch(9, N)):\n coin.append(9**i)\n\ndef rec(n):\n if n == 0: return 0\n if memo[n] != -1: return memo[n]\n \n res = n\n \n for c in coin:\n res = min(res, rec(n-c)+1)\n \n memo[n] = res\n return memo[n]\n\nmemo = [-1]*(10**5+10)\nrec(N)\nprint(memo[N])', 'import sys\nsys.setrecursionlimit(1000000)\n\ndef rec(n):\n if n == 0: return 0\n if memo[n] != -1: return memo[n]\n \n res = n\n i = 1\n while 6**i <= n:\n res = min(res, rec(n - 6**i) + 1)\n i += 1\n \n i = 1\n while 9**i <= n:\n res = min(res, rec(n - 9**i) + 1)\n i += 1\n \n memo[n] = res\n return res\n\nn = int(input())\nmemo = [-1]*(n+10)\nprint(rec(n))']
['Runtime Error', 'Accepted']
['s629605595', 's417068841']
[188504.0, 18036.0]
[546.0, 345.0]
[527, 402]
p03329
u842170774
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N=int(input())\ntimeslis2=[0,]*(100000)\ntimeslis2[1]=1\nnumlist2=numlist[::-1]\ndef times2(N):\n if N!=0:\n if timeslis2[N]==0:\n mini2=[]\n i=0\n while i<=11 and len(mini2)<=2:\n if N-numlist2[i]>=0:\n mini2.append(times2(N-numlist2[i]))\n #print(mini2,numlist2[i],i)\n i+=1\n mini2.sort()\n timeslis2[N]=mini2[0]+1\n return mini2[0]+1\n else:\n return timeslis2[N]\n return 0\nprint(times2(N))', 'N=int(input())\nnumlist=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]\ntimeslis2=[0,]*(100001)\ntimeslis2[1]=1\nnumlist2=numlist[::-1]\ndef times2(N):\n if N!=0:\n if timeslis2[N]==0:\n mini2=[]\n i=0\n while i<=11 and len(mini2)<=2:\n if N-numlist2[i]>=0:\n mini2.append(times2(N-numlist2[i]))\n #print(mini2,numlist2[i],i)\n i+=1\n mini2.sort()\n timeslis2[N]=mini2[0]+1\n return mini2[0]+1\n else:\n return timeslis2[N]\n return 0\nprint(times2(N))']
['Runtime Error', 'Accepted']
['s084201299', 's823254105']
[3828.0, 3956.0]
[19.0, 21.0]
[537, 605]
p03329
u845333844
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n=int(input())\na=100000\nfor i in range(n+1):\n j=i\n count=0\n while i>0:\n count+=i%6\n i//=6\n while j>0:\n count+=j%9\n j//=9\n a=min(a,count)\nprint(a)\n', 'n=int(input())\na=100000\nfor i in range(n+1):\n j=n-i\n count=0\n while i>0:\n count+=i%6\n i//=6\n while j>0:\n count+=j%9\n j//=9\n a=min(a,count)\nprint(a)\n']
['Wrong Answer', 'Accepted']
['s643346090', 's555144457']
[2940.0, 2940.0]
[311.0, 353.0]
[189, 191]
p03329
u853185302
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N=int(input())\nans=N\nfor i in range(N+1):\n cnt=0\n t=i\n cnt+=t%6\n while t>0:\n t//=6\n j=N-i\n cnt+=j%9\n while j>0:\n j//=9\n ans = min(ans,cnt)\nprint(ans)', 'N=int(input())\nans=N\nfor i in range(N+1):\n cnt=0\n t=i\n while t>0:\n cnt+=t%6\n t//=6\n j=N-i\n while j>0:\n cnt+=j%9\n j//=9\n ans = min(ans,cnt)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s781328826', 's258574184']
[3060.0, 3060.0]
[240.0, 346.0]
[187, 195]
p03329
u856169020
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\n\n\ndef solve():\n global N\n ans = 0\n a = []\n values = sorted([1] + [pow(6, _) for _ in range(1, 10)] + [pow(9, _) for _ in range(1, 10)])\n while N > 0:\n if 12 <= N <= 14:\n ans += 2 + (N - 12)\n break\n if 30 <= N <= 32:\n ans += 4 + (N - 30)\n break\n else:\n for i in range(len(values)):\n if N < values[i]:\n ans += 1\n a.append((values[i - 1], N))\n N -= values[i-1]\n break\n elif N == values[i]:\n ans += 1\n a.append((values[i], N))\n N -= values[i]\n break\n if N == 0:\n break\n return ans', "N = int(input())\n\n\ndef solve():\n global N\n ans = 0\n a = []\n values = sorted([1] + [pow(6, _) for _ in range(1, 10)] + [pow(9, _) for _ in range(1, 10)])\n while N > 0:\n if 12 <= N <= 17:\n ans += 2 + (N - 12)\n break\n else:\n for i in range(len(values)):\n if N < values[i]:\n ans += 1\n a.append((values[i - 1], N))\n N -= values[i-1]\n break\n elif N == values[i]:\n ans += 1\n a.append((values[i], N))\n N -= values[i]\n break\n if N == 0:\n break\n print(a, sum([_ for _, __ in a]))\n return ans\n\n\nif __name__ == '__main__':\n print(solve())", 'N = int(input())\ndp = [pow(10, 10)] * 100010\ndp[0] = 0\ndp[1] = 1\nfor n in range(100010):\n # for 6\n power = 1\n while n - power >= 0:\n dp[n] = min(dp[n], 1 + dp[n - power])\n power *= 6\n # for 9\n power = 1\n while n - power >= 0:\n dp[n] = min(dp[n], 1 + dp[n - power])\n power *= 9\nprint(dp[N])\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s292414556', 's566090471', 's242923839']
[3064.0, 3064.0, 3828.0]
[17.0, 17.0, 679.0]
[795, 805, 336]
p03329
u858136677
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['cost = [1]\ni = 1\nwhile 6**i <= 100000:\n\tcost.append(6**i)\n\ti += 1\ni = 1\nwhile 9**i <= 100000:\n\tcost.append(9**i)\n\ti += 1\ncost.sort()\ncost.reverse()\n\nprint(cost)\nn = int(input())\ncount = 0\nk = 0\nwhile n > 0:\n\tif n == 14:\n\t\tcount += 4\n\t\tn = 0\n\telif n == 13:\n\t\tcount += 3\n\t\tn = 0\n\telif n == 12:\n\t\tcount += 2\n\t\tn = 0\n\telif n >= cost[k]:\n\t\tprint(cost[k],n)\n\t\tn = n-cost[k]\n\t\tcount += 1\n\telse:\n\t\tk += 1\nprint(count)', 'cost = [1]\ni = 1\nwhile 6**i <= 100000:\n\tcost.append(6**i)\n\ti += 1\ni = 1\nwhile 9**i <= 100000:\n\tcost.append(9**i)\n\ti += 1\ncost.sort()\ncost.reverse()\n\nn = int(input())\nans = [0 for i in range(100001)]\nfor i in range(len(cost)):\n\tans[cost[i]] = 1\nfor i in range(1,100001):\n\tif ans[i] == 0:\n\t\ttempans = []\n\t\tfor k in range(len(cost)):\n\t\t\tif i-cost[k] >= 0:\n\t\t\t\ttempans.append(ans[i-cost[k]])\n\t\tans[i] = min(tempans)+1\nprint(ans[n])']
['Wrong Answer', 'Accepted']
['s951723740', 's132694541']
[3064.0, 3992.0]
[17.0, 493.0]
[409, 427]
p03329
u859897687
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n=int(input())\nans=1000000000\nfor i in range(0,n+1,6):\n j=n-i\n while j:\n a=j%9\n j//=9\n while i:\n a+=i%6\n i//=6\n ans=min(a,ans)\nprint(ans)', 'n=int(input())\nans=1000000000\nfor i in range(0,n+1,6):\n j=n-i\n while j:\n a=j%9\n j//=9\n while i:\n a+=i%6\n i//=6\n ans=min(a,ans)\nprgnt(ans)', 'n=int(input())\nans=0\nwhile n:\n a,b=1,1\n while a*6>n:\n a*=6\n while b*9>n:\n b*=9\n n-=max(a,b)\n ans+=1\nprint(ans)\n \n ', 'n=int(input())\nans=1000000000\nfor i in range(0,n+1,6):\n j=n-i\n a=0\n while j:\n a+=j%9\n j//=9\n while i:\n a+=i%6\n i//=6\n ans=min(a,ans)\nprint(ans)\n']
['Wrong Answer', 'Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s051034915', 's142168393', 's713493962', 's447265316']
[3060.0, 3060.0, 3060.0, 3064.0]
[67.0, 64.0, 2104.0, 71.0]
[153, 153, 127, 161]
p03329
u875361824
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['def main():\n """\n 1 <= N <= 10^5\n """\n N = int(input())\n\n ans = f(N)\n print(ans)\n\n\ndef test_ans():\n N_ans = [\n (127, 4),\n (3, 3),\n (44852, 16),\n ]\n for N, ans in N_ans:\n assert rec(N) == ans\n\n\ndef rec(N):\n import sys\n sys.setrecursionlimit(10 ** 7)\n memo = [-1] * (N+1)\n\n def _rec(i):\n if i == 0:\n return 0\n if memo[i] != -1:\n return memo[i]\n\n ans = N\n p = 1\n while p <= i:\n #print(6, i, i-p)\n ans = min(ans, _rec(i-p) + 1)\n p *= 6\n p = 1\n while p <= i:\n #print(9, i, i-p)\n ans = min(ans, _rec(i-p) + 1)\n p *= 9\n\n memo[i] = ans\n\n return ans\n\n ans = _rec(N)\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n', 'def main():\n """\n 1 <= N <= 10^5\n """\n N = int(input())\n\n ans = rec(N)\n print(ans)\n\n\ndef test_ans():\n N_ans = [\n (127, 4),\n (3, 3),\n (44852, 16),\n ]\n for N, ans in N_ans:\n assert rec(N) == ans\n\n\ndef rec(N):\n import sys\n sys.setrecursionlimit(10 ** 7)\n memo = [-1] * (N+1)\n\n def _rec(i):\n if i == 0:\n return 0\n if memo[i] != -1:\n return memo[i]\n\n ans = N\n p = 1\n while p <= i:\n #print(6, i, i-p)\n ans = min(ans, _rec(i-p) + 1)\n p *= 6\n p = 1\n while p <= i:\n #print(9, i, i-p)\n ans = min(ans, _rec(i-p) + 1)\n p *= 9\n\n memo[i] = ans\n\n return ans\n\n ans = _rec(N)\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Accepted']
['s666630614', 's802259075']
[3064.0, 108404.0]
[18.0, 605.0]
[833, 835]
p03329
u883792993
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N=int(input())\nnumber_of_withdrawal=[]\n\ndef floor(float_number):\n integer = 0\n while integer < float_number:\n integer+=1\n if integer == float_number:\n return integer\n else:\n integer-=1\n return integer\n\nfor money_6 in range(0, N+1):\n money_9 = N-money_6\n\n latest = count_6_pow_number+count_9_pow_number\n\n i=0\n count_6_pow_number=0\n while pow(6,i)<=money_6:\n count_6_pow_number += (floor(money_6/pow(6,i)))%6\n i+=1\n j=0\n count_9_pow_number=0\n while pow(9,j)<=money_9:\n count_9_pow_number += (floor(money_9/pow(9,j)))%9\n j+=1\n\n # print(money_6, money_9, sum(count_6_pow_number), sum(count_9_pow_number))\n number_of_withdrawal= count_6_pow_number+count_9_pow_number\n if number_of_withdrawal < latest:\n res = number_of_withdrawal\n\n\nprint(res)', 'N=int(input())\nmoney_list=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]\ndp=[0]\nfor i in range(1,N+1):\n dp.append(100000)\n\nfor i in range(1,N+1):\n for money in money_list:\n if i-money >= 0:\n dp[i]=min(dp[i-money]+1,dp[i])\nprint(dp[N])']
['Runtime Error', 'Accepted']
['s124060330', 's945191744']
[3064.0, 3860.0]
[18.0, 591.0]
[845, 260]
p03329
u905582793
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N=int(input())\ndstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]\nDP=[10**5]*(N*2)\nDP[0]=0\nfor i in range(N+1):\n for j in dstb:\n DP[i+j]=min(DP[i+j], DP[i]+1)\n\nprint(DP[N])\n', 'N=int(input())\ndstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]\nDP=[10**5]*(10**5*2)\nDP[0]=0\nfor i in range(N+1):\n for j in dstb:\n DP[i+j]=min(DP[i+j], DP[i]+1)\n\nprint(DP[N])\n']
['Runtime Error', 'Accepted']
['s735576237', 's046396576']
[4596.0, 4596.0]
[518.0, 517.0]
[189, 193]
p03329
u913392095
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N=int(input())\n\n#1*a+(6^b1)*b+(9^c1)*c\nlist=[99999]*(N+1)\nlist[0]=0\nlist[1]=1\n\nmax6end =True\ni=0\nwhile max6end:\n if N <= 6**i :\n max6=i\n max6end=False\n i+=1\nmax9end =True\ni=0\nwhile max9end:\n if N <= 9**i :\n max9=i\n max9end=False\n i+=1\n \nprint ("max6=%d max9=%d" % (max6,max9))\nfor n in range(1,N+1):\n list[n]=list[n-1]+1\n for i in range(1,max6+1):\n if n < 6**i:\n break\n else:\n if list[n] >= list[n-6**i]+1:\n list[n]=list[n-6**i]+1\n for i in range(1,max9+1):\n if n < 9**i:\n break\n else:\n if list[n] >= list[n-9**i]+1:\n list[n]=list[n-9**i]+1\nprint(list)', 'N=int(input())\n\n#1*a+(6^b1)*b+(9^c1)*c\nlist=[99999]*(N+1)\nlist[0]=0\nlist[1]=1\n\nmax6end =True\ni=0\nwhile max6end:\n if N <= 6**i :\n max6=i\n max6end=False\n i+=1\nmax9end =True\ni=0\nwhile max9end:\n if N <= 9**i :\n max9=i\n max9end=False\n i+=1\n \n#print ("max6=%d max9=%d" % (max6,max9))\nfor n in range(1,N+1):\n list[n]=list[n-1]+1\n for i in range(1,max6+1):\n if n < 6**i:\n break\n else:\n if list[n] >= list[n-6**i]+1:\n list[n]=list[n-6**i]+1\n for i in range(1,max9+1):\n if n < 9**i:\n break\n else:\n if list[n] >= list[n-9**i]+1:\n list[n]=list[n-9**i]+1\nprint(list[N])']
['Wrong Answer', 'Accepted']
['s743088352', 's820109802']
[4892.0, 3828.0]
[1057.0, 1119.0]
[756, 760]
p03329
u917558625
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['s=input()\na=int(s)\nlist=[]\nlist.append(1)\nlist.append(6)\nlist.append(9)\nlist.append(36)\nlist.append(81)\nlist.append(216)\nlist.append(729)\nlist.append(1296)\nlist.append(6561)\nlist.append(7776)\nlist.append(46656)\nlist.append(59049)\npp=[]\ndef money(x,y):\n for i in range(12):\n if 0<x//list[i]<6:\n if x%list[i]==0:\n pp.append(y+x//list[i])\n break\n else:\n money(x//list[i],y+1)\nmoney(a,0)\nprint(min(pp))', 's=input()\na=int(s)\nlist=[]\nlist.append(1)\nlist.append(6)\nlist.append(9)\nlist.append(36)\nlist.append(81)\nlist.append(216)\nlist.append(729)\nlist.append(1296)\nlist.append(6561)\nlist.append(7776)\nlist.append(46656)\nlist.append(59049)\npp=[]\ndef money(x,y):\n for i in range(12):\n if 0<x//list[i]<6:\n if x%list[i]==0:\n pp.append(y+x//list[i])\n break\n else:\n money(x%list[i],y+1)\nmoney(a,0)\nprint(min(pp))', 's=input()\na=int(s)\nlist=[]\nlist.append(1)\nlist.append(6)\nlist.append(9)\nlist.append(36)\nlist.append(81)\nlist.append(216)\nlist.append(729)\nlist.append(1296)\nlist.append(6561)\nlist.append(7776)\nlist.append(59049)\nlist.append(46656)\npp=[]\ndef money(x,y):\n for i in range(12):\n b=x//list[i]\n if b==0:\n continue\n if i%2==1:\n if 0<b<6:\n if x%list[i]==0:\n pp.append(y+b)\n else:\n if y>20:\n break\n money(x-list[i],y+1)\n elif i%2==0:\n if i!=0:\n if 0<b<9:\n if x%list[i]==0:\n pp.append(y+b)\n else:\n if y>20:\n break\n money(x-list[i],y+1)\n else:\n if 0<b<6:\n pp.append(y+b)\nmoney(a,0)\nprint(min(pp))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s233211440', 's766304695', 's641741331']
[3064.0, 3064.0, 4888.0]
[17.0, 18.0, 1487.0]
[433, 432, 756]
p03329
u928784113
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\nInf = float("inf")\ndp = [Inf]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n still1 = 1\n while still1 <= N:\n dp[i] = min(dp[i],1+dp[i-still1])\n still1 *= 6\n still2 = 1\n while still2 <= N:\n dp[i] = min(dp[i],1+dp[i-still2])\n still2 *= 9\nfor i in range(N+1):\n print(dp[i])', 'N = int(input())\nInf = float("inf")\ndp = [Inf]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n still1 = 1\n while still1 <= N:\n dp[i] = min(dp[i],1+dp[i-still1])\n still1 *= 6\n still2 = 1\n while still2 <= N:\n dp[i] = min(dp[i],1+dp[i-still2])\n still2 *= 9\nprint(dp[i])']
['Wrong Answer', 'Accepted']
['s734591608', 's788253838']
[4736.0, 3828.0]
[771.0, 742.0]
[375, 346]
p03329
u932868243
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n=int(input())\nans=n\nfor n1 in range(n+1):\n n2=n-n1\n cnt1=0\n while n1>0:\n cnt1+=n1%6\n n1=n1//6\n cnt2=0\n while n2>0:\n cnt2+=n2%9\n n2=n2//9\n ans=min(ans,n1+n2)\nprint(ans)', 'n=int(input())\nans=n\nfor n1 in range(n+1):\n n2=n-n1\n cnt1=0\n while n1>0:\n cnt1+=n1%6\n n1=n1//6\n cnt2=0\n while n2>0:\n cnt2+=n2%9\n n2=n2//9\n ans=min(ans,cnt1+cnt2)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s572438834', 's980476764']
[9136.0, 9132.0]
[212.0, 213.0]
[186, 190]
p03329
u934246119
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
["n = int(input())\ndp = [0 for i in range(n)]\na = [1]\ni = 1\n_ = 6\nwhile _ <= n:\n a.append(_)\n i += 1\n _ = 6 ** i\ni = 1\n_ = 9\nwhile _ <= n:\n a.append(_)\n i += 1\n _ = 9 ** i\ndp[0] = 1\nlen_a = len(a)\nfor i in range(n):\n target = []\n for j in range(len_a):\n if i + 1 >= a[j]:\n target.append(dp[i - a[j]])\n dp[i] = min(target) + 1\nprint('answer', dp[n-1])", 'n = int(input())\ndp = [0 for i in range(n)]\na = [1]\ni = 1\n_ = 6\nwhile _ <= n:\n a.append(_)\n i += 1\n _ = 6 ** i\ni = 1\n_ = 9\nwhile _ <= n:\n a.append(_)\n i += 1\n _ = 9 ** i\nlen_a = len(a)\nfor i in range(n):\n target = []\n for j in range(len_a):\n if i + 1 >= a[j]:\n target.append(dp[i - a[j]])\n dp[i] = min(target) + 1\nprint(dp[n-1])']
['Wrong Answer', 'Accepted']
['s743736126', 's727147346']
[3864.0, 3864.0]
[451.0, 454.0]
[393, 373]
p03329
u941284420
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import numpy as np\n\nN = int(input())\ndp = [float("inf")]*(N + 1)\ndp[0] = 0\npull_list_9 = [9**i for i in range(1, 6)]\npull_list_6 = [6**i for i in range(1, 7)]\npull_list = np.array(pull_list_9 + pull_list_6 + [1])\np_s = sorted(pull_list)\nfor i in range(1, N + 1):\n for j in p_s:\n if i - j < 0:\n break\n dp[i] = min(dp[i], dp[i-j] + 1)\nprint(dp[-1])\n', 'N = int(input())\ndp = [float("inf")]*(N + 1)\ndp[0] = 0\npull_list_9 = [9**i for i in range(1, 6)]\npull_list_6 = [6**i for i in range(1, 7)]\npull_list = pull_list_9 + pull_list_6 + [1]\np_s = sorted(pull_list)\n\nfor i in range(1, N + 1):\n for j in p_s:\n if i - j < 0:\n break\n dp[i] = min(dp[i], dp[i-j] + 1)\n\nprint(dp[-1])\n']
['Wrong Answer', 'Accepted']
['s912535174', 's759233533']
[13196.0, 3828.0]
[1927.0, 583.0]
[361, 331]
p03329
u960653324
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import math\nN = int(input())\n\nans = 0\nwhile N>0:\n if math.floor(math.log(N,9)) > 0 or math.floor(math.log(N,6)) > 0:\n print(max(9**(math.floor(math.log(N,9))), 6**(math.floor(math.log(N,6)))))\n N -= max(9**(math.floor(math.log(N,9))), 6**(math.floor(math.log(N,6))))\n else:\n N -= 1\n ans += 1\n\nprint(ans)\n', 'import math\nN = int(input())\n\nans = N\nfor i in range(N+1):\n count = 0\n t=i\n while t>0:\n count+=t%6\n t=math.floor(t/6)\n\n t = N-i\n\n while t>0:\n count += t%9\n t=math.floor(t/9)\n\n if ans>count:\n ans = count\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s743082792', 's067137839']
[3060.0, 3064.0]
[17.0, 441.0]
[316, 236]
p03329
u969190727
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['import math\nn=int(input())\ndp=[100000 for i in range(n+1)]\ndp[0]=0\ndp[1]=1\nfor i in range(1,n+1):\n dp[i]=dp[i-1]+1\n j,k=int(math.log(i)/math.log(6)),int(math.log(i)/math.log(9))\n for jj in range(j+2):\n dp[i]=min(dp[i],dp[max(0,i-6**jj)]+1)\n for kk in range(k+1):\n dp[i]=min(dp[i],dp[i-9**kk]+1) \nprint(dp[n])', 'n=int(input())\ndp=[100000 for i in range(n+1)]\ndp[0]=0\ndp[1]=1\nfor i in range(1,n+1):\n dp[i]=dp[i-1]+1\n j,k=0,0\n while 6**j<=i:\n dp[i]=min(dp[i],dp[i-6**j]+1)\n j+=1\n while 9**k<=i:\n dp[i]=min(dp[i],dp[i-9**k]+1)\n k+=1\nprint(dp[n])\n']
['Wrong Answer', 'Accepted']
['s998880386', 's828784185']
[3864.0, 3864.0]
[1138.0, 1092.0]
[318, 247]
p03329
u970899068
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\ndp = [0] * (N + 1)\ndp[0] = 0\nprint(dp)\nfor i in range(1, N + 1):\n cnt = i\n for j in range(1, 7):\n q = 6 ** j\n if i >= q:\n cnt = min(cnt, dp[i - q] + 1)\n print(i,cnt)\n for j in range(1, 6):\n q = 9 ** j\n if i >= q:\n cnt = min(cnt, dp[i - q] + 1)\n dp[i] = cnt\nprint(dp)\n', 'N = int(input())\ndp = [0] * (N + 1)\ndp[0] = 0\nfor i in range(1, N + 1):\n cnt = i\n for j in range(1, 7):\n q = 6 ** j\n if i >= q:\n cnt = min(cnt, dp[i - q] + 1)\n for j in range(1, 6):\n q = 9 ** j\n if i >= q:\n cnt = min(cnt, dp[i - q] + 1)\n dp[i] = cnt\nprint(dp[N])']
['Wrong Answer', 'Accepted']
['s837590226', 's439365479']
[10224.0, 3828.0]
[1543.0, 744.0]
[357, 324]
p03329
u982591663
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['N = int(input())\nprint(1)', 'N = int(input())\n\nmemo = [N+1] * (N+1)\n\nmemo[0] = 0\nmemo[1] = 1\n\nexp_sixs = []\nexp_nines = []\n\nfor i in range(1, 100000):\n if 6 ** i <= N:\n exp_sixs.append(6**i)\n else:\n break\n\nfor i in range(1, 100000):\n if 9 ** i <= N:\n exp_nines.append(9**i)\n else:\n break\n\n# print(exp_sixs)\n# print(exp_nines)\nfor exp_six in exp_sixs:\n memo[exp_six] = 1\n\nfor exp_nine in exp_nines:\n memo[exp_nine] = 1\n\nfor i in range(1, N+1):\n \n one_result = memo[i-1] + 1\n\n \n six_result = N+1\n for exp_six in exp_sixs:\n if (i - exp_six) >= 0:\n six_result = min(six_result, memo[i-exp_six] + 1)\n else:\n break\n\n \n nine_result = N+1\n for exp_nine in exp_nines:\n if (i - exp_nine) >= 0:\n nine_result = min(nine_result, memo[i-exp_nine] + 1)\n else:\n break\n memo[i] = min(one_result, six_result, nine_result)\nprint(memo[N])\n']
['Wrong Answer', 'Accepted']
['s971747388', 's709955074']
[2940.0, 3828.0]
[17.0, 502.0]
[25, 1050]
p03329
u994988729
2,000
262,144
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: * 1 yen (the currency of Japan) * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew.
['n=int(input())\n\nsix=[6**i for i in range(1, 7)]\nnine=[9**i for i in range(0, 6)]\nCash=sorted(six+nine, reverse=True)\n\nans=0\ni=0\nwhile i<len(Cash):\n c=Cash[i]\n num=n//c\n n-=num*c\n ans+=num\n print(num, c, n)\n if n==0:\n break\n i+=1\nprint(ans)\n \n', 'n=int(input())\n\ndp=[200000]*(n+1)\ndp[0]=0\n\nfor i in range(n+1):\n power=1\n while power<=i:\n dp[i]=min(dp[i], dp[i-power]+1)\n power*=6\n power=9\n while power<=i:\n dp[i]=min(dp[i], dp[i-power]+1)\n power*=9\n\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s365158087', 's698227927']
[3064.0, 3828.0]
[18.0, 583.0]
[273, 255]
p03330
u001024152
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
["N,C = map(int, input().split())\ncost = [list(map(int, input().split())) for _ in range(C)]\ncolor = [list(map(int, input().split())) for _ in range(N)]\n\nmod3 = {0:[], 1:[], 2:[]}\nfor i in range(N):\n for j in range(N):\n m = (i+j)%3\n mod3[m].append(color[i][j])\n \nfrom collections import Counter\nfrom itertools import combinations, permutations\ncnts = [Counter(mod3[i]) for i in range(3)]\n# print(cnts)\nans = float('inf')\nfor comb in combinations(range(C), 3):\n for p in permutations(comb):\n cond = 0\n for i in range(3):\n for col in cnts[i].keys():\n cond += cnts[i][col]*cost[col][p[i]]\n ans = min(ans, cond)\n #print(cond, p)\nprint(ans)\n ", "from collections import Counter\nfrom itertools import permutations\nN,C = map(int, input().split())\ncost = [list(map(int, input().split())) for _ in range(C)]\ncolor = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]\n\n# 3 groups\nmod3 = {0:[], 1:[], 2:[]}\nfor i in range(N):\n for j in range(N):\n m = (i+j)%3\n mod3[m].append(color[i][j])\n\ncnts = [Counter(mod3[i]) for i in range(3)]\ncost_mod = [[-1]*C for _ in range(3)]\nfor i in range(3):\n for to_ in range(C):\n cond = 0\n for from_ in cnts[i].keys():\n cond += cnts[i][from_]*cost[from_][to_]\n cost_mod[i][to_] = cond\n\nans = float('inf')\nfor p in permutations(range(C), 3):\n cond = 0\n for i in range(3):\n cond += cost_mod[i][p[i]]\n ans = min(ans, cond)\n #print(cond, p)\nprint(ans)\n "]
['Runtime Error', 'Accepted']
['s678022946', 's662724158']
[7812.0, 8012.0]
[238.0, 245.0]
[719, 819]
p03330
u047668580
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['N,C = list(map(int,input().split()))\nD = [ list(map(int,input().split())) for i in range(C)]\nc = [ list(map(int,input().split())) for i in range(N)]\n\nsep = {0:[0 for i in range(C)],1:[0 for i in range(C)],2:[0 for i in range(C)]}\nfor i,cx in enumerate(c):\n for j,cy in enumerate(cx):\n if len(c) == 2 and (i + j) % 3 == 2:\n sep[(i + j) % 3 - 1][cy -1] += 1\n else:\n sep[(i + j) % 3][cy - 1] += 1\nminimums = [[],[],[]]\nfor key,values in sep.tems():\n for i in range(C):\n m0 = 0\n am0 = 0\n m1 = 0\n am1 = 1\n deposit = 0\n for j,value in enumerate(values):\n deposit += D[j][i] * valuea\n sep[key].append(deposit)\nmin0 = min(sep[0])\nmin1 = min(sep[1])\nmin2 = min(sep[2])\n\nprint(min1 + min2 + min0)\n', '\n\n\nimport numpy as np\nN,C = map(int,input().split())\na = np.zeros((3,C))\nD = np.array([ list(map(int,input().split()))) for i in range(C)])\nc = np.array([ list(map(int,input().split()))) for i in range(N)])\n\n\nfor i in range(N):\n for j in range(N):\n a[(i+j)%3] += D[c[i][j]-1]\n\nsum_arr = []\nfor C1 in range(C):\n for C2 in range(C):\n for C3 in range(C):\n if C1 != C2 and C2 != C3 and C3 != C1:\n sum_arr.append(a[0][C1]+a[1][C2]+a[2][C3])\n\nprint(int(min(l)))\n', 'N,C = list(map(int,input().split()))\nD = [ list(map(int,input().split())) for i in range(C)]\nc = [ list(map(int,input().split())) for i in range(N)]\n\nsep = {0:[0 for i in range(C)],1:[0 for i in range(C)],2:[0 for i in range(C)]}\nfor i,cx in enumerate(c):\n for j,cy in enumerate(cx):\n sep[(i + j) % 3][cy] + = 1\nminimums = [[],[],[]]\nfor key,values in sep.tems():\n for i in range(C):\n m0 = 0\n am0 = 0\n m1 = 0\n am1 = 1\n deposit = 0\n for j,value in enumerate(values):\n deposit += D[j][i] * valuea\n sep[key].append(deposit)\nmin0 = min(sep[0])\n\nmin1 = min(sep[1])\nmin2 = min(sep[2])\nmin3 = min(sep[2])\n\nprint(min1 + min2 + min3)\n', '\n\n\nimport numpy as np\nN,C = map(int,input().split())\na = np.zeros((3,C))\nD = np.array([ list(map(int,input().split())) for i in range(C)])\nc = np.array([ list(map(int,input().split())) for i in range(N)])\n\n\nfor i in range(N):\n for j in range(N):\n a[(i+j)%3] += D[c[i][j]-1]\n\nsum_arr = []\nfor C1 in range(C):\n for C2 in range(C):\n for C3 in range(C):\n if C1 != C2 and C2 != C3 and C3 != C1:\n sum_arr.append(a[0][C1]+a[1][C2]+a[2][C3])\n\nprint(int(min(sum_arr)))\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s146692781', 's479742166', 's868682060', 's578714367']
[5620.0, 2940.0, 3064.0, 18920.0]
[162.0, 17.0, 17.0, 1687.0]
[791, 673, 700, 677]
p03330
u118642796
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import sys\ns =sys.stdin.readlines()\nN,C = map(int,s[0].split())\nD = [[int(i) for i in sys[1+j].split()] for j in range(C)]\nc = [[int(i) for i in sys[C+j].split()] for j in range(N)]\n\nD_sum = [[0]*C for _ in range(3)]\n\nfor i in range(C):\n for j in range(N):\n for k in range(N):\n D_sum[(j+k)%3][i] += D[c[j][k]-1][i]\n \nans = 1000*500*500\nfor i in range(C):\n for j in range(C):\n for k in range(C):\n if i==j or j==k or k==i:\n continue\n else:\n ans = min(ans, D_sum[0][i]+D_sum[1][j]+D_sum[2][k])\nprint(ans) \n', 'import sys\n\ns = sys.stdin.readlines()\n\nN,C = map(int,s[0].split())\nD = [[int(i) for i in s[j+1].split()] for j in range(C)]\nc = [[int(i) for i in s[c+1+j].split()] for j in range(N)]\n\nc_sum = [[0]*C for _ in range(3)]\nfor i in range(N):\n for j in range(N):\n c_sum[(i+j)%3][c[i][j]-1] += 1\n\nD_sum = [[0]*C for _ in range(3)]\nfor i in range(C):\n for j in range(C):\n for k in range(3):\n D_sum[k][j] += D[i][j] * c_sum[k][i]\n\nans = 1000*500*500\nfor i in range(C):\n for j in range(C):\n for k in range(C):\n if i==j or j==k or k==i:\n continue\n else:\n ans = min(ans, D_sum[0][i]+D_sum[1][j]+D_sum[2][k])\nprint(ans)\n', 'N,C = map(int,input().split())\nD = [[int(i) for i in input().split()] for j in range(C)]\nc = [[int(i) for i in input().split()] for j in range(N)]\n\nc_sum = [[0]*C for _ in range(3)]\nfor i in range(N):\n for j in range(N):\n c_sum[(i+j)%3][c[i][j]-1] += 1\n\nD_sum = [[0]*C for _ in range(3)]\nfor i in range(C):\n for j in range(C):\n for k in range(3):\n D_sum[k][j] += D[i][j] * c_sum[k][i]\n\nans = 1000*500*500\nfor i in range(C):\n for j in range(C):\n for k in range(C):\n if i==j or j==k or k==i:\n continue\n else:\n ans = min(ans, D_sum[0][i]+D_sum[1][j]+D_sum[2][k])\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s227302881', 's519250980', 's957191409']
[3828.0, 3828.0, 5364.0]
[19.0, 19.0, 176.0]
[602, 700, 663]
p03330
u123896133
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from itertools import product\nN,C=map(int,input().split())\nD=[]\nfor i in range(C):\n Dlist=list(map(int,input().split()))\n D.append(Dlist)\nc=[[0]*N*N for i in range(3)]\nx=[]\nX=[]\nfor i in range(N):\n x=list(map(int,input().split()))\n X.append(x)\nfor i in range(N):\n for j in range(N):\n x=X[i][j]\n c[(i+j)%3][x-1]+=1\ndef func(res):\n print(res)\n for i in range(C):\n for j in range(C):\n if i!=j:\n for k in range(C):\n if i!=k and j!=k:\n total=0\n for l in range(C): \n total+=D[l][i]*c[0][l]\n total+=D[l][j]*c[1][l]\n total+=D[l][k]*c[2][l]\n if total<res:\n res=total\n return res\nx=10**6\nres=func(x)\nprint(res) ', 'from itertools import product\nN,C=map(int,input().split())\nD=[]\nfor i in range(C):\n Dlist=list(map(int,input().split()))\n D.append(Dlist)\nc=[[0]*N*N for i in range(3)]\nx=[]\nX=[]\nfor i in range(N):\n x=list(map(int,input().split()))\n X.append(x)\nfor i in range(N):\n for j in range(N):\n x=X[i][j]\n c[(i+j)%3][x-1]+=1\nprint(D,c)\ndef func(res):\n print(res)\n for i in range(C):\n for j in range(C):\n if i!=j:\n for k in range(C):\n if i!=k and j!=k:\n total=0\n for l in range(C): \n total+=D[l][i]*c[0][l]\n total+=D[l][j]*c[1][l]\n total+=D[l][k]*c[2][l]\n if total<res:\n res=total\n return res\nx=10**6\nres=func(x)\nprint(res)', 'N,C=map(int,input().split())\nD=[]\nfor i in range(C):\n Dlist=list(map(int,input().split()))\n D.append(Dlist)\nc=[[0]*(10**6) for i in range(3)]\nx=[]\nX=[]\nfor i in range(N):\n x=list(map(int,input().split()))\n X.append(x)\nfor i in range(N):\n for j in range(N):\n x=X[i][j]\n c[(i+j)%3][x-1]+=1\ndef func(res):\n for i in range(C):\n for j in range(C):\n if i!=j:\n for k in range(C):\n if i!=k and j!=k:\n total=0\n for l in range(C): \n total+=D[l][i]*c[0][l]\n total+=D[l][j]*c[1][l]\n total+=D[l][k]*c[2][l]\n if total<res:\n res=total\n return res\ny=10**20\nres=func(y)\nprint(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s046700256', 's492706671', 's332805731']
[11380.0, 18756.0, 29044.0]
[549.0, 571.0, 553.0]
[925, 904, 853]
p03330
u129836004
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import copy\nN , C = map(int, input().split())\nds =[list(map(int, input().split())) for i in range(C)]\ncs =[list(map(int, input().split())) for i in range(N)]\nc0 = []\nc1 = []\nc2 = []\nfor i in range(N):\n for j in range(N):\n if (i+j) % 3 == 0:\n c0.append(cs[i][j])\n elif (i+j) % 3 == 1:\n c1.append(cs[i][j])\n else:\n c2.append(cs[i][j])\nd = 10**9\nl0 = len(c0)\nl1 = len(c1)\nl2 = len(c2)\nfor i in range(C):\n d0 = 0\n for l in range(l0):\n if (c0[l]-1) != i:\n d0 += ds[c0[l]-1][i]\n for j in range(C):\n if i == j:\n continue\n d1 = copy,copy(d0)\n for h in range(l1):\n if (c1[h]-1) != j:\n d1 += ds[c1[h]-1][j]\n for k in range(C):\n if i == k or j == k:\n continue\n d2 = copy.copy(d1)\n for l in range(l2):\n if (c2[l]-1) != k:\n d2 += ds[c2[l]-1][k]\n if d > d2:\n d = d2\nprint(d)', 'import copy\nN , C = map(int, input().split())\nds =[list(map(int, input().split())) for i in range(C)]\ncs =[list(map(int, input().split())) for i in range(N)]\nc0 = []\nc1 = []\nc2 = []\nfor i in range(N):\n for j in range(N):\n if (i+j) % 3 == 0:\n c0.append(cs[i][j])\n elif (i+j) % 3 == 1:\n c1.append(cs[i][j])\n else:\n c2.append(cs[i][j])\nd = 10**9\nl0 = len(c0)\nl1 = len(c1)\nl2 = len(c2)\nfor i in range(C):\n d0 = 0\n for l in range(l0):\n if (c0[l]-1) != i:\n d0 += ds[c0[l]-1][i]\n for j in range(C):\n if i == j:\n continue\n d1 = copy,copy(d0)\n for h in range(l1):\n if (c1[h]-1) != j:\n d1 += ds[c1[h]-1][j]\n for k in range(C):\n if i == k or j == k:\n continue\n d2 = copy.copy(d1)\n for l in range(l2):\n if (c2[l]-1) != k:\n d2 += ds[c2[l]-1][k]\n if d > d2:\n d = d2\nprint(d)\n\n', 'mport collections\nN , C = map(int, input().split())\nds =[list(map(int, input().split())) for i in range(C)]\ncs =[list(map(int, input().split())) for i in range(N)]\nc0 = collections.defaultdict(int)\nc1 = collections.defaultdict(int)\nc2 = collections.defaultdict(int)\nfor i in range(N):\n for j in range(N):\n if (i+j) % 3 == 0:\n c0[cs[i][j]] += 1\n elif (i+j) % 3 == 1:\n c1[cs[i][j]] += 1\n else:\n c2[cs[i][j]] += 1\n \nd = 10**9\nfor i in range(C):\n for j in range(C):\n if i == j:\n continue\n for k in range(C):\n if i == k or j == k:\n continue\n d0 = 0\n for l in c0:\n if l != i:\n d0 += c0[l] * ds[l-1][i]\n for l in c1:\n if l != j:\n d0 += c1[l] * ds[l-1][j]\n for l in c2:\n if l != k:\n d0 += c2[l] * ds[l-1][k]\n if d > d0:\n d = d0\nprint(d)', 'import collections\nN , C = map(int, input().split())\nds =[list(map(int, input().split())) for i in range(C)]\ncs =[list(map(int, input().split())) for i in range(N)]\nc0 = collections.defaultdict(int)\nc1 = collections.defaultdict(int)\nc2 = collections.defaultdict(int)\nfor i in range(N):\n for j in range(N):\n if (i+j) % 3 == 0:\n c0[cs[i][j]] += 1\n elif (i+j) % 3 == 1:\n c1[cs[i][j]] += 1\n else:\n c2[cs[i][j]] += 1\n \nd = 10**9\nfor i in range(C):\n for j in range(C):\n if i == j:\n continue\n for k in range(C):\n if i == k or j == k:\n continue\n d0 = 0\n for l in c0:\n d0 += c0[l] * ds[l-1][i]\n for l in c1:\n d0 += c1[l] * ds[l-1][j]\n for l in c2:\n d0 += c2[l] * ds[l-1][k]\n if d > d0:\n d = d0\n \nprint(d)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s014190892', 's561659553', 's994331663', 's658297023']
[3064.0, 8176.0, 2940.0, 5876.0]
[17.0, 205.0, 17.0, 768.0]
[1018, 1020, 1022, 943]
p03330
u149260203
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['N,C = [int(i) for i in input().split()]\nD = [[int(j) for j in input().split()] for i in range(C)]\nc_temp = [[int(j)-1 for j in input().split()] for i in range(N)]\nc = [[0 for i in range(C)] for j in range(3)]\nprint(c)\nfor i in range(N):\n for j in range(N):\n c[(i+j+2)%3][c_temp[i][j]] += 1\n print((i+j+2)%3, c_temp[i][j])\n\nmin = 100000\nfor i in [ii for ii in range(C)]:\n for j in [jj for jj in range(C) if jj != i]:\n for k in [kk for kk in range(C) if kk != i and kk != j]:\n count = sum([D[x][i]*c[0][x] + D[x][j]*c[1][x] + D[x][k]*c[2][x] for x in range(C)])\n if min > count:\n min = count\nprint(min)\n\n\n', 'N,C = [int(i) for i in input().split()]\nD = [[int(j) for j in input().split()] for i in range(C)]\nc_temp = [[int(j)-1 for j in input().split()] for i in range(N)]\nc = [[0 for i in range(C)] for j in range(3)]\nprint(c)\nfor i in range(N):\n for j in range(N):\n c[(i+j+2)%3][c_temp[i][j]] += 1\n\nmin = 100000\nfor i in [ii for ii in range(C)]:\n for j in [jj for jj in range(C) if jj != i]:\n for k in [kk for kk in range(C) if kk != i and kk != j]:\n count = sum([D[x][i]*c[0][x] + D[x][j]*c[1][x] + D[x][k]*c[2][x] for x in range(C)])\n if min > count:\n min = count\nprint(min)\n\n\n', 'N,C = [int(i) for i in input().split()]\nD = [[int(j) for j in input().split()] for i in range(C)]\nc_temp = [[int(j)-1 for j in input().split()] for i in range(N)]\nc = [[0 for i in range(C)] for j in range(3)]\nfor i in range(N):\n for j in range(N):\n c[(i+j)%3][c_temp[i][j]] += 1\n\nmin = 10**15\nfor i in [ii for ii in range(C)]:\n for j in [jj for jj in range(C) if jj != i]:\n for k in [kk for kk in range(C) if kk != i and kk != j]:\n count = sum([D[x][i]*c[0][x] + D[x][j]*c[1][x] + D[x][k]*c[2][x] for x in range(C)])\n if min > count:\n min = count\nprint(min)\n\n\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s354643906', 's861783129', 's768806410']
[7228.0, 5364.0, 5492.0]
[846.0, 530.0, 532.0]
[667, 628, 617]
p03330
u167988719
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from collections import Counter\nfrom itertools import permutations\n\ndef main():\n N, C = map(int, input().split())\n D = [[int(x) for x in input().split()] for _ in range(C)]\n\n cnt = [Counter() for _ in range(3)]\n\n for i in range(N):\n c = [int(x)-1 for x in input().split()]\n for j in range(3):\n cnt[j].update(c[(3-(i+2)+j)%3::3])\n\n ans = 1000*500*500+5\n for p in permutations(range(C), 3):\n s = sum(D[k][p[j]] * v for k, v in cnt[j].items() for j in range(3))\n ans = min(ans, s)\n\n print(ans)\n\nmain()', 'from collections import Counter\nfrom itertools import permutations\n\ndef main():\n N, C = map(int, input().split())\n D = tuple(tuple(map(int, input().split())) for _ in range(C))\n\n cnt = [Counter() for _ in range(3)]\n\n for i in range(N):\n c = [int(x)-1 for x in input().split()]\n for j in range(3):\n cnt[j].update(c[(3-(i+2)+j)%3::3])\n\n ans = 1000*500*500+5\n for p in permutations(range(C), 3):\n s = 0\n for j in range(3):\n s += sum(D[k][p[j]] * v for k, v in cnt[j].items())\n if s < ans: ans = s\n print(ans)\n\nmain()\n']
['Wrong Answer', 'Accepted']
['s888318075', 's113460628']
[3436.0, 3436.0]
[577.0, 445.0]
[558, 592]
p03330
u176645218
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
["import itertools\nN,C = map(int,input().split(' '))\nD = [list(map(int,input().split(' '))) for i in [0]*C]\nc = [list(map(int,input().split(' '))) for i in [0]*N]\n\n\nl = [[],[],[]]\nn = 0\nfor i in range(N):\n\tfor j in range(i+1):\n\t\tl[n].append(c[i-j][j])\n\tn = (n+1) % 3\nfor i in range(N-1):\n\tfor j in range(N-i-1):\n\t\tl[n].append(c[i+j+1][N-j-1])\n\tn = (n+1) % 3\n\nd1,d2,d3 = [[sum([D[j-1][i] for j in l[n]]) for i in range(C)] for n in range(3)]\n\nans = 1000*500*500\ncolors = list(range(C))\nfor c1,c2,c3 in itertools.combinations(colors,3):\n\tans = min(ans,d1[c1] + d2[c2] + d3[c3])\nprint(ans)\n\n\n\n\n\n", "import itertools\nN,C = map(int,input().split(' '))\nD = [list(map(int,input().split(' '))) for i in [0]*C]\nc = [list(map(int,input().split(' '))) for i in [0]*N]\n\n\nl = [[],[],[]]\nn = 0\nfor i in range(N):\n\tfor j in range(i+1):\n\t\tl[n].append(c[i-j][j])\n\tn = (n+1) % 3\nfor i in range(N-1):\n\tfor j in range(N-i-1):\n\t\tl[n].append(c[i+j+1][N-j-1])\n\tn = (n+1) % 3\n\nd1,d2,d3 = [[sum([D[j-1][i] for j in l[n]]) for i in range(C)] for n in range(3)]\n\nans = 1000*500*500\ncolors = list(range(C))\nfor c1,c2,c3 in itertools.permutations(colors,3):\n\tans = min(ans,d1[c1] + d2[c2] + d3[c3])\nprint(ans)\n\n\n\n"]
['Wrong Answer', 'Accepted']
['s050542480', 's589589630']
[8356.0, 8356.0]
[728.0, 713.0]
[590, 588]
p03330
u207707177
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['n,c = [int(i) for i in input().split()]\neffort = []\ngroup1 = []\ngroup2 = []\ngroup3 = []\n\neffort1 = []\neffort2 = []\neffort3 = []\n\ncolor1 = [0 for i in range(c)]\ncolor2 = [0 for i in range(c)]\ncolor3 = [0 for i in range(c)]\n\nfor i in range(c):\n effort.append(list(map(int,input().split())))\n\nfor i in range(n):\n k = 0\n for j in input().split():\n k+=1\n tot = i+1+k\n if tot % 3 == 0:\n group1.append(int(j))\n elif tot % 3 == 1:\n group2.append(int(j))\n elif tot % 3 == 2:\n group3.append(int(j))\n\nfor i in group1:\n color1[i-1] +=1\nfor i in group2:\n color2[i-1] +=1\nfor i in group3:\n color3[i - 1] += 1\n\nprint(color1,color2,color3)\n\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color1[k] * effort[k][i]\n effort1.append([eff,i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color2[k] * effort[k][i]\n effort2.append([eff, i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color3[k] * effort[k][i]\n effort3.append([eff, i])\n\neffort1 = sorted(effort1)\neffort2 = sorted(effort2)\neffort3 = sorted(effort3)\nprint(effort1,effort2,effort3)\ntoteff = 10000000000000000000\nfor i in range(3):\n col1 = effort1[i][1]\n for k in range(3):\n col2 = effort2[k][1]\n for j in range(3):\n col3 = effort3[j][1]\n if col1 != col2 and col2 !=col3 and col1!=col3:\n print(col1,col2,col3)\n print(effort1[i][0],effort2[k][0],effort3[j][0])\n toteff = min(toteff,effort1[i][0]+effort2[k][0]+effort3[j][0])\n\nprint(toteff)', 'n,c = [int(i) for i in input().split()]\neffort = []\ngroup1 = []\ngroup2 = []\ngroup3 = []\n\neffort1 = []\neffort2 = []\neffort3 = []\n\ncolor1 = [0 for i in range(c)]\ncolor2 = [0 for i in range(c)]\ncolor3 = [0 for i in range(c)]\n\nfor i in range(c):\n effort.append(list(map(int,input().split())))\n\nfor i in range(n):\n k = 0\n for j in input().split():\n k+=1\n tot = i+1+k\n if tot % 3 == 0:\n group1.append(int(j))\n elif tot % 3 == 1:\n group2.append(int(j))\n elif tot % 3 == 2:\n group3.append(int(j))\n\nfor i in group1:\n color1[i-1] +=1\nfor i in group2:\n color2[i-1] +=1\nfor i in group3:\n color3[i - 1] += 1\n\nprint(color1,color2,color3)\n\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color1[k] * effort[k][i]\n effort1.append([eff,i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color2[k] * effort[k][i]\n effort2.append([eff, i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color3[k] * effort[k][i]\n effort3.append([eff, i])\n\neffort1 = sorted(effort1)\neffort2 = sorted(effort2)\neffort3 = sorted(effort3)\nprint(effort1,effort2,effort3)\ntoteff = 10000000000000000000\nfor i in range(3):\n col1 = effort1[i][1]\n for k in range(3):\n col2 = effort2[k][1]\n for j in range(3):\n col3 = effort3[j][1]\n if col1 != col2 and col2 !=col3 and col1!=col3:\n print(col1,col2,col3)\n print(effort1[i][0],effort2[k][0],effort3[j][0])\n toteff = min(toteff,effort1[i][0]+effort2[k][0]+effort3[j][0])\n\nprint(toteff)', 'n,c = [int(i) for i in input().split()]\neffort = []\ngroup1 = []\ngroup2 = []\ngroup3 = []\n\neffort1 = []\neffort2 = []\neffort3 = []\n\ncolor1 = [0 for i in range(c)]\ncolor2 = [0 for i in range(c)]\ncolor3 = [0 for i in range(c)]\n\nfor i in range(c):\n effort.append(list(map(int,input().split())))\n\nfor i in range(n):\n k = 0\n for j in input().split():\n k+=1\n tot = i+1+k\n if tot % 3 == 0:\n group1.append(int(j))\n elif tot % 3 == 1:\n group2.append(int(j))\n elif tot % 3 == 2:\n group3.append(int(j))\n\nfor i in group1:\n color1[i-1] +=1\nfor i in group2:\n color2[i-1] +=1\nfor i in group3:\n color3[i - 1] += 1\n\n\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color1[k] * effort[k][i]\n effort1.append([eff,i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color2[k] * effort[k][i]\n effort2.append([eff, i])\nfor i in range(c):\n eff = 0\n for k in range(c):\n eff += color3[k] * effort[k][i]\n effort3.append([eff, i])\n\neffort1 = sorted(effort1)\neffort2 = sorted(effort2)\neffort3 = sorted(effort3)\ntoteff = 10000000000000000000\nfor i in range(3):\n col1 = effort1[i][1]\n for k in range(3):\n col2 = effort2[k][1]\n for j in range(3):\n col3 = effort3[j][1]\n if col1 != col2 and col2 !=col3 and col1!=col3:\n toteff = min(toteff,effort1[i][0]+effort2[k][0]+effort3[j][0])\n\nprint(toteff)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s120991483', 's433185978', 's758771667']
[5264.0, 5264.0, 5304.0]
[210.0, 213.0, 203.0]
[1631, 1631, 1469]
p03330
u225388820
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from itertools import combinations\nn,C=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(C)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*C for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in combinations(range(C),3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(30):\n\t\t\ttmp+=a[i][j]*d[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)', 'from itertools import combinations\nn,C=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(C)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*C for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in combinations(range(C),3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(C):\n\t\t\ttmp+=a[i][j]*d[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)', 'from itertools import combinations\nn,c=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(c)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*c for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in combinations(c,3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(30):\n\t\t\ttmp+=a[i][j]*c[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)', 'from itertools import combinations\nn,C=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(C)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*C for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in combinations(C,3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(30):\n\t\t\ttmp+=a[i][j]*c[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)', 'from itertools import combinations\nn,C=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(C)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*C for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in combinations(range(C),3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(30):\n\t\t\ttmp+=a[i][j]*c[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)', 'from itertools import permutations\nn,C=map(int,input().split())\nd=[list(map(int,input().split())) for _ in range(C)]\nc=[list(map(int,input().split())) for _ in range(n)]\na=[[0]*C for _ in range(3)]\nfor i in range(n):\n\tfor j in range(n):\n\t\ta[(i+j)%3][c[i][j]-1]+=1\nans=10**9\nfor v in permutations(range(C),3):\n\ttmp=0\n\tfor i in range(3):\n\t\tfor j in range(C):\n\t\t\ttmp+=a[i][j]*d[j][v[i]]\n\tans=min(ans,tmp)\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s056294977', 's111765523', 's463064655', 's478521917', 's567032905', 's278910637']
[11544.0, 11652.0, 11792.0, 11700.0, 11640.0, 11616.0]
[196.0, 199.0, 62.0, 116.0, 196.0, 641.0]
[414, 413, 407, 407, 414, 412]
p03330
u239528020
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['#!/usr/bin/env python3\n\nfrom itertools import product\n\nN, C = list(map(int, input().split()))\n\nD = [list(map(int, input().split())) for i in range(C)]\n\n\ncolors = [[0]*C for i in range(3)]\nfor i in range(N):\n tmp = list(map(int, input().split()))\n for j, color in enumerate(tmp):\n num = ((i+1) + (j+1)) % 3\n colors[num][color-1] += 1\n\n\ndata = [[0]*C for i in range(3)]\n\n\nfor i in range(3):\n # color[i]\n for j in range(C):\n for k in range(C):\n data[i][k] += colors[i][j] * D[j][k]\n# print(data)\n\nans = 10**10\n# for iter_ in product([0, 1, 2], repeat=C):\n# if len(set(iter_)) != C:\n# continue\n# tmp = []\n# for i, j in enumerate(iter_):\n# tmp.append(data[i][j])\n# ans = min(ans, sum(tmp))\nprint(ans)\n', '#!/usr/bin/env python3\n\nfrom itertools import permutations\n\nN, C = list(map(int, input().split()))\n\nD = [list(map(int, input().split())) for i in range(C)]\n\n\ncolors = [[0]*C for i in range(3)]\nfor i in range(N):\n tmp = list(map(int, input().split()))\n for j, color in enumerate(tmp):\n num = ((i+1) + (j+1)) % 3\n colors[num][color-1] += 1\n\n\ndata = [[0]*C for i in range(3)]\n\n\nfor i in range(3):\n # color[i]\n for j in range(C):\n for k in range(C):\n data[i][k] += colors[i][j] * D[j][k]\n# print(data)\n\nans = 10**10\nfor iter_ in permutations(list(range(C)), 3):\n # print(iter_)\n tmp = []\n for i, j in enumerate(iter_):\n tmp.append(data[i][j])\n ans = min(ans, sum(tmp))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s901941782', 's330010176']
[9348.0, 9316.0]
[126.0, 151.0]
[844, 811]
p03330
u325227960
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['n,c=map(int,input().split())\nD=[]\nfor i in range(c):\n D.append(list(map(int,input().split())))\nC=[]\nfor i in range(n):\n C.append(list(map(int,input().split())))\n\nprint(D)\n\nC1=[]\nC2=[]\nC3=[]\nfor i in range(n):\n for j in range(n):\n f=(i+j)%3\n if f==0:\n C1.append(C[i][j])\n if f==1:\n C2.append(C[i][j])\n if f==2:\n C3.append(C[i][j])\n \n\nminiwa=1000*500*500\n\nprint(C3)\n\nfor c1 in range(0,c):\n iwa1=sum(D[i-1][c1] for i in C1)\n for c2 in range(0,c):\n iwa2=sum(D[j-1][c2] for j in C2)\n for c3 in range(0,c):\n if c1!=c2 and c2!=c3 and c3!=c1 :\n iwa3=sum(D[k-1][c3] for k in C3)\n iwa=iwa1+iwa2+iwa3\n miniwa=min(miniwa,iwa)\n\nprint(miniwa)\n', 'n,c=map(int,input().split())\nD=[]\nfor i in range(c):\n D.append(list(map(int,input().split())))\nC=[]\nfor i in range(n):\n C.append(list(map(int,input().split())))\n\n#print(D)\n\nC1=[]\nC2=[]\nC3=[]\nfor i in range(n):\n for j in range(n):\n f=(i+j)%3\n if f==0:\n C1.append(C[i][j])\n if f==1:\n C2.append(C[i][j])\n if f==2:\n C3.append(C[i][j])\n \n\nminiwa=1000*500*500\n\n#print(C3)\niwa1=[]\niwa2=[]\niwa3=[]\n\nfor cc in range(0,c):\n iwa1.append(sum(D[i-1][cc] for i in C1))\n iwa2.append(sum(D[i-1][cc] for i in C2))\n iwa3.append(sum(D[i-1][cc] for i in C3))\n\nfor c1 in range(0,c):\n for c2 in range(0,c):\n for c3 in range(0,c):\n if c1!=c2 and c2!=c3 and c3!=c1 :\n iwa=iwa1[c1]+iwa2[c2]+iwa3[c3]\n miniwa=min(miniwa,iwa)\n\nprint(miniwa)\n']
['Wrong Answer', 'Accepted']
['s113424175', 's657449231']
[8596.0, 7764.0]
[2104.0, 926.0]
[782, 851]
p03330
u338824669
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from collections import defaultdict\n\nN,C=map(int,input().split())\nD=[list(map(int,input().split())) for _ in range(C)]\ngrid=[list(map(int,input().split())) for _ in range(N)]\n\nmod_0=defaultdict(int)\nmod_1=defaultdict(int)\nmod_2=defaultdict(int)\n\nfor i in range(N):\n for j in range(N):\n n=(i+j+2)%3\n if n==0:\n mod_0[grid[i][j]]+=1\n elif n==1:\n mod_1[grid[i][j]]+=1\n else:\n mod_2[grid[i][j]]+=1\n\nans=float("inf")\nfor i in range(C):\n for j in range(C):\n if i==j:\n continue\n for k in range(C):\n if k in [i,j]:\n continue\n\n total\n for prev,cnt in mod_0.items():\n total+=D[prev-1][i]*cnt\n for prev,cnt in mod_1.items():\n total+=D[prev-1][j]*cnt\n for prev,cnt in mod_2.items():\n total+=D[prev-1][k]*cnt\n \n ans=min(ans,total)\nprint(ans)', 'from collections import defaultdict\n\nN,C=map(int,input().split())\nD=[list(map(int,input().split())) for _ in range(C)]\ngrid=[list(map(int,input().split())) for _ in range(N)]\n\nmod_0=defaultdict(int)\nmod_1=defaultdict(int)\nmod_2=defaultdict(int)\n\nfor i in range(N):\n for j in range(N):\n n=(i+j+2)%3\n if n==0:\n mod_0[grid[i][j]]+=1\n elif n==1:\n mod_1[grid[i][j]]+=1\n else:\n mod_2[grid[i][j]]+=1\n\nans=float("inf")\nfor i in range(C):\n for j in range(C):\n if i==j:\n continue\n for k in range(C):\n if k in [i,j]:\n continue\n\n total=0\n for prev,cnt in mod_0.items():\n total+=D[prev-1][i]*cnt\n for prev,cnt in mod_1.items():\n total+=D[prev-1][j]*cnt\n for prev,cnt in mod_2.items():\n total+=D[prev-1][k]*cnt\n \n ans=min(ans,total)\nprint(ans)']
['Runtime Error', 'Accepted']
['s521938583', 's671117707']
[5876.0, 5876.0]
[175.0, 788.0]
[956, 958]
p03330
u423585790
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['#!usr/bin/env python3\nfrom collections import defaultdict\nfrom collections import deque\nfrom heapq import heappush, heappop\nimport sys\nimport math\nimport bisect\nimport random\nimport itertools\nsys.setrecursionlimit(10**5)\nstdin = sys.stdin\ndef LI(): return list(map(int, stdin.readline().split()))\ndef LF(): return list(map(float, stdin.readline().split()))\ndef LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))\ndef II(): return int(stdin.readline())\ndef IF(): return float(stdin.readline())\ndef LS(): return list(map(list, stdin.readline().split()))\ndef S(): return list(stdin.readline().rstrip())\ndef IR(n): return [II() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef FR(n): return [IF() for _ in range(n)]\ndef LFR(n): return [LI() for _ in range(n)]\ndef LIR_(n): return [LI_() for _ in range(n)]\ndef SR(n): return [S() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\nmod = 1000000007\ninf = float("INF")\n\n#A\ndef A():\n return\n\n#B\ndef B():\n return\n\n#C\ndef C():\n n = II()\n dp = [inf for i in range(n + 1)]\n ans = [1]\n x = 6\n while x <= n:\n ans.append(x)\n x = x * 6\n x = 9\n while x <= n:\n ans.append(x)\n x = x * 9\n ans.sort()\n for i in ans:\n dp[i] = 1\n for i in range(1, n + 1):\n if not i in ans:\n a = bisect.bisect_left(ans, i)\n for k in range(a):\n #print(i,ans[k], a)\n dp[i] = min(dp[i - ans[k]] + 1, dp[i])\n print(dp[n])\n\n return\n\n#D\ndef D():\n n, c = LI()\n D = LIR(c)\n C = LIR_(n)\n CL = list(itertools.permutations(range(c), 3))\n ans = inf\n amari0 = [0 for i in range(30)]\n amari1 = amari0[::1]\n amari2 = amari0[::1]\n for y in range(n):\n for x in range(n):\n amari = (x + y) % 3\n if amari == 0:\n amari0[C[y][x]] += 1\n if amari == 1:\n amari1[C[y][x]] += 1\n if amari == 2:\n amari2[C[y][x]] += 1\n for c0, c1, c2 in CL:\n ansb = 0\n for i in range(C):\n ansb += D[i][c0] * amari0[i]\n ansb += D[i][c1] * amari1[i]\n ansb += D[i][c2] * amari2[i]\n ans = min(ans, anb)\n\n \n print(ans)\n\n return\n\n#E\ndef E():\n return\n\n#F\ndef F():\n return\n\n#G\ndef G():\n return\n\n#H\ndef H():\n return\n\n#Solve\nif __name__ == \'__main__\':\n D()\n', '#!usr/bin/env python3\nfrom collections import defaultdict\nfrom collections import deque\nfrom heapq import heappush, heappop\nimport sys\nimport math\nimport bisect\nimport random\nimport itertools\nsys.setrecursionlimit(10**5)\nstdin = sys.stdin\ndef LI(): return list(map(int, stdin.readline().split()))\ndef LF(): return list(map(float, stdin.readline().split()))\ndef LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))\ndef II(): return int(stdin.readline())\ndef IF(): return float(stdin.readline())\ndef LS(): return list(map(list, stdin.readline().split()))\ndef S(): return list(stdin.readline().rstrip())\ndef IR(n): return [II() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef FR(n): return [IF() for _ in range(n)]\ndef LFR(n): return [LI() for _ in range(n)]\ndef LIR_(n): return [LI_() for _ in range(n)]\ndef SR(n): return [S() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\nmod = 1000000007\ninf = float("INF")\n\n#A\ndef A():\n return\n\n#B\ndef B():\n return\n\n#C\ndef C():\n n = II()\n dp = [inf for i in range(n + 1)]\n ans = [1]\n x = 6\n while x <= n:\n ans.append(x)\n x = x * 6\n x = 9\n while x <= n:\n ans.append(x)\n x = x * 9\n ans.sort()\n for i in ans:\n dp[i] = 1\n for i in range(1, n + 1):\n if not i in ans:\n a = bisect.bisect_left(ans, i)\n for k in range(a):\n #print(i,ans[k], a)\n dp[i] = min(dp[i - ans[k]] + 1, dp[i])\n print(dp[n])\n\n return\n\n#D\ndef D():\n n, c = LI()\n D = LIR(c)\n C = LIR_(n)\n CL = list(itertools.permutations(range(c), 3))\n ans = inf\n amari0 = [0 for i in range(30)]\n amari1 = amari0[::1]\n amari2 = amari0[::1]\n for y in range(n):\n for x in range(n):\n amari = (x + y) % 3\n if amari == 0:\n amari0[D[y][x]] += 1\n if amari == 1:\n amari1[D[y][x]] += 1\n if amari == 2:\n amari2[D[y][x]] += 1\n for c0, c1, c2 in CL:\n ansb = 0\n for i in range(C):\n ansb += D[i][c0] * amari0[i]\n ansb += D[i][c1] * amari1[i]\n ansb += D[i][c2] * amari2[i]\n ans = min(ans, anb)\n\n \n print(ans)\n\n return\n\n#E\ndef E():\n return\n\n#F\ndef F():\n return\n\n#G\ndef G():\n return\n\n#H\ndef H():\n return\n\n#Solve\nif __name__ == \'__main__\':\n D()\n\n', '#!usr/bin/env python3\nfrom collections import defaultdict\nfrom collections import deque\nfrom heapq import heappush, heappop\nimport sys\nimport math\nimport bisect\nimport random\nimport itertools\nsys.setrecursionlimit(10**5)\nstdin = sys.stdin\ndef LI(): return list(map(int, stdin.readline().split()))\ndef LF(): return list(map(float, stdin.readline().split()))\ndef LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))\ndef II(): return int(stdin.readline())\ndef IF(): return float(stdin.readline())\ndef LS(): return list(map(list, stdin.readline().split()))\ndef S(): return list(stdin.readline().rstrip())\ndef IR(n): return [II() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef FR(n): return [IF() for _ in range(n)]\ndef LFR(n): return [LI() for _ in range(n)]\ndef LIR_(n): return [LI_() for _ in range(n)]\ndef SR(n): return [S() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\nmod = 1000000007\ninf = float("INF")\n\n#A\ndef A():\n return\n\n#B\ndef B():\n return\n\n#C\ndef C():\n n = II()\n dp = [inf for i in range(n + 1)]\n ans = [1]\n x = 6\n while x <= n:\n ans.append(x)\n x = x * 6\n x = 9\n while x <= n:\n ans.append(x)\n x = x * 9\n ans.sort()\n for i in ans:\n dp[i] = 1\n for i in range(1, n + 1):\n if not i in ans:\n a = bisect.bisect_left(ans, i)\n for k in range(a):\n #print(i,ans[k], a)\n dp[i] = min(dp[i - ans[k]] + 1, dp[i])\n print(dp[n])\n\n return\n\n#D\ndef D():\n n, c = LI()\n D = LIR(c)\n C = LIR_(n)\n CL = list(itertools.permutations(range(c), 3))\n ans = inf\n amari0 = [0 for i in range(30)]\n amari1 = amari0[::1]\n amari2 = amari0[::1]\n for y in range(n):\n for x in range(n):\n amari = (x + y) % 3\n if amari == 0:\n amari0[C[y][x]] += 1\n if amari == 1:\n amari1[C[y][x]] += 1\n if amari == 2:\n amari2[C[y][x]] += 1\n for c0, c1, c2 in CL:\n ansb = 0\n for i in range(c):\n ansb += D[i][c0] * amari0[i]\n ansb += D[i][c1] * amari1[i]\n ansb += D[i][c2] * amari2[i]\n ans = min(ans, ansb)\n\n \n print(ans)\n\n return\n\n#E\ndef E():\n return\n\n#F\ndef F():\n return\n\n#G\ndef G():\n return\n\n#H\ndef H():\n return\n\n#Solve\nif __name__ == \'__main__\':\n D()\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s246699917', 's413178521', 's310819956']
[8416.0, 8416.0, 8416.0]
[171.0, 108.0, 475.0]
[2407, 2408, 2408]
p03330
u466335531
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['N,C=map(int,input().split())\nD=[list(map(int,input().split())) for _ in range(C)]\nG=[list(map(int,input().split())) for _ in range(N)]\n\nminiwa=250000000\nfor c0 in range(1,C+1):\n for c1 in range(1,C+1):\n for c2 in range(1,C+1):\n if (c1-c0)*(c2-c1)*(c0-c2)==0: break\n iwa=0\n for x in range(N):\n for y in range(N):\n if (x+y+2)%3==0: iwa+=D[G[x][y]-1][c0-1]\n elif (x+y+2)%3==1: iwa+=D[G[x][y]-1][c1-1]\n elif (x+y+2)%3==2: iwa+=D[G[x][y]-1][c2-1]\n miniwa=min(miniwa,iwa)\nprint(miniwa)', 'N,C=map(int,input().split())\nD=[list(map(int,input().split())) for _ in range(C)]\nG=[list(map(int,input().split())) for _ in range(N)]\nC0=[0]*(C+1)\nC1=[0]*(C+1)\nC2=[0]*(C+1)\n\nfor x in range(N):\n for y in range(N):\n if (x+y+2)%3==0: C0[G[x][y]]+=1\n elif (x+y+2)%3==1: C1[G[x][y]]+=1\n elif (x+y+2)%3==2: C2[G[x][y]]+=1\n\nminiwa=250000000\nfor c0 in range(1,C+1):\n for c1 in range(1,C+1):\n for c2 in range(1,C+1):\n if (c1-c0)*(c2-c1)*(c0-c2)==0: break\n iwa=0\n for i in range(1,C+1):\n iwa+=(D[i-1][c0-1]*C0[i]+D[i-1][c1-1]*C1[i]+D[i-1][c2-1]*C2[i])\n miniwa=min(miniwa,iwa)\nprint(miniwa)', 'N,C=map(int,input().split())\nD=[list(map(int,input().split())) for _ in range(C)]\nG=[list(map(int,input().split())) for _ in range(N)]\nC0=[0]*(C+1)\nC1=[0]*(C+1)\nC2=[0]*(C+1)\n\nfor x in range(N):\n for y in range(N):\n if (x+y+2)%3==0: C0[G[x][y]]+=1\n elif (x+y+2)%3==1: C1[G[x][y]]+=1\n elif (x+y+2)%3==2: C2[G[x][y]]+=1\n\nminiwa=250000000\nfor c0 in range(1,C+1):\n for c1 in range(1,C+1):\n for c2 in range(1,C+1):\n if (c1-c0)*(c2-c1)*(c0-c2)==0: continue\n iwa=0\n for i in range(1,C+1):\n iwa+=(D[i-1][c0-1]*C0[i]+D[i-1][c1-1]*C1[i]+D[i-1][c2-1]*C2[i])\n miniwa=min(miniwa,iwa)\nprint(miniwa)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s795195305', 's956660012', 's238495618']
[7540.0, 5620.0, 5620.0]
[2104.0, 377.0, 733.0]
[605, 673, 676]
p03330
u497625442
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import functools # Python3 \nN,M = map(int,input().split())\nx, y, z = [0] * N, [0] * N, [0] * N\nfor i in range(N):\n\tx[i], y[i], z[i] = map(int,input().split())\n\nif M==0:\n\tprint(0)\n\texit()\n\nppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])\npmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])\nppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])\npmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])\nmpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])\nmpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])\nmmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])\nmmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])\n\nMAX = 0\nfor lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:\n\tif lis > MAX:\n\t\tMAX = lis\nprint(MAX)\n', 'N,C = map(int,input().split())\nD = []\nfor i in range(C):\n D.append(list(map(int,input().split())))\nc = []\nfor i in range(N):\n c.append(list(map(int,input().split())))\n\nimport itertools\ncurrent_minimum = 1000 * 500 * 500 + 1\nZ = []\nZ.append([0]*C)\nZ.append([0]*C)\nZ.append([0]*C)\n#print(Z)\n\nfor (i,j) in itertools.product(range(N),range(N)):\n\tcur_mod = ((i+1)+(j+1)) % 3\n\tcur_color = c[i][j]\n\t#print(cur_mod)\n\t#print(cur_color)\n\tZ[cur_mod][cur_color-1] += 1\n\ncurrent_minimum = 1000 * 500 * 500 + 1\nfor (c0,c1,c2) in itertools.permutations(range(C), 3):\n\ttmp = 0\n\tcolor = [c0,c1,c2]\n\tfor cur_mod in range(3):\n\t\ttarget_color = color[cur_mod]\n\t\tfor cur_color in range(C):\n\t\t\ttmp += Z[cur_mod][cur_color] * D[cur_color][target_color]\n\tif current_minimum >= tmp:\n\t\tcurrent_minimum = tmp\nprint(current_minimum)\n']
['Runtime Error', 'Accepted']
['s202430453', 's730750257']
[3572.0, 5620.0]
[23.0, 817.0]
[995, 810]
p03330
u543954314
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from collections import defaultdict\ntot = 10**12\nn,c = map(int, input().split())\nd = [list(map(int, input().split())) for _ in range(n)]\nclr = [list(map(int, input().split())) for _ in range(n)]\nl = [dict()]*3\nfor y in range(n):\n for x in range(n):\n l[(x+y)%3][clr[y][x]] += 1\nfor c1 in range(c):\n for c2 in range(c):\n if c1 == c2:\n continue\n for c3 in range(c):\n if c1==c3 or c2==c3:\n continue\n ctot = 0\n cl = [c1,c2,c3]\n for i in range(3):\n for x in l[i]:\n ctot += d[x-1][c[i]]*l[i][x]\n if tot > ctot:\n tot = ctot\nprint(tot)\n ', 'from collections import defaultdict as ddict\ntot = 10**12\nn,c = map(int, input().split())\nd = [list(map(int, input().split())) for _ in range(c)]\nclr = [list(map(int, input().split())) for _ in range(n)]\nl = [ddict(int) for _ in range(3)]\nfor y in range(n):\n for x in range(n):\n l[(x+y)%3][clr[y][x]] += 1\nfor c1 in range(c):\n for c2 in range(c):\n if c1 == c2:\n continue\n for c3 in range(c):\n if c1==c3 or c2==c3:\n continue\n ctot = 0\n cl = [c1,c2,c3]\n for i in range(3):\n for x in l[i]:\n ctot += d[x-1][cl[i]]*l[i][x]\n if tot > ctot:\n tot = ctot\nprint(tot)']
['Runtime Error', 'Accepted']
['s661441681', 's556655360']
[5876.0, 5876.0]
[67.0, 924.0]
[604, 627]
p03330
u585742242
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['# -*- coding: utf-8 -*-\nfrom itertools import permutations\nN, C = map(int, input().split())\nD = [int(_) for c in range(C) for _ in input().split()]\n\ntable = [0] * C * 3\nfor i, g in enumerate([int(_) for n in range(N) for _ in input().split()]):\n for c in range(C):\n table[i % 3 * C + c] += D[C * (g - 1) + c]\n\n\ndef cost(comb):\n return table[C * 0 + comb[0]] + table[C * 1 + comb[1]] + table[C * 2\n + comb[2]]\n\n\ncombs = permutations(range(C), 3)\nmin_cst = cost(min(combs, key=lambda comb: cost(comb)))\nprint(min_cst)\n', '# -*- coding: utf-8 -*-\nfrom itertools import permutations\nN, C = map(int, input().split())\nD = [int(_) for c in range(C) for _ in input().split()]\nG = [int(_) for n in range(N) for _ in input().split()]\n\ntable = [0] * C * 3\nfor i in range(N * N):\n for c in range(C):\n table[i % 3 * C + c] += D[C * (G[i] - 1) + c]\n\n\ndef cost(comb):\n return table[C * 0 + comb[0]] + table[C * 1 + comb[1]] + table[C * 2\n + comb[2]]\n\n\ncombs = permutations(range(C), 3)\nmin_cst = cost(min(combs, key=lambda comb: cost(comb)))\nprint(min_cst)\n', "# -*- coding: utf-8 -*-\n# import functools\n\n# @functools.lru_cache(maxsize=None)\n\n# cost = 0\n# for row in range(N):\n# for col in range(N):\n# if (row + col) % 3 == i:\n# cost += D[G[row][col] - 1][c - 1]\n\n# return cost\n\n\n# cost = 0\n# for i, c in enumerate(comb):\n# cost += paint(i, c)\n\n# return cost\n\n\ndef cost(comb):\n cost = 0\n for r in range(N):\n for c in range(N):\n if (r + c) % 3 == 0:\n cost += D[G[r][c] - 1][comb[0]]\n elif (r + c) % 3 == 1:\n cost += D[G[r][c] - 1][comb[1]]\n else:\n cost += D[G[r][c] - 1][comb[2]]\n\n\nif __name__ == '__main__':\n from itertools import permutations\n N, C = map(int, input().split())\n D = [[int(_) for _ in input().split()] for i in range(C)]\n G = [[int(_) for _ in input().split()] for i in range(N)]\n combs = permutations(range(1, C + 1), 3)\n min_cost = min([cost(comb) for comb in combs])\n print(min_cost)\n", '# -*- coding: utf-8 -*-\nN, C = map(int, input().split())\n\nD = []\nfor c in range(C):\n D.append([int(d) for d in input().split()])\n\nGmod = [[0 for i in range(C)] for i in range(3)]\nfor n in range(N):\n for m, g in enumerate(input().split()):\n Gmod[(n + m) % 3][int(g) - 1] += 1\n\nK = []\nfor c0 in range(C):\n d0 = sum([Gmod[0][c] * D[c][c0] for c in range(C)])\n for c1 in [i for i in range(C) if not i == c0]:\n d1 = sum([Gmod[1][c] * D[c][c1] for c in range(C)])\n for c2 in [i for i in range(C) if (not i == c0) and (not i == c1)]:\n d2 = sum([Gmod[2][c] * D[c][c2] for c in range(C)])\n K.append(d0 + d1 + d2)\n\nprint(min(K))\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s269983280', 's366864194', 's725086239', 's438566128']
[5188.0, 5188.0, 5492.0, 4076.0]
[2104.0, 2104.0, 2104.0, 293.0]
[595, 601, 1072, 674]
p03330
u594859393
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from itertools import product\nfrom collections import Counter\n \nn, c = map(int, input().split())\ncolor_costs = [list(map(int, input().split())) for _ in range(c)]\nmatrix = [list(map(int, input().split())) for _ in range(n)]\n \ncolord = {(i, j):cost for i, row in enumerate(color_costs)\n for j, cost in enumerate(row)}\n \nres = []\nfor n in range(3):\n color_count = Counter(c-1 for i, row in enumerate(matrix) \n for j, c in enumerate(row) \n if (i + j) % 3 == n)\n def color_cost(color):\n return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items())\n cx = [(color, color_cost(color)) for color in range(c)]\n sorted_by_cost = sorted(cx, key=lambda x:x[1])\n cheapest3 = sorted_by_cost[:3]\n res.append(cheapest3)\n \ncolor_pickss = product(*res)\nfiltered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3)\ncosts = (sum(x[1] for x in picks) for pick in filtered_unique)\nprint(min(costs))\nfrom itertools import product\nfrom collections import Counter\n \nn, c = map(int, input().split())\ncolor_costs = [list(map(int, input().split())) for _ in range(c)]\nmatrix = [list(map(int, input().split())) for _ in range(n)]\n\ncolord = {(i, j):cost for i, row in enumerate(color_costs)\n for j, cost in enumerate(row)}\n \nres = []\nfor n in range(3):\n color_count = Counter(c-1 for i, row in enumerate(matrix) \n for j, c in enumerate(row) \n if (i + j) % 3 == n)\n def color_cost(color):\n return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items())\n cx = [(color, color_cost(color)) for color in range(c)]\n sorted_by_cost = sorted(cx, key=lambda x:x[1])\n cheapest3 = sorted_by_cost[:3]\n res.append(cheapest3)\n\ncolor_pickss = product(*res)\nfiltered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3)\ncosts = (sum(x[1] for x in picks) for picks in filtered_unique)\nprint(min(costs))', 'from itertools import product\nfrom collections import Counter\n \nn, c = map(int, input().split())\ncolor_costs = [list(map(int, input().split())) for _ in range(c)]\nmatrix = [list(map(int, input().split())) for _ in range(n)]\n\ncolord = {(i, j):cost for i, row in enumerate(color_costs)\n for j, cost in enumerate(row)}\n \nres = []\nfor n in range(3):\n color_count = Counter(c-1 for i, row in enumerate(matrix) \n for j, c in enumerate(row) \n if (i + j) % 3 == n)\n def color_cost(color):\n return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items())\n cx = [(color, color_cost(color)) for color in range(c)]\n sorted_by_cost = sorted(cx, key=lambda x:x[1])\n cheapest3 = sorted_by_cost[:3]\n res.append(cheapest3)\n\ncolor_pickss = product(*res)\nfiltered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3)\ncosts = (sum(x[1] for x in picks) for pick in filtered_unique)\nprint(min(costs))', 'from itertools import product\nfrom collections import Counter\n \nn, c = map(int, input().split())\ncolor_costs = [list(map(int, input().split())) for _ in range(c)]\nmatrix = [list(map(int, input().split())) for _ in range(n)]\n\ncolord = {(i, j):cost for i, row in enumerate(color_costs)\n for j, cost in enumerate(row)}\n \nres = []\nfor n in range(3):\n color_count = Counter(c-1 for i, row in enumerate(matrix) \n for j, c in enumerate(row) \n if (i + j) % 3 == n)\n def color_cost(color):\n return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items())\n cx = [(color, color_cost(color)) for color in range(c)]\n sorted_by_cost = sorted(cx, key=lambda x:x[1])\n cheapest3 = sorted_by_cost[:3]\n res.append(cheapest3)\n\ncolor_pickss = product(*res)\nfiltered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3)\ncosts = (sum(x[1] for x in picks) for picks in filtered_unique)\nprint(min(costs))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s252378783', 's929233980', 's569888086']
[6112.0, 5996.0, 5996.0]
[195.0, 195.0, 202.0]
[2026, 1011, 1012]
p03330
u631277801
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['def main():\n# N, C = 2, 3\n# D = [[0, 1, 1],\n# [1, 0, 1],\n# [1, 4, 0]]\n# c_init = [[1, 2],\n# [3, 3]]\n \n# N, C = 4, 3\n# D = [[0, 12, 71],\n# [81, 0, 53],\n# [14, 92, 0]]\n# c_init = [[1, 1, 2, 1],\n# [2, 1, 1, 2],\n# [2, 2, 1, 3],\n# [1, 1, 2, 2]]\n \n N, C = map(int, input().split())\n D = []\n for i in range(C):\n D.append(list(map(int, input().split())))\n \n c_init = []\n for i in range(N):\n c_init.append(list(map(int,input().split())))\n \n group0 = [0]*C\n group1 = [0]*C\n group2 = [0]*C\n \n \n \n for i in range(N):\n for j in range(N):\n if (i+j+2)%3==0:\n group0[c_init[i][j] - 1] += 1\n elif (i+j+2)%3 == 1:\n group1[c_init[i][j] - 1] += 1\n else:\n group2[c_init[i][j] - 1] += 1\n \n print(group0)\n print(group1)\n print(group2)\n \n \n iwakan =[]\n for color0 in range(C):\n for color1 in range(C):\n if color1 == color0:\n continue\n \n for color2 in range(C):\n if color2==color0 or color2==color1:\n continue\n \n iwakan_temp = 0\n for colorN in range(C):\n iwakan_temp += group0[colorN]*D[colorN][color0]\n iwakan_temp += group1[colorN]*D[colorN][color1]\n iwakan_temp += group2[colorN]*D[colorN][color2]\n \n iwakan.append(iwakan_temp)\n \n print(min(iwakan))\n \nif __name__ == "__main__":\n main()', "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\nn,c = li()\nd = [list(li()) for _ in range(c)]\ninitial = [list(li_()) for _ in range(n)] \n\nmod_col = [[0]*c for _ in range(3)]\n\nfor i,initi in enumerate(initial):\n for j, initij in enumerate(initi):\n mod_col[(i+j) % 3][initij] += 1\n \nans = float('inf')\ncolors = [-1]*3\nfor c0 in range(c):\n for c1 in range(c):\n for c2 in range(c):\n if c0 == c1 or c1 == c2 or c2 == c0:\n continue\n \n colors = [c0, c1, c2]\n \n tmp = 0\n for modnum in range(3):\n tmp += sum([d[color][colors[modnum]] * mod_col[modnum][color] for color in range(c)])\n \n ans = min(ans, tmp)\n\n\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s060662914', 's492319081']
[6688.0, 5620.0]
[444.0, 693.0]
[1802, 1141]
p03330
u667469290
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import numpy as np\nN, C = map(int, input().split())\nD = np.array(list(map(int, input().split())), dtype=int)\nfor i in range(C-1):\n D = np.vstack((D, np.array(list(map(int, input().split())), dtype=int)))\nZ = np.array(list(map(int, input().split())), dtype=int)\nfor i in range(N-1):\n Z = np.vstack((Z, np.array(list(map(int, input().split())), dtype=int)))\nnum = np.zeros((3,C), dtype=int)\nfor i in range(3):\n X = np.array([[(x+y+2)%3==i for y in range(N)] for x in range(N)])\n for c in range(C):\n Y = (Z*X)==c+1\n num[i,c] = Y.sum()\ncosts = np.dot(num, D.T)\nmincost = 10**10\nfor c0 in range(C):\n for c1 in range(C):\n if c1 ==c0:\n continue\n for c2 in range(C):\n if c2 == c1:\n continue\n cost = costs[0,c0]+costs[1,c1]+costs[2,c2]\n mincost = min(mincost, cost)\nprint(mincost)', 'import numpy as np\nN, C = map(int, input().split())\nD = np.array(map(int, input().split()), dtype=int)\nfor i in range(C-1):\n D = np.vstack((D, np.array(map(int, input().split()), dtype=int)))\nZ = np.array(map(int, input().split()), dtype=int)\nfor i in range(N-1):\n Z = np.vstack((c, np.array(map(int, input().split()), dtype=int)))\nnum = np.zeros(size=(3,C), dtype=int)\nfor i in range(3):\n X = np.array([[(x+y+2)%3==i for y in range(N)] for x in range(N)])\n for c in range(C):\n Y = (Z*X)==c+1\n num[i,c] = Y.sum()\ncosts = np.matmul(num, D)\nmincost = 10**10\nfor c0 in range(C):\n for c1 in range(C):\n if c1 ==c0:\n continue\n for c2 in range(C):\n if c2 == c1:\n continue\n cost = costs[0,c0]+costs[1,c1]+costs[2,c2]\n mincost = min(mincost, cost)\nprint(mincost)', 'import numpy as np\nN, C = map(int, input().split())\nD = np.array(list(map(int, input().split())), dtype=int)\nfor i in range(C-1):\n D = np.vstack((D, np.array(list(map(int, input().split())), dtype=int)))\nZ = np.array(list(map(int, input().split())), dtype=int)\nfor i in range(N-1):\n Z = np.vstack((Z, np.array(list(map(int, input().split())), dtype=int)))\nnum = np.zeros((3,C), dtype=int)\nfor i in range(3):\n X = np.array([[(x+y+2)%3==i for y in range(N)] for x in range(N)])\n for c in range(C):\n Y = ((Z*X)==(c+1))\n num[i,c] = Y.sum()\ncosts = np.dot(num, D)\nmincost = 10**10\nfor c0 in range(C):\n for c1 in range(C):\n if c1 ==c0:\n continue\n for c2 in range(C):\n if c2 == c0 or c2 == c1:\n continue\n cost = costs[0,c0]+costs[1,c1]+costs[2,c2]\n mincost = min(mincost, cost)\nprint(mincost)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s138925849', 's885269870', 's002492551']
[19364.0, 12440.0, 19384.0]
[681.0, 149.0, 687.0]
[873, 855, 887]
p03330
u729133443
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['n,c=map(int,input().split())\nd=[list(map(int,input().split()))for _ in range(c)]\nl=[[i for i in[0]*c]for _ in range(3)]\nfor i in range(n):\n t=list(map(int,input().split()))\n for j in range(n):\n l[(i+j)%3][t[j]-1]+=1\nc=10**18\nfor i in range(c):\n for j in range(c):\n for k in range(c):\n if i==j or j==k or k==i:continue\n c=min(c,sum(d[x][i]*l[0][x]+d[x][j]*l[1][x]+d[x][k]*l[2][x]for x in range(c)))\nprint(c)', 'n,c=map(int,input().split());d=[list(map(int,input().split()))for _ in range(c)];l=[[i for i in[0]*c]for _ in range(3)]\nfor i in range(n):\n for j,t in zip(range(n),map(int,input().split())):l[(i+j)%3][t-1]+=1\nprint(min([[sum(d[x][i]*l[0][x]+d[x][j]*l[1][x]+d[x][k]*l[2][x]for x in range(c))for k in range(c)if i!=j and j!=k and k!=i]for j in range(c)]for i in range(c)))', 'n,c=map(int,input().split())\nd=[list(map(int,input().split()))for _ in range(c)]\nl=[[i for i in[0]*c]for _ in range(3)]\nfor i in range(n):\n t=list(map(int,input().split()))\n for j in range(n):\n l[(i+j)%3][t[j]-1]+=1\na=10**18\nfor i in range(c):\n for j in range(c):\n for k in range(c):\n if i==j or j==k or k==i:continue\n a=min(a,sum(d[x][i]*l[0][x]+d[x][j]*l[1][x]+d[x][k]*l[2][x]for x in range(c)))\nprint(a)']
['Time Limit Exceeded', 'Wrong Answer', 'Accepted']
['s690458627', 's725057903', 's478320691']
[3064.0, 3064.0, 3064.0]
[2108.0, 480.0, 496.0]
[425, 371, 425]
p03330
u741397536
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['N, C = map(int, input().split())\nD = []\nfor i in range(C):\n D.append(list(map(int, input().split())))\n\nc_arr = []\nfor i in range(N):\n c_arr.append(list(map(int, input().split())))\n\n\nc_arr1 = []\nc_arr2 = []\nc_arr3 = []\n\nfor i in range(N):\n for j in range(N):\n if (i+j)%3 == 0: \n c_arr1.append(c_arr[i][j])\n if (i+j)%3 == 1: \n c_arr2.append(c_arr[i][j])\n if (i+j)%3 == 2: \n c_arr3.append(c_arr[i][j])\n\ntmp = 1000*500*500\n\ndef cost(arr, aft):\n sum = 0\n for i in range(len(arr)):\n sum += D[arr[i]-1][aft]\n return sum\n\nans_arr = []\n\nfor l in range(C):\n for m in range(C):\n if l == m:\n pass\n else:\n for n in range(C):\n if l == n or m == n:\n pass\n else:\n print(l,m,n)\n ans_arr.append(cost(c_arr1, l) + cost(c_arr2, m) + cost(c_arr3, n))\n\nprint(min(ans_arr))', 'N, C = map(int, input().split())\nD = []\nfor i in range(C):\n D.append(list(map(int, input().split())))\n\nc_arr = []\nfor i in range(N):\n c_arr.append(list(map(int, input().split())))\n\n\nc_arr1 = []\nc_arr2 = []\nc_arr3 = []\n\nfor i in range(N):\n for j in range(N):\n if (i+j)%3 == 0: \n c_arr1.append(c_arr[i][j])\n if (i+j)%3 == 1: \n c_arr2.append(c_arr[i][j])\n if (i+j)%3 == 2: \n c_arr3.append(c_arr[i][j])\n\ntmp = 1000*500*500\n\ndef cost(arr, aft):\n sum = 0\n for i in range(len(arr)):\n sum += D[arr[i]-1][aft]\n return sum\n\nans_arr1 = []\nans_arr2 = []\nans_arr3 = []\n\nfor l in range(C):\n ans_arr1.append(cost(c_arr1, l))\nfor l in range(C):\n ans_arr2.append(cost(c_arr2, l))\nfor l in range(C):\n ans_arr3.append(cost(c_arr3, l))\n\n\nans_arr = []\nfor l in range(C):\n for m in range(C):\n for n in range(C):\n if l == n or n == m or m == l:\n pass\n else:\n ans_arr.append(ans_arr1[l]+ans_arr2[m]+ans_arr3[n])\n\nprint(min(ans_arr))']
['Wrong Answer', 'Accepted']
['s485038009', 's420250397']
[7692.0, 8664.0]
[2105.0, 1075.0]
[955, 1058]
p03330
u768896740
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import numpy as np\n\n\nn, c = map(int, input().split())\n\na = []\nb = []\n\nfor _ in range(c):\n array = list(map(int, input().split()))\n a.append(array)\n\nfor _ in range(n):\n array = list(map(int, input().split()))\n b.append(array)\n\nd = np.array(b)\nd = d.flatten()\n\nd1 = d[0::3]\nd2 = d[1::3]\nd3 = d[2::3]\n\nans_1 = []\nans_2 = []\nans_3 = []\n\nfor i in range(c):\n sum = 0\n for j in d1:\n sum += a[j-1][i]\n ans_1.append(sum)\n\nfor i in range(c):\n sum = 0\n for j in d2:\n sum += a[j-1][i]\n ans_2.append(sum)\n\nfor i in range(c):\n sum = 0\n for j in d3:\n sum += a[j-1][i]\n ans_3.append(sum)\n\nmin_ans = 10**10\n\nimport itertools\n\nr = list(range(c))\n\nfor i, j, k in itertools.permutations(r, 3):\n ans = ans_1[i] + ans_2[j] + ans_3[k]\n if ans < min_ans:\n min_ans = ans\n\n\nprint(min_ans)\n', 'from collections import Counter\nfrom itertools import permutations\n\nn, c = map(int, input().split())\n\na = []\nb = []\n\nfor _ in range(c):\n array = list(map(int, input().split()))\n a.append(array)\n\nfor _ in range(n):\n array = list(map(int, input().split()))\n b.append(array)\n\n\ngroup1 = []\ngroup2 = []\ngroup3 = []\n\nfor i in range(n):\n for j in range(n):\n if (i + j) % 3 == 0:\n group1.append(b[i][j])\n elif (i + j) % 3 == 1:\n group2.append(b[i][j])\n else:\n group3.append(b[i][j])\n\ng1 = Counter(group1)\ng2 = Counter(group2)\ng3 = Counter(group3)\n\nsum1 = []\nsum2 = []\nsum3 = []\n\n\ndef cal(l, output):\n for i in range(c):\n s = 0\n for j in l.items():\n s += a[j[0]-1][i-1] * j[1]\n output.append(s)\n\n\nli = [g1, g2, g3]\nli2 = [sum1, sum2, sum3]\n\nfor i in range(3):\n cal(li[i], li2[i])\n\ncc = list(range(c))\n\nmin_sum = 10**10\nfor i, j, k in permutations(cc, 3):\n sum = sum1[i] + sum2[j] + sum3[k]\n if sum < min_sum:\n min_sum = sum\n\nprint(min_sum)']
['Wrong Answer', 'Accepted']
['s182157568', 's824298082']
[18892.0, 7920.0]
[2109.0, 204.0]
[836, 1050]
p03330
u782098901
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['import itertools\nimport sys\ninput = sys.stdin.readline()\n\n\ndef main():\n N, C = map(int, input().split())\n D = [list(map(int, input().split())) for _ in range(C)]\n CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]\n\n cost = [[0 for _ in range(C)] for _ in range(3)]\n for c in range(C):\n for i in range(N):\n for j in range(N):\n cost[(i + j) % 3][c] += D[CC[i][j]][c]\n\n res = float("inf")\n color = [i for i in range(C)]\n for i, c in enumerate(list(itertools.permutations(color, 3))):\n tmp = 0\n for it in range(3):\n tmp += cost[it][c[it]]\n res = min(res, tmp)\n\n print(res)\n\nmain()', 'import itertools\nimport sys\ninput = sys.input.readline()\n\n\ndef main():\n N, C = map(int, input().split())\n D = [list(map(int, input().split())) for _ in range(C)]\n CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]\n\n cost = [[0 for _ in range(C)] for _ in range(3)]\n for c in range(C):\n for i in range(N):\n for j in range(N):\n cost[(i + j) % 3][c] += D[CC[i][j]][c]\n\n res = float("inf")\n color = [i for i in range(C)]\n for i, c in enumerate(list(itertools.permutations(color, 3))):\n tmp = 0\n for it in range(3):\n tmp += cost[it][c[it]]\n res = min(res, tmp)\n\n print(res)\n\nmain()\n', 'from itertools import product, permutations\n\nN, C = map(int, input().split())\nD = [list(map(int, input().split())) for _ in range(C)]\ngrid = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]\n\ncost = [[0] * C for _ in range(3)]\n\nfor x, y in product(range(N), range(N)):\n cost[(x + y) % 3][grid[x][y]] += 1\n\nminn = float("inf")\nfor colors in permutations(range(C), 3):\n t = 0\n for s, color_n in enumerate(colors):\n for color_p, n in enumerate(cost[s]):\n t += n * D[color_p][color_n]\n minn = min(minn, t)\nprint(minn)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s182806797', 's496074995', 's081460883']
[3064.0, 3064.0, 5620.0]
[18.0, 18.0, 738.0]
[691, 692, 563]
p03330
u803848678
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['from itertools import permutations\n\nn, c = map(int, input().split())\nchange_cost = [list(map(int, input().split())) for i in range(c)]\n\niwakan = {}\nfor i in range(3):\n iwakan[i] = [0]*c\n\nfor i in range(n):\n for j, color in enumerate(list(map(int, input().split()))):\n print(i,j, color)\n for k in range(c):\n iwakan[(i+j)%3][k] += change_cost[color-1][k]\n\nans = float("inf")\nfor p in permutations(range(c), 3):\n cost = 0\n for i, color in enumerate(p):\n cost += iwakan[i][color]\n ans = min(ans, cost)\nprint(ans)', 'import numpy as np\nfrom itertools import permutations\n\nn, c = map(int, input().split())\nchange_cost = [np.array(list(map(int, input().split()))) for i in range(c)]\n\niwakan = {}\nfor i in range(3):\n iwakan[i] = np.zeros(c)\n\nfor i in range(n):\n for j, color in enumerate(list(map(int, input().split()))):\n iwakan[(i+j)%3] += change_cost[color-1]\n\nans = float("inf")\nfor p in permutations(range(c), 3):\n cost = 0\n for i, color in enumerate(p):\n cost += iwakan[i][color]\n ans = min(ans, cost)\nprint(int(ans))']
['Wrong Answer', 'Accepted']
['s082630012', 's094241166']
[5404.0, 12448.0]
[2104.0, 892.0]
[555, 532]
p03330
u983918956
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
["import itertools\nN,C = map(int,input().split())\nD = [list(map(int,input().split())) for i in range(C)]\ngrid = [list(map(int,input().split())) for i in range(N)]\ncolor = list(range(1,C+1))\nans = float('inf')\nfor x,y,z in itertools.permutations(color,3):\n print(x,y,z)\n res = 0\n for i in range(1,N+1):\n for j in range(1,N+1):\n if (i+j) % 3 == 0:\n res += D[grid[i-1][j-1]-1][x-1]\n elif (i+j) % 3 == 1:\n res += D[grid[i-1][j-1]-1][y-1]\n elif (i+j) % 3 == 2:\n res += D[grid[i-1][j-1]-1][z-1]\n if res < ans:\n ans = res\nprint(ans)", "import itertools\nN,C = map(int,input().split())\nD = [list(map(int,input().split())) for i in range(C)]\ngrid = [list(map(int,input().split())) for i in range(N)]\nl1 = [0]*C\nl2 = [0]*C\nl3 = [0]*C\nfor i in range(1,N+1):\n for j in range(1,N+1):\n if (i+j) % 3 == 0:\n l1[grid[i-1][j-1]-1] += 1\n elif (i+j) % 3 == 1:\n l2[grid[i-1][j-1]-1] += 1\n elif (i+j) % 3 == 2:\n l3[grid[i-1][j-1]-1] += 1\ncolor = list(range(1,C+1))\nans = float('inf')\nfor x,y,z in itertools.permutations(color,3):\n res = 0\n for i in range(C):\n res += D[i][x-1]*l1[i]\n for i in range(C):\n res += D[i][y-1]*l2[i]\n for i in range(C):\n res += D[i][z-1]*l3[i]\n if res < ans:\n ans = res\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s801384537', 's598045680']
[5620.0, 5620.0]
[2104.0, 799.0]
[627, 755]
p03330
u995062424
2,000
262,144
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}. We say the grid is a _good_ grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N: * If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. * If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y. We will repaint zero or more squares so that the grid will be a good grid. For a square, the _wrongness_ when the color of the square is X before repainting and Y after repainting, is D_{X,Y}. Find the minimum possible sum of the wrongness of all the squares.
['def main():\n N, Ma, Mb = map(int, input().split())\n yakuhin = []\n sa = 0\n sb = 0\n for i in range(N):\n yakuhin.append(list(map(int, input().split())))\n sa += yakuhin[i][0]\n sb += yakuhin[i][1]\n \n INF = 10**15\n DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]\n \n for i in range(N):\n DP[i][0][0] = 0\n \n for i in range(N):\n for j in range(sa+1):\n for k in range(sb+1):\n if(j >= yakuhin[i][0] and k >= yakuhin[i][1]):\n DP[i+1][j][k] = min(DP[i][j][k], DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]]+yakuhin[i][2])\n else:\n DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])\n \n ans = INF\n for i in range(1, N):\n for j in range(1, sa+1):\n for k in range(1, sb+1):\n if(j*Mb == k*Ma):\n ans = min(ans, DP[i][j][k]) \n \n print(ans if ans != INF else -1)\n \nmain()', 'N, C = map(int, input().split())\n\nD = []\nfor i in range(C):\n D.append(list(map(int, input().split())))\n\ncc = [[0]*C for i in range(3)]\nfor i in range(N):\n color = list(map(int, input().split()))\n for j in range(len(color)):\n cc[(i+j)%3][color[j]-1] += 1\n \niwakan = [[[0, 0] for _ in range(C)] for _ in range(3)]\n\nfor i in range(3):\n for j in range(C):\n tmp = 0\n for k in range(len(cc[i])):\n tmp += cc[i][k]*D[k][j]\n iwakan[i][j][0] = tmp\n iwakan[i][j][1] = j\n\nans = 10**15\nfor i in range(len(iwakan)):\n iwakan[i] = sorted(iwakan[i], key=lambda x:x[0])\n \nfor i in range(3):\n for j in range(3):\n if(iwakan[0][i][1] == iwakan[1][j][1]):\n continue\n for k in range(3):\n if(iwakan[0][i][1] == iwakan[2][k][1]):\n continue\n if(iwakan[1][j][1] == iwakan[2][k][1]):\n continue\n ans = min(ans, iwakan[0][i][0]+iwakan[1][j][0]+iwakan[2][k][0])\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s495972234', 's665907670']
[3064.0, 3188.0]
[19.0, 140.0]
[998, 1012]
p03331
u013408661
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\ndef num(x):\n rec=0\n while x>0:\n rec+=x%10\n rec//=10\nans=10**18\nfor i in range(1,n//2):\n ans=min(ans,num(i)+num(n-i))\nprint(ans)', 'n=int(input())\ndef num(x):\n rec=0\n while x>0:\n rec+=x%10\n rec//=10\n return rec\nans=10**18\nfor i in range(1,n//2):\n ans=min(ans,num(i)+num(n-i))\nprint(ans)', 'n=int(input())\ndef num(x):\n rec=0\n while x>0:\n rec+=x%10\n x//=10\n return rec\nans=10**18\nfor i in range(1,(n+3)//2):\n ans=min(ans,num(i)+num(n-i))\nprint(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s316548584', 's850237487', 's233338735']
[2940.0, 2940.0, 3316.0]
[2107.0, 2104.0, 110.0]
[151, 164, 167]
p03331
u018679195
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['def soma(a):\n res=0\n if(int(a)<10):\n return int(a)\n \n for i in range(0, len(a)-1):\n res+=int(a[i])\n\n if(res>=10):\n return soma(str(res))\n\n return res\n\ndef main():\n n = int(input())\n menor = soma(str(n-1))+1\n \n for i in range(1,10):\n if(soma(str(i))+soma(str(n-i))<menor):\n menor = soma(str(i))+soma(str(n-i))\n\n print(menor,"\\n")\n\nmain()\n', 'def soma(a):\n res=0\n for i in range(0, len(a)):\n res+=int(a[i])\n\n if(res>=10):\n return soma(str(res))\n\n return res\n\ndef main():\n n = int(input())\n menor = soma("1")+soma(str(n-1))\n \n for i in range(1,10):\n if(soma(str(i))+soma(str(n-i))<menor):\n menor = soma(str(i))+soma(str(n-i))\n\n print(menor,"\\n")\n \nmain()\n', 'def main():\n n = int(input())\n a = n - 1\n b = 1\n menor = soma_digitos(a) + soma_digitos(b)\n temp = 0\n for i in range(n-2):\n a -= 1\n b += 1\n temp = soma_digitos(a) + soma_digitos(b)\n if menor > temp:\n menor = temp\n print(menor)\n\ndef soma_digitos(n):\n soma = 0\n while n >= 1:\n soma += n%10\n n = n//10\n return soma\nmain()']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s761026915', 's880196401', 's922422316']
[3064.0, 3064.0, 3060.0]
[17.0, 17.0, 174.0]
[413, 373, 401]
p03331
u019584841
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\na = 0\nfor i in range(len(n)):\n a += n[i]\nif a == 1:\n print(10)\nelse:\n print(a)', 'n = input()\na = 0\nfor i in range(len(n)):\n a += int(n[i])\nif a == 1:\n print(10)\nelse:\n print(a)\n']
['Runtime Error', 'Accepted']
['s591776764', 's015694219']
[2940.0, 2940.0]
[17.0, 17.0]
[104, 105]
p03331
u044026875
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N=int(input())\nif N%10==0:\n print(10)\nelse:\n ans = 0\n for i in range(len(N)):\n ans+= int(N[i])\n print(ans)', 'N=int(input())\nans=[]\n\nif N%10==0:\n print(10)\nelse:\n for i in range(1,N+1):\n ls=list(map(int,list(str(i))))\n x=sum(ls)\n lst=list(map(int,list(str(N-i))))\n y=sum(lst)\n ans.append(x+y)\n print(min(ans))', 'N=input()\nif int(N)%10==0:\n print(10)\nelse:\n ans = 0\n for i in range(len(N)):\n ans+= int(N[i])\n print(ans)\n', 'N=int(input())\nans=[]\n\nif N%10==0:\n print(10)\nelse:\n ans = 0\n for i in range(len(N)):\n ans+= int(N[i])\n print(ans)\n', 'N=input()\nif int(N)%10==0:\n print(10)\nelse:\n ans = 0\n for i in range(len(N)):\n ans+= int(N[i])\n print(ans)\n']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s561498513', 's687114764', 's727864056', 's745068261', 's773357435']
[2940.0, 3784.0, 2940.0, 2940.0, 2940.0]
[17.0, 2104.0, 17.0, 18.0, 17.0]
[129, 247, 130, 138, 126]
p03331
u066455063
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nans = float("inf")\n\nA = 0\nB = N\nfor i in range(N//2):\n\n A += 1\n B -= 1\n\n if A + B > N:\n break\n\n else:\n\n s_a = str(A)\n s_b = list(str(B))\n\n a = [int(i) for i in s_a]\n b = [int(i) for i in s_b]\n\n ans = min(ans, sum(a)+sum(b)\n\nprint(ans)\n', 'N = int(input())\n\nans = float("inf")\n\nA = 0\nB = N\nfor i in range(N//2):\n\n A += 1\n B -= 1\n\n if A + B > N:\n break\n\n else:\n\n s_a = str(A)\n s_b = list(str(B))\n\n a = [int(i) for i in s_a]\n b = [int(i) for i in s_b]\n\n ans = min(ans, sum(a)+sum(BytesWarning))\n\nprint(ans)\n', 'N = int(input())\n\nans = float("inf")\n\nA = 0\nB = N\nfor i in range(N//2):\n\n A += 1\n B -= 1\n\n if A + B > N:\n break\n\n else:\n\n s_a = str(A)\n s_b = list(str(B))\n\n a = [int(i) for i in s_a]\n b = [int(i) for i in s_b]\n\n ans = min(ans, sum(a)+sum(b))\n\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s330206788', 's993158931', 's974355759']
[2940.0, 3060.0, 3060.0]
[17.0, 17.0, 238.0]
[307, 319, 308]
p03331
u089230684
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['A = int(input())\ns=0\nwhile (A > 0):\n\n r = A % 10\n A= (A - r) / 10\n s = s+r\nprint(s)\n', 'def soma(n):\n x = sum(int(digit) for digit in str(n))\n if x < 10:\n return x\n else:\n return soma(x)\n\ndef main():\n n = int(input())\n\n somad = soma(n) \n\n n-=n%10\n \n while(n>=1):\n somaf=soma(n-1)+1\n \n if(somaf>somad):\n somad=somaf\n \n n=n//10\n \n print(somad,"\\n")\n \nmain()\n', 'n = input()\n\npowers10 = [10**i for i in range(1, 6)]\nprint(10 if int(n) in powers10 else sum(int(d) for d in n))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s146386959', 's260818974', 's751036264']
[2940.0, 3060.0, 2940.0]
[17.0, 17.0, 17.0]
[94, 381, 113]
p03331
u103341055
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nn = 1\nans = 10**5\n\ndef calucurate(M):\n n = 0\n while M > 0:\n n += M%10\n M //= 10\n return n\n\nwhile n < N:\n t = N - n\n m = calucurate(t) + calucurate(n)\n ans = min(ans,m)\n n += 1', 'N = int(input())\n\nn = 1\nans = 10**5\n\ndef calucurate(M):\n n = 0\n while M > 0:\n n += M%10\n M //= 10\n return n\n\nwhile n < N:\n t = N - n\n m = calucurate(t) + calucurate(n)\n ans = min(ans,m)\n n += 1\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s876732672', 's146220058']
[9080.0, 9140.0]
[139.0, 142.0]
[228, 240]
p03331
u105302073
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['def find_sum_digits(num):\n total = 0\n while num > 0:\n total += num % 10\n num //= 10\n return total\n\nN = int(input())\nret = 10**5\nfor a in range(1, N + 1):\n b = N - a\n total = find_sum_digits(a) + find_sum_digits(b)\n print(a, b, total)\n if ret > total:\n ret = total\nprint(ret)', 'def find_sum_digits(num):\n total = 0\n while num > 0:\n total += num % 10\n num //= 10\n return total\n\nN = int(input())\nret = 10**5\nfor a in range(2, N + 1):\n b = N - a\n if b == 0:\n continue\n total = find_sum_digits(a) + find_sum_digits(b)\n print(a, b, total)\n if ret > total:\n ret = total\nprint(ret)', 'N=int(input())\nm=[]\nfor A in range(1,N):\n s=0\n B=N-A\n a="".join(str(A))\n b="".join(str(B))\n for x in range(0,len(a)):\n s+=int(a[x])\n for y in range(0,len(b)):\n s+=int(b[y])\n m.append(s)\nprint(min(m))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s581812828', 's931130074', 's382881632']
[4808.0, 4808.0, 3864.0]
[339.0, 350.0, 558.0]
[316, 348, 212]
p03331
u109133010
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N=int(input())\ndef f(x):\n s=0\n while x!=0:\n s+=x%10\n x//=10\n return(s)\nminn=50\nfor i in range(1,N/2):\n minn=min(f(i)+f(N-i),minn)\nprint(minn)', 'N=int(input())\ndef f(x):\n s=0\n while x!=0:\n s+=x%10\n x//=10\n return(s)\nminn=50\nfor i in range(1,N//2+1):\n minn=min(f(i)+f(N-i),minn)\nprint(minn)']
['Runtime Error', 'Accepted']
['s981247658', 's155229718']
[2940.0, 3060.0]
[17.0, 104.0]
[151, 154]
p03331
u111421568
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\n\nm = len(n)\nf = 0\nans = 0\n\nfor i in range(m):\n ans += n[i]\n \n \nif m>1 and n[0] == 1:\n if n[1] == 0:\n ans += 9\nprint(ans)', "n = input()\n\nm = len(n)\nf = 0\nans = 0\n\nfor i in range(m):\n ans += int(n[i])\n \n \nif m>1 and n[0] == '1':\n if n[1] == '0':\n ans += 9\nprint(ans)"]
['Runtime Error', 'Accepted']
['s462795975', 's170134490']
[3060.0, 3060.0]
[17.0, 17.0]
[151, 160]
p03331
u127499732
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nm=0\nfor x in range(n//2):\n y=n-x\n x,y=list(x),list(y)\n z=sum(list(map(int,x)))+sum(list(map(int,y)))\n m=max(m,z)\nprint(m)', 'n=int(input())\nm=0\nfor x in range(1,n//2+1):\n y=n-x\n x,y=list(str(x)),list(str(y))\n z=sum(list(map(int,x)))+sum(list(map(int,y)))\n m=max(m,z)\nprint(m)', 'n=int(input())\nm=0\nfor x in range(1,n//2+1):\n y=n-x\n x,y=list(str(x)),list(str(y))\n z=sum(list(map(int,x)))+sum(list(map(int,y)))\n m=min(m,z)\nprint(m)', 'n=int(input())\nm=0\nfor x in range(n//2):\n y=n-x\n x,y=list(str(x)),list(str(y))\n z=sum(list(map(int,x)))+sum(list(map(int,y)))\n m=max(m,z)\nprint(m)', 'n=int(input())\nm=100000\nfor x in range(1,n//2+1):\n y=n-x\n x,y=list(str(x)),list(str(y))\n z=sum(list(map(int,x)))+sum(list(map(int,y)))\n m=min(m,z)\nprint(m)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s173640224', 's267454167', 's524646751', 's748992121', 's138479690']
[2940.0, 3060.0, 3060.0, 3060.0, 3060.0]
[17.0, 222.0, 220.0, 223.0, 224.0]
[140, 154, 154, 150, 159]
p03331
u136090046
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\n\nif int(n) % 10 == 0:\n print(10)\nelse:\n res = 0\n for i in n:\n \tres += int(n)\n print(n)\n', 'n = input()\n\nif int(n) % 10 == 0:\n print(10)\nelse:\n res = 0\n for i in n:\n \tres += int(i)\n print(res)\n']
['Wrong Answer', 'Accepted']
['s253428179', 's588526334']
[2940.0, 2940.0]
[20.0, 17.0]
[104, 106]
p03331
u143051858
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\n\nmask = 10 ** (len(n)-1)\nn = int(n)\n\nif n //mask == 1:\n print(10)\nelse:\n print(n//mask + n%10)', 'n = int(input())\n\nres = 0\n\nwhile n:\n res += n % 10\n n //= 10\nif res == 1:\n print(10)\nelse:\n print(res)']
['Wrong Answer', 'Accepted']
['s770942680', 's731147580']
[9096.0, 8980.0]
[27.0, 28.0]
[112, 114]
p03331
u161776322
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nresult =10**10\nfor i in range(1, n):\n A = str(i)\n print(A)\n a_sum = 0\n B = str(n - i)\n print(B)\n b_sum = 0\n for j in range(len(A)):\n a_sum += int(A[j])\n for k in range(len(B)):\n b_sum += int(B[k])\n if a_sum + b_sum <= result:\n result = a_sum + b_sum\n\nprint(result)', 'n = int(input())\nresult =10**10\nfor i in range(1, n):\n A = str(i)\n a_sum = 0\n B = str(n - i)\n b_sum = 0\n for j in range(len(A)):\n a_sum += int(A[j])\n for k in range(len(B)):\n b_sum += int(B[k])\n if a_sum + b_sum <= result:\n result = a_sum + b_sum\n\nprint(result)']
['Wrong Answer', 'Accepted']
['s693582707', 's411952526']
[4464.0, 3064.0]
[573.0, 435.0]
[329, 303]
p03331
u177481830
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nret = 10000\nfor A in range(1, N):\n ret = min(ret, digit_sum(A) + digit_sum(N-A))\nprint(ret)', 'def digit_sum(i):\n return sum([int(digit) for digit in list(str(i))])\n\nN = int(input())\nret = 10000\nfor A in range(1, N):\n ret = min(ret, digit_sum(A) + digit_sum(N-A))\nprint(ret)']
['Runtime Error', 'Accepted']
['s286480676', 's428184434']
[2940.0, 2940.0]
[17.0, 413.0]
[111, 185]
p03331
u189487046
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input().split()\nif n[0] == 1 and sum(n):\n print(10)\nelse:\n print(sum(n))\n', 'n = list(map(int, list(input())))\n\nif n[0] == 1 and sum(n) == 1:\n print(10)\nelse:\n print(sum(n))\n']
['Runtime Error', 'Accepted']
['s509317721', 's438353414']
[2940.0, 2940.0]
[17.0, 19.0]
[83, 104]
p03331
u223904637
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nif a%2==0:\n a=n//2+1\nelse:\n a=n//2+2\ndef wa(k):\n kai=0\n while k>0:\n kai+=round(k%10)\n k=round((k-round(k%10))/10)\n return kai\nans=10000000000\nfor i in range(1,a+1):\n b=i\n c=n-i\n if ans>(wa(b)+wa(c)):\n ans=wa(b)+wa(c)\nprint(ans)', 'n=int(input())\nif n%2==0:\n a=n//2+1\nelse:\n a=n//2+2\ndef wa(k):\n kai=0\n while k>0:\n kai+=round(k%10)\n k=round((k-round(k%10))/10)\n return kai\nans=10000000000\nfor i in range(1,a+1):\n b=i\n c=n-i\n if ans>(wa(b)+wa(c)):\n ans=wa(b)+wa(c)\nprint(ans)']
['Runtime Error', 'Accepted']
['s106444821', 's827626564']
[3064.0, 3064.0]
[19.0, 360.0]
[287, 287]
p03331
u227082700
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input());minn=100\ndef digit_sum(x):\n a,b=0,str(x)\n for i in range(len(b)):a+=int(b[i])\n return a\nfor i in range(1,n//2+1):\n a=digit_sum(i)+digit_sum(n-i)\n minn=min(100,a)\nprint(minn)', 'n=int(input());minn=100\ndef digit_sum(x):\n a,b=0,str(x)\n for i in range(len(b)):a+=int(b[i])\n return a\nfor i in range(1,n//2+1):\n a=digit_sum(i),digit_sum(n-i)\n minn=min(100,a)\nprint(minn)', 'n=int(input());minn=100\ndef digit_sum(x):\n a,b=0,str(x)\n for i in range(len(b)):a+=int(b[i])\n return a\nfor i in range(1,n//2+1):a=digit_sum(i)+digit_sum(n-i);minn=min(minn,a)\nprint(minn)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s278344482', 's825124321', 's346200888']
[3060.0, 3060.0, 3060.0]
[240.0, 18.0, 196.0]
[193, 193, 189]
p03331
u247904511
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["n = int(input())\nans = 1234567890\ndef c(x):\n ers = 0\n for i in str(x):\n ers += ord(i) - ord('0')\n return ers\nfor a in range(1, n):\n ans = min(ans, c(a) + c(n - a))", "n = int(input())\nans = 1234567890\ndef c(x):\n ers = 0\n for i in str(x):\n ers += ord(i) - ord('0')\n return ers\nfor a in range(1, n):\n ans = min(ans, c(a) + c(n - a))\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s171334378', 's411172446']
[3316.0, 3316.0]
[262.0, 235.0]
[182, 193]
p03331
u260036763
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nans = 10**5\nfor a in range(N//2):\n b = N - a\n while a > 0:\n suma += a % 10\n a //= 10\n while b > 0:\n sumb += b % 10\n b //= 10\n if (suma + sumb) < ans:\n ans = suma + sumb\nprint(ans)', 'N = int(input())\nans = 10**5\nfor a in range(1, N//2 + 1):\n suma = 0\n sumb = 0\n b = N - a\n while a > 0:\n suma += a % 10\n a //= 10\n while b > 0:\n sumb += b % 10\n b //= 10\n if (suma + sumb) < ans:\n ans = suma + sumb\nprint(ans)']
['Runtime Error', 'Accepted']
['s168565380', 's738027269']
[3060.0, 3064.0]
[17.0, 125.0]
[215, 276]
p03331
u302292660
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\nsum = 0\nif n[0] == "1" and n[1:-1]=="0"*(len(n)-1):\n print("10")\nelse:\n for i in range(len(n)):\n sum +=int(i)\n print(sum)', 'n = input()\nsum = 0\nif n[0] == "1" and n[1:len(n)]=="0"*(len(n)-1):\n print("10")\nelse:\n for i in range(len(n)):\n sum +=int(n[i])\n print(sum)']
['Wrong Answer', 'Accepted']
['s566906486', 's442384386']
[2940.0, 2940.0]
[17.0, 17.0]
[139, 146]
p03331
u329709276
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nLR = [tuple(map(int,input().split()))for i in [None] * N]\nLmin = sorted(LR,key=lambda x:x[0])\nRmax = sorted(LR,key=lambda x:x[1],reverse=True)\n\nT = 0\ndef t_len(lr):\n a = lr[1] - T\n b = T - lr[0]\n return a if a > b else b\n\ndef select(l):\n return sorted(l,key=t_len,reverse=True)[0]\n\ndef select2(l):\n a = abs(Lmin[0][0] - T)\n b = abs(Rmax[0][1] - T)\n return Lmin[0] if a > b else Rmax[0]\n\ndef selectT(lr):\n if lr[0] <= T <= lr[1]:\n return T\n a = lr[1] - T\n b = T - lr[0]\n return lr[0] if a > b else lr[1]\nK = 0\nfor i in [None]*N:\n s = select2(LR)\n nextT = selectT(s)\n K += abs(nextT-T)\n T = nextT\n LR.remove(s)\n Lmin.remove(s)\n Rmax.remove(s)\nK += abs(T)\nprint(K)', "N = sum([int(i) for i in input()])\nprint('10' if N == 1 else N)"]
['Runtime Error', 'Accepted']
['s064829652', 's204377792']
[3828.0, 2940.0]
[18.0, 18.0]
[741, 63]
p03331
u331672674
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['# -*- coding: utf-8 -*-\n\ndef sum_digits(val):\n work = 0\n while True:\n work += val % 10\n val //= 10\n if val == 0:\n break\n return work\n \nn = int(input())\n\nvalues = []\nfor a in range(2, n + 1):\n b = n - a\n if b < 2:\n continue\n print("{}, {} / {}, {}".format(a, sum_digits(a), b, sum_digits(b)))\n values.append(sum_digits(a) + sum_digits(b))\n\nvalues.sort()\n# print(values)\nprint("0" if len(values) == 0 else values[0])', '# -*- coding: utf-8 -*-\n\ndef sum_digits(val):\n work = 0\n while True:\n work += val % 10\n val //= 10\n if val == 0:\n break\n return work\n \nn = int(input())\n\nvalues = []\nfor a in range(1, n + 1):\n b = n - a\n if b < 1:\n continue\n \n values.append(sum_digits(a) + sum_digits(b))\n\nvalues.sort()\n# print(values)\nprint("0" if len(values) == 0 else values[0])']
['Wrong Answer', 'Accepted']
['s834907130', 's324483080']
[6012.0, 3864.0]
[474.0, 187.0]
[476, 478]
p03331
u335295553
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['print(sum(map(int,input().split())))', 'n = int(input())\nnmin = 10000000\nfor n1 in range(1,n):\n n2 = n-n1\n nsum = sum(map(int, list(str(n1))))+sum(map(int, list(str(n2))))\n\n if nmin > nsum:\n nmin = nsum\nprint(nmin)']
['Wrong Answer', 'Accepted']
['s978392222', 's305161655']
[3316.0, 3060.0]
[116.0, 327.0]
[36, 190]
p03331
u338107614
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['import math\nn,a,b,k = map(int, input().split())\nun = 998244353\ndef combination(n,r):\n return math.factorial(n)//(math.factorial(r) * math.factorial(n-r))\n\ntotal = 0\nfor i in range(n+1):\n if((k-a*i)%b==0):\n count_b = (k-a*i)//b\n total += combination(n, i) * combination(n, count_b)\n\nprint(str(total % un))\n', 'n = int(input())\ndp = [0 for i in range(n)]\nmin = float("inf")\nfor i in range(1, n//2):\n a_sum = sum(map(int, list(str(i))))\n b_sum = sum(map(int, list(str(n - i))))\n c = a_sum + b_sum\n if(min > c):\n min = c\nif min == float("inf"):\n min = n\nprint(min)\n']
['Runtime Error', 'Accepted']
['s364974208', 's921480593']
[3060.0, 3864.0]
[18.0, 183.0]
[325, 274]
p03331
u353919145
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['def soma(n):\n x = sum(int(digit) for digit in str(n))\n if x < 10:\n return x\n else:\n return soma(x)\n\ndef main():\n n = int(input())\n\n somad = soma(n)\n \n for i in range(1, n):\n soman = soma(i)+soma(n-i);\n if(soman==somad):\n break\n \n print(soman,"\\n")\n \nmain()\n', 'def soma(n):\n x = sum(int(digit) for digit in str(n))\n if x < 10:\n return x\n else:\n return soma(x)\n\ndef main():\n n = int(input())\n\n somad = soma(n) \n\n n-=n%10\n \n while(n>=1):\n somaf=soma(n-1)+1\n \n if(somaf>somad):\n somad=somaf\n \n n=n//10\n \n print(somad,"\\n")\n \nmain()\n', 'a = int(input())\nlim = a // 2\nsoma_lista = []\nmenor = 100000\nfor i in range(a - 1, lim, -1):\n b = str(a - abs(i)) + str(abs(i))\n soma = 0\n for digit in b:\n soma += int(digit)\n if soma < menor:\n menor = soma\nif a == 2:\n print(a)\nelse:\n print(menor)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s107493980', 's602305415', 's975782054']
[3060.0, 3060.0, 3060.0]
[585.0, 17.0, 171.0]
[329, 381, 280]
p03331
u354618612
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['digit(num):\n sum = 0\n while(num > 0):\n sum += num % 10\n num = int(num / 10)\n return sum\n \n \nfor a in range(2,n):\n sum_A =sum_digit(a)\n sum_B =sum_digit(n-a)\n all=min(all,(sum_A + sum_B))\n\nprint(all)', 'n = int(input())\nall = 0\n \ndef sum_digit(num):\n sum = 0\n while(num > 0):\n sum += num % 10\n num = int(num / 10)\n return sum\n \n \nfor a in range(2,n):\n sum_A =sum_digit(a)\n sum_B =sum_digit(n-a)\n all=min(all,(sum_A + sum_B))\n\nprint(all)', 'n = list(map(int, list(input())))\n \nif n[0] == 1 and sum(n) == 1:\n print(10)\nelse:\n print(sum(n))']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s565855499', 's855570965', 's602359268']
[2940.0, 3060.0, 2940.0]
[17.0, 289.0, 17.0]
[230, 265, 104]
p03331
u371467115
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nans=0\nfor i in range(n//2+1):\n l=[int(j) for j in list(str(i))]\n m=[int(k) for k in list(str(n-i))]\n if ans<sum(j)+sum(m):\n ans=sum(j)+sum(m)\nprint(ans)', '# A\nNL = list(map(int, list(input())))\n\nif NL[0] == 1 and sum(NL) == 1:\n print(10)\nelse:\n print(sum(NL))\n#copy code']
['Runtime Error', 'Accepted']
['s354799107', 's511276618']
[3060.0, 2940.0]
[18.0, 18.0]
[173, 121]
p03331
u373274281
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N, A, B, K = map(int, input().split())\nM = 998244353\n\nX = set()\nfor n in range(0, K//A+1):\n m = (K - n * A) // B\n if n <= N and m <= N and n * A + m * B == K:\n X.add((n, m))\n\ncomb = [0]*(N+1)\ncomb[0] = 1\ncomb[N] = 1\nfor i in range(1, N//2+1):\n comb[i] = comb[i-1]*(N-i+1)//i\n comb[i] = comb[i]\n comb[N-i] = comb[i]\n\nans = 0\nfor n, m in X:\n ans += comb[n] * comb[m]\n ans = ans % M\nprint(ans)\n', 'N = int(input())\n\ndef digit_sum(X):\n s = 0\n while(X > 0):\n s += X % 10\n X = int(X / 10)\n return s\n\nmin_ = 10 ** 5\nfor A in range(1, int(N/2)+1):\n B = N - A\n val = digit_sum(A) + digit_sum(B)\n min_ = min(min_, val)\n\nprint(min_)\n']
['Runtime Error', 'Accepted']
['s918066732', 's882500931']
[3064.0, 3060.0]
[18.0, 152.0]
[419, 259]
p03331
u374103100
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["\n\nimport itertools\nimport collections\nimport bisect\n\ndef main():\n N = int(input())\n if N % 10:\n print(10)\n else:\n print(sum(map(int, list(str(N)))))\n\n\nif __name__ == '__main__':\n main()\n ", "\n\nimport itertools\nimport collections\nimport bisect\n\ndef main():\n N = int(input())\n if N % 10 == 0:\n print(10)\n else:\n print(sum(map(int, list(str(N)))))\n\n\nif __name__ == '__main__':\n main()\n "]
['Wrong Answer', 'Accepted']
['s128299455', 's407762124']
[3316.0, 3444.0]
[22.0, 25.0]
[267, 272]
p03331
u375616706
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nans=0\nwhile n>0:\n n%10+=ans\n n//=10\nprint(ans)', 'from math import log10\nn = int(input())\nans=0\nl = log10(n)\nif int(l)==l:\n ans=10\nelse:\n while n>0:\n ans+=n%10\n n//=10\nprint(ans)\n', '# python template for atcoder1\nfrom math import log10\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nn = int(input())\nans = 0\nl = log10(n)\nif int(l) == l:\n ans = 10\nelse:\n while n > 0:\n ans += n % 10\n n //= 10\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s090248526', 's997355098', 's312728042']
[2940.0, 2940.0, 3060.0]
[17.0, 17.0, 18.0]
[65, 133, 262]
p03331
u391875425
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nif N % 10 == 0:\n print(10)\nelse:\n s = 0\n for i in str(N):\n s += int(i)\n\tprint(s)', 'N = int(input())\nif N % 10 == 0:\n print(10)\nelse:\n s = 0\n for i in str(N):\n s += int(i)\n print(s)']
['Runtime Error', 'Accepted']
['s176882692', 's812308890']
[3188.0, 2940.0]
[19.0, 20.0]
[113, 116]
p03331
u409064224
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nres = 0\nfor i in range(len(n)):\n res = res + n[i]\n \nprint(res)', 'n = int(input())\nres = n\nfor i in range(1,n//2+1):\n tmp = 0\n a = str(n-i)\n b = str(i)\n for j in a:\n tmp += int(j)\n for j in b:\n tmp += int(j)\n res = min(res,tmp)\nelse:\n print(res)']
['Runtime Error', 'Accepted']
['s294992995', 's076636622']
[2940.0, 3060.0]
[17.0, 193.0]
[81, 214]
p03331
u413019025
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["#!/usr/bin/env python3\n\n\ndef read_h(typ=int):\n return map(typ, input().split())\n\n\ndef read_v(n, typ=int):\n return [typ(input()) for _ in range(n)]\n\n\ndef digit_sum(i):\n return sum([int(d) for d in str(i)])\n\n\ndef main():\n n, = read_h()\n ans = 10000\n for a in range(1, n):\n b = n - a\n s = digit_sum(a) + digit_sum(b)\n if s < ans:\n print(a, b)\n ans = s\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\n\n\ndef read_h(typ=int):\n return map(typ, input().split())\n\n\ndef read_v(n, typ=int):\n return [typ(input()) for _ in range(n)]\n\n\ndef digit_sum(i):\n return sum([int(d) for d in str(i)])\n\n\ndef main():\n n, = read_h()\n ans = 10000\n for a in range(1, n):\n b = n - a\n s = digit_sum(a) + digit_sum(b)\n if s < ans:\n ans = s\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s292698944', 's024392118']
[3064.0, 3064.0]
[323.0, 337.0]
[466, 442]
p03331
u422104747
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['s=input()\nres=0\nflag=s[0]=="1"\nfor c in s[1:]:\n res+=int(c)\n if c!="0":\n flag=False\nif flag:\n print(10)\nelse:\n print(res)', 'n=int(input())\ns=0\nwhile n>0:\n s+=n%10\n n//=10\nif s==1:\n print(10)\nelse:\n print(s)']
['Wrong Answer', 'Accepted']
['s642805936', 's174602279']
[3060.0, 2940.0]
[17.0, 17.0]
[122, 86]
p03331
u430223993
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["n = int(input())\ndef sumNum(i):\n s = 0\n while i//10 > 0:\n s += i%10\n if i//10 < 10:\n s += i//10\n i = i//10\n return s\n\nsumab = float('inf')\nfor i in range(1,n):\n j = n - i\n tmp = sumNum(i) + sumNum(j)\n if tmp < sumab:\n sumab = tmp\nprint(sumab)", "n = int(input())\ndef sumNum(i):\n if i//10 == 0:\n s = i\n else:\n s = 0\n while i//10 > 0:\n s += i%10\n if i//10 < 10:\n s += i//10\n i = i//10\n return s\n\nsumab = float('inf')\nfor i in range(1,n):\n j = n - i\n tmp = sumNum(i) + sumNum(j)\n if tmp < sumab:\n sumab = tmp\nprint(sumab)"]
['Wrong Answer', 'Accepted']
['s853573551', 's744807032']
[3060.0, 3060.0]
[278.0, 290.0]
[299, 346]
p03331
u456878170
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\n\nans = [0]\n\nfor i in range(2, n):\n a = sum([int(j) for j in str(i)])\n b = sum([int(j) for j in str(n - i)])\n ans.append(a + b)\n\nprint(min(ans))', 'n = int(input())\n\nans = list()\n\nfor i in range(2, n // 2):\n a = sum([int(j) for j in str(i)])\n b = sum([int(j) for j in str(n - i)])\n ans.append(a + b)\n\nif len(ans) > 0:\n print(min(ans))\nelse:\n print(2)']
['Wrong Answer', 'Accepted']
['s618135375', 's480156138']
[3860.0, 3480.0]
[359.0, 182.0]
[169, 217]
p03331
u478266845
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\ndef Num_Each_Digit(N,limit):\n ans = np.array([])\n \n if N < 10**(limit):\n for i in range(1,limit+1):\n if (10**(i-1) > N):\n break\n if i == 1:\n ans = np.append( ans, (N%(10**i)))\n elif i > 1:\n ans = np.append( ans, (N%(10**i)-N%(10**(i-1)))/(10**(i-1)))\n ans = np.flip(ans)\n return ans\n \n else:\n print("too large")\n return N\n \ndigit = Num_Each_Digit(N,10)\n \nif N == 10**(len(digit)+1):\n print(10)\n \nelse:\n print(np.sum(digit))', 'import numpy as np\nN = int(input())\n\ndef Num_Each_Digit(N,limit):\n ans = np.array([])\n \n if N < 10**(limit):\n for i in range(1,limit+1):\n if (10**(i-1) > N):\n break\n if i == 1:\n ans = np.append( ans, (N%(10**i)))\n elif i > 1:\n ans = np.append( ans, (N%(10**i)-N%(10**(i-1)))/(10**(i-1)))\n\n return ans\n \n else:\n print("too large")\n return N\n \ndigit = Num_Each_Digit(N,10)\n \nif N == 10**(len(digit)-1):\n print(10)\n \nelse:\n print(int(np.sum(digit)))\n']
['Runtime Error', 'Accepted']
['s243421533', 's502014170']
[3064.0, 12740.0]
[18.0, 156.0]
[596, 595]
p03331
u498575211
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nmin = 100000000000000\nfor i in range(1, (N+1)//2):\n A = str(i)\n B = str(N - i)\n ref = 0\n for a in A:\n ref += int(a)\n for b in B:\n ref += int(b)\n if ref < min:\n min = ref\nprint(min)', 'N = int(input())\nmin = 100000000000000\nfor i in range(1, N):\n A = str(i)\n B = str(N - i)\n ref = 0\n for a in A:\n ref += int(a)\n for b in B:\n ref += int(b)\n if ref < min:\n min = ref\nprint(min)']
['Runtime Error', 'Accepted']
['s426520719', 's141209728']
[2940.0, 3060.0]
[17.0, 340.0]
[213, 205]
p03331
u499106786
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["def func(a):\n result = 0\n \n while a != 0:\n result += a%10\n a = int(a/10)\n \n if result == 1:\n print '10'\n else:\n print result\n\na=int(input())\nfunc(a)\n ", "a = int(input())\n\ndef func(a):\n result = 0\n \n while a != 0:\n result += a%10\n a = int(a/10)\n \n if result == 1:\n print('10')\n else:\n print(result)\n\nfunc(a)"]
['Runtime Error', 'Accepted']
['s013279928', 's556495977']
[2940.0, 2940.0]
[18.0, 17.0]
[207, 203]