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):
#-*-coding:utf-8-*-
from collections import deque

def nearest_num_six(n):
    temp = 1
    if n < 6:
        return n -1
    else:
        while n > temp:
            temp *= 6
        return n - temp // 6

def nearest_num_nine(n):
    temp = 1
    if n < 9:
        return n -1
    else:
        while n > temp:
            temp *= 9
        return n - temp // 9

def any_one(lists):
    if 1 in lists:
        return True
    else:
        return False

def main():
    
    N = int(input())
    q = deque([N])
    cnt = 0
    j = 1

    while not any_one(q):
        print(q)
        for i in range(j):
            n = q.popleft()
            q.append(nearest_num_six(n))
            q.append(nearest_num_nine(n))
        cnt += 1
        j *= 2

    print(cnt+1)
        

if __name__ == '__main__':
    main()

#-*-coding:utf-8-*-

def main(): 
    N = int(input()) 
    num_list = set([1]) 
    i = 1 
    j = 1 
    while 6 ** i <= N: 
        num_list.add(6 ** i) 
        i += 1 
    while 9 ** j <= N: 
        num_list.add(9 ** j)
        j += 1 
    num_list = list(num_list) 
    num_list.sort()

    dp = [] 

    for i in range(1, N+1): 
        if i in num_list: 
            dp.append(1) 
        else: 
            temp = [] 
            for k in num_list: 
                if i - k > 0: 
                    temp.append(i - k) 
            small_dp = [dp[x-1] for x in temp] 
            dp.append(min(small_dp) + 1) 

    print(dp[-1])

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):
n = int(input())

ans = 0
while n > 0:
    nine = 0
    while 9 ** nine <= n:
        nine += 1

    six = 0
    while 6 ** six <= n:
        six += 1

    print(n, max(9 ** (nine - 1), 6 ** (six - 1)))
    n -= max(9 ** (nine - 1), 6 ** (six - 1))
    ans += 1

print(ans)

n = int(input())

dp = [float("inf")] * (n + 1)

dp[0] = 0

for i in range(n):
    six = 1
    while i + six <= n:
        dp[i + six] = min(dp[i + six], dp[i] + 1)
        six *= 6

    nine = 1
    while i + nine <= n:
        dp[i + nine] = min(dp[i + nine], dp[i] + 1)
        nine *= 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):


import numpy as np
from collections import deque
#from copy import deepcopy

N = int(input())

## 6^6 < 1e5 < 6^7
## 9^5 < 1e5 < 9^6





drawable_6 = sorted([6, 6**2, 6**3, 6**4, 6**5, 6**6], reverse=True)
drawable_9 = sorted([9, 9**2, 9**3, 9**4, 9**5, 9**6], reverse=True)
solver = []

if N < 6:
  print(N)
  exit()

dq = deque()
dq.append((N,0,[[0,0],[0,0]])) 


loop_cnt = 0
while dq:
  loop_cnt += 1
  rest, cnt, draw_lst = dq.popleft()
  
  if rest < 6:
    solver.append(rest + cnt)
    continue
  
  if draw_lst[0][1] < 4:
    rest_afterdraw_6 = rest - drawable_6[draw_lst[0][0]]
    if rest_afterdraw_6 >= 0:
      new_draw_lst = [[draw_lst[0][0],draw_lst[0][1]+1],draw_lst[1]]
      dq.append((rest_afterdraw_6,cnt+1,new_draw_lst))
      
  
  if draw_lst[0][0] < 5:
    new_draw_lst = [[draw_lst[0][0]+1,0],draw_lst[1]]
    dq.append((rest,cnt,new_draw_lst))
    
  
  if draw_lst[1][1] < 4:
    rest_afterdraw_9 = rest - drawable_9[draw_lst[1][0]]
    if rest_afterdraw_9 >= 0:
      new_draw_lst = [draw_lst[0],[draw_lst[1][0],draw_lst[1][1]+1]]
      dq.append((rest_afterdraw_9,cnt+1,new_draw_lst))
      
  
  if draw_lst[1][0] < 5:
    new_draw_lst = [draw_lst[0],[draw_lst[1][0]+1,0]]
    dq.append((rest,cnt,new_draw_lst))
    

print(min(solver))
print('n_loop =', loop_cnt)








def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def Base_n_to_10(X,n):
    out = 0
    for i in range(1,len(str(X))+1):
        out += int(str(X)[-i])*(n**(i-1))
    return out


