TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
n=int(input())
s=[]
t=[]
p=0
def f9(n,p):
    while n>=9:
        n//=9
        p+=1
        f9(n,p)
    return p
def f6(n,p):
    while n>=6:
        n//=6
        p+=1
        f6(n,p)
    return p    
s.append((n,0))
while s:
    print(s)
    a=s[0][0]
    b=s[0][1]
    if a<6:
        t.append(b+a)
    else:
        p=0
        s.append((a-9**f9(a,p),b+1))
        p=0
        s.append((a-6**f6(a,p),b+1))
    s.pop(0)    
print(min(t))




a=int(input())
p=0
def f9(n,b):
    while n>=9:
        n//=9
        b+=1
        return f9(n,b)
    return b
def f6(n,b):
    while n>=6:
        n//=6
        b+=1
        return f6(n,b)
    return b
while a:
    b,c=0,0
    s=max(1,9**f9(a,b),6**f6(a,c))
    print(s,a)
    a-=s
    p+=1
print(p)    
    
    

n=int(input())
s=[]
t=1000
p=0
def f9(n,p):
    while n>=9:
        n//=9
        p+=1
        f9(n,p)
    return p
def f6(n,p):
    while n>=6:
        n//=6
        p+=1
        f6(n,p)
    return p    
s.append((n,0))
while s:
    a=s[0][0]
    b=s[0][1]
    if a<6:
    t=min(t,b+a)
    if t>=b+1:
        p=0
        s.append((a-9**f9(a,p),b+1))
        p=0
        s.append((a-6**f6(a,p),b+1))
    s.pop(0)    
print(t)




N=int(input())
dp=[0]*(N+1)
def f(n):
    p=0
    q=0
    m=n
    while n>=1:
        n//=9
        p+=1
    while m>=1:
        m//=6
        q+=1
    s=[]
    for i in range(p):
        s.append(9**i)
    for j in range(q):    
        s.append(6**j)
    s.pop(0)    
    return s
for i in range(1,N+1):
    dp[i]=dp[i-1]+1
    for j in f(i):
        dp[i]=min(dp[i-j]+1,dp[i])
print(dp[N])        
        

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())

def num_withdraw_ll(N):
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(1, N):
        dp[n + 1] = min(dp[n + 1], dp[n] + 1)
        coin = 6
        while coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 6
        coin = 9
        while coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 9
    return dp[N]    

print(num_withdraw_ll(N))

N = int(input())

ef num_withdraw_ll(N):
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(0, N):
        dp[n + 1] = min(dp[n + 1], dp[n] + 1)
        coin = 6
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 6
        coin = 9
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 9
    return dp[N]

print(num_withdraw_ll(N))

N = int(input())

def num_withdraw_ll(N):
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(1, N):
        dp[n + 1] = min(dp[n + 1], dp[n] + 1)
        coin = 6
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 6
        coin = 9
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 9
    return dp[N]    

print(num_withdraw_ll(N))

N = int(input())

def num_withdraw_ll(N):
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(0, N):
        dp[n + 1] = min(dp[n + 1], dp[n] + 1)
        coin = 6
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 6
        coin = 9
        while n + coin <= N:
            dp[n + coin] = min(dp[n + coin], dp[n] + 1)
            coin *= 9
    return dp[N]

print(num_withdraw_ll(N))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#encoding utf-8

n = int(input())

withdraw_list = []
withdraw_list.append(1)
# 6
count = 0
while (1):
    count += 1
    if 6**count <=10**5:
        withdraw_list.append(6**count)
    else:
        break
count = 0
while (1):
    count += 1
    if 9**count <=10**5:
        withdraw_list.append(9**count)
    else:
        break
withdraw_list.sort()
withdraw_list.reverse()
print(withdraw_list)

wi_cou = 0
while (1):
    for i in range(len(withdraw_list)):
        if withdraw_list[i] <= n:
            n -= withdraw_list[i]
            wi_cou += 1
            # print(withdraw_list[i])
            break

    if n == 0:
        break

print(wi_cou)


# encoding:utf-8
import copy
import numpy as np
import random
import queue

n = int(input())

withdraws = [1]
price = 1
while True:
    price *= 6
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break

price = 1
while True:
    price *= 9
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break


withdraws.sort()
# print(withdraws)
money = 0
count = 0



