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
u131406572
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=[1]\nn=int(input())\nfor i in range(1,7):\n s.append(6**i)\nfor i in range(1,6):\n s.append(9**i)\ns.sort(reverse=True)\nprint(s)\nc=0;i=0\nwhile n>0:\n if n<s[i]:\n i+=1\n else:\n n-=s[i]\n c+=1\nprint(c)\n', 'a=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]\nn=int(input())\ndp=[0]*(n+1)\ndp[0]=0\nfor i in range(1,n+1):\n s=[]\n for j in a:\n if i-j<0:\n continue\n s.append(dp[i-j])\n dp[i]=min(s)+1\nprint(dp[-1])\n']
['Wrong Answer', 'Accepted']
['s639532744', 's622090606']
[3064.0, 3828.0]
[17.0, 371.0]
[250, 248]
p03329
u134789640
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\nimport numpy as np\n\n\nN = int(input())\n\ndp = np.zeros(N,dtype=np.int)\ndp[0] = 1\n\nsix_count = 1\nnine_count = 1\n\nfor i in range(1,N):\n a = dp[i-1] + 1\n\n if i == pow(6,six_count):\n six_count = six_count + 1\n if i == pow(9,nine_count):\n nine_count = nine_count + 1\n\n b = float('inf')\n c = float('inf')\n if i>=6:\n for _ in range(six_count):\n b = min(b,dp[i-pow(6,_)]+1)\n\n if i>=9:\n for _ in range(nine_count):\n c = min(c,dp[i-pow(9,_)]+1)\n\n dp[i] = min(a,b,c)\n\nprint(dp[N-1])\n", "import sys\nimport numpy as np\n\n\nN = int(input())\n\ndp = [float('inf')]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n\n power = 1\n while power <= i:\n dp[i] = min(dp[i],dp[i-power]+1)\n power *= 6\n\n power = 1\n while power <= i:\n dp[i] = min(dp[i],dp[i-power]+1)\n power *= 9\nprint(dp[N])\n"]
['Wrong Answer', 'Accepted']
['s278253996', 's986864896']
[14792.0, 15032.0]
[2109.0, 769.0]
[555, 316]
p03329
u139115460
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.
["num = int(input())\nres = num\nfor i in range(num):\n cc = 0\n t = i\n while(t > 0):\n cc += t%6\n t //=6\n t = num-i\n while(t > 0):\n cc += t%9\n t //=9\n if res > cc:\n print('res:',res)\n print('cc:',cc)\n res = cc\n\nprint(res)\n", "num = int(input())\nres = num\nfor i in range(num):\n cc = 0\n t = i\n while(t > 0):\n cc += t%6\n t //=6\n t = num-i\n while(t > 0):\n cc += t%9\n t //=9\n if res > cc:\n print('res:',res)\n print('cc:',cc)\n res = cc\n\nprint(res)\n", 'num = int(input())\nres = num\nfor i in range(num+1):\n cc = 0\n t = i\n while(t > 0):\n cc += t%6\n t //=6\n t = num-i\n while(t > 0):\n cc += t%9\n t //=9\n if res > cc:\n res = cc\n\nprint(res)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s091859916', 's569421314', 's229092581']
[3060.0, 3060.0, 3060.0]
[335.0, 305.0, 286.0]
[283, 283, 235]
p03329
u160244242
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\ndp = [0]*100001\nfor i in range(1, n+1):\n candi = []\n for j in lst:\n if i >= j:\n candi.append(dp[i-j]+1)\n dp[i] = min(candi)\nprint(dp[i])', 'n = int(input())\n\nlst = []\nfor i in range(7):\n lst.append(6**i)\nfor i in range(1, 6):\n lst.append(9**i)\n\ndp = [0]*100001\nfor i in range(1, n+1):\n candi = []\n for j in lst:\n if i >= j:\n candi.append(dp[i-j]+1)\n dp[i] = min(candi)\nprint(dp[i])']
['Runtime Error', 'Accepted']
['s591950568', 's983905248']
[3828.0, 3828.0]
[18.0, 340.0]
[181, 274]
p03329
u163320134
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=10**10\ndp=[0]*100001\nfor i in range(1,n+1):\n tmp=[dp[i]+1]\n if i>=6**1:\n tmp.append(dp[i-6**1]+1)\n if i>=9**1:\n tmp.append(dp[i-9**1]+1)\n if i>=6**2:\n tmp.append(dp[i-6**2]+1)\n if i>=9**2:\n tmp.append(dp[i-9**2]+1)\n if i>=6**3:\n tmp.append(dp[i-6**3]+1)\n if i>=9**3:\n tmp.append(dp[i-9**3]+1)\n if i>=6**4:\n tmp.append(dp[i-6**4]+1)\n if i>=9**4:\n tmp.append(dp[i-9**4]+1)\n if i>=6**5:\n tmp.append(dp[i-6**5]+1)\n if i>=9**5:\n tmp.append(dp[i-9**5]+1)\n if i>=6**6:\n tmp.append(dp[i-6**6]+1)\n if i>=9**6:\n tmp.append(dp[i-9**6]+1)\n dp[i]=min(tmp)\nprint(dp[n])', 'n=int(input())\nans=10**10\ndp=[0]*100001\nfor i in range(1,n+1):\n tmp=[dp[i-1]+1]\n if i>=6**1:\n tmp.append(dp[i-6**1]+1)\n if i>=9**1:\n tmp.append(dp[i-9**1]+1)\n if i>=6**2:\n tmp.append(dp[i-6**2]+1)\n if i>=9**2:\n tmp.append(dp[i-9**2]+1)\n if i>=6**3:\n tmp.append(dp[i-6**3]+1)\n if i>=9**3:\n tmp.append(dp[i-9**3]+1)\n if i>=6**4:\n tmp.append(dp[i-6**4]+1)\n if i>=9**4:\n tmp.append(dp[i-9**4]+1)\n if i>=6**5:\n tmp.append(dp[i-6**5]+1)\n if i>=9**5:\n tmp.append(dp[i-9**5]+1)\n if i>=6**6:\n tmp.append(dp[i-6**6]+1)\n if i>=9**6:\n tmp.append(dp[i-9**6]+1)\n dp[i]=min(tmp)\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s024658885', 's126759997']
[3956.0, 3956.0]
[298.0, 285.0]
[624, 626]
p03329
u168489836
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.
['cnt = 0\nn = int(input())\nres = n - n%9\ncnt += int(res/9)\nres = res - res%6\ncnt += int(res/6)\ncnt += res\nprint(cnt)', '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']
['s975551126', 's303763491']
[3060.0, 3060.0]
[17.0, 329.0]
[114, 195]
p03329
u173329233
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())\nlist = []\nfor i in [6,5,4,3,2,1]:\n\n for r in [9,6,]:\n while n > r**i:\n n = n - r**i\n list.append(r**i)\n print(n)\n\n\nlength = len(list) + n\nprint(length)\n', 'n = int(input())\nres = n\nans = 0\nfor i in range(n+1):\n t = i\n cc = 0\n while t >= 1:\n cc = cc + t % 6\n t = t // 6\n\n t = n-i\n while t >= 1:\n cc = cc + t%9\n t = t // 9\n\n\n if res > cc:\n res = cc\n\nprint(res)']
['Wrong Answer', 'Accepted']
['s183105981', 's780621800']
[2940.0, 3064.0]
[17.0, 270.0]
[212, 255]
p03329
u180058306
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 math import log\n\nN = int(input())\n\n\ndef func(N, a):\n index = int(log(N) / log(a))\n return a ** index\n\n\ndef search_times_re(N):\n times = 0\n if N < 6:\n times = N\n return times\n elif N < 9:\n times = 1 + (N - 6)\n else:\n N1 = search_times_re(N - func(N, 6))\n N2 = search_times_re(N - func(N, 9))\n if N1 < N2:\n return 1 + N1\n else:\n return 1 + N2\n\nprint(search_times_re(N))', 'N = int(input())\nans = N\nfor i in range(0, N + 1, 6):\n cnt = 0\n j = N - i\n while i > 0:\n cnt += i % 6\n i //= 6\n while j > 0:\n cnt += j % 9\n j //= 9\n ans = min(ans, cnt)\nprint(ans)']
['Runtime Error', 'Accepted']
['s663478185', 's030477914']
[3064.0, 3060.0]
[19.0, 65.0]
[661, 222]
p03329
u192908410
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 times(money, mod):\n ans = 0\n x = 1\n while( x * mod < money):\n x *= mod\n while(money > mod):\n ans += money // x\n money = money % x\n x = x // mod\n return(ans + money)\n\na = []\nb = []\nfor i in range(100001):\n a.append(times(i,6))\n b.append(times(i,9))\n\nc = []\nn = int(input())\nfor i in range(n):\n c.append(a[i]+b[n-i])\nprint(min(c))', 'def times(money, mod):\n ans = 0\n while(money != 0):\n ans += money % mod\n money = money // mod\n return ans\n\nc = []\nn = int(input())\nfor i in range(n+1):\n c.append(times(i,6)+times(n-i,9))\nprint(min(c))']
['Wrong Answer', 'Accepted']
['s266220424', 's970412660']
[5508.0, 3864.0]
[408.0, 217.0]
[352, 211]
p03329
u201234972
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 bisect import bisect_right\nN = int(input())\nc = 0\nroku = [6**i for i in range(1,7)]\nkyu = [9**i for i in range(1,6)]\nable = sorted([0,1] + roku + kyu)\nprint(able)\nwhile N != 0:\n N = N - able[bisect_right(able,N)-1]\n c += 1\nprint(c)', 'from bisect import bisect_right\nN = int(input())\nc = 0\ndef croku(N):\n roku =[0,1] + [6**i for i in range(1,7)]\n c = 0\n while N != 0:\n N = N - roku[bisect_right(roku,N)-1]\n c += 1\n return c\n\ndef ckyu(N):\n kyu = [0,1] + [9**i for i in range(1,6)]\n c = 0\n while N != 0:\n N = N - kyu[bisect_right(kyu,N)-1]\n c += 1\n return c\n\nK = 10**5\nfor i in range(0,N+1):\n K = min(K, croku(i) + ckyu(N-i))\nprint(K)']
['Wrong Answer', 'Accepted']
['s567394346', 's802898799']
[3188.0, 3064.0]
[19.0, 1388.0]
[242, 452]
p03329
u202570162
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())\nc = [1]\nfor i in [6,9]:\n j = 0\n k = 0\n while True:\n j += 1\n k = i**j\n if k > 10**5:\n break\n c += [k]\nprint(c)\nc.sort(reverse=True)\nflag = 0\nfor i in range(len(c)):\n m = int(n//c[i])\n n %= c[i]\n flag += m\n # print('withdraw',c[i],m,'times and sum is',flag)\nprint(flag)\n", '\n#D\n\ndef sixnine(m):\n ret=[]\n for n in [6,9]:\n tmp=1\n while True:\n tmp*=n\n if tmp<=m:\n ret.append(tmp)\n else:\n break\n ret.sort()\n return ret\n\n\nN=int(input())\ndp=[0 for i in range(N+1)]\nfor i in range(1,N+1):\n if i<=5:\n dp[i]=i\n continue\n sn=sixnine(i)\n if i in sn:\n dp[i]=1\n continue\n ans=10**19\n for k in sn:\n ans=min(ans,dp[k]+dp[i-k])\n dp[i]=ans\n# print(dp)\nprint(dp[-1])']
['Wrong Answer', 'Accepted']
['s754683287', 's060310416']
[3064.0, 3864.0]
[17.0, 650.0]
[345, 516]
p03329
u218843509
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\nans = 0\n\nmod_list = [59409, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6]\n\nfor i in mod_list:\n\tprint(n // i)\n\tans += n // i\n\tn = n % i\n\nprint(ans + n)', 'n = int(input())\n\nans = 0\nmod_base = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]\nmod_list = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]\nans_list = [0 for _ in range(100000)]\n\nfor mod in mod_base:\n\tans_list[mod - 1] = 1\n\nfor i in range(10000):\n\tif ans_list[n - 1] != 0:\n\t\tbreak\n\tnew_mod_list = []\n\tfor j in mod_list:\n\t\tfor k in mod_base:\n\t\t\tif j + k <= 100000 and ans_list[j + k - 1] == 0:\n\t\t\t\tnew_mod_list.append(j + k)\n\t\t\t\tans_list[j + k - 1] = i + 2\n\tmod_list = sorted(new_mod_list, reverse=True)\n\nprint(ans_list[n - 1])']
['Wrong Answer', 'Accepted']
['s459165038', 's302761263']
[3060.0, 5472.0]
[17.0, 308.0]
[171, 554]
p03329
u220843654
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\nimport os\nimport sys\n\ndef main():\n n = int(input())\n l1 = lis(n, 9)\n l2 = lis(n, 6)\n print(l1)\n print(l2)\n l1.extend(l2)\n l1 = list(set(l1))\n l1.sort(key=int, reverse=True)\n print(minus(n, l1))\n\ndef lis(n, i):\n count = 0\n res = []\n oi = i\n while i < n:\n res.append(i)\n i = i * oi\n count = count + 1\n return res\n\ndef minus(n, l):\n minus_count = 0\n for i in l:\n while n > i:\n if n - i > 0:\n n = n - i\n minus_count = minus_count + 1\n else:\n break\n print(i, n)\n return minus_count, n\n\nif __name__ == '__main__':\n main()", "# -*- coding: utf-8 -*-\n\nimport os\nimport sys\n\ndef main():\n n = int(input())\n l1 = lis(n, 9)\n l2 = lis(n, 6)\n l1.extend(l2)\n l1 = list(set(l1))\n l1.sort(key=int, reverse=True)\n print(minus(n, l1))\n\ndef lis(n, i):\n count = 0\n res = []\n oi = i\n while i < n:\n res.append(i)\n i = i * oi\n count = count + 1\n return res\n\ndef minus(n, l):\n minus_count = 0\n for i in l:\n while n > i:\n if n - i > 0:\n n = n - i\n minus_count = minus_count + 1\n else:\n break\n return minus_count, n\n\nif __name__ == '__main__':\n main()", "# -*- coding: utf-8 -*-\n\ndef main():\n n = int(input())\n li = dp(n)\n print(li)\n print(li[n])\n\ndef dp(n):\n inf=float('inf')\n dp = [inf for i in range(n+1)]\n dp[0] = 0\n money_list = get_money_list()\n for i in range(1, n + 1):\n for pay in money_list:\n if pay > i:\n continue\n else:\n dp[i] = min(dp[i - pay] + 1, dp[i])\n return dp\n\ndef create_list(n):\n i = 1\n money_list = []\n while i < 100000:\n money_list.append(i)\n i = i * n\n return money_list\n\ndef get_money_list():\n li = create_list(9)\n li.extend(create_list(6))\n li = list(set(li))\n li.sort(key=int, reverse=True)\n return li\n\nif __name__ == '__main__':\n main()", "# -*- coding: utf-8 -*-\n\ndef main():\n n = int(input())\n li = dp(n)\n print(li[n])\n\ndef dp(n):\n inf=float('inf')\n dp = [inf for i in range(n+1)]\n dp[0] = 0\n money_list = get_money_list()\n for i in range(1, n + 1):\n for pay in money_list:\n if pay > i:\n continue\n else:\n dp[i] = min(dp[i - pay] + 1, dp[i])\n return dp\n\ndef create_list(n):\n i = 1\n money_list = []\n while i < 100000:\n money_list.append(i)\n i = i * n\n return money_list\n\ndef get_money_list():\n li = create_list(9)\n li.extend(create_list(6))\n li = list(set(li))\n li.sort(key=int, reverse=True)\n return li\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s168679484', 's449118948', 's969117266', 's948259204']
[3064.0, 3064.0, 5012.0, 3992.0]
[18.0, 19.0, 328.0, 317.0]
[696, 648, 743, 729]
p03329
u227082700
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=n\nfor i in range(n+1):\n ni,si=i,n-i\n m=0\n while ni!=0:m+=ni%6;ni//=6\n while si!=0:m+=si%6;si//=6\n a=min(a,m)\nprint(a)', 'n=int(input())\na=n\nfor i in range(n+1):\n ni,si=i,n-i\n m=0\n while ni!=0:m+=ni%9;ni//=9\n while si!=0:m+=si%6;si//=6\n a=min(a,m)\nprint(a)\n']
['Wrong Answer', 'Accepted']
['s854512336', 's178998150']
[2940.0, 2940.0]
[377.0, 329.0]
[139, 140]
p03329
u239528020
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.
['#!/usr/bin/env python3\n# import math\nn = int(input())\n\nans = [-1]*(n+1)\n\nans[0] = 0\nfor i in range(1, n):\n num = i\n data = ans[i-1]+1\n for j in range(8):\n index = i-6**j\n if index < 0:\n break\n data = min(data, ans[index]+1)\n for j in range(8):\n index = i-9**j\n if index < 0:\n break\n data = min(data, ans[index]+1)\n ans[i] = data\nprint(ans)\n', '#!/usr/bin/env python3\n# import math\nn = int(input())\n\nans = [-1]*(n+1)\n\nans[0] = 0\nfor i in range(1, n+1):\n num = i\n data = ans[i-1]+1\n for j in range(8):\n index = i-6**j\n if index < 0:\n break\n data = min(data, ans[index]+1)\n for j in range(8):\n index = i-9**j\n if index < 0:\n break\n data = min(data, ans[index]+1)\n ans[i] = data\nprint(ans[-1])\n']
['Wrong Answer', 'Accepted']
['s028311181', 's552725439']
[10372.0, 9656.0]
[652.0, 670.0]
[419, 425]
p03329
u243572357
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())\nlst_take = []\nmax_val = 100000\nused = []\nfor i in range(1,15):\n if 6 ** i <= max_val:\n lst_take.append(6**i)\n if 9 ** i <= max_val:\n lst_take.append(9**i) \nlst_take = sorted(set(lst_take), reverse=True)\nwhile True:\n if n==0:\n break\n \n flag = True\n for i in lst_take:\n if i <= n and i not in used:\n n -= i\n count += 1\n used.append(i)\n flag = False\n break\n if flag:\n count += n\n break\nprint(count)', 'import math\nn = int(input())\ncount = 0\nwhile count != 0:\n max_value = 1\n for i in range(1, n):\n if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):\n \tmax_value = max(max_value, i)\n n = n - max_value\n count += 1\nprint(count)', 'import math\nn = int(input())\ncount = 0\nlst = []\nwhile n != 0:\n max_value = 1\n for i in range(1, n):\n if i in max_value:\n continue\n if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):\n \tmax_value = max(max_value, i)\n n = n - max_value\n lst.add(max_value)\n count += 1\nprint(count)', 'import math\nn = int(input())\ncount = 0\nwhile n != 0:\n max_value = 1\n for i in range(1, n+1):\n if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):\n \tmax_value = max(max_value, i)\n n = n - max_value\n lst.add(max_value)\n count += 1\nprint(count)', '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)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s056010374', 's065796981', 's357310751', 's407199543', 's577508274']
[9020.0, 3060.0, 3064.0, 3060.0, 9192.0]
[22.0, 17.0, 17.0, 170.0, 213.0]
[466, 264, 328, 283, 195]
p03329
u244416763
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 = [100000000000 for _ in range(n+1)]\ndp[0] = 0\nfor i in range(n):\n dp[i+1] = min(dp[i]+1,dp[i+1])\n six = 0\n nine = 0\n while (6**six < i):\n dp[i+1] = min(dp[(i+1) - 6**six] + 1,dp[i+1])\n six += 1\n while (9**nine < i):\n dp[i+1] = min(dp[(i+1) - 9**nine] + 1,dp[i+1])\n nine += 1\nprint(dp[-1])', 'n = int(input())\ndp = [100000000000 for _ in range(n+1)]\ndp[0] = 0\nfor i in range(1,n+1):\n dp[i] = min(dp[i-1]+1,dp[i])\n six = 0\n nine = 0\n while (6**six <= i):\n dp[i] = min(dp[i - 6**six] + 1,dp[i])\n six += 1\n while (9**nine <= i):\n dp[i] = min(dp[i - 9**nine] + 1,dp[i])\n nine += 1\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s340732872', 's121980298']
[3864.0, 3864.0]
[1230.0, 1138.0]
[352, 339]
p03329
u246820565
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.
['dpの基本形\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nn = int(input())\npre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]\n\n\ndp = [n]*(n+1)\n\ndp[0] = 0\n\n\n\nfor i in range(1,n+1):\n\n\tfor j in pre_list:\n\t\tif i - j >= 0:\n\t\t\tdp[i] = min(dp[i],dp[i-j]+1)\n\nprint(dp[n])\n', '\nn = int(input())\npre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]\n \n\ndp = [n]*(n+1)\n\ndp[0] = 0\n \n \n\nfor i in range(1,n+1):\n\n\tfor j in pre_list:\n\t\tif i - j >= 0:\n\t\t\tdp[i] = min(dp[i],dp[i-j]+1)\n \nprint(dp[n])']
['Runtime Error', 'Accepted']
['s836800970', 's158337116']
[3064.0, 3828.0]
[18.0, 539.0]
[1084, 429]
p03329
u254871849
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# created: 2019-11-08 02:12:52(JST)\n## internal modules\nimport sys\n# import collections\nimport math\n# import string\n\n# import re\n# import itertools\n# import statistics\n# import functools\n\n## external modules\n# import scipy.special # if use comb function on AtCoder, \n# import scipy.misc # select scipy.misc.comb (old version) \n\ndef main():\n n = int(sys.stdin.readline().rstrip())\n count = 0\n for _ in range(n):\n if n < 6:\n count += n\n break\n elif n >= 15 or 12 > n >= 6:\n n -= max(6 ** math.floor(math.log(n, 6)), 9 ** math.floor(math.log(n, 9)))\n count += 1\n elif 15 > n >= 12:\n n -= 6\n count += 1\n\n print(n)\n print(count)\n\nif __name__ == "__main__":\n # execute only if run as a script\n main()\n', "import sys\n\ndef count(n, b):\n res = 0\n while n:\n res += n % b\n n //= b\n return res\n\nn = int(sys.stdin.readline().rstrip())\n\ndef main():\n res = float('inf')\n for i in range(n + 1):\n res = min(res, count(i, 6) + count(n - i, 9))\n print(res)\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s492162001', 's099155998']
[3064.0, 3060.0]
[18.0, 210.0]
[915, 317]
p03329
u255067135
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\ndef dfs(cost, N):\n if N<6 :\n return cost+N\n else:\n ret0 = 6 ** math.floor(math.log(N, 6))\n ret1 = 9 ** math.floor(math.log(N, 9))\n return min(dfs(cost+1, N-ret0), dfs(cost+1, N-ret1))\n\nN = int(input())', 'def dfs(cost, N):\n if N<6 :\n return cost+N\n else:\n ret0 = 6 ** math.floor(math.log(N, 6))\n ret1 = 9 ** math.floor(math.log(N, 9))\n if (ret0>1) and (ret1>1):\n return min(dfs(cost+1, N-ret0), dfs(cost+1, N-ret1))\n else:\n ret = max(ret0, ret1)\n return dfs(cost+1, N-ret)\n\nN = int(input())\nprint(dfs(0, N))', '\nN = int(input())\ndp = {}\nfor n in range(N+1):\n if n == 0:\n dp[0] = 0\n else:\n res = n\n pow6 = 1\n while n - pow6 >= 0:\n res = min(res, dp[n-pow6] +1)\n pow6 *= 6\n pow9 = 1\n while n -pow9 >= 0:\n res = min(res, dp[n-pow9] +1)\n pow9 *= 9\n dp[n] = res\nprint(dp[N])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s090633797', 's906464073', 's509030582']
[3060.0, 3064.0, 15088.0]
[18.0, 18.0, 617.0]
[247, 376, 370]
p03329
u256833330
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())\nnl=[9**i for i in range(1,6)]\nsl=[6**i for i in range(1,7)]\nl = sorted(nl+sl)[::-1]\nx=0\nfor i in l:\n while True:\n if i <=n:\n n=n-i\n x+=1\n print(n)\n else:\n break\nprint(x+n)\n', 'n=int(input())\nnl=[9**i for i in range(1,6)]\nsl=[6**i for i in range(1,7)]\nl = sorted(nl+sl)[::-1]\nprint(l)\nx=0\nfor i in l:\n while True:\n if i <=n:\n n=n-i\n x+=1\n print(n)\n else:\n break\nprint(x+n)\n', 'n=int(input())\nnl=[9**i for i in range(1,6)][::-1]\nsl=[6**i for i in range(1,7)][::-1]\na=n\nfor i in range(n+1):\n totals=0\n ps=i\n for j in sl:\n if ps >= j:\n totals+=ps//j\n ps= ps-ps//j*j\n totaln=0\n pn=n-i\n for k in nl:\n if pn >=k:\n totaln+= pn //k\n pn=pn-pn//k*k\n a=min(a,totals+totaln+ps+pn)\nprint(a)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s168448892', 's857731718', 's440066279']
[3060.0, 3060.0, 3064.0]
[19.0, 18.0, 440.0]
[248, 257, 380]
p03329
u261082314
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.
['L=[1]\nn=int(input())\nx = 6\ny = 9\nwhile x <= n:\n L.append(x)\n x *= 6\nwhile y <= n:\n L.append(y)\n y *= 9\nL.sort()#[1,6,9,36,81]\ndp = [float("Inf")]*(n+1)\ndp[0] = 0\nfor i in range(n+1):#0~81\n for j in L:#1,6,9\n dp[i+j] = min(dp[i+j],dp[i]+1)#dp=[0,1,...1,.1]\nprint(dp[n])', 'L=[1]\nn=int(input())\nx = 6\ny = 9\nwhile x <= n:\n L.append(x)\n x *= 6\nwhile y <= n:\n L.append(y)\n y *= 9\nL.sort()#[1,6,9,36,81]\ndp = [float("Inf")]*(n+1)\ndp[0] = 0\nfor i in range(n+1):#0~81\n for j in L:#1,6,9\n if i+j <= n:\n dp[i+j] = min(dp[i+j],dp[i]+1)#dp=[0,1,...1,.1]\n else:\n break\nprint(dp[n])']
['Runtime Error', 'Accepted']
['s330909392', 's194617935']
[9524.0, 9588.0]
[194.0, 475.0]
[276, 317]
p03329
u267325300
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 get_rest(base, target):\n i = 0\n while base**i < target:\n i += 1\n return target - base**(i - 1)\n\n\ndef greedy(base, target):\n count = 0\n rest = target\n while rest >= base:\n rest = get_rest(base, rest)\n count += 1\n return count + rest\n\n\nMin = float("inf")\nfor i in range(N + 1):\n Min = min(Min, greedy(6, i) + greedy(9, N - i))\n\nprint(Min)\n', 'N = int(input())\n\n\ndef hoge(kind, target):\n i = 0\n while kind**i <= target:\n i += 1\n rest = target - kind**(i - 1)\n return rest\n\n\ndef search(count, target):\n if target <= 5:\n return count + target\n six_rest = hoge(6, target)\n nine_rest = hoge(9, target)\n return min(search(count + 1, six_rest), hoge(count + 1, nine_rest))\n\n\nprint(search(0, N))\n', 'N = int(input())\n\n\ndef count(base, total):\n count = 0\n exp = 1\n while exp * base <= total:\n exp *= base\n remain = total\n while exp != 1:\n count += remain // exp\n remain %= exp\n exp //= base\n count += remain\n return count\n\n\nMin = float("inf")\nfor i in range(N + 1):\n c = 0\n c += count(6, i)\n c += count(9, N - i)\n Min = min(Min, c)\nprint(Min)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s060319712', 's322827734', 's463458843']
[3060.0, 2940.0, 3064.0]
[2104.0, 2104.0, 417.0]
[405, 383, 403]
p03329
u271934630
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 while i > 0:\n cnt += i % 6\n i //= 6\n j = N-i\n while j > 0:\n cnt += j % 9\n j //= 9\n ans = min(ans, cnt)\nprint(ans)\n', 'n = int(input())\n\nans = n\nfor i in range(n+1):\n count = 0\n t = i\n while(t):\n count += t % 6\n t = int(t/6)\n t = n-i\n while(t):\n count += t % 9\n t = int(t/9)\n ans = min(ans, count)\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s033806800', 's795534495']
[2940.0, 3060.0]
[342.0, 457.0]
[213, 236]
p03329
u276468459
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())\nwd = []\nfor i in range(1, 7):\n wd.append(6**i)\nfor i in range(1, 6):\n wd.append(9**i)\nwd.append(1)\n\ndp = [N]*(N+1)\ndp[0] = 0\n\nfor i in range(len(wd)):\n for j in range(i, N+1):\n dp[j] = min(dp[j], dp[j-i]+1)\n\nprint(dp[N])', 'N = int(input())\nwd = []\nfor i in range(1, 7):\n wd.append(6**i)\nfor i in range(1, 6):\n wd.append(9**i)\nwd.append(1)\n\ndp = [N]*(N+1)\ndp[0] = 0\n\nfor i in wd:\n for j in range(i, N+1):\n dp[j] = min(dp[j], dp[j-i]+1)\n\nprint(dp[N])']
['Wrong Answer', 'Accepted']
['s657924061', 's295672364']
[6900.0, 4276.0]
[525.0, 434.0]
[253, 241]
p03329
u278430856
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())\ncount = 0\nitr = 1\n\nwhile(N >= 9 or N >= 6):\n itr = 1\n flag = 0\n itr2 = 0\n while(N >= 9**itr or N >= 6**itr):\n itr += 1\n if N < 9**itr and flag == 0:\n itr2 = itr-1\n flag = 1\n if flag == 1:\n if 9**itr2 > 6**(itr-1):\n N = N - 9**itr2\n print(N, 9**itr2, 9)\n else:\n N = N - 6**(itr-1)\n print(N, 6**(itr-1), 6)\n else:\n if 9**(itr-1) > 6**(itr-1):\n N = N - 9**(itr-1)\n print(N, 9**(itr-1), 9)\n else:\n N = N - 6**(itr-1)\n print(N, 6**(itr-1), 6)\n count += 1\n if N == 0:\n break\nif N > 0:\n count += N\nprint(count)\n', "from itertools import count, takewhile\n\ndef calc(N, d={}):\n if N < 6:\n return N\n if N in d:\n return d[N]\n\n max9 = max(takewhile(lambda x: x<=N, (9**i for i in count())))\n max6 = max(takewhile(lambda x: x<=N, (6**i for i in count())))\n\n d[N] = min(calc(N-max9), calc(N-max6))+1\n #print(N, ':', d[N])\n return d[N]\n\nprint(calc(int(input())))\n"]
['Wrong Answer', 'Accepted']
['s896999173', 's963926278']
[3064.0, 3060.0]
[18.0, 18.0]
[707, 374]
p03329
u314089899
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 copy\nimport itertools\n\nN = int(input())\nsix_nines = set()\n\n\nfor i in range(1,6):\n a = 6**i\n if a <= N and a not in six_nines:\n six_nines.add(a)\n for j in range(1,N//a):\n six_nines.add(a*j)\n a = 9**i\n if a <= N and a not in six_nines:\n six_nines.add(a)\n for j in range(1,N//a):\n six_nines.add(a*j)\n\ncomb_six_nines = copy.copy(six_nines)\n\n\nfor comb in itertools.combinations(six_nines,2):\n if comb[0]+comb[1] <= N and comb[0]+comb[1] not in comb_six_nines:\n comb_six_nines.add(comb[0]+comb[1])\n\n\n#comb_six_nines.sort(reverse=True)\n#comb_six_nines.append(1)\nsix_nines = list(six_nines)\nsix_nines.sort(reverse=True)\nsix_nines.append(1)\n\n#print(comb_six_nines)\nprint(six_nines)\n\n\nans = 0\nwhile N != 0:\n for comb in six_nines:\n if N >= comb:\n print(N,comb)\n if N \n N -= comb\n ans += 1\n\nprint(ans)', '#99c\nimport math\n\nN = int(input()) #<=100000\n\n\n\n\nsingle_withdraw_set = set()\nsingle_withdraw_set.add(1)\nsingle_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}\nsingle_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}\n#print(single_withdraw_set)\n\n\nwithdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }\nwithdraw_dict[0] = 0\n\n\nfor i in range(1,N+1):\n if i in single_withdraw_set:\n \n withdraw_dict[i] = 1\n else:\n \n withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])\n \n #print(i,":",withdraw_dict[i])\n \n#print(withdraw_dict)\nprint(withdraw_dict[N])']
['Runtime Error', 'Accepted']
['s815662250', 's811006829']
[3064.0, 51040.0]
[18.0, 360.0]
[1007, 1092]
p03329
u325282913
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())\nbank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]\nans = 0\nwhile N != 0:\n for i in bank:\n if 6 <= N <= 14:\n N -= 6\n ans += 1\n # print(6,N)\n break\n if i <= N:\n N -= i\n ans += 1\n # print(i,N)\n break\nprint(ans)', 'N = int(input())\nbank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]\nans = 0\nwhile N != 0:\n for i in bank:\n if i <= N:\n N -= i\n ans += 1\n print(i,N)\n break\nprint(ans)', 'import sys\nsys.setrecursionlimit(10**7)\nN = int(input())\nmemo = [-1]*(N+1)\ndef rec(n):\n if n == 0:\n return 0\n if memo[n] != -1:\n return memo[n]\n res = n\n m = 1\n while m <= n:\n res = min(res,rec(n-m)+1)\n m *= 6\n m = 1\n while m <= n:\n res = min(res,rec(n-m)+1)\n m *= 9\n memo[n] = res\n return memo[n]\n\nprint(rec(N))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s194981844', 's268756259', 's054429657']
[3060.0, 3060.0, 89716.0]
[17.0, 17.0, 625.0]
[345, 235, 381]
p03329
u327532412
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 sys\nsys.setrecursionlimit(100000)\ndp = [-1] * (N + 1)\ndef rec(n):\n if n == 0:\n return 0\n if dp[n] != -1:\n return dp[n]\n res = n\n i = 0\n while n >= i ** 6:\n pow6 = i ** 6\n res = min(res, rec(n - pow6) + 1)\n i += 1\n\n j = 0\n while n >= j ** 9:\n pow9 = j ** 9\n res = min(res, rec(n - pow9) + 1)\n i += 1\n\n dp[n] = res\n return dp[n]\nprint(rec(N))', 'import sys\nsys.setrecursionlimit(10**6)\nN = int(input())\ndp = [-1] * (N + 1)\n\ndef rec(n):\n if n == 0:\n return 0\n if dp[n] != -1:\n return dp[n]\n res = n\n i = 0\n while n >= 6 ** i:\n pow6 = 6 ** i\n res = min(res, rec(n - pow6) + 1)\n i += 1\n j = 0\n while n >= 9 ** j:\n pow9 = 9 ** j\n res = min(res, rec(n - pow9) + 1)\n j += 1\n dp[n] = res\n return res\nprint(rec(N))']
['Runtime Error', 'Accepted']
['s116526085', 's718347754']
[97492.0, 89716.0]
[292.0, 1193.0]
[447, 443]
p03329
u329407311
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())\ndone = []\n\narr = [N]\nans = 0\nstop = 0\n \n\nwhile arr:\n\n a = arr.pop(0)\n\n done.append(a)\n\n Next = []\n if a-1 >= 0:\n Next.append(a-1)\n if a-6 >= 0:\n Next.append(a-6)\n if a-36 >= 0:\n Next.append(a-36)\n if a-216 >= 0:\n Next.append(a-216)\n if a-1296 >= 0:\n Next.append(a-1296)\n if a-7776 >= 0:\n Next.append(a-7776)\n if a-46656 >= 0:\n Next.append(a-46656)\n if a-9 >= 0:\n Next.append(a-9)\n if a-81 >= 0:\n Next.append(a-81)\n if a-729 >= 0:\n Next.append(a-729)\n if a-6561 >= 0:\n Next.append(a-6561)\n if a-59049 >= 0:\n Next.append(a-59049)\n \n for i in Next:\n if i in done:\n continue\n elif i in arr:\n continue\n else:\n arr.append(i)\n if i == 0:\n stop = 1\n break\n ans += 1\n if stop == 1:\n break\n\nprint(ans)', 'def knapsack(N,W,weight,value):\n \n dp=[[10**7 for i in range(W+1)] for j in range(N+1)]\n for i in range(W+1):\n dp[0][i]=i\n #DP\n for i in range(N):\n for w in range(W+1):\n if weight[i]<=w: \n dp[i+1][w]=min(dp[i+1][w-weight[i]]+value[i], dp[i][w])\n else:\n dp[i+1][w]=dp[i][w]\n \n \n return dp[N][W]\n\nN = 12\nW = int(input())\nweight = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]\nvalue = [1,1,1,1,1,1,1,1,1,1,1,1,1]\n\na = knapsack(N,W,weight,value)\n\nprint(a)']
['Wrong Answer', 'Accepted']
['s662237121', 's085026494']
[3316.0, 27032.0]
[2104.0, 541.0]
[1184, 581]
p03329
u329865314
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())\nsixs = [6,36,216,1296,7776,46656]\nnines = [9,81,729,6561,59049]\nlis = [0] + [100000 for i in range(170000)]\nfor i in range(0,100001):\n for j in sixs:\n if lis[i+j] > lis[i]+1:\n lis[i+j] = lis[i] + 1\n for j in nines:\n if lis[i+j] > lis[i]+1:\n lis[i+j] = lis[i] + 1\nprint(lis[n])', 'n = int(input())\nsixs = [6,36,216,1296,7776,46656]\nnines = [9,81,729,6561,59049]\nlis = [i for i in range(170000)]\nfor i in range(0,100001):\n for j in sixs:\n if lis[i+j] > lis[i]+1:\n lis[i+j] = lis[i] + 1\n for j in nines:\n if lis[i+j] > lis[i]+1:\n lis[i+j] = lis[i] + 1\nprint(lis[n])']
['Wrong Answer', 'Accepted']
['s643457251', 's788529124']
[5784.0, 9752.0]
[306.0, 297.0]
[301, 290]
p03329
u335295553
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\ndef hikidashi(n):\n if 35 >= n:\n tmp1 = n//9 + (n%9)//6 + (n%9)%6\n tmp2 = n//6 + n%6\n\n if tmp1 == tmp2:\n if n >= 9:\n return 9\n elif n >= 6:\n return 6\n else:\n return 1\n elif tmp1 > tmp2:\n if n >= 6:\n return 6\n else:\n return 1\n else:\n if n >= 9:\n return 9\n else:\n return 1\n\n else:\n count = 0\n while True:\n tmp = pow(9, count)\n if tmp > n:\n break\n n9 = tmp\n count += 1\n\n count = 0\n while True:\n tmp = pow(6, count)\n if tmp > n:\n break\n n6 = tmp\n count += 1\n return max(n6, n9)\n\n\nresult = 0\nwhile N != 0:\n result += 1\n print(N,hikidashi(N))\n N = N - hikidashi(N)\nprint(result)\n \n', 'N = int(input())\n\nresult = N\nfor i in range(0,N+1):\n count = 0\n tmp = i \n while tmp > 0:\n count += tmp%6\n tmp //= 6\n tmp = N - i \n while tmp > 0:\n count += tmp%9\n tmp //=9\n \n if result > count:\n result = count\n\nprint(result)']
['Wrong Answer', 'Accepted']
['s958095959', 's665278540']
[3064.0, 3060.0]
[18.0, 358.0]
[980, 280]
p03329
u344813796
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.
['dp=[0 for i in range(100010)]\ndp[0]=0\nfor n in range(1,100001):\n dp[n]=200000\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=6\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=9\n\nn=int(input())\nprint(dp[n])', 'dp=[1000000 for i in range(100010)]\ndp[0]=0\nfor n in range(1,11):\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=6\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=9\n\ni=int(input())\nprint(dp[i])', 'n=int(input())\ndp=[0 for i in range(100010)]\ndp[0]=0\nfor i in range(100000):\n dp[i]=200000\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=6\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=9\n\nprint(dp[n])', 'dp=[1000000 for i in range(100010)]\ndp[0]=0\nfor n in range(1,100010):\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=6\n power=1\n while(power<=n):\n dp[n]=min(dp[n],dp[n-power]+1)\n power*=9\n\ni=int(input())\nprint(dp[i])']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s341238211', 's445725900', 's960156533', 's211477499']
[3956.0, 3956.0, 3956.0, 3956.0]
[409.0, 22.0, 426.0, 720.0]
[251, 248, 249, 252]
p03329
u354638986
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.
["nine, six = [9 ** i for i in range(1, 6)], [6 ** i for i in range(1, 7)]\n\n\ndef minimize(n, a_idx, b_idx, t):\n if n == 0:\n return t\n elif a_idx == -1 and b_idx == -1:\n return t + n\n\n t1, t2 = 100000, 100000\n if a_idx != -1:\n p = n // nine[a_idx]\n t1 = minimize(n-p*nine[a_idx], a_idx-1, b_idx, t+p)\n\n if b_idx != -1:\n q = n // six[b_idx]\n t2 = minimize(n-q*six[b_idx], a_idx, b_idx-1, t+q)\n\n return min(t1, t2, t+n-1)\n\n\ndef main():\n n = int(input())\n\n cnt9, cnt6 = 0, 0\n while 9 ** (cnt9+1) <= n:\n cnt9 += 1\n\n while 6 ** (cnt6+1) <= n:\n cnt6 += 1\n\n t = minimize(n, cnt9-1, cnt6-1, 0)\n\n print(t)\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n n = int(input())\n\n min_t = 100000\n for i in range(n+1):\n x, six = i, 0\n while x > 0:\n six += x % 6\n x //= 6\n\n y, nine = n - i, 0\n while y > 0:\n nine += y % 9\n y //= 9\n\n if six + nine < min_t:\n min_t = six + nine\n\n print(min_t)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s640516241', 's003364738']
[3064.0, 3060.0]
[18.0, 202.0]
[726, 382]
p03329
u367130284
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 itertools as i\nn=int(input())\ncount=[]\ndef f(x):\n if x==0:\n return count\n b=list(i.takewhile(lambda i:9**i<=x,(i for i in range(100))))[-1]\n c=list(i.takewhile(lambda i:6**i<=x,(i for i in range(100))))[-1]\n if 9**b>6**c:\n count.append(b)\n return f(x-9**b)\n else:\n count.append(c)\n return f(x-6**c)\n\nprint(f(n))', 'n=int(input())\nfrom copy import*\nans=[]\nfor i in range(n+1): \n count=0\n money6=i\n money9=n-i\n while money6:\n count+=money6%6\n money6//=6\n while money9:\n count+=money9%9\n money9//=9\n ans.append(count)\nprint(min(ans))\n']
['Wrong Answer', 'Accepted']
['s966499054', 's201374959']
[3064.0, 4348.0]
[20.0, 324.0]
[368, 321]
p03329
u374103100
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\nM = 100000\n\nc = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]\n\n\n# val = 9 ** i\n# if val <= M:\n# print(val)\n# c.append(val)\n#\n\n# val = 6 ** i\n# if val <= M:\n# print(val)\n# c.append(val)\n\ncount = 0\nrest = N\n\nfor i in c:\n if rest // i > 0:\n count += rest // i\n print(str(i) + ', ' + str(rest // i) + ' times, rest = ' + str(rest % i))\n rest = rest % i\n\n if rest == 0:\n break\n\nprint(count)", "\n\ndef main():\n max_val = 10**5 + 1\n dp = [i for i in range(max_val)]\n\n for i in range(max_val):\n p = 1\n while p < max_val:\n dp[i] = min(dp[i], dp[i - p] + 1)\n p *= 6\n p = 1\n while p < max_val:\n dp[i] = min(dp[i], dp[i - p] + 1)\n p *= 9\n\n N = int(input())\n print(dp[N])\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s194376175', 's554025321']
[3064.0, 7064.0]
[19.0, 428.0]
[541, 447]
p03329
u375616706
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 = n\nl = (int)(math.log(n, 9)+1)\n\nfor i in range(n+1):\n tmp_ans = 0\n a_six = i\n a_nine = n-i\n for i in reversed(range(-1, 6)):\n tmp = a_six//6**i\n tmp_ans += tmp\n a_six -= tmp*6**i\n a_nine += a_six\n for i in reversed(range(-1, 5)):\n tmp = a_nine//9**i\n tmp_ans += tmp\n a_nine -= tmp*9**i\n if ans > tmp_ans:\n ans = tmp_ans\n\nprint(ans)\n', 'import math\nn = (int)(input())\n\nans = n\nl = (int)(math.log(n, 9)+1)\n\nfor i in range(n+1):\n tmp_ans = 0\n a_six = i\n a_nine = n-i\n for i in reversed(range(7)):\n tmp = a_six//6**i\n tmp_ans += tmp\n a_six -= tmp*6**i\n a_nine += a_six\n for i in reversed(range(7)):\n tmp = a_nine//9**i\n tmp_ans += tmp\n a_nine -= tmp*9**i\n if ans > tmp_ans:\n ans = tmp_ans\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s789076241', 's922482641']
[3188.0, 3064.0]
[1316.0, 1174.0]
[397, 389]
p03329
u422104747
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 zlib\nsol=b"x\\x9c\\xed\\x9dm\\x8f\\xe36\\x0c\\x84\\x7fk\\xaf\\xed%\\x96\\xb7\\xbd\\xeb\\xff\\xffR\\xc1\\xc1\\x12\\x01\\xb8\\x1e\\xd8c.3\\x8a\\x08\\x18\\x0b\\xc3\\xd4\\x0bE=\\x19\\xcbT6\\xfe\\xe3\\xc7\\x9f\\x7f\\xfd\\xfd\\xb3\\xff\\xe9G?{\\x1c\\xfd\\xca\\xe3\\xf8\\xfb\\xe7\\xad\\x1f[\\x91\\xdb\\x97\\xa6~\\xfc\\xbc\\xdd\\xfb\\xb1\\x15\\xb9?\\x9a\\xda+\\xdcOz\\x99\\x87\\xf5Q\\xd8\\xb7\\xd3On\\xf7\\xe5a\\xed\\\'g\\x0b\\x9bI\\xc4\\x8d~\\xf4+\\x0f\\xeb}i\\x0fk?9[\\xd8L"n\\xf4\\xa3_yX\\x97\\xb6>\\xac\\xfd\\xe4la3\\x85\\xbbq\\nZo\\xb2..\\x02`&k\\xf0=\\x000\\x93M\\x81\\x1a\\x00\\x9c\\x1b"\\xd8\\x80\\xb1\\x9f\\xea\\xfd\\x88\\xcfV\\xd8\\x84\\xd17h\\xbd\\x1f\\xf1\\xd9\\x17\\xf6S`\\x91\\xb7\\x01r\\x00\\x84\\xbb\\x01\\xb0\\xf1\\x85\\xcd\\xd4\\x8fnzX\\xdb\\xfa\\xf1\\xcc\\x18\\xc7a\\xb8\\x1b\\x1c6\\xbe\\xf7\\xef\\xd3\\x8dS\\xbd\\xab\\x01`q\\xf6\\\'"\\x00\\xf8.@a3\\x89`\\x03"\\xa6\\x8f\\r0Y\\x9c\\xa3\\x00\\x08\\xa7\\x17`\\x03L\\xfd\\xa4\\x13\\xf5\\x8c\\xd6\\x91Z\\x80C\\xae\\x96\\xb9\\xe1O8l@\\x10\\xb8\\x8f\\xb9\\xf7\\xd9\\x86\\x93\\x89\\r\\xa7\\x1bC\\x03\\xe0\\x1d\\xebG\\xbf\\xd2\\x0f`\\x12\\xc1\\x06\\xc4yhl\\xc0\\x14db\\xe3{\\xbf\\x88\\xcdf\\xf9\\xe7\\xb9\\x9d\\x97\\xd42\\x93]\\xe9\\\'\\xfdJ?\\xe1\\xb0\\x01A\\xe0\\xc4\\x01\\xf8\\x9c\\x89\\r\\x08&\\x07\\x80\\xc5\\xd9O\\x81\\x08\\x00\\xde\\xd4\\x8f~\\xa5\\x1f\\xc0$\\x82\\r\\x18\\xce\\xd0\\xd8\\x80)\\x18\\x1a\\x9b\\xcd\\xf2\\xefs;/\\xa9e&\\xbb\\xd2O\\xfa\\x95~\\xc2a\\x03\\x82\\xc0\\x89\\x03\\xf09\\x13\\x1b\\x10L\\x0e\\x00\\x8b\\xb3\\x9f\\x02\\x11\\x00\\xbc\\xa9\\x1f\\xfdJ?\\x80)\\x1c\\x1b\\xfd\\x84\\xe4\\xd0y\\xec\\xdb\\xfeb\\x9b[\\x99\\x8b\\xb8\\x01n\\x9a\\xdc\\x1d6\\xdc\\r\\x91\\xcc\\x92\\x7f\\xa8y\\x0f\\x00n\\xfb\\x0f5\\x99\\x00L(_"\\xfb)\\xdc\\x13\\xbd\\x88\\x1b\\x1e\\xda\nprint(zlib.decompress(sol)[int(input())]-97)', 'l=[100000 for i in range(100001)]\nl[0]=0\ndif=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]\nfor i in range(1,100001):\n\tfor j in dif:\n\t\tif j>i:\n\t\t\tbreak\n\t\tl[i]=min(l[i],l[i-j]+1)\nn=int(input())\nprint(l[n])']
['Runtime Error', 'Accepted']
['s221221156', 's740805379']
[3060.0, 3956.0]
[17.0, 524.0]
[9340, 206]
p03329
u427984570
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.
['a = int(input())\nl1 = [6**i for i in range(7)]\nl2 = [9**i for i in range(7)]\nl = sorted(l1 + l2)\nl.pop(0)\nl.pop(-1)\ncnt = 0\nprint(l)\nwhile a != 0:\n print(a)\n for i in range(len(l)):\n if a - l[i] < 0:\n a -= l[i-1]\n cnt += 1\n break\n \nprint(cnt)', 'a = int(input())\nl = [6**i for i in range(10) if 6**i < 10**5]\nl += [9**i for i in range(10) if 9**i < 10**5]\nl = sorted(list(set(l)))\n\nans = [10 ** 9 for i in range(a+1)]\nans[0] = 0\n\nfor i in range(a):\n for j in l:\n# print(j)\n if i + j <= a:\n ans[i+j] = min(ans[i] + 1, ans[i+j])\n\nprint(ans[a])']
['Wrong Answer', 'Accepted']
['s635307391', 's498615096']
[8764.0, 3864.0]
[2104.0, 596.0]
[265, 307]
p03329
u428397309
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\nN = int(input())\n\nans = N\nfor i in range(N // 9 + 1):\n nine = i * 9\n six = N - nine\n tmp_ans = 0\n print(nine, six)\n while nine > 0:\n tmp_ans += nine % 9\n nine = nine // 9\n while six > 0:\n tmp_ans += six % 6\n six = six // 6\n ans = min(tmp_ans, ans)\n\nprint(ans)\n', '# -*- coding: utf-8 -*-\n\nN = int(input())\n\nans = N\nfor i in range(N // 9 + 1):\n nine = i * 9\n six = N - nine\n tmp_ans = 0\n while nine > 0:\n tmp_ans += nine % 9\n nine = nine // 9\n while six > 0:\n tmp_ans += six % 6\n six = six // 6\n ans = min(tmp_ans, ans)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s956372400', 's811630760']
[3460.0, 3060.0]
[63.0, 53.0]
[334, 313]
p03329
u440161695
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.
['A=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]\nN=int(input())\nans=0\nwhile N!=0:\n N-=max([a for _ in A if A<=N])\n ans+=1\nprint(ans)', 'N=int(input())\ndp=[float("INF")]*(N+2)\ndp[0]=0\na,b,c=1,1,0\nfor i in range(1,N+1):\n if i==6*a:\n a*=6\n if i==9*b:\n b*=9\n dp[i]=min(dp[i],dp[i-1],dp[i-a],dp[i-b])+1\nprint(dp[N])']
['Runtime Error', 'Accepted']
['s549770051', 's099215479']
[3060.0, 3828.0]
[18.0, 98.0]
[136, 241]
p03329
u440904221
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\ndef search(n,num):\n i = 1\n while True:\n if n < num**i:\n return i-1\n i += 1\n \nans = n\nfor i1 in range(0,6):\n for i2 in range(0,6):\n for i3 in range(0,6):\n for i4 in range(0,6):\n for i5 in range(0,6):\n for i6 in range(0,6):\n res = n\n res -= (6**1)*i1+(6**2)*i2+(6**3)*i3+(6**4)*i4+(6**5)*i5+(6**6)*i6\n if res > 0:\n count = i1+i2+i3+i4+i5+i6\n for i in reversed(range(1,6)):\n cnt = int(res / (9**i))\n res -= (9**i) * cnt\n count += cnt\n if ans > count:\n ans = count\nprint(ans)', 'n = int(input())\n\ndef search(n,num):\n i = 1\n while True:\n if n < num**i:\n return i-1\n i += 1\n \nans = n\nfor i1 in range(0,6):\n for i2 in range(0,6):\n for i3 in range(0,6):\n for i4 in range(0,6):\n for i5 in range(0,6):\n for i6 in range(0,6):\n res = n\n res -= (6**1)*i1+(6**2)*i2+(6**3)*i3+(6**4)*i4+(6**5)*i5+(6**6)*i6\n if res >= 0:\n count = i1+i2+i3+i4+i5+i6\n while res > 6:\n i = search(res,9)\n cnt = int(res / (9**i))\n res -= (9**i) * cnt\n count += cnt\n count += res\n if ans > count:\n ans = count\nprint(ans)']
['Wrong Answer', 'Accepted']
['s217540598', 's015754265']
[3064.0, 3064.0]
[130.0, 200.0]
[896, 932]
p03329
u455104068
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 tans(N, sei):\n import math\n sin = int(math.log(N,9))\n cos = int(math.log(N,6))\n count = sei\n if ((sin != 0) and (cos != 0)):\n if N < 15:\n if N >= 12:\n count += 2\n b2 = N - 12\n return tans(b2, count)\n elif (math.pow(9, sin) > math.pow(6,cos)):\n c = int(N - math.pow(9,sin))\n count += 1\n return tans (c, count)\n else:\n c2 = int(N - math.pow(6,cos))\n count += 1\n return tans (c2, count)\n else:\n count += N\n return count\n\nn1 = int(input())\nprint(tans(n1, 0))', 'from itertools import count, takewhile, dropwhile\n \ndef dfs(n, max9, max6, d={0:0}):\n if n in d: \n return d[n]\n \n max9 = next(dropwhile(lambda x: x>n, (max9 / 9**i for i in count())))\n max6 = next(dropwhile(lambda x: x>n, (max6 / 6**i for i in count())))\n d[n] = min(dfs(n-max9, max9, max6), dfs(n-max6, max9, max6)) + 1\n return d[n]\n \nn = int(input())\n \nmax9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))\nmax6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))\n \nprint(dfs(n, max9, max6))\n']
['Runtime Error', 'Accepted']
['s999280574', 's758731503']
[3188.0, 3064.0]
[18.0, 18.0]
[535, 530]
p03329
u482680085
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())\ncount = 0\nans = []\nfor i in range(N+1):\n count1 = 0\n count2 = 0\n N1 = N - i\n x = i\n while x:\n count1 += x % 6\n x //= 6\n while N1\n count2 += x % 9\n N1 //= 9\n count = count1 + count2\n ans.append(count)\nprint(min(ans))\n', 'N = int(input())\ncount = 0\nans = []\nfor i in range(N+1):\n count1 = 0\n count2 = 0\n N1 = N - i\n x = i\n while x:\n count1 += x % 6\n x //= 6\n while N1\n count2 += N1 % 9\n N1 //= 9\n count = count1 + count2\n ans.append(count)\nprint(min(ans))\n', 'N = int(input())\ncount = 0\nans = []\nfor i in range(N+1):\n count1 = 0\n count2 = 0\n N1 = N - i\n x = i\n while x:\n count1 += x % 6\n x //= 6\n while N1:\n count2 += N1 % 9\n N1 //= 9\n count = count1 + count2\n ans.append(count)\nprint(min(ans))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s328161585', 's450287908', 's149084091']
[2940.0, 2940.0, 3864.0]
[17.0, 17.0, 308.0]
[285, 286, 287]
p03329
u503228842
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())\nnums = [1]\ndef under_nums(N,m):\n nums = []\n i = 1\n while m**i <= N:\n nums.append(m**i)\n i += 1\n return nums\nall_nums = nums+under_nums(N,6)+under_nums(N,9)\nall_nums.sort(reverse=True)\nprint(all_nums)\ncnt = 0\nidx = 0\nmoney = N\na = []\nwhile money > 0:\n while money >= all_nums[idx]:\n #print(all_nums[idx])\n\n money -= all_nums[idx]\n a.append(all_nums[idx])\n #print("money="+str(money))\n cnt += 1\n idx += 1\nprint(cnt)\n# print(a)\n# print(sum(a))', "N = int(input())\nmemo = [-1]*(N+1)\nimport sys\nsys.setrecursionlimit(10**8)\ndef rec(n):\n if n == 0:return 0\n if memo[n] != -1:return memo[n]\n\n res = float('inf')\n\n pow6 = 1\n while pow6 <= n:\n res = min(res,rec(n-pow6)+1)\n pow6 *= 6\n\n pow9 = 1\n while pow9 <= n:\n res = min(res,rec(n-pow9)+1)\n pow9 *= 9\n\n memo[n] = res\n return memo[n]\n\nprint(rec(N))"]
['Wrong Answer', 'Accepted']
['s208321349', 's422834985']
[3064.0, 92020.0]
[18.0, 650.0]
[524, 402]
p03329
u513081876
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\na = [9**i for i in range(1, 6)]\nb = [6**i for i in range(1, 7)]\nab = a+b\nab.sort(reverse=True)\nwhile N >= 6:\n for i in ab:\n if N >= i:\n N = N - i\n ans += 1\n break\nprint(ans+N)\nprint(ans)\nprint(N)', 'N = int(input())\n\ndp = [int(i) for i in range(N+1)]\nB6 = [6**i for i in range(1,7)]\nB9 = [9**i for i in range(1,6)]\nL = B6 + B9\nL = sorted(list(set(L)))\n\nfor i in L:\n for j in range(1, N+1):\n if j - i >= 0:\n dp[j] = min(dp[j], dp[j-i] + 1)\nprint(dp[N])\n']
['Wrong Answer', 'Accepted']
['s720349283', 's033848414']
[3060.0, 7064.0]
[17.0, 522.0]
[263, 274]
p03329
u514383727
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())\nws = [1]\nws += [6**i for i in range(1, 8)]\nws += [9**i for i in range(1, 6)]\nws = sorted(set(ws))\n\nprint(ws)\nINF = 10**5\ndp = [INF] * (n+1)\ndp[0] = 0\nfor i in range(n+1):\n for w in ws:\n if i + w <= n:\n dp[i+w] = min(dp[i]+1, dp[i+w])\nprint(dp[-1])', 'n = int(input())\nws = [1]\nws += [6**i for i in range(1, 8)]\nws += [9**i for i in range(1, 6)]\nws = sorted(set(ws))\n\nINF = 10**5\ndp = [INF] * (n+1)\ndp[0] = 0\nfor i in range(n+1):\n for w in ws:\n if i + w <= n:\n dp[i+w] = min(dp[i]+1, dp[i+w])\nprint(dp[-1])\n']
['Wrong Answer', 'Accepted']
['s482811196', 's695076310']
[3828.0, 3956.0]
[724.0, 625.0]
[285, 276]
p03329
u518042385
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())\nnum6=6\nnum9=9\nwhile num6<=n:\n l.append(num6)\n num6*=6\nwhile num9<=n:\n l.append(num9)\n num9*=9\ncount=[0,1,2,3,4,5,1,2,3,1,2,3]\nfor i in range(12,n+1):\n min=100000\n for j in l:\n if i-j<0:\n pass\n else:\n if min>count[i-j]+1:\n min=count[i-j]+1\n count.append(min)\nprint(count[n])', 'l=[1]\nfor i in range(1,6):\n l.append(9**i)\nfor i in range(1,7):\n l.append(6**i)\nl=sorted(l)\ni=int(input())\nc=0\nfor j in range(1,len(l)+1):\n if i>=l[-j]:\n i=i%l[-j]\n c+=i//l[-j]\n elif i==0:\n break\nprint(c)\n \n \n\n ', 'n=int(input())\nnum6=6\nnum9=9\nl=[]\nwhile num6<=n:\n l.append(num6)\n num6*=6\nwhile num9<=n:\n l.append(num9)\n num9*=9\ncount=[0,1,2,3,4,5,1,2,3,1,2,3]\nfor i in range(12,n+1):\n min=100000\n for j in l:\n if i-j<0:\n pass\n else:\n if min>count[i-j]+1:\n min=count[i-j]+1\n count.append(min)\nprint(count[n])\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s404370361', 's517244434', 's855699272']
[3064.0, 3060.0, 3876.0]
[17.0, 17.0, 296.0]
[318, 229, 324]
p03329
u528005130
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!\nimport math\nfrom collections import defaultdict\n \nN = int(input())\n \nmemo = defaultdict(lambda: -1)\nmemo[0] = 0\ndef recursive(n):\n if memo[n] != -1:\n return memo[n]\n \n min_num_operation = n\n \n index = 0\n temp_n = n\n while temp_n > 0:\n if temp_n % 9 == 0:\n index += 1\n temp_n /= 9\n else:\n break\n if index > 0:\n min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(9, index))))\n \n index = 0\n temp_n = n\n while temp_n > 0:\n if temp_n % 6 == 0:\n index += 1\n temp_n /= 6\n else:\n break\n if index > 0:\n min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(6, index))))\n \n memo[n] = min_num_operation\n \n return min_num_operation\n \nprint(recursive(N))', '# coding: utf-8\n# Your code here!\nimport math\nfrom collections import defaultdict\n \nN = int(input())\n \nmemo = defaultdict(lambda: -1)\nmemo[0] = 0\ndef recursive(n):\n if memo[n] != -1:\n return memo[n]\n \n min_num_operation = n\n \n index = 0\n temp_n = n\n while temp_n > 0:\n if temp_n % 9 == 0:\n index += 1\n temp_n //= 9\n else:\n index += int(math.log(temp_n, 9))\n break\n if index > 0:\n min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(9, index))))\n \n index = 0\n temp_n = n\n while temp_n > 0:\n if temp_n % 6 == 0:\n index += 1\n temp_n //= 6\n else:\n index += int(math.log(temp_n, 6))\n break\n if index > 0:\n min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(6, index))))\n \n memo[n] = min_num_operation\n \n return min_num_operation\n \nprint(recursive(N))']
['Wrong Answer', 'Accepted']
['s267875598', 's433785099']
[4020.0, 3316.0]
[32.0, 22.0]
[892, 986]
p03329
u539517139
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())\nk=[59049,46646,7776,6561,1296,729,216,81,36,9,6]\nc=0\nwhile n>6:\n for i in k:\n if n-i>0:\n n=n-i\n c+1\nc+=n\nprint(n)', 'n=int(input())\nb=[1,6,36,216,1296,7776,46656]\nq=[9,81,729,6561,59049]\nd=[100000]*(n+1)\nd[0]=0\nfor i in range(n):\n for j in b:\n if i+j<=n:\n d[i+j]=min(d[i+j],d[i]+1)\n for k in q:\n if i+k<=n:\n d[i+k]=min(d[i+k],d[i]+1)\nprint(d[n])']
['Wrong Answer', 'Accepted']
['s969744802', 's289815830']
[2940.0, 3828.0]
[17.0, 658.0]
[142, 246]
p03329
u540761833
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 = [[float(\'inf\') for i in range(N+1)] for j in range(3)]\ndp[0][0] = 0\ndp[2][0]= 0\ndef below_power(n,a):\n "n以下になるa**xのxの最大値を求める"\n x = 0\n while n >= a**x:\n x += 1\n return x-1\nnine = below_power(N,9)\nsix = below_power(N,6)\nfor i in range(nine,0,-1):\n dp[1][9**i] = 1\n x= (9**i)\n for j in range(x,N+1):\n dp[1][j] = min(dp[1][j],dp[1][j-x]+1)\nfor i in range(1,six+1):\n dp[2][6**i] = 1\n x= (6**i)\n for j in range(N+1):\n if j >= 9:\n dp[2][j] = min(dp[2][j],dp[2][j-x]+1)\n if j >= x:\n dp[2][j] = min(dp[2][j],dp[1][j-x]+1)\nprint(dp)\nans = dp[2][N]\nfor i in range(1,min(N+1,6)):\n ans = min(ans,dp[2][N-i]+i)\nprint(ans)\n', 'N = int(input())\ndp = [float(\'inf\') for i in range(N+1)]\ndp[0] = 0\nif N >= 6:\n dp[6] = 1\ndef below_power(n,a):\n "n以下になるa**xのxの最大値を求める"\n x = 0\n while n >= a**x:\n x += 1\n return x-1\nnine = below_power(N,9)\nsix = below_power(N,6)\nfor i in range(six,0,-1):\n for j in range(N+1):\n if j - 6**i >= 0:\n dp[j] = min(dp[j],dp[j-6**i]+1)\n if j - 9**i >= 0:\n dp[j] = min(dp[j],dp[j-9**i]+1) \nans = dp[N]\nfor i in range(1,min(N+1,6)):\n ans = min(ans,dp[N-i]+i)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s844992951', 's425796871']
[17152.0, 6296.0]
[986.0, 1154.0]
[741, 556]
p03329
u543954314
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\nl9 = [9**i for i in range(6,0,-1)]\nl6 = [6**i for i in range(7,-1,-1)]\nfor i in range(n//9+1):\n x9 = i*9\n x61= n-x9\n csum = 0\n for x in l9:\n csum += x9//x\n x9 %= x\n for x in x61:\n csum += x61//x\n x61 %= x\n if ans > csum:\n ans = csum\nprint(ans) ', 'n = int(input())\nans = n\nl9 = [9**i for i in range(6,0,-1)]\nl6 = [6**i for i in range(7,-1,-1)]\nfor i in range(n//9+1):\n x9 = i*9\n x61= n-x9\n csum = 0\n for x in l9:\n csum += x9//x\n x9 %= x\n for x in l6:\n csum += x61//x\n x61 %= x\n if ans > csum:\n ans = csum\nprint(ans)']
['Runtime Error', 'Accepted']
['s671455003', 's977276797']
[3064.0, 3064.0]
[18.0, 57.0]
[293, 288]
p03329
u545368057
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())\nxs = [1]\ni = 1\nwhile N > 6**i:\n if 9**i < N:\n xs.append(9**i)\n xs.append(6**i)\n i += 1\nX = sorted(xs)\nprint(X)\n\n\ndp = [10000000000] * 1008000\ndp[1] = 1\nfor i in range(N):\n for x in X:\n dp[i+x] = min(dp[i]+1, dp[i+x])\nprint(dp[N])', 'N = int(input())\nn6 = 1\nn9 = 1\nli = []\nwhile 9**n9 <= N:\n li.append(9**n9)\n n9 += 1\nwhile 6**n6 <= N:\n li.append(6**n6)\n n6 += 1\n\nli.sort()\nINF = 10**10\n\ndp = [[i for i in range(N+1)] for i in range(len(li) + 1)]\ndp = [i for i in range(N+1)]\n\n\nfor i,l in enumerate(li):\n for j in range(N+1):\n if j+l > N : continue\n dp[j+l] = min(dp[j+l], dp[j]+1)\nprint(dp[N])\n']
['Wrong Answer', 'Accepted']
['s009067666', 's727963758']
[10868.0, 54436.0]
[569.0, 621.0]
[302, 411]
p03329
u548303713
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**9)\n\nn=int(input())\nmaxn=110000\nmemo=[-1 for i in range(maxn)]\ndef rec(n):\n if n==0:\n return 0\n if memo[n]!=-1:\n return memo[n]\n res=n\n i=1\n while i<=n:\n res=min(res,rec(n-i)+1)\n i*=6\n j=1\n while i<=n:\n res=min(res,rec(j-i)+1)\n j*=9\n memo[n]=res\n return memo[n]\nprint(rec(n))', 'n=int(input())\nmaxn=110000\ndp=[n for i in range(maxn)] \ndp[0]=0\nfor i in range(n): \n pow6=1\n while i+pow6<=n:\n dp[i+pow6]=min(dp[i+pow6],dp[i]+1)\n pow6*=6\n pow9=1\n while i+pow9<=n:\n dp[i+pow9]=min(dp[i+pow9],dp[i]+1)\n pow9*=9\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s341911969', 's170499313']
[89880.0, 3992.0]
[481.0, 731.0]
[380, 348]
p03329
u559103167
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\nfor i in range(N+1):\n cnt=0\n while i>0:\n cnt+=i%6\n i//=6\n j=N-i\n while j>0:\n cnt+=j%9\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 while i>0:\n cnt+=i%6\n i//=6\n j=N-i\n while j>0:\n cnt+=j%9\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', 'Wrong Answer', 'Accepted']
['s240742655', 's254910405', 's458470811']
[3060.0, 3060.0, 3060.0]
[404.0, 325.0, 352.0]
[185, 185, 203]
p03329
u576432509
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\nn9=9**5\nn6=6**6\n\nk9=5+1\nk6=6+1\nn9=9**k9\nsmin=n\nfor i9 in range(n9):\n ii9=i9\n s=0\n m=0\n astr=""\n for ii in range(1,k9+1):\n r9=ii9%9\n ii9=(ii9-r9)//9 \n s=s*9+r9\n m=m+r9\n astr=astr+str(r9)\n# print("i9",i9,"astr",astr,"s",s,"m",m)\n \n nr=n-s\n nr1=nr\n# print("nr",nr,"m",m)\n \n if nr==0:\n snra=m\n# print(nr,m)\n elif nr>0:\n snra=m\n for jj in range(k6,-1,-1):\n nra=nr1//(6**jj)\n nr1=nr1%(6**jj)\n snra=snra+nra\n\n if smin>snra:\n smin=snra\nprint(smin)', 'n=int(input())\n\n#n=44852\nn9=9**5\nn6=6**6\n\n#n9=9**3\n#n6=6**4\n\nk9=5\nk6=6\nn9=9**k9\nsmin=n\nfor i9 in range(n9):\n ii9=i9\n s=0\n m=0\n astr=""\n for ii in range(1,k9+1):\n r9=ii9%9\n ii9=(ii9-r9)//9 \n s=s*9+r9\n m=m+r9\n astr=astr+str(r9)\n# print("i9",i9,"astr",astr,"s",s,"m",m)\n \n nr=n-s\n nr1=nr\n# print("nr",nr,"m",m)\n \n if nr<=0:\n print(m)\n else:\n snra=m\n for jj in range(k6,-1,-1):\n nra=nr1//(6**jj)\n nr1=nr1%(6**jj)\n snra=snra+nra\n\n if smin>snra:\n smin=snra\n print(smin)', 'n=int(input())\n\nres=n\nfor i in range(n+1):\n cc=0\n t=i\n while t>0:\n cc=cc+t%6\n t=t//6\n t=n-i\n while t>0:\n cc=cc+t%9\n t=t//9\n if res>cc:\n res=cc\n\nprint(res)\n']
['Time Limit Exceeded', 'Wrong Answer', 'Accepted']
['s288554484', 's614738936', 's273605022']
[3064.0, 3884.0, 3060.0]
[2107.0, 638.0, 276.0]
[646, 662, 208]
p03329
u585742242
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 -*-\nimport sys\nimport functools\nsys.setrecursionlimit(10**6)\n\n# N = int(input())\nMAXN = 10**5\nsix_ps = [6**i for i in range(1, 7)]\nnine_ps = [9**i for i in range(1, 6)]\n\n\[email protected]_cache(maxsize=None)\ndef rec(n):\n if n < 6:\n return n\n\n if n in six_ps or n in nine_ps:\n return 1\n\n six_tmps = [1 + rec(n - six_p) if six_p < n else MAXN for six_p in six_ps]\n six_tmp = min(six_tmps)\n\n nine_tmps = [\n 1 + rec(n - nine_p) if nine_p < n else MAXN for nine_p in nine_ps\n ]\n nine_tmp = min(nine_tmps)\n\n return min(six_tmp, nine_tmp)\n', '# -*- coding: utf-8 -*-\nN = int(input())\nINF = 10**6\n\ndp = [INF] * (N + 100)\ndp[0] = 0\n\nfor n in range(1, N + 1):\n dp[n] = dp[n - 1] + 1\n\n power = 6\n while n - power >= 0:\n dp[n] = min(1 + dp[n - power], dp[n])\n power *= 6\n\n power = 9\n while n - power >= 0:\n dp[n] = min(1 + dp[n - power], dp[n])\n power *= 9\n\nprint(dp[N])\n']
['Wrong Answer', 'Accepted']
['s201613548', 's691962494']
[3828.0, 3828.0]
[275.0, 565.0]
[595, 366]
p03329
u591295155
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.
['INF = 10 ** 20\n\nW,N = map(int,input().split())\ncoin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]\ndp = [INF]*(W+1)\ndp[0] = 0\n \nfor coin in coin_list:\n for i in range(coin,W+1):\n dp[i] = min(dp[i], dp[i-coin]+1)\n \nprint(dp[W])', 'INF = 10 ** 20\n\nN = int(input())\ncoin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]\ndp = [INF]*(W+1)\ndp[0] = 0\n \nfor coin in coin_list:\n for i in range(coin,W+1):\n dp[i] = min(dp[i], dp[i-coin]+1)\n \nprint(dp[W])', 'INF = 10 ** 20\n\nN = int(input())\ncoin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]\ndp = [INF]*(N+1)\ndp[0] = 0\n \nfor coin in coin_list:\n for i in range(coin,N+1):\n dp[i] = min(dp[i], dp[i-coin]+1)\n \nprint(dp[N])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s255936540', 's371053891', 's069990399']
[3064.0, 3064.0, 6900.0]
[17.0, 18.0, 458.0]
[260, 246, 246]
p03329
u597374218
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 j=N-i\n cnt=0\n while i>0:\n cnt+=i%6\n i//=6\n print(cnt,j)\n while j>0:\n cnt+=j%9\n j//=9\n print(i,cnt)\n ans=min(ans,cnt)\nprint(ans)', 'N=int(input())\nans=N\nfor i in range(N+1):\n count=0\n t=i\n while t>0:\n count+=t%6\n t//=6\n t=N-i\n while t>0:\n count+=t%9\n t//=9\n ans=min(ans,count)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s706161322', 's545510849']
[4852.0, 9012.0]
[552.0, 214.0]
[219, 201]
p03329
u597455618
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\na = [0] * 12\nfor i in range(1, 7):\n print(i)\n a[2*(i-1)] += max((9**(i-1)), (6**i))\n a[2*(i-1)-1] += min((9**(i-1)), (6**i))\nprint(a)\nfor i in a:\n if (n//i) != 0:\n ans += n//i\n n -= n//i * i\n\nprint(ans)', 'import bisect as bi\n\ndef ref(n):\n if n < 6:\n return n\n else:\n s6 = l6[bi.bisect(l6, n)-1]\n s9 = l9[bi.bisect(l9, n)-1]\n return min(n//s6 + ref(n%s6), 1+ref(n-s9))\n\nl6 = [6**i for i in range(7)]\nl9 = [9**i for i in range(6)]\nprint (ref(int(input())))']
['Wrong Answer', 'Accepted']
['s179693523', 's208992833']
[3188.0, 3064.0]
[19.0, 19.0]
[237, 263]
p03329
u600402037
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())\ni=1\ncount=0\nn6=1\nn9=1\nl=[1]\nwhile True:\n if 9**i>n:\n n9=i-1\n break\n i+=1\ni=1\nwhile True:\n if 6**i>n:\n n6=i-1\n break\n i+=1\nfor i in range(n6):\n l.append(6**(i+1))\nfor i in range(n9):\n l.append(9**(i+1))\nl.sort(reverse=True)\nfor i in l:\n count+=n//i\n n%=i\n print(count)\nprint(count)\n', 'N=int(input())\nans=N\nfor i in range(N+1):\n cnt=0\n while i>0:\n cnt+=i%6\n i//=6\n j=N-i\n while j>0:\n cnt+=j%9\n j//=9\n ans=min(ans,cnt)\nprint(ans)', '# coding: utf-8\nimport sys\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\nN = ir()\nanswer = N\n\nfor i in range(N+1):\n temp = 0\n six_pay = i\n while six_pay:\n temp += six_pay%6\n six_pay //= 6\n nine_pay = N - i\n while nine_pay:\n temp += nine_pay%9\n nine_pay //= 9\n if temp < answer:\n answer = temp\n\nprint(answer)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s067282705', 's111845520', 's933249642']
[3064.0, 2940.0, 3064.0]
[17.0, 313.0, 326.0]
[351, 185, 480]
p03329
u607075479
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())\nsix = [6**i for i in range(7)]\nnine = [9**i for i in range(6)]\nL = []\nfor s in six:\n L.append(s)\nfor s in nine[1:]:\n L.append(s)\nL.sort(reverse=True)\nans = 0\nfor l in L:\n while N > 0:\n ans += N // l\n N %= l\nprint(ans)', 'import sys\nimport math\nfrom collections import deque\n\nsys.setrecursionlimit(1000000)\nMOD = 10 ** 9 + 7\ninput = lambda: sys.stdin.readline().strip()\nNI = lambda: int(input())\nNMI = lambda: map(int, input().split())\nNLI = lambda: list(NMI())\nSI = lambda: input()\n\n\ndef make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]\n\n\ndef get_num_draw(n, x):\n res = 0\n while n > 0:\n res += n % x\n n = n // x\n return res\n\n\ndef main():\n N = NI()\n ans = 10**10\n for i in range(0, N+1, 6):\n ans = min(get_num_draw(N-i, 9) + get_num_draw(i//6, 6), ans)\n print(ans)\n\n\nif __name__ == "__main__":\n main()']
['Time Limit Exceeded', 'Accepted']
['s659214406', 's320422392']
[9100.0, 9368.0]
[2205.0, 51.0]
[243, 639]
p03329
u611368136
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\nl = []\np = 0\nwhile True:\n power = pow(9, p)\n if power > n:\n break\n else:\n l.append(power)\n p += 1\np = 0\nwhile True:\n power = pow(6, p)\n if power > n:\n break\n else:\n l.append(power)\n p += 1\nl = list(set(l))\nl.sort()\nl.reverse()\nprint(l)\n\nfor i in l:\n d = n // i\n n -= d * i\n ans += d\n print(i, d)\n\nprint(ans)\n', 'n = int(input())\n\ndp = [0]\n\nfor i in range(1, n+1):\n dp.append(100000)\n power = 1\n while (i - power >= 0):\n dp[i] = min(dp[i], 1 + dp[i - power])\n power *= 6\n\n power = 9\n while (i - power >= 0):\n dp[i] = min(dp[i], 1 + dp[i - power])\n power *= 9\n\nprint(dp[n])\n \n']
['Wrong Answer', 'Accepted']
['s808991307', 's705646093']
[3064.0, 3860.0]
[17.0, 608.0]
[398, 308]
p03329
u614181788
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 = [float("Inf")]*(n+1)\ndp[0] = 0\nfor i in range(n):\n if dp[i] == float("Inf"):\n pass\n else:\n for j in range(1,n//6):\n if i + 6**j > n:\n break\n dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)\n for j in range(1,n//9):\n if i + 9**j > n:\n break\n dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)\nans = n\nfor i in range(max(0, n-5), n+1):\n ans = min(ans, dp[i]+n-i)\nprint(ans)\nprint(dp)', 'n = int(input())\ndp = [float("Inf")]*(n+1)\nfor i in range(min(6, n+1)):\n dp[i] = i\nfor i in range(n):\n for j in range(1,n//6+1):\n if i + 6**j > n:\n break\n dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)\n for j in range(1,n//9+1):\n if i + 9**j > n:\n break\n dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)\nprint(dp[-1])']
['Wrong Answer', 'Accepted']
['s012269145', 's635911655']
[10608.0, 9592.0]
[383.0, 1003.0]
[487, 360]
p03329
u619458041
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\ndef f(n):\n X6 = []\n X9 = []\n for i in range(1, 10):\n if n >= 6**i:\n X6.append(6**i)\n if n >= 9**i:\n X9.append(9**i)\n return X6, X9\n\n\ndef main():\n input = sys.stdin.readline\n N = int(input())\n X6, X9 = f(N)\n X = [1] + X6 + X9\n dp = [0 for _ in range(N+1)]\n for i in range(1, N+1):\n can = []\n for x in X:\n can.append(dp[i-x] + 1)\n dp[i] = min(can)\n print(dp[N])\n\nif __name__ == '__main__':\n main()", "import sys\nfrom itertools import count, takewhile\n\ndef dfs(n, d={}):\n if n < 6:\n return n\n if n in d:\n return d[n]\n\n max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))\n max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))\n d[n] = min(dfs(n-max9), dfs(n-max6)) + 1\n return d[n]\n\n\ndef main():\n input = sys.stdin.readline\n N = int(input())\n print(dfs(N))\n \nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s965291490', 's226185898']
[3864.0, 3064.0]
[235.0, 20.0]
[449, 427]
p03329
u620846115
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())\ndef f(x):\n ans=0\n while x >0:\n ans+=x%6\n x = x//6\n return ans\ndef g(x):\n ans=0\n while x >0:\n ans+=x%9\n x = x//9\n return ans\nans = n\nfor i in range(n+1):\n ans = min(ans,f(n-i),g(i))\nprint(ans)\n\n', 'n=int(input())\ndef f(x):\n ans=0\n while x>0:\n ans+=x%6\n x=x//6\n return ans\ndef g(x):\n ans=0\n while x>0:\n ans+=x%9\n x=x//9\n return ans\nans=n\nfor i in range(n+1): \n ans=min(ans,f(i)+g(n-i))\nprint(ans)']
['Wrong Answer', 'Accepted']
['s413608597', 's519927018']
[8996.0, 9096.0]
[152.0, 152.0]
[229, 244]
p03329
u623687794
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())\nw=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]\nans=0\nfor i in range(11,0,-1):\n ans+=(n//w[i])\n n-=ans*w[i]\nprint(ans)', 'n=int(input())\nINF=10**7\nw=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]\ndp=[INF]*100001\ndp[0]=0\nfor i in range(100001):\n for j in w:\n if i+j>100000:continue\n dp[i+j]=min(dp[i]+1,dp[i+j])\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s853267453', 's465180392']
[3060.0, 3828.0]
[17.0, 708.0]
[138, 210]
p03329
u626337957
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 = 10**6\ndp = [INF] * (N+1)\nfor i in range(9):\n if i < 6:\n dp[i] = i\n elif i < 9:\n dp[i] = i%6+1\n\nfor i in range(N):\n n = m = 1\n while i+9*n <= N:\n dp[i+9*n] = min(dp[i+9*n], dp[i] + 1)\n n += 1\n while i+6*m <= N:\n dp[i+6*m] = min(dp[i+6*m], dp[i] + 1)\n m += 1\nprint(dp[N])\n \n', 'N = int(input())\n\nd_list = [1]\n\na = 1\nwhile True:\n if 6**a <= N:\n d_list.append(6**a)\n a += 1\n else:\n break\na = 1\nwhile True:\n if 9**a <= N:\n d_list.append(9**a)\n a += 1\n else:\n break\nd_list.sort(key=lambda x:-x)\nrest = N\ncnt = 0\nwhile True:\n if rest < 6:\n cnt = rest\n print(cnt)\n break\n else:\n for num in d_list:\n if rest >= num:\n cnt += 1\n rest -= num\n break', 'N = int(input())\nINF = 10**6\ndp = [INF] * (max(9, N)+1)\nfor i in range(10):\n if 0 < i < 6:\n dp[i] = i\n elif i < 9:\n dp[i] = i%6+1\n else:\n dp[i] = 1\nfor i in range(N):\n n = m = 1\n for j in range(1, 6):\n dp[i+j] = min(dp[i+j], dp[i] + j)\n while i+9**n <= N:\n dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)\n n += 1\n while i+6**m <= N:\n dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)\n m += 1\nprint(dp[N])\n', 'N = int(input())\n\nd_list = [1]\n\na = 1\nwhile True:\n if 6**a <= N:\n d_list.append(6**a)\n a += 1\n else:\n break\na = 1\nwhile True:\n if 9**a <= N:\n d_list.append(9**a)\n a += 1\n else:\n break\nd_list.sort(key=lambda x:-x)\nrest = N\ncnt = 0\nwhile True:\n if rest < 6:\n cnt += rest\n print(cnt)\n break\n else:\n for num in d_list:\n if rest >= num:\n print(num)\n cnt += 1\n rest -= num\n break\n', 'N = int(input())\nINF = 10**6\ndp = [INF] * (N+1)\nfor i in range(10):\n if i < 6:\n dp[i] = i\n elif i < 9:\n dp[i] = i%6+1\n else:\n dp[i] = 1\nfor i in range(N):\n n = m = 1\n while i+9*n > N:\n dp[i+9*n] = min(dp[i+9*n], dp[i] + 1)\n n += 1\n while i+6*m > N:\n dp[i+6*m] = min(dp[i+6*m], dp[i] + 1)\n m += 1\nprint(dp[N])\n \n', 'N = int(input())\nINF = 10**6\ndp = [INF] * (max(9, N))\nfor i in range(10):\n if 0 < i < 6:\n dp[i] = i\n elif i < 9:\n dp[i] = i%6+1\nfor i in range(N):\n n = m = 1\n while i+9**n <= N:\n dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)\n n += 1\n while i+6**m <= N:\n dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)\n m += 1\nprint(dp[N])\n', 'N = int(input())\nINF = 10**6\ndp = [INF] * (max(9, N)+1)\ndp[0] = 0\nfor i in range(N):\n n = m = 0\n while i+9**n <= N:\n dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)\n n += 1\n while i+6**m <= N:\n dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)\n m += 1\nprint(dp[N])\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s209764170', 's362161180', 's389538286', 's468478083', 's773039416', 's997435537', 's401636670']
[3828.0, 3064.0, 3828.0, 3064.0, 3828.0, 3828.0, 3828.0]
[2104.0, 17.0, 1593.0, 17.0, 47.0, 618.0, 1445.0]
[321, 422, 419, 443, 341, 333, 262]
p03329
u633548583
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,k=map(int,input().split())\nh=list(map(int,input().split()))\ndp=[10**5]*n\ndp[0]=0\nfor i in range(n):\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=6\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=9\nprint(dp[n-1])', 'n=int(input())\ndp=[10**5]*n\ndp[0]=0\nfor i in range(n+1):\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=6\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=9\nprint(dp[n])\n', 'n=int(input())\ndp=[10**5]*n\ndp[0]=0\nfor i in range(n+1):\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=6\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=9\nprint(dp[n+1])\n', 'n=int(input())\ndp=[10**5]*n\ndp[0]=0\nfor i in range(n):\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=6\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=9\nprint(dp[n-1])\n', 'n=int(input())\ndp=[10**5]*(n+1)\ndp[0]=0\nfor i in range(n+1):\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=6\n pow=1\n while pow<=n:\n dp[i]=min(dp[i],dp[i-pow]+1)\n pow*=9\nprint(dp[n])\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s277667225', 's429801531', 's699477612', 's795115385', 's032147811']
[3064.0, 3828.0, 3828.0, 3828.0, 3828.0]
[18.0, 683.0, 660.0, 780.0, 823.0]
[276, 230, 232, 230, 234]
p03329
u639592190
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\nn=10\ns=10\nwhile N>=6:\n if N-max(6**s,9**n)>=0:\n N-=max(6**s,9**n)\n print(n,s,N)\n ans+=1\n else:\n bl=int(6**s<9**n)\n n-=bl\n s-=1-bl\n if n==0 and s==0:\n break\nprint(N)\nprint(ans+N)\n ', 'N=int(input())\nans=N\nfor i in range(N+1):\n cnt=0\n s=i\n while s>0:\n cnt+=s%6\n s//=6\n n=N-i\n while n>0:\n cnt+=n%9\n n//=9\n ans=min(ans,cnt)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s428362402', 's878293349']
[3064.0, 3060.0]
[17.0, 348.0]
[227, 193]
p03329
u652656291
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\narr6 = []\nfor i in range(10):\n\tarr6.append(6**i)\n\narr9 = []\nfor i in range(10):\n\tarr9.append(9**i)\n\n\nans = float("inf")\nfor i in range(n+1):\n\tcount = 0\n\ttmp = i\n\twhile tmp > 0:\n\t\tt = 0\n\t\twhile arr6[t] <= tmp:\n\t\t\tt+=1\n\n\t\ttmp -= arr6[t-1]\n\t\tcount += 1\n\n\ttmp = n-i\n\twhile tmp > 0:\n\t\tt = 0\n\t\twhile arr9[t] <= tmp:\n\t\t\tt += 1\n\t\ttmp -= arr9[t-1]\n\t\tcount += 1\n\n\tans = min(ans,count)\n\nprint ans\n', 'import numpy as np\nN = int(input())\n\ncoin = [6**n for n in range(10) if 6**n <= N]\ncoin += [9**n for n in range(10) if 9**n <= N]\n\ndp = np.zeros(N+1, dtype=np.int32)\ndp += 10**9\ndp[0] = 0\n\nfor c in coin:\n for _ in range(9):\n dp[c:] = np.minimum(dp[:-c] + 1, dp[c:])\n\nanswer = dp[-1]\nprint(answer)\n']
['Runtime Error', 'Accepted']
['s215247306', 's815555980']
[3064.0, 13636.0]
[17.0, 188.0]
[404, 301]
p03329
u654386293
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 solve():\n n = int(input())\n dp = [0 for _ in range(n+1)] \n\n for i in range(1, n+1):\n options = find_options(i)\n selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])\n print(selected)\n dp[i] = dp[i-selected[0]] + 1\n\n print(dp[n])\n\ndef find_options(n):\n sixs = find_sixs(n)\n nines = find_nines(n)\n options = [1]\n options.extend(sixs)\n options.extend(nines)\n return options\n\n\ndef find_sixs(n):\n sixs = 1\n powers = [] \n count = 0\n while n > sixs:\n count += 1\n sixs *= 6\n powers.append(sixs)\n \n if len(powers) == 0:\n return powers\n else:\n powers.pop()\n return powers\n\ndef find_nines(n):\n nines = 1\n powers = [] \n count = 0\n while n > nines:\n count += 1\n nines *= 9\n powers.append(nines)\n \n if len(powers) == 0:\n return powers\n else:\n powers.pop()\n return powers\n\nif __name__ == "__main__":\n solve()', 'def solve():\n n = int(input())\n dp = [0 for _ in range(n+1)] \n print(find_options(91414))\n\n for i in range(1, n+1):\n options = find_options(i)\n selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])\n dp[i] = selected[1] + 1\n\n print(dp[n])\n\ndef find_options(n):\n sixs = find_sixs(n)\n nines = find_nines(n)\n options = [1]\n options.extend(sixs)\n options.extend(nines)\n return options\n\n\ndef find_sixs(n):\n sixs = 1\n powers = [] \n count = 0\n while n > sixs:\n count += 1\n sixs *= 6\n powers.append(sixs)\n \n if len(powers) == 0:\n return powers\n else:\n powers.pop()\n return powers\n\ndef find_nines(n):\n nines = 1\n powers = [] \n count = 0\n while n > nines:\n count += 1\n nines *= 9\n powers.append(nines)\n \n if len(powers) == 0:\n return powers\n else:\n powers.pop()\n return powers\n\nif __name__ == "__main__":\n solve()', 'def solve():\n n = int(input())\n dp = [0 for _ in range(n+1)] \n\n for i in range(1, n+1):\n options = find_options(i)\n selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])\n dp[i] = selected[1] + 1\n\n print(dp[n])\n\ndef find_options(n):\n sixs = find_sixs(n)\n nines = find_nines(n)\n options = [1]\n options.extend(sixs)\n options.extend(nines)\n return options\n\n\ndef find_sixs(n):\n sixs = 1\n powers = [] \n count = 0\n while n > sixs:\n count += 1\n sixs *= 6\n powers.append(sixs)\n \n if sixs == n:\n return powers\n else:\n powers.pop()\n return powers\n\ndef find_nines(n):\n nines = 1\n powers = [] \n count = 0\n while n > nines:\n count += 1\n nines *= 9\n powers.append(nines)\n \n if nines == n:\n return powers\n else:\n powers.pop()\n return powers\n\nif __name__ == "__main__":\n solve()']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s128859202', 's820014565', 's666832818']
[4708.0, 3992.0, 3992.0]
[1010.0, 765.0, 776.0]
[997, 998, 954]
p03329
u667024514
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\nlis = [1, 6, 36, 216, 1296, 7776, 46656,\n 9, 81, 729, 6561, 59049]\nm = len(c)\n\ndp = [float('inf') for _ in range(n+1)]\ndp[0] = 0\n\nfor j in range(1,n+1):\n temp = []\n for i in range(m):\n if j < c[i]:\n continue\n else:\n temp.append(dp[j-lis[i]]+1)\n dp[j] = min(temp)\n\nprint(dp[n])\n", "n = int(input())\n\nlis = [1, 6, 36, 216, 1296, 7776, 46656,\n 9, 81, 729, 6561, 59049]\nm = len(c)\n\ndp = [float('inf') for _ in range(n+1)]\ndp[0] = 0\n\nfor j in range(1,n+1):\n temp = []\n for i in range(m):\n if j < lis[i]:\n continue\n else:\n temp.append(dp[j-lis[i]]+1)\n dp[j] = min(temp)\n\nprint(dp[n])\n", 'n = int(input())\nlis = [1, 6, 36, 216, 1296, 7776, 46656,9, 81, 729, 6561, 59049]\nlis.sort(reverse=True)\ndp = [10 ** 10 for i in range(n+1)]\ndp[0] = 0\nfor i in range(n):\n for num in lis:\n try:\n dp[i+num] = min(dp[i+num],dp[i]+1)\n except:\n continue\nprint(dp[n])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s401214960', 's801142033', 's266903667']
[3064.0, 3064.0, 3864.0]
[17.0, 17.0, 546.0]
[344, 346, 277]
p03329
u669173971
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\ndef solve():\n inf=10**7\n dp=[inf]*(n+1)\n dp[0]=0\n \n for i in range(1,n+1):\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=6\n #print(dp)\n\n \n for i in range(1,n+1):\n power2=1\n while power2<=i:\n dp[i]=min(dp[i],dp[i-power2]+1)\n power2*=9\n print(dp)\n return dp[n]\n\nprint(solve())', 'n=int(input())\n\ndef solve():\n inf=10**7\n dp=[inf]*(n+1)\n dp[0]=0\n \n for i in range(1,n+1):\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=6\n #print(dp)\n\n \n for i in range(1,n+1):\n power2=1\n while power2<=i:\n dp[i]=min(dp[i],dp[i-power2]+1)\n power2*=9\n return dp[n]\n\nprint(solve())']
['Wrong Answer', 'Accepted']
['s728966260', 's643176409']
[4848.0, 3828.0]
[390.0, 381.0]
[483, 469]
p03329
u677440371
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 = [int(i) for i in range(10 ** 5 + 1)]\n\nfor i in [6,9]:\n v = i\n while v < 10 ** 5:\n for j in range(len(dp)):\n if j+v <= 10 ** 5:\n dp[j+v] =min(dp[j]+1,dp[j+v])\n v *= i \n \nprint(dp[10**5])', 'n = int(input())\n\nmax_range = 10 ** 5\ndp = [int(i) for i in range(max_range + 1)]\n\nfor i in [6,9]:\n check = i\n while check < max_range:\n for j in range(max_range + 1):\n if j - check >= 0:\n dp[j] = min(dp[j],dp[j-check] + 1)\n\n check = check *\n \nprint(dp[n])', 'n = int(input())\nmax_n = 10 ** 5\ndp = [int(i) for i in range(max_n + 1)]\n\nfor i in (6,9):\n v = i\n while v < max_n:\n for j in range(len(dp)):\n if j + v < max_n:\n dp[j+v] = min(dp[j+v],dp[j]+1)\n v *= i\n \ndp[n]', 'n = int(input())\n\nmax_range = 10 ** 5\ndp = [int(i) for i in range(max_range + 1)]\n\nfor i in [6,9]:\n check = i\n while check < max_range:\n for j in range(max_range + 1):\n if j - check >= 0:\n dp[j] = min(dp[j],dp[j-check] + 1)\n\n check = check * i\n \nprint(dp[n])']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s213589762', 's274957739', 's505949282', 's893136267']
[7064.0, 2940.0, 7064.0, 7064.0]
[591.0, 17.0, 737.0, 687.0]
[261, 310, 260, 312]
p03329
u680851063
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.
['l_6 = []\n_ = 1\nwhile 6**_ < 100000:\n l_6.append(6**_)\n _ += 1\nl_6.sort(reverse = 1)\n\nl_9= []\n_ = 1\nwhile 9**_ < 100000:\n l_9.append(9**_)\n _ += 1\nl_9.sort(reverse = 1)\nprint(l_6, l_9)\n\nn = int(input())\n\nw = 0\nz = []\nfor i in range(n+1):\n x = i\n for j in range(len(l_6)):\n while l_6[j] <= x:\n x -= l_6[j]\n w += 1\n else:\n w += x\n \n y = n-i\n for k in range(len(l_9)):\n while l_9[k] <= y:\n y -= l_9[k]\n w += 1\n else:\n w += y\n\n z.append(w)\n w = 0\n\nprint(min(z))', 'n = int(input())\n\ndp = [0] + [100000]*n\n\nptn = [1]\n_ = 1\nwhile 6**_ < 100000:\n ptn.append(6**_)\n _ += 1\n\n_ = 1\nwhile 9**_ < 100000:\n ptn.append(9**_)\n _ += 1\n\nfor i in range(1,n+1):\n for j in ptn:\n if i-j >= 0:\n dp[i] = min(dp[i], dp[i-j]+1)\nprint(dp[-1])']
['Wrong Answer', 'Accepted']
['s077728597', 's941738018']
[3992.0, 4596.0]
[982.0, 568.0]
[567, 288]
p03329
u681340020
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_max = 100000\n\nbs = [(6 ** i, 6) for i in range (1, 10)]\nbs.extend([(9 ** i, 9) for i in range (1, 10)])\nbs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))\nbms = []\ns = 5\nfor b, i in bs:\n s += b * (i - 1)\n bms.append((b, i, s))\n\n#print(bs)\n\n\n#m = 44852\nm = int(input())\n\nstack = [(m, 0, len(bms) - 1)]\n\nresult = 10000\nwhile stack:\n m, n, bms_i = stack.pop()\n steps += 1\n b, i, s = bms[bms_i]\n #print(m, n, bms_i, b, i, s)\n\n if n > result:\n #print("skip!", m, n, bms_i)\n continue\n if m > s:\n continue\n if bms_i < 0:\n if m <= 6 and m + n < result:\n result = m + n\n # print(\'get result!\', result)\n continue\n\n for j in range(i):\n next_m = m - b * j\n if next_m >= 0 and n + j < result:\n stack.append((next_m, n + j, bms_i - 1))\n\nprint(result)\n', 'n_max = 100000\n\nbs = [(6 ** i, 6) for i in range (1, 10)]\nbs.extend([(9 ** i, 9) for i in range (1, 10)])\nbs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))\nbms = []\ns = 5\nfor b, i in bs:\n s += b * (i - 1)\n bms.append((b, i, s))\n\n#print(bs)\n\n\n#m = 44852\nm = int(input())\n\nstack = [(m, 0, len(bms) - 1)]\n\nresult = 10000\nwhile stack:\n m, n, bms_i = stack.pop()\n b, i, s = bms[bms_i]\n #print(m, n, bms_i, b, i, s)\n\n if n > result:\n #print("skip!", m, n, bms_i)\n continue\n if m > s:\n continue\n if bms_i < 0:\n if m <= 6 and m + n < result:\n result = m + n\n # print(\'get result!\', result)\n continue\n\n for j in range(i):\n next_m = m - b * j\n if next_m >= 0 and n + j < result:\n stack.append((next_m, n + j, bms_i - 1))\n\nprint(result)\n']
['Runtime Error', 'Accepted']
['s166202407', 's256761245']
[3064.0, 3064.0]
[18.0, 21.0]
[898, 883]
p03329
u684026548
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.
['arr = [1]\nfor i in range(1, 10):\n if 6 ** i < 100000:\n arr.append(6 ** i)\n if 9 ** i < 100000:\n arr.append(9 ** i)\n\narr.sort(reverse=True)\n\nn = 44852\n#n = 127\n# n=3\n\n\ndef wari(k, l=0):\n # print(k)\n if k == 0:\n return l\n i = 0\n while k < arr[i]:\n i += 1\n a = int(k / arr[i])\n b = k % arr[i]\n wari1 = wari(b, a+l)\n\n if i < len(arr)-1:\n c = int(k / arr[i+1])\n d = k % arr[i+1]\n wari2 = wari(d, c+l)\n if wari1 < wari2:\n return wari1\n else:\n return wari2\n return wari1\n\n\nprint(wari(n))\n\n\n', 'n = 44852\n# n = 127\n# n=3\n\ndef wari(n):\n res = n\n for i in range(n):\n cc = 0\n t = i\n while t > 0:\n cc += t % 6\n t = t // 6\n t = n - i\n while t > 0:\n cc += t % 9\n t = t // 9\n if res > cc:\n res = cc\n return res\n\nprint(wari(n))\n\n\n', 'n = int(input())\n\ndef sol(n):\n res = n\n for i in range(n+1):\n cc = 0\n t = i\n while t > 0:\n cc += t % 6\n t = t // 6\n t = n - i\n while t > 0:\n cc += t % 9\n t = t // 9\n if res > cc:\n res = cc\n return res\n\nprint(sol(n))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s038008655', 's723156740', 's630757559']
[3064.0, 2940.0, 3064.0]
[18.0, 91.0, 188.0]
[601, 333, 321]
p03329
u686036872
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.
['list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if N <= i:\n N=N-i\n count=+1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsort(list, reverse=True)\nN=int(input())\ncount=0\nfor i in range(19):\n if N <= i:\n N=N-i\n count=+1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**j)\nlist=sorted(list, reverse=True)\nN=44852\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\nprint(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if N <= i:\n N=N-i\n count+=1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N == 0:\n break\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N==0:\n break\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsort(list, reverse=True)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**j)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i < N:\n N=N-i\n count+=1\n if i == N:\n count+=1\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**j)\nlist=sorted(list, reverse=True)\nprint(list)\nN=128\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N == 0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**j)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N == 0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in range(19):\n if N <= i:\n N=N-i\n count=+1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N==0:\n break\nprint(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N == 0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i < N:\n N=N-i\n count+=1\n if i == N:\n count+=1\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N==0:\n print(count)', 'list=[1, 1, 1, 1, 1]\nfor i in range(1, 7):\n list.append(6**i)\nfor j in range(1, 7):\n list.append(9**i)\nsorted(list, reverse=True)\nN=int(input())\ncount=0\nfor i in list:\n if i <= N:\n N=N-i\n count+=1\n if N==0:\n print(count)\n else:\n continue', 'N = int(input())\n\ndp = list(range(0, N+1))\n\nfor i in range(1, N+1):\n for j in [6, 9]:\n for k in range(1, N):\n if 0 <= i-j**k:\n dp[i] = min(dp[i], dp[i-j**k]+1)\n else:\n break\n\nprint(dp[-1]) ']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s261784515', 's268517354', 's406761192', 's409678670', 's430984278', 's445259893', 's449960828', 's484865367', 's506599904', 's530721869', 's585019728', 's620195522', 's632894938', 's637169479', 's663209486', 's686596431', 's716747815', 's732714373', 's814676711', 's997244195', 's169462212']
[2940.0, 2940.0, 2940.0, 2940.0, 3060.0, 2940.0, 3064.0, 2940.0, 3064.0, 2940.0, 2940.0, 3064.0, 3064.0, 3064.0, 2940.0, 2940.0, 3064.0, 3064.0, 2940.0, 2940.0, 8692.0]
[17.0, 17.0, 17.0, 17.0, 18.0, 18.0, 17.0, 17.0, 17.0, 18.0, 21.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 18.0, 1179.0]
[241, 104, 241, 244, 226, 241, 251, 146, 205, 255, 129, 247, 249, 239, 246, 247, 239, 247, 241, 270, 251]
p03329
u690037900
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 bisect as bi\n\nli6 = [6 ** i for i in range(7)]\nli9 = [9 ** i for i in range(6)]\nprint(li6)\nprint(li9)\n\ndef s69(n):\n if n < 6:\n return n\n else:\n s6 = li6[bi.bisect(li6, n) - 1]\n s9 = li9[bi.bisect(li9, n) - 1]\n return min(n // s6 + s69(n % s6), 1 + s69(n - s9))\n\n\nprint(s69(int(input())))', 'li6 = [6 ** i for i in range(7)]\nli9 = [9 ** i for i in range(6)]\n\ndef s69(n):\n if n < 6:\n return n\n else:\n s6 = li6[bi.bisect(li6, n) - 1]\n s9 = li9[bi.bisect(li9, n) - 1]\n return min(n // s6 + s69(n % s6), 1 + s69(n - s9))\n\n\nprint(s69(int(input())))\n\n', 'import bisect as bi\n\nli6 = [6 ** i for i in range(7)]\nli9 = [9 ** i for i in range(6)]\n\ndef s69(n):\n if n < 6:\n return n\n else:\n s6 = li6[bi.bisect(li6, n) - 1]\n s9 = li9[bi.bisect(li9, n) - 1]\n return min(n // s6 + s69(n % s6), 1 + s69(n - s9))\n\n\nprint(s69(int(input())))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s368371366', 's590560602', 's123236512']
[3064.0, 3060.0, 3060.0]
[20.0, 18.0, 18.0]
[328, 287, 306]
p03329
u698176039
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\nl1 = 2 ** 30\np6 = [1] * 6\np9 = [1] * 5\nfor i in range(1,7):\n p6[i] = p6[i-1] * 6\n if i < 6 : p9[i] = p9[i-1] * 9\n\ndp = [l1] * (N+1)\ndp[0] = 0\n\nfor i in range(1,N+1):\n for j in p6:\n if j>i: break\n dp[i] = min(dp[i],dp[i-j]+1)\n \n for j in p9:\n if j>i: break\n dp[i] = min(dp[i],dp[i-j]+1)\n \nprint(dp[N])', 'N = int(input())\n\nl1 = 2 ** 30\np6 = [1] * 7\np9 = [1] * 6\nfor i in range(1,7):\n p6[i] = p6[i-1] * 6\n if i < 6 : p9[i] = p9[i-1] * 9\n\ndp = [l1] * (N+1)\ndp[0] = 0\n\nfor i in range(1,N+1):\n for j in p6:\n if j>i: break\n dp[i] = min(dp[i],dp[i-j]+1)\n \n for j in p9:\n if j>i: break\n dp[i] = min(dp[i],dp[i-j]+1)\n \nprint(dp[N])']
['Runtime Error', 'Accepted']
['s985192720', 's466730660']
[3064.0, 3828.0]
[19.0, 591.0]
[372, 372]
p03329
u698479721
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())\ni = 0\nj = 0\na = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]\nb = a.sort(reverse=True)\nwhile N > 0:\n if a[j] > N:\n j += 1\n if a[j] = N:\n N = 0\n i += 1\n print(i)\n if a[j] < N:\n N = N-a[j]\n i += 1\n', 'N = int(input())\ndef six(n):\n i = 0\n while n%6 == 0:\n n = n//6\n i += 1\n return i\n\ndef nine(n):\n i = 0\n while n%9 == 0:\n n = n//9\n i += 1\n return i\n\ndef ans(n):\n if n-6**six(n)==0:\n return 1\n elif n-9**nine(n)==0:\n return 1\n else:\n return max(six(n)+ans(n-6**six(n)),nine(n)+ans(n-9**nine(n)))\n\nans(44852)\n \n ', 'N = int(input())\na = [1,6,36,216,1296,7776,46656]\nb = [1,9,81,729,6561,59049]\ndef ans(n):\n if n<=0:\n return 1000\n elif n in a or n in b:\n return 1\n else:\n return(min(ans(n-1),ans(n-6),ans(n-36),ans(n-216),ans(n-1296),ans(n-7776),ans(n-46656),ans(n-9),ans(n-81),ans(n-729),ans(n-6561),ans(n-59049))+1)\nm = 1\nwhile m <= N:\n ans(m)\nprint(ans(N))\n ', 'N = int(input())\na = [1,6,36,216,1296,7776,46656]\nb = [1,9,81,729,6561,59049]\ndef six(n):\n i = 0\n if n < a[i]:\n return i-1\n else:\n i += 1\ndef nine(n):\n i = 0\n if n < b[i]:\n return i-1\n else:\n i += 1\ndef ans(n):\n if n in a or n in b:\n return 1\n else:\n return(min(six(n)+ans(n-6**six(n)),(nine(n)+ans(n-9**nine(n))\n \nprint(ans(44852))', 'N = int(input())\ndef cn(X, n):\n if (int(X/n)):\n return cn(int(X/n), n)+str(X%n)\n return str(X%n)\ndef su(n):\n ans = 0\n for chara in n:\n ans += int(chara)\n return ans\nlis = []\ni = 0\nwhile i <= N:\n lis.append(su(cn(i,6))+su(cn(N-i,9)))\n i += 1\nprint(min(lis))']
['Runtime Error', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Accepted']
['s114176435', 's120771103', 's513309431', 's829796378', 's312303116']
[2940.0, 3064.0, 3064.0, 3064.0, 3864.0]
[17.0, 2104.0, 2104.0, 18.0, 996.0]
[236, 344, 358, 397, 277]
p03329
u698771758
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())\ndef cou(n,x):\n i=0\n while(n>0):\n i+=n%x\n n//=x\n return i\nans=N\nfor i in range(N+1):\n ans=min(ans,cou(j,6)+cou(N-j,9))\nprint(ans)', 'N=int(input())\ndef cou(n,x):\n i=0\n while(n>0):\n i+=n%x\n n//=x\n return i\nans=N\nfor j in range(N+1):\n ans=min(ans,cou(j,6)+cou(N-j,9))\nprint(ans)']
['Runtime Error', 'Accepted']
['s022229547', 's849197280']
[3060.0, 3060.0]
[17.0, 231.0]
[169, 169]
p03329
u701318346
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\nN = int(input())\n\n\ndp = [10 ** 5] * N\nsix = [6 ** x for x in range(8)]\nnine = [9 ** x for x in range(6)]\n\n\ndp[0] = 1\n\n\nfor i in range(1, N):\n \n for s in six:\n if i + s >= N:\n break\n dp[i + s] = min(dp[i + s], dp[i] + 1)\n \n for n in nine:\n if i + n >= N:\n break\n dp[i + n] = min(dp[i + n], dp[i] + 1)\n\n\nprint(dp[N - 1])\n', '\n\nN = int(input())\n\n\ndp = [10 ** 5] * (N + 1)\n\n\nsix = []\nc = 0\nwhile True:\n w = 6 ** c\n if w > N:\n break\n six.append(w)\n c += 1\nnine = []\nc = 0\nwhile True:\n w = 9 ** c\n if w > N:\n break\n nine.append(w)\n c += 1\n\n\ndp[0] = 0\n\n\nfor i in range(N + 1):\n \n for s in six:\n if i + s > N:\n break\n dp[i + s] = min(dp[i + s], dp[i] + 1)\n \n for n in nine:\n if i + n > N:\n break\n dp[i + n] = min(dp[i + n], dp[i] + 1)\n\n\nprint(dp[N])\n']
['Wrong Answer', 'Accepted']
['s044491292', 's974248845']
[3828.0, 3828.0]
[746.0, 741.0]
[637, 803]
p03329
u703442202
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 = input().split()\ncand = [1]\nfor i in range(1,6):\n for j in range(1,7):\n cand.append(6**j)\n cand.append(9**i)\nimport bisect \ncount = 0\ncand.sort()\nwhile n > 0:\n\tindex = bisect.bisect_left(cand, n)\n if index != 0\n n = n - cand[index-1]\n count += 1\n else:\n n -= 1\n count += 1\nprint(count)\n \n\n\n ', 'n = int(input())\ncand = [1]\nfor i in range(1,7):\n cand.append(6**i)\nfor j in range(1,6):\n cand.append(9**j)\ncand.sort()\ndp = []\nfor c in cand:\n hoge = []\n for i in range(n+1):\n if i % c == 0:\n hoge.append(i//c)\n else:\n hoge.append(i)\n dp.append(hoge)\nfor a in range(1,12):\n for b in range(1,n+1):\n if b >= cand[a]:\n \tdp[a][b] = min(dp[a-1][b],dp[a][b - cand[a]] + 1)\n else:\n dp[a][b] = dp[a-1][b]\n \nprint(dp[-1][n])\n \n\n \n\n \n \n\n ']
['Runtime Error', 'Accepted']
['s823148718', 's524146706']
[2940.0, 50408.0]
[17.0, 946.0]
[332, 490]
p03329
u710952331
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\nres = 100000\n\nfor i in range(N+1):\n t = i\n cc = 0\n while t>0:\n cc += t%6\n t = int(t/6)\n t = N-i\n while t>0:\n cc += t%9\n t = int(t/9)\n if res > cc:\n res = cc\n\nprint(cc)\n ', 'N = int(input())\n\nres = 100000\n\nfor i in range(N+1):\n cc = 0\n t = i\n while t>0:\n cc += t%6\n t = int(t/6)\n t = N-i\n while t>0:\n cc += t%9\n t = int(t/9)\n if res > cc:\n res = cc\n\nprint(res)\n ']
['Wrong Answer', 'Accepted']
['s677164924', 's796988844']
[3316.0, 3060.0]
[422.0, 430.0]
[209, 210]
p03329
u716649090
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 while i>0:\n cnt+=i%6\n i//=6\n j=N-i\n while j>0:\n cnt+=j%9\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']
['s739557034', 's901289220']
[3060.0, 3060.0]
[323.0, 343.0]
[185, 226]
p03329
u726872801
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\nimport heapq, math\nfrom itertools import zip_longest, permutations, combinations, combinations_with_replacement\nfrom itertools import accumulate, dropwhile, takewhile, groupby\nfrom functools import lru_cache\nfrom copy import deepcopy\n\nN = int(input())\n\ndp = [N] * (N + 1)\ndp[0] = 0\nfor i in range(N):\n dp[i + 1] = min(dp[i + 1], dp[i] + 1)\n six = 6\n nine = 9\n for p in range(20):\n if i + six <= N:\n dp[i + six] = min(dp[i + six], dp[i] + 1)\n if i + nine <= N:\n dp[i + nine] = min(dp[i + nine], dp[i] + 1)\n six *= six\n nine *= nine\n\nprint(dp[N])', 'import sys\nimport heapq, math\nfrom itertools import zip_longest, permutations, combinations, combinations_with_replacement\nfrom itertools import accumulate, dropwhile, takewhile, groupby\nfrom functools import lru_cache\nfrom copy import deepcopy\n\nN = int(input())\n\ndp = [N] * (N + 1)\ndp[0] = 0\nfor i in range(N):\n dp[i + 1] = min(dp[i + 1], dp[i] + 1)\n six = 6\n nine = 9\n for p in range(10):\n if i + six <= N:\n dp[i + six] = min(dp[i + six], dp[i] + 1)\n if i + nine <= N:\n dp[i + nine] = min(dp[i + nine], dp[i] + 1)\n six *= 6\n nine *= 9\n\nprint(dp[N])\n']
['Time Limit Exceeded', 'Accepted']
['s192240456', 's617483437']
[6664.0, 4468.0]
[2104.0, 883.0]
[617, 613]
p03329
u729133443
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 s(n,p):\n while n>0:yield n%p;n//=p\nc=lambda*a:sum(s(*a))\nprint(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))', 'def s(a,b):return[s(a//b,b)+a%b,a][a<b]\nn=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))', 'def s(n,p):\n while n>0:yield n%p;n//=p\nc=lambda*a:sum(s(*a));n=int(input())print(min(c(i,6)+c(n-i,9)for i in range(n+1)))', 'def solve(n, c):\n if n < 6:\n return n + c\n a = b = 2000000000\n if n % 6 == 0:\n a = solve(n // 6, c + 1)\n if n % 9 == 0:\n b = solve(n // 9, c + 1)\n return min(a, b)\nprint(solve(int(input()), 0))', 'def s(n,p):\n while n>0:yield n%p;n//=p\nc=lambda*a:sum(s(*a));print(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))', 's=lambda a,b:a*(a<b)or s(a//b,b)+a%b;n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))', 's=lambda a,b:a if a<b else s(a//b,b)+a%b;n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s078303204', 's106603389', 's297855811', 's720123697', 's970419886', 's976282702', 's183035637']
[3060.0, 3860.0, 2940.0, 3060.0, 3056.0, 3840.0, 2940.0]
[17.0, 74.0, 17.0, 18.0, 18.0, 78.0, 244.0]
[119, 101, 122, 207, 119, 98, 102]
p03329
u747602774
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 bisect import bisect_right\nN = int(input())\nli = sorted([1]+[6**i for i in range(1,10)]+[9**i for i in range(1,8)])\nprint(li)\nans = N%3\nN -= ans\nwhile N >= 36:\n a = bisect_right(li,N)\n N -= li[a-1]\n ans += 1\nif N == 3:\n ans += 3\nelif N <= 9:\n ans += 1\nelif N <= 18:\n ans += 2\nelif N <= 33:\n ans += 3\nprint(ans)\n', 'N = int(input())\nli = [1]\n\nsix = 1\nwhile six <= N:\n six = six*6\n li.append(six)\n\nnine = 1\nwhile nine <= N:\n nine = nine*9\n li.append(nine)\n\nINF = 10**10\n\ndp = [INF for i in range(N+1)]\ndp[0] = 0\n\nfor i in range(N):\n for num in li:\n if i+num <= N:\n dp[i+num] = min(dp[i+num], dp[i] + 1)\nprint(dp[N])\n']
['Wrong Answer', 'Accepted']
['s977140624', 's801108573']
[3064.0, 3864.0]
[18.0, 675.0]
[337, 332]
p03329
u754022296
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.
['d = tuple([1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)])\nM = 10**6+1\nB = [float("inf")]*M\nB[0] = 0\nfor i in range(M):\n for j in d:\n if i+j < M:\n B[i+j] = min(B[i+j], B[i]+1)\nn = int(input())\nprint(B[n])', 'd = tuple([1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)])\nM = 10**5+1\nB = [float("inf")]*M\nB[0] = 0\nfor i in range(M):\n for j in d:\n if i+j < M:\n B[i+j] = min(B[i+j], B[i]+1)\nn = int(input())\nprint(B[n])']
['Time Limit Exceeded', 'Accepted']
['s857577426', 's891083565']
[10868.0, 3956.0]
[2104.0, 675.0]
[229, 229]
p03329
u756988562
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\nN = int(input())\n# judge = True\nans = 0\ntemp = 9\ntemp_list = [1,2,3,4,5]\nwhile 100000>temp:\n temp_list.append(temp)\n temp *=9 \ntemp = 6\nwhile 100000>temp:\n temp_list.append(temp)\n temp *=6 \ntemp_list=sorted(temp_list)\n# print(temp_list)\nfor i in range(1,len(temp_list)+1):\n if N%temp_list[-i] == 0:\n print(N//temp_list[-i])\n sys.exit() \n else:\n judge = True\n while judge:\n if N - temp_list[-i] > 9 and (temp_list[-i] >5):\n # print(N)\n # print(temp_list[-i])\n N -= temp_list[-i]\n ans+=1\n else:\n judge = False\n# print(N)\n# print(N//9)\n# print(N//6)\n# print(N)\nif N%9 < N%6:\n ans += N//9\n N = N%9\n # N -= 9*N//9\nelse:\n ans += N//6\n N = N%6\n # N -= 6*N//6\n# print(N)\n# print(ans)\nprint(N+ans)\n# print(N)\n# print(ans)\n# print(ans+N)\n\n# temp_9 = []\n# temp_6 = []\n# judge = True\n\n# while judge:\n\n# if N -temp_9[-i] >=0:\n# N -= temp_9[-i]\n# print(N)\n# judge = False\n# print(N) \n\n# # while N > temp:\n# # temp *= 9\n# # ans += 1 \n# # N = N - temp/9\n# # print(N)\n', 'import sys\nN = int(input())\ndp = [ 100000 for i in range(N+1)]\ndp[0] = 0\nfor i in range(1,N+1):\n power = 1\n while power <= i:\n dp[i] = min(dp[i],dp[i-power]+1)\n power *= 6\n power = 1\n while power <= i:\n dp[i] = min(dp[i],dp[i-power]+1)\n power *= 9\n while power <= i:\n dp[i] = min(dp[i],dp[i-power]+1)\n power += 1\nprint(dp[N])\n\n']
['Wrong Answer', 'Accepted']
['s947058922', 's670340304']
[3064.0, 3864.0]
[18.0, 612.0]
[1208, 384]
p03329
u757446793
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\n\nN = int(input())\nmemo = [0]*(N+1)\nmemo[0] = 0\n\nfor i in range(1,N+1):\n\tmemo[i] = memo[i-1]+1\n\tfor j in range(1,iny(math.log(i,6))+1):\n\t\tmemo[i] = min(memo[i],memo[i-pow(6,j)]+1)\n\tfor j in range(1,int(math.log(i,9))+1):\n\t\tmemo[i] = min(memo[i],memo[i-pow(9,j)]+1)\n\nprint(memo[-1])\n', 'import math\n\nN = int(input())\nmemo = [0]*(N+1)\nmemo[0] = 0\n\nfor i in range(1,N+1):\n\tmemo[i] = memo[i-1]+1\n\tj = 1\n\twhile pow(6,j) <= i: \n\t\tmemo[i] = min(memo[i],memo[i-pow(6,j)]+1)\n\t\tj += 1\n\tj = 1\n\twhile pow(9,j) <= i:\n\t\tmemo[i] = min(memo[i],memo[i-pow(9,j)]+1)\n\t\tj += 1\n\nprint(memo[-1])\n']
['Runtime Error', 'Accepted']
['s526180836', 's139460982']
[3828.0, 3828.0]
[19.0, 1222.0]
[293, 289]
p03329
u759651152
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-*-\nfrom collections import deque\n\ndef nearest_num_six(n):\n temp = 1\n if n < 6:\n return n -1\n else:\n while n > temp:\n temp *= 6\n return n - temp // 6\n\ndef nearest_num_nine(n):\n temp = 1\n if n < 9:\n return n -1\n else:\n while n > temp:\n temp *= 9\n return n - temp // 9\n\ndef any_one(lists):\n if 1 in lists:\n return True\n else:\n return False\n\ndef main():\n \n N = int(input())\n q = deque([N])\n cnt = 0\n j = 1\n\n while not any_one(q):\n print(q)\n for i in range(j):\n n = q.popleft()\n q.append(nearest_num_six(n))\n q.append(nearest_num_nine(n))\n cnt += 1\n j *= 2\n\n print(cnt+1)\n \n\nif __name__ == '__main__':\n main()", "#-*-coding:utf-8-*-\n\ndef main(): \n N = int(input()) \n num_list = set([1]) \n i = 1 \n j = 1 \n while 6 ** i <= N: \n num_list.add(6 ** i) \n i += 1 \n while 9 ** j <= N: \n num_list.add(9 ** j)\n j += 1 \n num_list = list(num_list) \n num_list.sort()\n\n dp = [] \n\n for i in range(1, N+1): \n if i in num_list: \n dp.append(1) \n else: \n temp = [] \n for k in num_list: \n if i - k > 0: \n temp.append(i - k) \n small_dp = [dp[x-1] for x in temp] \n dp.append(min(small_dp) + 1) \n\n print(dp[-1])\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s288039281', 's608444402']
[3808.0, 3992.0]
[48.0, 380.0]
[822, 678]
p03329
u761989513
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\nans = 0\nwhile n > 0:\n nine = 0\n while 9 ** nine <= n:\n nine += 1\n\n six = 0\n while 6 ** six <= n:\n six += 1\n\n print(n, max(9 ** (nine - 1), 6 ** (six - 1)))\n n -= max(9 ** (nine - 1), 6 ** (six - 1))\n ans += 1\n\nprint(ans)', 'n = int(input())\n\ndp = [float("inf")] * (n + 1)\n\ndp[0] = 0\n\nfor i in range(n):\n six = 1\n while i + six <= n:\n dp[i + six] = min(dp[i + six], dp[i] + 1)\n six *= 6\n\n nine = 1\n while i + nine <= n:\n dp[i + nine] = min(dp[i + nine], dp[i] + 1)\n nine *= 9\n\nprint(dp[n])']
['Wrong Answer', 'Accepted']
['s170177412', 's725192965']
[3064.0, 3828.0]
[17.0, 791.0]
[273, 304]
p03329
u762557532
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\nimport numpy as np\nfrom collections import deque\n#from copy import deepcopy\n\nN = int(input())\n\n## 6^6 < 1e5 < 6^7\n## 9^5 < 1e5 < 9^6\n\n\n\n\n\ndrawable_6 = sorted([6, 6**2, 6**3, 6**4, 6**5, 6**6], reverse=True)\ndrawable_9 = sorted([9, 9**2, 9**3, 9**4, 9**5, 9**6], reverse=True)\nsolver = []\n\nif N < 6:\n print(N)\n exit()\n\ndq = deque()\ndq.append((N,0,[[0,0],[0,0]])) \n\n\nloop_cnt = 0\nwhile dq:\n loop_cnt += 1\n rest, cnt, draw_lst = dq.popleft()\n \n if rest < 6:\n solver.append(rest + cnt)\n continue\n \n if draw_lst[0][1] < 4:\n rest_afterdraw_6 = rest - drawable_6[draw_lst[0][0]]\n if rest_afterdraw_6 >= 0:\n new_draw_lst = [[draw_lst[0][0],draw_lst[0][1]+1],draw_lst[1]]\n dq.append((rest_afterdraw_6,cnt+1,new_draw_lst))\n \n \n if draw_lst[0][0] < 5:\n new_draw_lst = [[draw_lst[0][0]+1,0],draw_lst[1]]\n dq.append((rest,cnt,new_draw_lst))\n \n \n if draw_lst[1][1] < 4:\n rest_afterdraw_9 = rest - drawable_9[draw_lst[1][0]]\n if rest_afterdraw_9 >= 0:\n new_draw_lst = [draw_lst[0],[draw_lst[1][0],draw_lst[1][1]+1]]\n dq.append((rest_afterdraw_9,cnt+1,new_draw_lst))\n \n \n if draw_lst[1][0] < 5:\n new_draw_lst = [draw_lst[0],[draw_lst[1][0]+1,0]]\n dq.append((rest,cnt,new_draw_lst))\n \n\nprint(min(solver))\nprint('n_loop =', loop_cnt)\n\n", '\n\n\n\n\ndef Base_10_to_n(X, n):\n if (int(X/n)):\n return Base_10_to_n(int(X/n), n)+str(X%n)\n return str(X%n)\n\ndef Base_n_to_10(X,n):\n out = 0\n for i in range(1,len(str(X))+1):\n out += int(str(X)[-i])*(n**(i-1))\n return out\n\n\nN = int(input())\n\nafter_draw_9 = []\nfor i in range(N // 9 + 1):\n cost_9 = sum(map(int, Base_10_to_n(9*i,9)))\n after_draw_9.append((N-9*i, cost_9))\n\n\nsolver = []\nfor i in range(len(after_draw_9)):\n cost_6 = sum(map(int, Base_10_to_n(after_draw_9[i][0], 6)))\n solver.append(after_draw_9[i][1] + cost_6)\n \n#print(solver)\nprint(min(solver))']
['Wrong Answer', 'Accepted']
['s879911083', 's227721825']
[266344.0, 4152.0]
[2126.0, 127.0]
[2026, 915]
p03329
u763968347
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\n\nN = int(input())\nans = N\n\nfor N1 in range(N):\n \n count = 0\n N2 = N - N1\n\n while N1 > 0:\n count += N1%6\n N1 = math.floor(N1/6)\n print(N1)\n print(count)\n \n while N2 > 0:\n count += N2%9\n N2 = math.floor(N2/9)\n \n if ans > count:\n ans = count\n\nprint(ans)', 'N = int(input())\nINF = 10**18\n\ndp = [INF]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n n6 = 6\n n9 = 9\n if i+1 < N+1:\n dp[i+1] = min(dp[i+1],dp[i]+1)\n while n6 < N+1:\n if i+n6 < N+1:\n dp[i+n6] = min(dp[i+n6],dp[i]+1)\n n6 *= 6\n while n9 < N+1:\n if i+n9 < N+1:\n dp[i+n9] = min(dp[i+n9],dp[i]+1)\n n9 *= 9\n\nprint(dp[N])']
['Wrong Answer', 'Accepted']
['s018757194', 's119873621']
[5988.0, 3828.0]
[955.0, 828.0]
[331, 379]
p03329
u774539708
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())\ndef money(n):\n dp=[n]*(n+1)\n dp[0]=0\n for i in range(1,n+1):\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=6\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=9\n print(dp)\n return dp[n]\nprint(money(N))', 'N=int(input())\ndef money(n):\n dp=[n]*(n+1)\n dp[0]=0\n for i in range(1,n+1):\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=6\n power=1\n while power<=i:\n dp[i]=min(dp[i],dp[i-power]+1)\n power*=9\n return dp[n]\nprint(money(N))']
['Wrong Answer', 'Accepted']
['s332209529', 's229863063']
[4848.0, 3828.0]
[393.0, 390.0]
[339, 325]
p03329
u776929617
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\n\nN = int(input())\n\nans = 0\n\nc = int(math.pow(N, (1.0/9.0))+1)\n\nwhile c > 0:\n\tif N >= 9**c:\n\t\tN-=9**c\n\t\tans+=1\n\t\tc+=1\n\tc-=1\n\t\nc = int(math.pow(N, (1.0/6.0))+1)\nwhile c > 0:\n\tif N >= 6**c:\n\t\tN-=6**c\n\t\tans+=1\n\t\tc+=1\n\tc-=1\nprint(ans+N)', '\nN = int(input())\n\nans = 100000000000000\nfor i in range(N+1):\n\ttmp_ans = 0\n\tn6 = i\n\twhile n6 > 0:\n\t\ttmp_ans += (n6%6)\n\t\tn6 = n6//6\n\tn9 = N-i\n\twhile n9 > 0:\n\t\ttmp_ans += (n9%9)\n\t\tn9 = n9//9\n\tif tmp_ans < ans:\n\t\tans = tmp_ans\n\t\t\nprint(ans)']
['Wrong Answer', 'Accepted']
['s192574113', 's260423804']
[3064.0, 3064.0]
[17.0, 292.0]
[243, 237]
p03329
u780962115
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.
['lists=[0 for j in range(1000)]\nn=int(input())\nnums=0\nwhile nums!=n+1:\n \n \n if nums<6:\n lists[nums]==nums\n nums=+1\n elif nums==6 or nums==36 or nums==216 or nums==1296 or nums==7726 or nums==46656:\n lists[nums]==1\n nums+=1\n elif nums==9 or nums==81 or nums==729 or nums==6561 or nums==59049:\n lists[nums]==1\n nums+=1\n else:\n order6=0\n order9=0\n for k in range(6):\n if 6**(k+1)< nums <6**(k+2):\n order6=k+1\n \n \n break\n else:\n continue\n for j in range(5):\n if 9**(j+1) <nums< 9**(j+2):\n order9=j+1\n \n \n break\n else:\n continue\n lists[nums]=min(min(lists[nums-6**(k)] for k in range(0,order6+1)),min(lists[nums-9**(j)] for j in range(0,order9+1)))\n nums+=1\n \nprint(lists[n])', 'lists=[]\nn=int(input())\nnums=0\nwhile nums<=n+1:\n \n \n if nums<6:\n lists.append(nums)\n nums=+1\n elif nums==6 or nums==36 or nums==216 or nums==1296 or nums==7726 or nums==46656:\n lists.append(1)\n nums+=1\n elif nums==9 or nums==81 or nums==729 or nums==6561 or nums==59049:\n lists.append(1)\n nums+=1\n else:\n order6=0\n order9=0\n for k in range(6):\n if 6**(k+1)< nums <6**(k+2):\n order6=k+1\n \n break\n \n else:\n continue\n \n for j in range(5):\n if 9**(j+1) <nums< 9**(j+2):\n order9=j+1\n \n break\n else:\n continue\n \n add=min(min(lists[n-6**(k)] for k in range(0,order6+1)),min(lists[n-9**(j)] for j in range(0,order9+1)))\n lists.append(add)\n nums+=1\nprint(lists)', '#strange bank\nn=int(input())\ndp=[10**10 for i in range(200000)]\ndp[0]=0\nfor i in range(1,100001):\n for j in range(9):\n num=3**j\n if i>=6**j and dp[i-6**j]+1<dp[i]:\n dp[i]=dp[i-6**j]+1\n if i>=9**j and dp[i-9**j]+1<dp[i]:\n dp[i]=dp[i-9**j]+1\nprint(dp[n])']
['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s051347168', 's055662989', 's180034016']
[3064.0, 102448.0, 4724.0]
[2109.0, 2108.0, 1218.0]
[1101, 1099, 298]