N = int(input())

after_draw_9 = []
for i in range(N // 9 + 1):
  cost_9 = sum(map(int, Base_10_to_n(9*i,9)))
  after_draw_9.append((N-9*i, cost_9))


solver = []
for i in range(len(after_draw_9)):
  cost_6 = sum(map(int, Base_10_to_n(after_draw_9[i][0], 6)))
  solver.append(after_draw_9[i][1] + cost_6)
  
#print(solver)
print(min(solver))

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

N = int(input())
ans = N

for N1 in range(N):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = math.floor(N1/6)
        print(N1)
    print(count)
    
    while N2 > 0:
        count += N2%9
        N2 = math.floor(N2/9)
    
    if ans > count:
        ans = count

print(ans)

N = int(input())
INF = 10**18

dp = [INF]*(N+1)
dp[0] = 0
for i in range(N+1):
    n6 = 6
    n9 = 9
    if i+1 < N+1:
        dp[i+1] = min(dp[i+1],dp[i]+1)
    while n6 < N+1:
        if i+n6 < N+1:
            dp[i+n6] = min(dp[i+n6],dp[i]+1)
        n6 *= 6
    while n9 < N+1:
        if i+n9 < N+1:
            dp[i+n9] = min(dp[i+n9],dp[i]+1)
        n9 *= 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):
N=int(input())
def money(n):
    dp=[n]*(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)
    return dp[n]
print(money(N))

N=int(input())
def money(n):
    dp=[n]*(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
    return dp[n]
print(money(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):
import math

N = int(input())

ans = 0

c = int(math.pow(N, (1.0/9.0))+1)

while c > 0:
	if N >= 9**c:
		N-=9**c
		ans+=1
		c+=1
	c-=1
	
c = int(math.pow(N, (1.0/6.0))+1)
while c > 0:
	if N >= 6**c:
		N-=6**c
		ans+=1
		c+=1
	c-=1
print(ans+N)


N = int(input())

ans = 100000000000000
for i in range(N+1):
	tmp_ans = 0
	n6 = i
	while n6 > 0:
		tmp_ans += (n6%6)
		n6 = n6//6
	n9 = N-i
	while n9 > 0:
		tmp_ans += (n9%9)
		n9 = n9//9
	if tmp_ans < ans:
		ans = tmp_ans
		
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):
lists=[0 for j in range(1000)]
n=int(input())
nums=0
while nums!=n+1:
    
    
    if nums<6:
        lists[nums]==nums
        nums=+1
    elif nums==6 or nums==36 or nums==216 or nums==1296 or nums==7726 or nums==46656:
        lists[nums]==1
        nums+=1
    elif nums==9 or nums==81 or nums==729 or nums==6561 or nums==59049:
        lists[nums]==1
        nums+=1
    else:
        order6=0
        order9=0
        for k in range(6):
            if 6**(k+1)< nums <6**(k+2):
                order6=k+1
                
                
                break
            else:
                continue
        for j in range(5):
            if 9**(j+1) <nums< 9**(j+2):
                order9=j+1
                
                
                break
            else:
                continue
        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)))
        nums+=1
        
print(lists[n])

lists=[]
n=int(input())
nums=0
while nums<=n+1:
    
    
    if nums<6:
        lists.append(nums)
        nums=+1
    elif nums==6 or nums==36 or nums==216 or nums==1296 or nums==7726 or nums==46656:
        lists.append(1)
        nums+=1
    elif nums==9 or nums==81 or nums==729 or nums==6561 or nums==59049:
        lists.append(1)
        nums+=1
    else:
        order6=0
        order9=0
        for k in range(6):
            if 6**(k+1)< nums <6**(k+2):
                order6=k+1
                
                break
                
            else:
                continue
                
        for j in range(5):
            if 9**(j+1) <nums< 9**(j+2):
                order9=j+1
                
                break
            else:
                continue
                
        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)))
        lists.append(add)
        nums+=1
print(lists)

#strange bank
n=int(input())
dp=[10**10 for i in range(200000)]
dp[0]=0
for i in range(1,100001):
    for j in range(9):
        num=3**j
        if i>=6**j and dp[i-6**j]+1<dp[i]:
            dp[i]=dp[i-6**j]+1
        if i>=9**j and dp[i-9**j]+1<dp[i]:
            dp[i]=dp[i-9**j]+1