'''
que = queue.Queue()

que.put((0,0))
memory = []
while not(que.empty()):
    money,count = que.get()
    print(money,count)
    if money > n:
        pass
    else:
        for withdraw in withdraws:
            if money+withdraw == n:
                print(count+1)
                exit()

            elif money+withdraw in memory:
                pass
            else:
                memory.append(money+withdraw)
                next = (money+withdraw,count+1)
                que.put(next)
'''
'''
# 分割

ans = 10**10
if n < 6:
    ans = n
for i in range(n+1):
    t = i
    count = 0
    while t>0:
        count += t%6
        t = t//6
    t = n - i
    while t>0:
        count += t%9
        t = t//9
    # print(ans)
    ans =min(ans,count)

print(ans)

'''

max_num = 10**5
dp = [99999999]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    # print(dp)
    dp[i] = dp[i-1]+1
    k = 6
    while i>=k:
        dp[i] = min(dp[i],dp[i-k]+1)
        k *= 6
    k = 9
    while i>=k:
        dp[i] = min(dp[i],dp[i-k]+1)
        k *= 9



print(dp[n])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
N,C = map(int,input().split())
D=[[int(i) for i in input().split()] for j in range(C)]
co=[[int(i) for i in input().split()] for j in range(N)]
d0= defaultdict(int)
d1= defaultdict(int)
d2= defaultdict(int)
for i in range(N):
    for j in range(N):
        if (j+i) %3==0:
            d0[co[j][i]] +=1
        elif (j+i)%3==1:
            d1[co[j][i]] +=1
        else:
            d2[co[j][i]] +=1
A0=[]
A1=[]
A2=[]
for i in range(C):
    iwa =0
    for s in d0.keys():
        iwa += D[s-1][i-1]*d0[s] 
    A0.append([iwa,i])
for i in range(C):
    iwa =0
    for s in d1.keys():
        iwa += D[s-1][i-1]*d1[s] 
    A1.append([iwa,i])
for i in range(C):
    iwa =0
    for s in d2.keys():
        iwa += D[s-1][i-1]*d2[s] 
    A2.append([iwa,i])

A0.sort()
A1.sort()
A2.sort()
B=[[] for i in range(3)]
for i in range(3):
    B[0].append(A0[i])
for i in range(3):
    B[1].append(A1[i])
for i in range(3):
    B[2].append(A2[i])
ans =[]
for i in range(3):
    for j in range(3):
        for k in range(3):
            if B[0][i][1] ==B[1][j][1]:
                continue
            if B[0][i][1] ==B[2][k][1]:
                continue
            if B[1][j][1] ==B[2][k][1]:
                continue
            ans.append(B[0][i][0]+B[1][j][0]+B[2][k][0])
print(min(ans))


N = int(input())
def shin(n,q):
    s = n
    a = 0
    while(s>0):
        t=s%q
        a +=t
        s=(s-t)//q
    return a
ans = N
for i in range(N+1):
    c=shin(i,6)+shin(N-i,9)
    ans = min(ans,c)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8


# 15:00-


def main():
    N = int(input())

    ans = 0

    while True:
        if N < 6:
            ans += N
            return ans

        n = 0
        while 9**(n+1) <= N:
            n += 1
        
        m = 0
        while 6**(m+1) <= N:
            m += 1
        
        print(N, -9**n, -6**m)
        N -= max(9**n, 6**m)
        ans += 1


print(main())


# coding: utf-8


# 15:00-


def main():
    N = int(input())
    INF = 10**6

    moneys = [1]

    n = 1
    while 9**n <= N:
        moneys.append(9**n)
        n += 1

    n = 1
    while 6**n <= N:
        moneys.append(6**n)
        n += 1

    dp = [[INF] * (N+1) for _ in range(len(moneys))]
    for i in range(len(dp)):
        dp[i][0] = 0
    
    for i in range(len(dp)):
        for j in range(N+1):
            if j + moneys[i] <= N:
                dp[i][j+moneys[i]] = min(dp[i][j]+1, dp[i][j+moneys[i]])
                if i+1 < len(dp):
                    dp[i+1][j+moneys[i]] = min(dp[i][j]+1, dp[i+1][j+moneys[i]])
            if i+1 < len(dp):
                dp[i+1][j] = min(dp[i][j], dp[i+1][j])
    
    return dp[-1][-1]