print(dp[n])

Verdicts: Time Limit Exceeded

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):
def calc(x, base):
    res = 0
    while x:
        x, m = divmod(x, base)
        res += m
    return res

ans = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))

print(ans)

N = int(input())


def f(x, base):
    ret = 0
    while x:
        x, m = divmod(x, base)
        ret += m
    return ret

print(min([f(i, 6) + f(N - i, 9) for i in range(N + 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())

count = 0
numbers = sorted([9**5, 9**4, 9**3, 9**2, 9, 6**6, 6**5, 6**4, 6**3, 6**2, 6], reverse=True)

def search(n):
    for i in numbers:
        if i <= n:
            return i

def search_max(n):
    mincount = 1000
    inp = n
    for i in range(3):
        n = inp
        n -= 9*i
        mincount = min((i + n // 6 + n % 6), mincount)
    print(mincount)
    return mincount


for i in range(100):
    if 1 <= N <= 5:
        count += N
        break
    elif N == 0:
        break
    elif 5 < N < 35:
        count += search_max(N)
        break
    else:
        count += N // search(N)
        N %= search(N)

print(count)

n = int(input())
v = []
i = 6
while i<=n:
    v.append(i)
    i *= 6
i=9
while i <= n:
    v.append(i)
    i *= 9
v.sort(reverse=True)
dic = dict()
def dp(i, N):
    if i == len(v):
        return N
    if (i, N) not in dic:
        dic[(i, N)] = min(dp(i, N-v[i])+1, dp(i+1, N)) if N-v[i] >= 0 else dp(i+1, N)
    return dic[(i, N)]
print(dp(0, 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())

yen9=[9**i for i in range(5)]
yen6=[6**i for i in range(6)]
yen1=[1]

def withdraw(n,count):
  if n ==0:
    return count

  maxmoney = 0
  for i in range(5):
    if yen9[i] <= n:
      maxmoney = max(yen9[i],maxmoney)
      
  for i in range(6):
    if yen6[i] <= n:
      maxmoney = max(yen6[i],maxmoney)
      
  if maxmoney ==0:
    maxmoney = 1
  print(maxmoney)
  return withdraw(n-maxmoney,count+1)

print(withdraw(n,0))

n = int(input())
c = [1]
for i in range(6):
    c.append(6**(i+1))
for i in range(5):
    c.append(9**(i+1))
INF = float("inf")
 
dp = [INF]*(n+1)
dp[0] = 0
 
for i in range(len(c)):
    for j in range(n+1):
        if j - c[i] < 0:
            continue
        else:
            dp[j] = min(dp[j], dp[j - c[i]] + 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):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)



N = int(input())
dp=[inf]*(110000)
dp[0]=0
for n in range(N):
    pow6,pow9 = 1,1
    while pow6<=n:
        dp[n+po6] = min(dp[n+pow6],dp[n]+1)
        pow6 *= 6
    while pow9 <=n:
        dp[n+pow9] = min(dp[n+pow9],dp[n]+1)
        pow9 *= 9
print(dp[N])

from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)



N = int(input())
dp=[inf]*(110000)
for i in range(110000):
    dp[i] = N 
dp[0]=0
for n in range(N):
    pow6,pow9 = 1,1
    while n+pow6<=N:
        dp[n+pow6] = min(dp[n+pow6],dp[n]+1)
        pow6 *= 6
    while n+pow9 <=N:
        dp[n+pow9] = min(dp[n+pow9],dp[n]+1)
        pow9 *= 9
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):
# coding: utf-8
# Your code here!
N=int(input())

ans=[]

def saiki(tgt,i,count):
    print(i)
    num=0
    if i==0:
        ans.append(tgt+count)
        print("終わり")
        return
    while tgt-num*temp[i]:
        count+=num
        saiki(tgt-num*temp[i],i-1,count)
        num+=1
    return

temp=[1]
n=1
while N>=6**n:
    temp.append(6**n)
    n+=1
    
n=1
while N>=9**n:
    temp.append(9**n)
    n+=1

temp.sort()

saiki(N,len(temp)-1,0)

print(ans)
    


# coding: utf-8
# Your code here!
N=int(input())
l=[1]
count=0

def cand(num):
    i=1
    while N>=num**i:
        l.append(num**i)
        i+=1

def sub(target,index):
    i=0
    if target==0:
        
    elif index==0:
        
    while target-l[index]>0:
        sub(target-l[index]**i,l[index-1])
        

cand(6)
cand(9)

l.sort()
print(l)



# coding: utf-8
# Your code here!
N=int(input())

lis=[]

temp=6
while temp<=N:
    lis.append(temp)
    temp*=6

temp=9
while temp<=N:
    lis.append(temp)
    temp*=9

lis.sort(reverse=True)

dp=[10**9]*(N+1)
dp[0]=0

for item in lis:
    for i in range(N+1):
        if dp[i]!=10**9:
            if i+item<=N:
                dp[i+item]=min(dp[i]+1,dp[i+item])
            
ans=10**10
for index,item in enumerate(dp):
    ans=min(ans,item+N-index)
print(ans)



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())
li=[6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp = [i for i in range(100010)]
for a in li:
    for x in range(a,N+1):
        print(dp[x],dp[x-a]+1)
        dp[x] = min(dp[x],dp[x-a]+1)
print(dp[N])

N = int(input())
li=[6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp = [i for i in range(100010)]
for a in li:
    for x in range(a,N+1):
        dp[x] = min(dp[x],dp[x-a]+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=0

def solve(ans,n):
    sq_nine=1
    sq_six=1
    while n>=9**sq_nine:
        sq_nine+=1
    sq_nine-=1
    while n>=6**sq_six:
        sq_six+=1
    sq_six-=1
    if sq_nine==0 and sq_six==0:
        ans+=n
        return print(ans)
    else:
        n=n-max(9**sq_nine,6**sq_six)
        ans+=1
        print(max(9**sq_nine,6**sq_six),n)
        solve(ans,n)

solve(ans,n)

n=int(input())
ans=0

def solve(ans,n):
    sq_nine=1
    sq_six=1
    while n>=9**sq_nine:
        sq_nine+=1
    sq_nine-=1
    while n>=6**sq_six:
        sq_six+=1
    sq_six-=1
    if sq_nine==0 and sq_six==0:
        ans+=n
        return print(ans)
    else:
        n=n-max(9**sq_nine,6**sq_six)
        ans+=1
        print(max(9**sq_nine,6**sq_six),n)
        solve(ans,n)

solve(ans,n)

n=int(input())
dp=[float("inf")]*100010
dp[0]=0

for i in range(n+1):
    power = 1
    while i + power <= n:
        dp[i + power] = min(dp[i + power],dp[i] + 1)
        power *= 6
    power = 1
    while i + power <= n:
        dp[i + power] = min(dp[i + power],dp[i] + 1)
        power *= 9

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):
n = int(input())
import math

ans = []
for i in range(n+1):
    cnt6 = i
    cnt9 = n - i

    ans6 = 0
    ans9 = 0
    
    list6 = [6, 36, 216, 1296, 7776, 46656]
    list9 = [9, 81, 729, 6561, 59049]
    
    while cnt6 > 0:
        if cnt6 in list6:
            ans6 = 1
            break
        else:
            sho = 6**math.floor(math.log(cnt6, 6))
            ans6 += cnt6//sho
            cnt6= cnt6%sho
        
    while cnt9 > 0:
        if cnt9 in list9:
            ans9 = 1
            break
        else:
            sho2 = 9**math.floor(math.log(cnt9, 9))
            ans9 += cnt9//sho2
            cnt9 = cnt9%sho2

    ans.append(ans6+ans9)

print(min(ans))

n = int(input())

import math
def bank2(n):
    ans = 1
    list_six = [6**i for i in range(math.floor(math.log(n, 6)+1))]
    list_nine = [9**i for i in range(math.floor(math.log(n, 9)+1))]
    
    if n in list_six or n in list_nine:
        pass
    elif n == 12 or n == 13 or n == 14:
        ans += bank(n-6)
    elif n > 1:
        ans += min(bank(n - list_six[-1]), bank(n - list_nine[-1]))
        
    return ans

print(bank2(n))

n = int(input())
import math

ans = []
for i in range(n+1):
    cnt6 = i
    cnt9 = n - i
    ans6 = 0
    ans9 = 0
    
    while cnt6 > 0:
        sho = 6**math.floor(math.log(cnt6, 6))
        ans6 += cnt6//sho
        cnt6= cnt6%sho
        
    while cnt9 > 0:
        if cnt9 != 59049:
            sho2 = 9**math.floor(math.log(cnt9, 9))
        else:
            sho2=59049
        ans9 += cnt9//sho2
        cnt9 = cnt9%sho2
        
    ans.append(ans6+ans9)
    sho, sho2 = 0, 0
        
print(min(ans))

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):
import sys

input = sys.stdin.readline

n = int(input())
dp = [i for i in range(n+1)]

yen = [6 ** i for i in range(1, 8) if 6 ** i <= n]
yen += [9 ** i for i in range(1, 7) if 9 ** i <= n]

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

dp[-1]

import sys

input = sys.stdin.readline

n = int(input())
dp = [i for i in range(n+1)]

yen = [6 ** i for i in range(1, 8) if 6 ** i <= n]
yen += [9 ** i for i in range(1, 7) if 9 ** i <= n]

for i in range(n+1):
    for j in yen:
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + 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 math
from typing import List, Any

N: int = 44852

def nsin(N, base):
    if N == 0: return [0]
    Nsin: List[Any] = []
    for i in range((int(math.log(N,base)//1)+1)):
        ithdigit = N%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin

ans = N
for i in range(N):
    coins: int = sum(nsin(i,6)) + sum(nsin(N-i,9))
    if coins < ans: ans = coins

print(ans)

import math
N = int(input())
 
def Nsinpou(x, base):
    
    if x == 0: return [0]
    Nsin = []
    for i in range((round(math.log(x,base))+1)):
        ithdigit = x%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin
 
ans = N
for i in range(N+1):
    coins = sum(Nsinpou(i,6)) + sum(Nsinpou(N-i,9))
    if coins < ans:
        ans = coins
    
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):
N = int(input())
arr = [1]
result = 0

i = 6
while True:
	arr.append(i)
	i *= 6
	if i>N:
		break

i = 9
while True:
	arr.append(i)
	i *= 9
	if i>N:
		break

arr.sort()
arr.reverse()

while N>14:
	for i in arr:
		if i<=N:
			N -= i
			result += 1
			break
if N>=12:
	result += 2		
	N -= 12
elif N>=6:
	result += 1		
	N -= 6

print(result + N)

n = int(input())
six = []
for i in range(20):
    six.append(6 ** i)
nine = []
for i in range(20):
    nine.append(9 ** i)

res = 10 ** 10
for i in range(n + 1):
    j = n - i
    k = i
    # print(i,j )
    cnt = 0

    #6
    piv = 19
    while k > 0 and piv >= 0:
        cnt += k // six[piv]
        k %= six[piv]
        piv -= 1

    #9
    piv = 19
    while j > 0 and piv >= 0:
        cnt += j // nine[piv]
        j %= nine[piv]
        piv -= 1

    res = min(res,cnt)
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):
import sys
sys.setrecursionlimit(10**7) 

N = int(input())

def ch(x, y):
    cnt = 0
    while x**cnt <= y:
        cnt += 1
    return cnt

coin = [1]
for i in range(1, ch(6, N)):
    coin.append(6**i)

for i in range(1, ch(9, N)):
    coin.append(9**i)

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    
    res = n
    
    for c in coin:
        res = min(res, rec(n-c)+1)
    
    memo[n] = res
    return memo[n]

memo = [-1]*(10**5+10)
rec(N)
print(memo[N])

import sys
sys.setrecursionlimit(1000000)

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    
    res = n
    i = 1
    while 6**i <= n:
        res = min(res, rec(n - 6**i) + 1)
        i += 1
    
    i = 1
    while 9**i <= n:
        res = min(res, rec(n - 9**i) + 1)
        i += 1
    
    memo[n] = res
    return res

n = int(input())
memo = [-1]*(n+10)
print(rec(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):
N=int(input())
timeslis2=[0,]*(100000)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(N))

N=int(input())
numlist=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
timeslis2=[0,]*(100001)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(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):
n=int(input())
a=100000
for i in range(n+1):
    j=i
    count=0
    while i>0:
        count+=i%6
        i//=6
    while j>0:
        count+=j%9
        j//=9
    a=min(a,count)
print(a)


n=int(input())
a=100000
for i in range(n+1):
    j=n-i
    count=0
    while i>0:
        count+=i%6
        i//=6
    while j>0:
        count+=j%9
        j//=9
    a=min(a,count)
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):
N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    cnt+=t%6
    while t>0:
        t//=6
    j=N-i
    cnt+=j%9
    while j>0:
        j//=9
    ans = min(ans,cnt)
print(ans)

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())


def solve():
    global N
    ans = 0
    a = []
    values = sorted([1] + [pow(6, _) for _ in range(1, 10)] + [pow(9, _) for _ in range(1, 10)])
    while N > 0:
        if 12 <= N <= 14:
            ans += 2 + (N - 12)
            break
        if 30 <= N <= 32:
            ans += 4 + (N - 30)
            break
        else:
            for i in range(len(values)):
                if N < values[i]:
                    ans += 1
                    a.append((values[i - 1], N))
                    N -= values[i-1]
                    break
                elif N == values[i]:
                    ans += 1
                    a.append((values[i], N))
                    N -= values[i]
                    break
            if N == 0:
                break
    return ans

N = int(input())


def solve():
    global N
    ans = 0
    a = []
    values = sorted([1] + [pow(6, _) for _ in range(1, 10)] + [pow(9, _) for _ in range(1, 10)])
    while N > 0:
        if 12 <= N <= 17:
            ans += 2 + (N - 12)
            break
        else:
            for i in range(len(values)):
                if N < values[i]:
                    ans += 1
                    a.append((values[i - 1], N))
                    N -= values[i-1]
                    break
                elif N == values[i]:
                    ans += 1
                    a.append((values[i], N))
                    N -= values[i]
                    break
            if N == 0:
                break
    print(a, sum([_ for _, __ in a]))
    return ans


if __name__ == '__main__':
    print(solve())

N = int(input())
dp = [pow(10, 10)] * 100010
dp[0] = 0
dp[1] = 1
for n in range(100010):
    # for 6
    power = 1
    while n - power >= 0:
        dp[n] = min(dp[n], 1 + dp[n - power])
        power *= 6
    # for 9
    power = 1
    while n - power >= 0:
        dp[n] = min(dp[n], 1 + dp[n - power])
        power *= 9
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):
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

print(cost)
n = int(input())
count = 0
k = 0
while n > 0:
	if n == 14:
		count += 4
		n = 0
	elif n == 13:
		count += 3
		n = 0
	elif n == 12:
		count += 2
		n = 0
	elif n >= cost[k]:
		print(cost[k],n)
		n = n-cost[k]
		count += 1
	else:
		k += 1
print(count)

cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

n = int(input())
ans = [0 for i in range(100001)]
for i in range(len(cost)):
	ans[cost[i]] = 1
for i in range(1,100001):
	if ans[i] == 0:
		tempans = []
		for k in range(len(cost)):
			if i-cost[k] >= 0:
				tempans.append(ans[i-cost[k]])
		ans[i] = min(tempans)+1
print(ans[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=1000000000
for i in range(0,n+1,6):
  j=n-i
  while j:
    a=j%9
    j//=9
  while i:
    a+=i%6
    i//=6
  ans=min(a,ans)
print(ans)

n=int(input())
ans=1000000000
for i in range(0,n+1,6):
  j=n-i
  while j:
    a=j%9
    j//=9
  while i:
    a+=i%6
    i//=6
  ans=min(a,ans)
prgnt(ans)

n=int(input())
ans=0
while n:
  a,b=1,1
  while a*6>n:
    a*=6
  while b*9>n:
    b*=9
  n-=max(a,b)
  ans+=1
print(ans)
  
  

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


Verdicts: Wrong Answer

Runtime Error

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):
def main():
    """
    1 <= N <= 10^5
    """
    N = int(input())

    ans = f(N)
    print(ans)


def test_ans():
    N_ans = [
        (127, 4),
        (3, 3),
        (44852, 16),
    ]
    for N, ans in N_ans:
        assert rec(N) == ans


def rec(N):
    import sys
    sys.setrecursionlimit(10 ** 7)
    memo = [-1] * (N+1)

    def _rec(i):
        if i == 0:
            return 0
        if memo[i] != -1:
            return memo[i]

        ans = N
        p = 1
        while p <= i:
            #print(6, i, i-p)
            ans = min(ans, _rec(i-p) + 1)
            p *= 6
        p = 1
        while p <= i:
            #print(9, i, i-p)
            ans = min(ans, _rec(i-p) + 1)
            p *= 9

        memo[i] = ans

        return ans

    ans = _rec(N)
    return ans


if __name__ == '__main__':
    main()


def main():
    """
    1 <= N <= 10^5
    """
    N = int(input())

    ans = rec(N)
    print(ans)


def test_ans():
    N_ans = [
        (127, 4),
        (3, 3),
        (44852, 16),
    ]
    for N, ans in N_ans:
        assert rec(N) == ans


def rec(N):
    import sys
    sys.setrecursionlimit(10 ** 7)
    memo = [-1] * (N+1)

    def _rec(i):
        if i == 0:
            return 0
        if memo[i] != -1:
            return memo[i]

        ans = N
        p = 1
        while p <= i:
            #print(6, i, i-p)
            ans = min(ans, _rec(i-p) + 1)
            p *= 6
        p = 1
        while p <= i:
            #print(9, i, i-p)
            ans = min(ans, _rec(i-p) + 1)
            p *= 9

        memo[i] = ans

        return ans

    ans = _rec(N)
    return ans


if __name__ == '__main__':
    main()


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())
number_of_withdrawal=[]

def floor(float_number):
    integer = 0
    while integer < float_number:
        integer+=1
    if integer == float_number:
        return integer
    else:
        integer-=1
        return integer

for money_6 in range(0, N+1):
    money_9 = N-money_6

    latest = count_6_pow_number+count_9_pow_number

    i=0
    count_6_pow_number=0
    while pow(6,i)<=money_6:
        count_6_pow_number += (floor(money_6/pow(6,i)))%6
        i+=1
    j=0
    count_9_pow_number=0
    while pow(9,j)<=money_9:
        count_9_pow_number += (floor(money_9/pow(9,j)))%9
        j+=1

    # print(money_6, money_9, sum(count_6_pow_number), sum(count_9_pow_number))
    number_of_withdrawal= count_6_pow_number+count_9_pow_number
    if number_of_withdrawal < latest:
        res = number_of_withdrawal


print(res)

N=int(input())
money_list=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
dp=[0]
for i in range(1,N+1):
    dp.append(100000)

for i in range(1,N+1):
    for money in money_list:
        if i-money >= 0:
            dp[i]=min(dp[i-money]+1,dp[i])
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):
N=int(input())
dstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]
DP=[10**5]*(N*2)
DP[0]=0
for i in range(N+1):
  for j in dstb:
    DP[i+j]=min(DP[i+j], DP[i]+1)