print(main())


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#ABC099C
N=int(input())
#1:6 2:36 3:216 4:1296 5:7776 6:46656 7:9 8:81 9:729 10:6561 11:59049
#dv=[6,36,216,1296,7776,46656,9,81,729,6561,59049]
lm=[6, 6, 6, 6, 6, 3, 9, 9, 9, 9, 2]
#ans=[0]*11
ans=0
sums=0
for i in range(lm[0]):
    for j in range(lm[1]):
        for k in range(lm[2]):
            for l in range(lm[3]):
                for m in range(lm[4]):
                    for n in range(lm[5]):
                        for o in range(lm[6]):
                            for p in range(lm[7]):
                                for q in range(lm[8]):
                                    for r in range(lm[9]):
                                        for s in range(lm[10]):
                                            sums=i*6+j*36+k*216+l*1296+m*7776+n*46656+o*9+p*81+q*729+r*6561+s*59049
                                            if N-sums>=0:
                                                ans_tmp=N-sums+i+j+k+l+m+n+o+p+q+r+s
                                                if ans_tmp<ans:
                                                    ans=ans_tmp
print(ans)

#ABC099C
N=int(input())
i=0
t=0
ans=N
for i in range(N+1):
    nine = 0
    six = 0
    t=i
    while (t>0):
        nine+=t%9
        t//=9
    t=N-i
    while (t>0):
        six+=t%6
        t//=6
    if ans>nine+six:
        ans=nine+six
print(ans)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**7],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])


N = int(input())
dp = [float('inf')] * (2*10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**7],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])


N = int(input())


dp = [float('inf')] * (N + 1)
dp[0] = 0
operates = sorted([1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049])
for i in range(N):
    for ope in operates:
        if i + ope > N:
            break
        dp[i + ope] = min(dp[i + ope], dp[i] + 1)

print(dp[N])


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def calc(money, count):
    if money == n:
        return count
    if money > n:
        return inf
    a = [calc(money+i, count+1) for i in num]
    return min(a)
import bisect
inf = 10 ** 10
num = [6 ** i for i in range(7)] + [9 ** i for i in range(1, 6)]
n = int(input())
num = num[:bisect.bisect_left(num, n)]
calc(0, 0)

n = int(input())
inf = 10 ** 9
dp = [inf] * (n+1)
dp[0] = 0
for i in range(n):
    dp[i+1] = min(dp[i]+1, dp[i+1])
    j, k = 1, 1
    while (i + 6**j) <= n:
        dp[i + 6**j] = min(dp[i]+1, dp[i + 6**j])
        j += 1
    while (i + 9**k) <= n:
        dp[i + 9**k] = min(dp[i]+1, dp[i + 9**k])
        k += 1
print(dp[-1])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
dp=[i for i in range(n+1)]
k=0
lw=[6,9]
for w in lw:
    while w**k<=n:
        k+=1
        q=w**k
        for j in range(n+1-q):
            dp[j+q]=min(dp[j]+1,dp[j+q])
            if j==q*w:
                break
print(dp[n])

n=int(input())
dp=[i for i in range(n+1)]
k=0
lw=[6,9]
for w in lw:
    while w**k<=n:
        k+=1
        q=w**k
        for j in range(n+1-q):
            dp[j+q]=min(dp[j]+1,dp[j+q])
            if j==q*(w-1):
                break
print(dp[n])

n=int(input())
dp=[i for i in range(n+1)]
lw=[6,9]
for w in lw:
    k=1
    while w**k<=n:
        q=w**k
        for j in range(n+1-q):
            dp[j+q]=min(dp[j]+1,dp[j+q])
        k+=1
print(dp[n])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

#N = int(input())
N = 44852
#candidates = [1, 6, 36, 216, 1296, 7776, 46656,
#              9, 81, 729, 6561, 59049]
candidates = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776,
              46656, 59049]
cnt = 0
while True:
    if N == 0:
        break
    for i, cand in enumerate(candidates):
        print(N, cand)
        if N-cand < 0:
            now_draw = candidates[i-1]
            candidates = candidates[:i]
            N -= now_draw
            cnt += 1
            break
        if i == len(candidates) - 1:
            now_draw = candidates[-1]
            N -= now_draw
            cnt += 1
            break
            
print(cnt)






# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
#N = 44852
#candidates = [1, 6, 36, 216, 1296, 7776, 46656,
#              9, 81, 729, 6561, 59049]
candidates = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776,
              46656, 59049]
cnt = 0
while True:
    if N == 0:
        break
    for i, cand in enumerate(candidates):
        print(N, cand)
        if N-cand < 0:
            now_draw = candidates[i-1]
            candidates = candidates[:i]
            N -= now_draw
            cnt += 1
            break
        if i == len(candidates) - 1:
            now_draw = candidates[-1]
            N -= now_draw
            cnt += 1
            break
            
print(cnt)






# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

ans = [0] * 100100
ans[0] = 0

n = int(input())
#n = 127
for i in range(1,n+1):
    cand1 = ans[i-1]
    cand2 = 100001
    cand3 = 100001
    x = 6
    while (x<=i):
        #cand2 = min(ans[i-x], cand2)
        cand2 = ans[i-x]
        x=6*x
    y = 9
    while (y<=i):
        #cand3 = min(ans[i-y], cand3)
        cand3 = ans[i-y]
        y=9*y
    ans[i] = min(cand1,cand2,cand3) + 1


print(ans[n])



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
#n = int(input())
n = 44852
inf = float('inf')

dp = [inf]*(n+10000000)
dp[0]=0
#print(dp)
#print(len(dp))

def motome(target):
    tmp = []
    a = int(math.log(target,9))
    b = int(math.log(target,6))
    for i in range(a+1):
        tmp.append(6**i)
    for j in range(b+1):
        tmp.append(9**j)
    #print(tmp) [1, 6, 36, 1, 9, 81]
    #print(dp)
    for k in range(1,target+1):
        for t in sorted(list(set(tmp))):
            if k-t>=0:
                dp[k] = min(dp[k],1 + dp[k-t])
                '''
                try:
                    dp[k] = min(dp[k],1 + min([dp[k-t] for t in tmp]))
                except:
                    print(len(dp),dp[k-t],dp[k])
                    pass
                '''
        #print(k)
        #print([t for t in tmp])
        #print([dp[k-t] for t in tmp])

motome(n)
#print(dp[n-1])
print(dp[n])

n = int(input())
inf = float('inf')
dp = [inf]*(n+1)
dp[0] = 0
a = 1
b = 6
c = 9
for i in range(1,n+1):
    if i>=b*6:
        b*=6
    if i>=c*9:
        c*=9
    if i<6:
        dp[i] = i
    elif i<9:
        dp[i] = min(dp[i],dp[i-b]+1)
    else:
        dp[i] = min(dp[i],dp[i-b]+1,dp[i-c]+1)
print(dp[n])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
ans=N
def func1():
    global ans
    for i in range(N+1):
        cnt=0
        t=i
        while(t>0):
            cnt+=t%6
            t/=6
            t=int(t)
        t=N-i
        while(t>0):
            cnt+=t%9
            t/=9
            t=int(t)
        print(cnt)
        if(ans>cnt):
            ans=cnt
    return ans

func1()
print(ans)

N=int(input())
a,b,cnt=0,0,0
def nine():
    global a
    for i in range(N):
        if 9**i<=N:
            a=9**i
        else:
            break
def six():
    global b
    for i in range(N):
        if 6**i<=N:
            b=6**i
        else:
            break

for i in range(N):
    nine()
    six()
    N-=max(a,b)        
    cnt+=1
    print(N,a,b,cnt)
    if N==0:
        break
print(cnt)

N=int(input())
ans=N
def func1():
    global ans
    for i in range(N+1):
        cnt=0
        t=i
        while(t>0):
            cnt+=t%6
            t/=6
            t=int(t)
        t=N-i
        while(t>0):
            cnt+=t%9
            t/=9
            t=int(t)
        if(ans>cnt):
            ans=cnt
    return ans

func1()
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
c9 = 0
m = n
while(m>1):
  m = m//9
  if m !== 0: 
  	pass
  else:
    c9 += 1
m = n - 9**c9

c6 = 0
while(m>1):
  m = m//9
  if m !== 0: 
  	pass
  else:
    c6 += 1
    
c1 = n - (9**c9+c6**c6)
print(c9+c6+c1) 

n = int(input())
l9 = [9**i for i in range(0,6)]
l6 = [6**i for i in range(0,6)]
l = sorted(l9+l6,reverse=True)
print(l)
i = 0
ans = 0
while(n>0):
  if n - l[i] < 0:
    i += 1
    n = n
  else:
    ans+=1
    #print(n,"-",l[i],"=",n-l[i],"ans=",ans)
    n = n - l[i]
    
print(ans)