print(DP[N])


N=int(input())
dstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]
DP=[10**5]*(10**5*2)
DP[0]=0
for i in range(N+1):
  for j in dstb:
    DP[i+j]=min(DP[i+j], DP[i]+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):
N=int(input())

#1*a+(6^b1)*b+(9^c1)*c
list=[99999]*(N+1)
list[0]=0
list[1]=1

max6end =True
i=0
while max6end:
    if N <= 6**i :
        max6=i
        max6end=False
    i+=1
max9end =True
i=0
while max9end:
    if N <= 9**i :
        max9=i
        max9end=False
    i+=1
    
print ("max6=%d max9=%d" % (max6,max9))
for n in range(1,N+1):
    list[n]=list[n-1]+1
    for i in range(1,max6+1):
        if n < 6**i:
            break
        else:
            if list[n] >= list[n-6**i]+1:
                list[n]=list[n-6**i]+1
    for i in range(1,max9+1):
        if n < 9**i:
            break
        else:
            if list[n] >= list[n-9**i]+1:
                list[n]=list[n-9**i]+1
print(list)

N=int(input())

#1*a+(6^b1)*b+(9^c1)*c
list=[99999]*(N+1)
list[0]=0
list[1]=1

max6end =True
i=0
while max6end:
    if N <= 6**i :
        max6=i
        max6end=False
    i+=1