def main():
    import bisect
    n = int(input())
    m = [10 ** 5 for _ in range(n + 1)]
    m[0] = 0
    a = [6 ** i for i in range(7)]
    b = [9 ** i for i in range(6)]
    c = sorted(a + b)
    for i in range(1, n + 1):
        j = bisect.bisect_right(c, i)
        k = [1 + m[i - x] for l, x in enumerate(c) if l < j]
        m[i] = min(k)

    print(m[-1])


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=[1]
n=int(input())
for i in range(1,7):
    s.append(6**i)
for i in range(1,6):
    s.append(9**i)
s.sort(reverse=True)
print(s)
c=0;i=0
while n>0:
    if n<s[i]:
        i+=1
    else:
        n-=s[i]
        c+=1
print(c)


a=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
n=int(input())
dp=[0]*(n+1)
dp[0]=0
for i in range(1,n+1):
    s=[]
    for j in a:
        if i-j<0:
            continue
        s.append(dp[i-j])
    dp[i]=min(s)+1
print(dp[-1])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import numpy as np


N = int(input())

dp = np.zeros(N,dtype=np.int)
dp[0] = 1

six_count = 1
nine_count = 1

for i in range(1,N):
    a = dp[i-1] + 1

    if i == pow(6,six_count):
        six_count = six_count + 1
    if i == pow(9,nine_count):
        nine_count = nine_count + 1

    b = float('inf')
    c = float('inf')
    if i>=6:
        for _ in range(six_count):
            b = min(b,dp[i-pow(6,_)]+1)

    if i>=9:
        for _ in range(nine_count):
            c = min(c,dp[i-pow(9,_)]+1)

    dp[i] = min(a,b,c)

print(dp[N-1])


import sys
import numpy as np


N = int(input())

dp = [float('inf')]*(N+1)
dp[0] = 0
for i in range(1,N+1):

    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 6

    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 9
print(dp[N])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
num = int(input())
res = num
for i in range(num):
    cc = 0
    t = i
    while(t > 0):
        cc += t%6
        t //=6
    t = num-i
    while(t > 0):
        cc += t%9
        t //=9
    if res > cc:
        print('res:',res)
        print('cc:',cc)
        res = cc

print(res)


num = int(input())
res = num
for i in range(num):
    cc = 0
    t = i
    while(t > 0):
        cc += t%6
        t //=6
    t = num-i
    while(t > 0):
        cc += t%9
        t //=9
    if res > cc:
        print('res:',res)
        print('cc:',cc)
        res = cc

print(res)


num = int(input())
res = num
for i in range(num+1):
    cc = 0
    t = i
    while(t > 0):
        cc += t%6
        t //=6
    t = num-i
    while(t > 0):
        cc += t%9
        t //=9
    if res > cc:
        res = cc

print(res)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

dp = [0]*100001
for i in range(1, n+1):
    candi = []
    for j in lst:
        if i >= j:
            candi.append(dp[i-j]+1)
    dp[i] = min(candi)
print(dp[i])

n = int(input())

lst = []
for i in range(7):
    lst.append(6**i)
for i in range(1, 6):
    lst.append(9**i)

dp = [0]*100001
for i in range(1, n+1):
    candi = []
    for j in lst:
        if i >= j:
            candi.append(dp[i-j]+1)
    dp[i] = min(candi)
print(dp[i])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
ans=10**10
dp=[0]*100001
for i in range(1,n+1):
  tmp=[dp[i]+1]
  if i>=6**1:
    tmp.append(dp[i-6**1]+1)
  if i>=9**1:
    tmp.append(dp[i-9**1]+1)
  if i>=6**2:
    tmp.append(dp[i-6**2]+1)
  if i>=9**2:
    tmp.append(dp[i-9**2]+1)
  if i>=6**3:
    tmp.append(dp[i-6**3]+1)
  if i>=9**3:
    tmp.append(dp[i-9**3]+1)
  if i>=6**4:
    tmp.append(dp[i-6**4]+1)
  if i>=9**4:
    tmp.append(dp[i-9**4]+1)
  if i>=6**5:
    tmp.append(dp[i-6**5]+1)
  if i>=9**5:
    tmp.append(dp[i-9**5]+1)
  if i>=6**6:
    tmp.append(dp[i-6**6]+1)
  if i>=9**6:
    tmp.append(dp[i-9**6]+1)
  dp[i]=min(tmp)
print(dp[n])

n=int(input())
ans=10**10
dp=[0]*100001
for i in range(1,n+1):
  tmp=[dp[i-1]+1]
  if i>=6**1:
    tmp.append(dp[i-6**1]+1)
  if i>=9**1:
    tmp.append(dp[i-9**1]+1)
  if i>=6**2:
    tmp.append(dp[i-6**2]+1)
  if i>=9**2:
    tmp.append(dp[i-9**2]+1)
  if i>=6**3:
    tmp.append(dp[i-6**3]+1)
  if i>=9**3:
    tmp.append(dp[i-9**3]+1)
  if i>=6**4:
    tmp.append(dp[i-6**4]+1)
  if i>=9**4:
    tmp.append(dp[i-9**4]+1)
  if i>=6**5:
    tmp.append(dp[i-6**5]+1)
  if i>=9**5:
    tmp.append(dp[i-9**5]+1)
  if i>=6**6:
    tmp.append(dp[i-6**6]+1)
  if i>=9**6:
    tmp.append(dp[i-9**6]+1)
  dp[i]=min(tmp)
print(dp[n])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
cnt = 0
n = int(input())
res = n - n%9
cnt += int(res/9)
res = res - res%6
cnt += int(res/6)
cnt += res
print(cnt)

N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
list = []
for i in [6,5,4,3,2,1]:

    for r in [9,6,]:
        while n > r**i:
            n = n - r**i
            list.append(r**i)
            print(n)


length = len(list) + n
print(length)


n = int(input())
res = n
ans = 0
for i in range(n+1):
    t = i
    cc = 0
    while t >= 1:
        cc = cc + t % 6
        t = t // 6

    t = n-i
    while t >= 1:
        cc = cc + t%9
        t = t // 9


    if res > cc:
        res = cc

print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from math import log

N = int(input())


def func(N, a):
    index = int(log(N) / log(a))
    return a ** index


def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    elif N < 9:
        times = 1 + (N - 6)
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return 1 + N1
        else:
            return 1 + N2

print(search_times_re(N))

N = int(input())
ans = N
for i in range(0, N + 1, 6):
    cnt = 0
    j = N - i
    while i > 0:
        cnt += i % 6
        i //= 6
    while j > 0:
        cnt += j % 9
        j //= 9
    ans = min(ans, cnt)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def times(money, mod):
  ans = 0
  x = 1
  while( x * mod < money):
    x *= mod
  while(money > mod):
    ans += money // x
    money = money % x
    x = x // mod
  return(ans + money)

a = []
b = []
for i in range(100001):
  a.append(times(i,6))
  b.append(times(i,9))

c = []
n = int(input())
for i in range(n):
  c.append(a[i]+b[n-i])
print(min(c))

def times(money, mod):
  ans = 0
  while(money != 0):
    ans +=  money % mod
    money = money // mod
  return ans

c = []
n = int(input())
for i in range(n+1):
  c.append(times(i,6)+times(n-i,9))
print(min(c))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from bisect import bisect_right
N = int(input())
c = 0
roku = [6**i for i in range(1,7)]
kyu = [9**i for i in range(1,6)]
able = sorted([0,1] + roku + kyu)
print(able)
while N != 0:
    N = N - able[bisect_right(able,N)-1]
    c += 1
print(c)

from bisect import bisect_right
N = int(input())
c = 0
def croku(N):
    roku =[0,1] + [6**i for i in range(1,7)]
    c = 0
    while N != 0:
        N = N - roku[bisect_right(roku,N)-1]
        c += 1
    return c

def ckyu(N):
    kyu = [0,1] + [9**i for i in range(1,6)]
    c = 0
    while N != 0:
        N = N - kyu[bisect_right(kyu,N)-1]
        c += 1
    return c

K = 10**5
for i in range(0,N+1):
    K = min(K, croku(i) + ckyu(N-i))
print(K)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
c = [1]
for i in [6,9]:
    j = 0
    k = 0
    while True:
        j += 1
        k = i**j
        if k > 10**5:
            break
        c += [k]