max9end =True
i=0
while max9end:
    if N <= 9**i :
        max9=i
        max9end=False
    i+=1
    
#print ("max6=%d max9=%d" % (max6,max9))
for n in range(1,N+1):
    list[n]=list[n-1]+1
    for i in range(1,max6+1):
        if n < 6**i:
            break
        else:
            if list[n] >= list[n-6**i]+1:
                list[n]=list[n-6**i]+1
    for i in range(1,max9+1):
        if n < 9**i:
            break
        else:
            if list[n] >= list[n-9**i]+1:
                list[n]=list[n-9**i]+1
print(list[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):
s=input()
a=int(s)
list=[]
list.append(1)
list.append(6)
list.append(9)
list.append(36)
list.append(81)
list.append(216)
list.append(729)
list.append(1296)
list.append(6561)
list.append(7776)
list.append(46656)
list.append(59049)
pp=[]
def money(x,y):
  for i in range(12):
    if 0<x//list[i]<6:
      if x%list[i]==0:
        pp.append(y+x//list[i])
        break
      else:
        money(x//list[i],y+1)
money(a,0)
print(min(pp))

s=input()
a=int(s)
list=[]
list.append(1)
list.append(6)
list.append(9)
list.append(36)
list.append(81)
list.append(216)
list.append(729)
list.append(1296)
list.append(6561)
list.append(7776)
list.append(46656)
list.append(59049)
pp=[]
def money(x,y):
  for i in range(12):
    if 0<x//list[i]<6:
      if x%list[i]==0:
        pp.append(y+x//list[i])
        break
      else:
        money(x%list[i],y+1)
money(a,0)
print(min(pp))

s=input()
a=int(s)
list=[]
list.append(1)
list.append(6)
list.append(9)
list.append(36)
list.append(81)
list.append(216)
list.append(729)
list.append(1296)
list.append(6561)
list.append(7776)
list.append(59049)
list.append(46656)
pp=[]
def money(x,y):
  for i in range(12):
    b=x//list[i]
    if b==0:
      continue
    if i%2==1:
      if 0<b<6:
        if x%list[i]==0:
          pp.append(y+b)
        else:
          if y>20:
            break
          money(x-list[i],y+1)
    elif i%2==0:
      if i!=0:
        if 0<b<9:
          if x%list[i]==0:
            pp.append(y+b)
          else:
            if y>20:
              break
            money(x-list[i],y+1)
      else:
        if 0<b<6:
          pp.append(y+b)
money(a,0)
print(min(pp))

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())
Inf = float("inf")
dp = [Inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
        still1 = 1
        while still1 <= N:
                dp[i] = min(dp[i],1+dp[i-still1])
                still1 *= 6
        still2 = 1
        while still2 <= N:
                dp[i] = min(dp[i],1+dp[i-still2])
                still2 *= 9
for i in range(N+1):
        print(dp[i])

N = int(input())
Inf = float("inf")
dp = [Inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
        still1 = 1
        while still1 <= N:
                dp[i] = min(dp[i],1+dp[i-still1])
                still1 *= 6
        still2 = 1
        while still2 <= N:
                dp[i] = min(dp[i],1+dp[i-still2])
                still2 *= 9
print(dp[i])

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
for n1 in range(n+1):
  n2=n-n1
  cnt1=0
  while n1>0:
    cnt1+=n1%6
    n1=n1//6
  cnt2=0
  while n2>0:
    cnt2+=n2%9
    n2=n2//9
  ans=min(ans,n1+n2)
print(ans)

n=int(input())
ans=n
for n1 in range(n+1):
  n2=n-n1
  cnt1=0
  while n1>0:
    cnt1+=n1%6
    n1=n1//6
  cnt2=0
  while n2>0:
    cnt2+=n2%9
    n2=n2//9
  ans=min(ans,cnt1+cnt2)
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())
dp = [0 for i in range(n)]
a = [1]
i = 1
_ = 6
while _ <= n:
    a.append(_)
    i += 1
    _ = 6 ** i
i = 1
_ = 9
while _ <= n:
    a.append(_)
    i += 1
    _ = 9 ** i
dp[0] = 1
len_a = len(a)
for i in range(n):
    target = []
    for j in range(len_a):
        if i + 1 >= a[j]:
            target.append(dp[i - a[j]])
    dp[i] = min(target) + 1
print('answer', dp[n-1])

n = int(input())
dp = [0 for i in range(n)]
a = [1]
i = 1
_ = 6
while _ <= n:
    a.append(_)
    i += 1
    _ = 6 ** i
i = 1
_ = 9
while _ <= n:
    a.append(_)
    i += 1
    _ = 9 ** i
len_a = len(a)
for i in range(n):
    target = []
    for j in range(len_a):
        if i + 1 >= a[j]:
            target.append(dp[i - a[j]])
    dp[i] = min(target) + 1
print(dp[n-1])

Verdicts: Wrong Answer

Accepted