print(c)
c.sort(reverse=True)
flag = 0
for i in range(len(c)):
    m = int(n//c[i])
    n %= c[i]
    flag += m
    # print('withdraw',c[i],m,'times and sum is',flag)
print(flag)



#D

def sixnine(m):
    ret=[]
    for n in [6,9]:
        tmp=1
        while True:
            tmp*=n
            if tmp<=m:
                ret.append(tmp)
            else:
                break
    ret.sort()
    return ret


N=int(input())
dp=[0 for i in range(N+1)]
for i in range(1,N+1):
    if i<=5:
        dp[i]=i
        continue
    sn=sixnine(i)
    if i in sn:
        dp[i]=1
        continue
    ans=10**19
    for k in sn:
        ans=min(ans,dp[k]+dp[i-k])
    dp[i]=ans
# print(dp)
print(dp[-1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

ans = 0

mod_list = [59409, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6]

for i in mod_list:
	print(n // i)
	ans += n // i
	n = n % i

print(ans + n)

n = int(input())

ans = 0
mod_base = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
mod_list = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans_list = [0 for _ in range(100000)]

for mod in mod_base:
	ans_list[mod - 1] = 1

for i in range(10000):
	if ans_list[n - 1] != 0:
		break
	new_mod_list = []
	for j in mod_list:
		for k in mod_base:
			if j + k <= 100000 and ans_list[j + k - 1] == 0:
				new_mod_list.append(j + k)
				ans_list[j + k - 1] = i + 2
	mod_list = sorted(new_mod_list, reverse=True)

print(ans_list[n - 1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=n
for i in range(n+1):
  ni,si=i,n-i
  m=0
  while ni!=0:m+=ni%6;ni//=6
  while si!=0:m+=si%6;si//=6
  a=min(a,m)
print(a)

n=int(input())
a=n
for i in range(n+1):
  ni,si=i,n-i
  m=0
  while ni!=0:m+=ni%9;ni//=9
  while si!=0:m+=si%6;si//=6
  a=min(a,m)
print(a)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python3
# import math
n = int(input())

ans = [-1]*(n+1)

ans[0] = 0
for i in range(1, n):
    num = i
    data = ans[i-1]+1
    for j in range(8):
        index = i-6**j
        if index < 0:
            break
        data = min(data, ans[index]+1)
    for j in range(8):
        index = i-9**j
        if index < 0:
            break
        data = min(data, ans[index]+1)
    ans[i] = data
print(ans)


#!/usr/bin/env python3
# import math
n = int(input())

ans = [-1]*(n+1)

ans[0] = 0
for i in range(1, n+1):
    num = i
    data = ans[i-1]+1
    for j in range(8):
        index = i-6**j
        if index < 0:
            break
        data = min(data, ans[index]+1)
    for j in range(8):
        index = i-9**j
        if index < 0:
            break
        data = min(data, ans[index]+1)
    ans[i] = data
print(ans[-1])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
lst_take = []
max_val = 100000
used = []
for i in range(1,15):
  if 6 ** i <=  max_val:
    lst_take.append(6**i)
  if 9 ** i <= max_val:
    lst_take.append(9**i)  
lst_take = sorted(set(lst_take), reverse=True)
while True:
  if n==0:
    break
    
  flag = True
  for i in lst_take:
    if i <= n and i not in used:
      n -= i
      count += 1
      used.append(i)
      flag = False
      break
  if flag:
    count += n
    break
print(count)

import math
n = int(input())
count = 0
while count != 0:
  max_value = 1
  for i in range(1, n):
    if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):
    	max_value = max(max_value, i)
  n = n - max_value
  count += 1
print(count)

import math
n = int(input())
count = 0
lst = []
while n != 0:
  max_value = 1
  for i in range(1, n):
    if i in max_value:
      continue
    if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):
    	max_value = max(max_value, i)
  n = n - max_value
  lst.add(max_value)
  count += 1
print(count)

import math
n = int(input())
count = 0
while n != 0:
  max_value = 1
  for i in range(1, n+1):
    if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):
    	max_value = max(max_value, i)
  n = n - max_value
  lst.add(max_value)
  count += 1
print(count)

N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
dp = [100000000000 for _ in range(n+1)]
dp[0] = 0
for i in range(n):
    dp[i+1] = min(dp[i]+1,dp[i+1])
    six = 0
    nine = 0
    while (6**six < i):
        dp[i+1] = min(dp[(i+1) - 6**six] + 1,dp[i+1])
        six += 1
    while (9**nine < i):
        dp[i+1] = min(dp[(i+1) - 9**nine] + 1,dp[i+1])
        nine += 1
print(dp[-1])

n = int(input())
dp = [100000000000 for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
    dp[i] = min(dp[i-1]+1,dp[i])
    six = 0
    nine = 0
    while (6**six <= i):
        dp[i] = min(dp[i - 6**six] + 1,dp[i])
        six += 1
    while (9**nine <= i):
        dp[i] = min(dp[i - 9**nine] + 1,dp[i])
        nine += 1
print(dp[n])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
dpの基本形














n = int(input())
pre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]


dp = [n]*(n+1)

dp[0] = 0



for i in range(1,n+1):

	for j in pre_list:
		if i - j >= 0:
			dp[i] = min(dp[i],dp[i-j]+1)

print(dp[n])



n = int(input())
pre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
 

dp = [n]*(n+1)

dp[0] = 0
 
 

for i in range(1,n+1):

	for j in pre_list:
		if i - j >= 0:
			dp[i] = min(dp[i],dp[i-j]+1)
 
print(dp[n])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

#                         created: 2019-11-08 02:12:52(JST)
## internal modules
import sys
# import collections
import math
# import string

# import re
# import itertools
# import statistics
# import functools

## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    count = 0
    for _ in range(n):
        if n < 6:
            count += n
            break
        elif n >= 15 or 12 > n >= 6:
            n -= max(6 ** math.floor(math.log(n, 6)), 9 ** math.floor(math.log(n, 9)))
            count += 1
        elif 15 > n >= 12:
            n -= 6
            count += 1

        print(n)
    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()


import sys

def count(n, b):
    res = 0
    while n:
        res += n % b
        n //= b
    return res

n = int(sys.stdin.readline().rstrip())

def main():
    res = float('inf')
    for i in range(n + 1):
        res = min(res, count(i, 6) + count(n - i, 9))
    print(res)

if __name__ ==  '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
def dfs(cost, N):
    if N<6 :
        return cost+N
    else:
        ret0 = 6 ** math.floor(math.log(N, 6))
        ret1 = 9 ** math.floor(math.log(N, 9))
        return min(dfs(cost+1, N-ret0), dfs(cost+1, N-ret1))

N = int(input())

def dfs(cost, N):
    if N<6 :
        return cost+N
    else:
        ret0 = 6 ** math.floor(math.log(N, 6))
        ret1 = 9 ** math.floor(math.log(N, 9))
        if (ret0>1) and (ret1>1):
            return min(dfs(cost+1, N-ret0), dfs(cost+1, N-ret1))
        else:
            ret = max(ret0, ret1)
            return dfs(cost+1, N-ret)

N = int(input())
print(dfs(0, N))


N = int(input())
dp = {}
for n in range(N+1):
    if n == 0:
        dp[0] = 0
    else:
        res = n
        pow6 = 1
        while n - pow6 >= 0:
            res = min(res, dp[n-pow6] +1)
            pow6 *= 6
        pow9 = 1
        while n -pow9 >= 0:
            res = min(res, dp[n-pow9] +1)
            pow9 *= 9
        dp[n] = res
print(dp[N])

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
nl=[9**i for i in range(1,6)]
sl=[6**i for i in range(1,7)]
l = sorted(nl+sl)[::-1]
x=0
for i in l:
    while True:
        if i <=n:
            n=n-i
            x+=1
            print(n)
        else:
            break
print(x+n)


n=int(input())
nl=[9**i for i in range(1,6)]
sl=[6**i for i in range(1,7)]
l = sorted(nl+sl)[::-1]
print(l)
x=0
for i in l:
    while True:
        if i <=n:
            n=n-i
            x+=1
            print(n)
        else:
            break
print(x+n)


n=int(input())
nl=[9**i for i in range(1,6)][::-1]
sl=[6**i for i in range(1,7)][::-1]
a=n
for i in range(n+1):
    totals=0
    ps=i
    for j in sl:
        if ps >= j:
            totals+=ps//j
            ps= ps-ps//j*j
    totaln=0
    pn=n-i
    for k in nl:
        if pn >=k:
            totaln+= pn //k
            pn=pn-pn//k*k
    a=min(a,totals+totaln+ps+pn)
print(a)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
L=[1]
n=int(input())
x = 6
y = 9
while x <= n:
  L.append(x)
  x *= 6
while y <= n:
  L.append(y)
  y *= 9
L.sort()#[1,6,9,36,81]
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n+1):#0~81
  for j in L:#1,6,9
    dp[i+j] = min(dp[i+j],dp[i]+1)#dp=[0,1,...1,.1]
print(dp[n])

L=[1]
n=int(input())
x = 6
y = 9
while x <= n:
  L.append(x)
  x *= 6
while y <= n:
  L.append(y)
  y *= 9
L.sort()#[1,6,9,36,81]
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n+1):#0~81
  for j in L:#1,6,9
    if i+j <= n:
      dp[i+j] = min(dp[i+j],dp[i]+1)#dp=[0,1,...1,.1]
    else:
      break
print(dp[n])

Verdicts: Runtime Error

Accepted