Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq N \leq 100000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Sample Input 1

127

Sample Output 1

4

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

Sample Input 2

3

Sample Output 2

3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.

Sample Input 3

44852

Sample Output 3

16



Sample input:
127


Sample output:
4

Submission status: Wrong Answer

Solution code:
N = int(input())
six = []
i = 6
while i <= 100000:
    six.append(i)
    i *= 6
six.reverse()
nine = []
i = 9
while i <= 100000:
    nine.append(i)
    i *= 9
nine.reverse()
ansmin = 100000
for i in range(1, 1+(N//6)):
    ans = 0
    money = N - 6 * i
    for j in nine:
        ans += money // j
        money = money % j
    ans += money
    money = 6 * i
    for j in six:
        ans += money // j
        money = money % j
    ansmin = min(ansmin, ans)

print(ansmin)

Submission status: Wrong Answer

Solution code:
N = int(input())
drawlist = [1]
i = 6
while i <= 100000:
    drawlist.append(i)
    i *= 6
i = 9
while i <= 100000:
    drawlist.append(i)
    i *= 9
drawlist.sort(reverse = True)
ans = 0
while N != 0:
    for i in drawlist:
        if N >= i:
            ans += 1
            N -= i
            break
print(ans)

Submission status: Wrong Answer

Solution code:
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
  return withdraw(n-maxmoney,count+1)

print(withdraw(n,0))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())

dp = [10**7 for i in range(100010)]
dp[0] = 0

for i in range(1,N+1):
    dp[i] = min(dp[i-1]+1,min([dp[i-pow(6,j)]+1 for j in range(int(math.log(i,6)+1))]),min([dp[i-pow(9,j)]+1 for j in range(int(math.log(i,9))+1)]))

print(dp[N])

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
six = [6**i for i in range(1,8)][::-1]
nine = [9**i for i in range(1,8)] [::-1]
def DP(n):
	if n < 6:
		return n
	tmp = n
	count6 = 0
	count9 = 0
	for sixx in six:
		if sixx <= n:
			n -= sixx
			count6 = 1
			break
	count6 += DP(n)
	n = tmp
	if n < 9:
		return n
	for ninee in nine:
		if ninee<= n:
			n -= ninee
			count9 = 1
			break
	count9 += DP(n)
	n = tmp
	return min(count6,count9)
print(DP(N))

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [1]

i = 1
a = 6
while(a**i<=n):
    A.append(a**i)
    i+=1

b = 9
j = 1
while(b**j<=n):
    A.append(b**j)
    j+=1
A.sort()
A.reverse()
ans=0
for i in A:
    if(i<=n):
        a = int(n/i)
        ans+=a
        n -= i*a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n
for i in range(1, n+1):
    count = 0
    j = n - i
    while i > 0:
        count += i % 6
        i //= 6
    
    while j > 0:
        count += j % 9
        j //= 9
        
    ans = min(ans, count)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []

for s in range(1, n + 1):
    count = 0
    t = n - s
    while s > 0:
        count += s % 6
        s //= 6
    while t > 0:
        count += t % 9
        t //= 9
    A.append(count)
    
print(min(A))

Submission status: Wrong Answer

Solution code:

n = int(input())

ar = []

for l in range(2):  # 59049
    abc = (n - (59049*l))
    if abc < 0:
        break
    for k in range(3):  # 46656
        abc = (n - (46656 * k+59049*l))
        if abc < 0:
            break
        for j in range(6):  # 7776
            abc = (n - (776 * j + 46656 * k+59049*l))
            if abc < 0:
                break
            for h in range(3):  # 1296,6
                abc = (n - (1296 * h+ 7776 * j + 46656 * k+59049*l))
                if abc < 0:
                    break
                for g in range(4):  # 729,9
                    abc = (n - (729 * g + 1296 * h+ 7776 * j + 46656 * k+59049*l))
                    if abc < 0:
                        break
                    for f in range(3):#216,5(4)
                        abc = (n - (216 * f+ 729 * g + 1296 * h+ 7776 * j + 46656 * k+59049*l))
                        if abc < 0:
                            break
                        for e in range(4):  # 81
                            abc = (n - (81 * e + 216 * f + 729 * g + 1296 * h+ 7776 * j + 46656 * k+59049*l))
                            if abc < 0:
                                break
                            for d in range(5):  # 36
                                abc = (n - (36 * d + 81 * e + 216 * f + 729 * g + 1296 * h+ 7776 * j + 46656 * k+59049*l))
                                if abc < 0:
                                    break
                                for c in range(4):  # 9
                                    abc = (n - (9 * c + 36 * d + 81 * e + 216 * f + 729 * g + 1296 * h + 7776 * j + 46656 * k+59049*l))
                                    if abc < 0:
                                        break
                                    for b in range(3):  # 6
                                        abc = (n - (6 * b + 9 * c + 36 * d + 81 * e + 216 * f + 729 * g + 1296 * h + 7776 * j + 46656 * k+59049*l))
                                        if abc < 0:
                                            break
                                        for a in range(6):  # 1
                                            abc = (n - (1*a+6*b+9*c+36*d+81*e+216*f+729*g+1296*h+7776*j+46656*k+59049*l))
                                            if abc < 0:
                                                break
                                            if abc % 6561 == 0 and abc >= 0:
                                                i = abc//6561
                                                ar.append(a+b+c+d+e+f+g+h+i+j+k+l)
print(min(ar))

Submission status: Wrong Answer

Solution code:
n = int(input())
ar = []
g = 0
#h = 0
for a in range(6):#1
    for b in range(3):#6
        for c in range(4):#9
            for d in range(5):#36
                for e in range(4):#81
                    for f in range(5):#216

                            for h in range(6):  # 1296
                                    for j in range(6):#7776
                                        for k in range(3):#46656
                                            for l in range(2):#59049
                                                abc = (n - (1 * a + 6 * b + 9 * c + 36 * d + 81 * e + 216 * f + 729 * g + 1296 * h + 7776 * j + 46656 * k + 59049 * l))
                                                if abc < 0:
                                                    break
                                                if abc % 6561 == 0 and abc >= 0:
                                                    i = abc // 6561
                                                    ar.append(a + b + c + d + e + f + g + h + i + j + k + l)
print(min(ar))

Submission status: Wrong Answer

Solution code:
n = int(input())
count = 0

for i in range(6, -1, -1):
    while n >= 9 ** i or n >= 6 ** i:
        if n >= 9 ** i:
            n -= 9 ** i
            count += 1
        if n >= 6 ** i:
            n -= 6 ** i
            count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
note = 0
l = reversed(sorted([6 ** i for i in range(7)] + [9 ** i for i in range(1,6)]))
for e in l:
    while N >= e:
        count += 1
        N -= e
        note += e
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = n

for i in range(n):
    c = 0
    t = i
    while t>0:
        c += t%6
        t = int(t/6)

    t = n-i

    while t>0:
        c += t%9
        t = int(t/9)

    if res>c:
        res = c


print(res)

Submission status: Wrong Answer

Solution code:
import math as m

n = int(input())
dp = [-1]*(n+1)
dp[0] = 0

k_six =int(m.log(n, 6))
k_nine = int(m.log(n, 9))

plus = set([1] + [6**(i+1) for i in range(k_six)] + [9**(i+1) for i in range(k_nine)])

for i in range(n+1):
    for p in plus:
        if i + p > n:
            continue
        if dp[i+p]<0:
            dp[i+p] = dp[i] + 1
        else:
            dp[i+p] = min(dp[i]+1, dp[i+p])

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

Submission status: Wrong Answer

Solution code:
import math
n = (int)(input())

ans = n
l = (int)(math.log(n, 9)+1)

for i in range(n+1):
  tmp_ans = 0
  a_six = i
  a_nine = n-i
  for i in reversed(range(-1, 6)):
    tmp = a_six//6**i
    tmp_ans += tmp
    a_six -= tmp*6**i
  a_nine += a_six
  for i in reversed(range(-1, 5)):
    tmp = a_nine//9**i
    tmp_ans += tmp
    a_nine -= tmp*9**i
  if ans > tmp_ans:
    ans = tmp_ans

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = (int)(input())

ans = n
l = (int)(math.log(n, 9)+1)

for i in range(n+1):
  tmp_ans = 0
  a_six = i
  a_nine = n-i
  for i in reversed(range(6)):
    tmp = a_six//6**i
    tmp_ans += tmp
    a_six -= tmp*6**i
  a_nine += a_six
  for i in reversed(range(5)):
    tmp = a_nine//9**i
    tmp_ans += tmp
    a_nine -= tmp*9**i
  if ans > tmp_ans:
    ans = tmp_ans


print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = (int)(input())

c = 0

i = (int)(math.log(n, 9)+1)
while(n >= 6):
  tmp = n//9**i
  n -= tmp*9**i
  c += tmp
  tmp = n//6**i
  n -= tmp*6**i
  c += tmp
  i -= 1
c += n

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
money_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
money_list.reverse()
rest = n
ans = 0

for number in money_list:
        if rest//number >= 1:
                ans += rest//number
                rest -= rest//number * number
                

print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=[]
d=[]
b=0
for i in range(1,7):
    for j in range(1,4):
        a.append([(6**i)*j,j]) 
    for j in range(1,4):
        a.append([(9**i)*j,j]) 
c=sorted(a,reverse=True)
while x>0:
    for j in range(len(a)):
        if x>=6:
            if c[j][0]<=x:
                x-=c[j][0]
                b+=c[j][1]
                break
        
        elif 0<=x<6:
            b+=x
            x-=x
print(b)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=[]
d=[]
b=0
for i in range(1,7):
    for j in range(1,6):
        a.append([(6**i)*j,j]) 
    for j in range(1,9):
        a.append([(9**i)*j,j]) 
c=sorted(a,reverse=True)
while x>0:
    for j in range(len(a)):
        if x>=6:
            if c[j][0]<=x:
                x-=c[j][0]
                b+=c[j][1]
                break
        
        elif 0<=x<6:
            b+=x
            x-=x
print(b)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=[]
b=0
for i in range(1,7):
    a.append(6**i)
    a.append(9**i)
c=sorted(a,reverse=True)
while x>0:
    for j in c:
        if x==14:
            b+=4
            x=0
        elif x==13:
            b+=3
            x=0
        elif x==12:
            b+=2
            x=0
        elif x>=6:
            if j<=x:
                x-=j
                b+=1
                break
        
        elif 0<=x<6:
            b+=x
            x-=x
print(b)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=[]
b=0
for i in range(1,7):
    a.append(6**i)
    a.append(9**i)
c=sorted(a,reverse=True)
while x>0:
    for j in c:
        if x>=6:
            if j<=x:
                x-=j
                b+=1
        elif 0<=x<6:
            b+=x
            x-=x
print(b)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
# A = [int(x) for x in input().split()]


C = [1]
for i in range(math.floor(math.log(N,9)) + 1):
    if i !=0 :
        C.append(9 ** i)
for i in range(math.floor(math.log(N,6)) + 1):
    if i != 0:
        C.append(6 ** i)


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

for i in range(1,N+1):
    for c in C:
        if i - c >= 0:
            dp[i] = min(dp[i], dp[i - c] + 1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
# A = [int(x) for x in input().split()]


C = [1]
for i in range(math.ceil(math.log(N,9))):
    if i !=0 :
        C.append(9 ** i)
for i in range(math.ceil(math.log(N,6))):
    if i != 0:
        C.append(6 ** i)


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

for i in range(1,N+1):
    for c in C:
        if i - c >= 0:
            dp[i] = min(dp[i], dp[i - c] + 1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
# A = [int(x) for x in input().split()]


C = [1]
for i in range(math.ceil(math.log(N,9))):
    C.append(9 ** i)
for i in range(math.ceil(math.log(N,6))):
    C.append(6 ** i)


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

for i in range(1,N+1):
    for c in C:
        if i - c >= 0:
            dp[i] = min(dp[i], dp[i - c] + 1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
from math import log
n = int(input())

def log9(x):
    return log(x)/log(9)

def log6(x):
    return log(x)/log(6)

ans1 = 0
while n > 35:
    x = int(log9(n))
    y = int(log6(n))
    if x >= y:
        n -= 9**x
    elif x < y:
        n -= 6**y
    ans1 += 1

ans2 = 35
for i in range(4):
    for j in range(6):
        for k in range(6):
            if i * 9 + j * 6 + k == n:
                ans2 = min(ans2, i+j+k)

print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
N = int(input())
nine = [9, 9**2, 9**3, 9**4, 9**5, 9**6]
six = [6, 6**2, 6**3, 6**4, 6**5, 6**6, 6**7]
total = 0
counter = 0

while total != N:
    for i in nine:
        if total + i > N:
            candN = i // 9
            break

    for i in six:
        if total + i > N:
            candS = i // 6
            break

    total += max(candN, candS)
    counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []

for i in range(1,6):
    arr += [9 ** i]
for j in range(1,7):
    arr += [6 ** j]

arr += [1]
    
arr.sort(reverse=True)

k = 0
ans = 0

while n > 0:
    if arr[k] <= n:
        ans += n // arr[k]
        n = n - (arr[k] * (n // arr[k]))
    k += 1

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []

for i in range(1,6):
    arr += [9 ** i]
for j in range(1,7):
    arr += [6 ** j]

arr += [1]
    
arr.sort(reverse=True)

k = 0
ans = 0

while n > 0:
    if arr[k] <= n:
        ans += n // arr[k]
        n = n - (arr[k] * (n // arr[k]))
    k += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())

base=[]
for i in range(1, 7):
    if 6 ** i <= N:
        base.append(6 ** i)
for i in range(1, 6):
    if 9 ** i <= N:
        base.append(9 ** i)
ans = N
ary =[]
for flags in itertools.product(range(2) ,repeat=len(base)):
    x = sum([base[i] * flags[i] for i in range(len(base))])
    if x <= N:
        ary.append(x)
        ans = min(ans, sum(flags) + N - x)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
for i in range(len(li)):
  if i != 0:
    if li[i - 1] <= n < li[i]:
      a = li[:i]
    elif li[i] <= n and i == len(li) - 1:
      a = li
coli = [0]*len(a)
for j in range(len(a) - 1,-1,-1):
  coli[j] += n // a[j]
  res = n % a[j]
  #if res == 0:
      #break
  if j != 0:
    for k in range(j - 1,-1,-1):
      coli[j] += res // a[k]
      res = res % a[k]
      #if res == 0:
        #break
print(min(coli))

Submission status: Wrong Answer

Solution code:
from math import log
N = int(input())

hiki9 = []
hiki6 = []
n = int(log(N) / log(9))
for i in range(n+1):
    hiki9.append(9**i)
n = int(log(N) / log(6))
for i in range(n+1):
    hiki6.append(6**i)
hiki9.sort(reverse=True)
hiki6.sort(reverse=True)
x = []
for i in range(N+1):
    n9 = i
    tmpx = 0
    for h in hiki9:
        while h <= n9:
            n9 -= h
            tmpx += 1
    n6 = N - i
    for h in hiki6:
        while h <= n6:
            n6 -= h
            tmpx += 1
    x.append(tmpx)
x.sort()
print(x[0])

Submission status: Wrong Answer

Solution code:
from math import log
N = int(input())

hiki9 = []
hiki6 = []
n = int(log(N) / log(9))
for i in range(n+1):
    hiki9.append(9**i)
n = int(log(N) / log(6))
for i in range(n+1):
    hiki6.append(6**i)
hiki9.sort(reverse=True)
hiki6.sort(reverse=True)
x = []
for i in range(1, N+1):
    n9 = i
    tmpx = 0
    for h in hiki9:
        while h <= n9:
            n9 -= h
            tmpx += 1
    n6 = N - i
    for h in hiki6:
        while h <= n6:
            n6 -= h
            tmpx += 1
    x.append(tmpx)
x.sort()
print(x[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
B6 = [6**i for i in range(1,8)]
B9 = [9**i for i in range(1,7)]
L = sorted(list(set((B6+B9))))
dp = [i for i in range(1,N+1)]
for i in L :
    for j in range(i,N) :
        try :
            dp[j] = min(dp[j], dp[j-i]+1)
        except IndexError :
            print(i,j)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

B6 = [6**i for i in range(7)]
B9 = [9**i for i in range(6)]

L = B6 + B9
L = sorted(list(set(L)))

for i in L :
    for j in range(len(dp)) :
        if j-i >= 0 :
            dp[j] = min(dp[j], dp[j-i]+1)
print(dp[N-1])

Submission status: Wrong Answer

Solution code:

iN = int(input())

"""
9**i
0 1
1 9
2 81
3 729
4 6561
5 59049

1 6
2 36
3 216
4 1296
5 7776
6 46656

1 6
1 9
2 36
2 81
3 216
3 729
4 1296
4 6561
5 7776
6 46656
5 59049

"""

aG = [531441, 59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
#aG = [1]
#for i in range(1,7):
#   aG.append(9**i)
#   aG.append(6**i)
#aG.sort(reverse=True)
#iL = len(aG)
iL = 13
aC = [0]*iL
iC = 0
for i in range(iL):
    iPe = 0
    a = aG[i]
    while a <= iN :
        iN -=a
        iPe += 1
        iC += 1
    aC[i] = iPe
    # 2*9 + 3 = 1*9 + 2*6 # 5個 -> 3個
    if aC[10] >=2 and aC[12]>=3:
        iC -= 2
print(iC)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import math

d_in = lambda: int(stdin.readline())  # N = d_in()



def get_order(n, m):
    order = 0
    while n > 0:
        n = n // 9
        order += 1
    return order


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    if n == 0:
        return []
    order = get_order(n, m)
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = float('inf')
    for i in range(n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import math

d_in = lambda: int(stdin.readline())  # N = d_in()


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    if n == 0:
        return []
    order = int(math.log(n, m))
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = float('inf')
    for i in range(n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)

Submission status: Wrong Answer

Solution code:
n = int(input())

cands = [1]
for i in range(1, 10):
    if 6**i <= 100000:
        cands.append(6**i)
    if 9**i <= 100000:
        cands.append(9**i)
cands = sorted(cands, reverse = True)

ans = n
for i in range(1<<len(cands)):
    ans_cur = 0
    n_cur = n
    for b in range(len(cands)):
        if i&(1<<b) > 0:
            ans_cur += n_cur//cands[b]
            n_cur -= cands[b]*(n_cur//cands[b])
    if n_cur == 0:
        ans = min(ans, ans_cur)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
nums = (59049,46656,7776,6561,1296,729,216,81,36)
for i in nums:
    ans += n // i
    n -= i * (n // i)
unt = 210
for a in range(4):
    for b in range(6):
        for c in range(37):
            if a * 9 + b * 6 + c * 1 == n:
                unt = min(unt,a+b+c)
print(ans + unt)

Submission status: Wrong Answer

Solution code:
# C 
import numpy as np

# n = 127
n = int(input())

max_n = 100000
memo = np.full(max_n,999999999)
memo[0] = 0

nl = [1]
nl6 = nl+[6**i for i in range(1,1000) if 6**i <= 100000]
nl9 = nl+[9**i for i in range(1,1000) if 9**i <= 100000]
nl.sort(reverse=True)


for i in range(1,n+1):
    memo[i] = memo[i-1]+1
    for i6 in nl6:
        if(i-i6 >= 0):
            memo[i] = min(memo[i], memo[i-i6]+1)
        
    for i9 in nl9:
        if(i-i9 >= 0):
            memo[i] = min(memo[i], memo[i-i9]+1)
            
print(memo[n])

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
c=[59049,46656,7776,6561,1296,729,216,81,36,9,6,1]
while True:
    if N>=c[0]:
        ans+=1
        N-=c[0]
        if N==0:
            break
        elif N>=c[0]:
            continue
        else:
            c.pop(0)
    else:
        c.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
c=59049,46656,7776,6561,1296,729,216,81,36,9,6,1
for i in c:
    if N>=i:
        ans+=1
        N-=i
        if N==0:
            break
        else:
            continue
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
def run(n):
    cost = [6**i for i in range(6)]
    cost.extend([9**i for i in range(1, 5)])
    cost = sorted(cost)
    
    dp = {0: 0}
    for i in range(1, n+1):
        dp[i] = dp[i-1] + 1
        for c in cost:
            if i >= c:
                dp[i] = min(dp[i-c]+1, dp[i])
            else:
                break
    return dp[n]


def main():
    n = int(input())
    print(run(n))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def run(n):
    cost = [6**i for i in range(6)]
    cost.extend([9**i for i in range(1, 5)])
    cost = sorted(cost)
    
    dp = {0: 0}
    for i in range(1, n+1):
        if i in cost:
            dp[i] = 1
        else:
            dp[i] = dp[i-1] + 1
        for c in cost:
            if i >= c:
                dp[i] = min(dp[i-c]+1, dp[i])
            else:
                break
    return dp[n]


def main():
    n = int(input())
    print(run(n))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
ans = n
for i in range(1, n+1):
    cnt = 0
    t = i
    while t > 0:
        cnt += t % 6
        t = int(t/6)
    t = n - i
    while t > 0:
        cnt += t % 9
        t = int(t/9)
    if ans > cnt:
        ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

yen_list = [9**i for i in range(5, 0, -1)] + [6**i for i in range(6, 0, -1)]
yen_list.sort(reverse=True)

cnt = 1000
for k in range(1, 6):
    comp_cnt = 0
    num = n
    while num > 5:
        check = 0
        tmp_yen = 0
        tmp_cnt = 0
        for yen in yen_list:
            for i in range(1, 3):
                tmp_yen = yen * i
                if num >= tmp_yen:
                    if check < tmp_yen:
                        check = tmp_yen
                        tmp_cnt = i
        num -= check
        comp_cnt += tmp_cnt
    comp_cnt += num
    cnt = min(cnt, comp_cnt)
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

x = {1}
for k in [6, 9]:
    v = k
    while v < N:
        x.add(v)
        v *= k

dp = [999 for _ in range(N+1)]
dp[0] = 0
for k in range(N+1):
    for v in x:
        if 0 <= k - v:
            dp[k] = min(dp[k-v]+1, dp[k])
print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys
import functools
sys.setrecursionlimit(100000)

N = int(input())
accepts = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
interim = 0
min_dfs = float("inf")

@functools.lru_cache(maxsize=None)
def dfs(n, cnt):
    global min_dfs
    if n == 0:
        min_dfs = cnt
        return cnt
    elif n < 0:
        return min_dfs
    else:
        return min([dfs(n - a, cnt+1) for a in accepts[:5][::-1]])

while N > 81:
    for n in accepts:
        if n > N:
            break
        sub_num = n
    N -= sub_num
    interim += 1

print(interim + dfs(N, 0))

Submission status: Wrong Answer

Solution code:
N = int(input())
accepts = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
interim = 0
min_dfs = float("inf")

def dfs(n, cnt):
    global min_dfs
    if n == 0:
        min_dfs = cnt
        return cnt
    elif n < 0:
        return min_dfs
    else:
        return min([dfs(n - a, cnt+1) for a in accepts[:3][::-1]])

while N > 36:
    for n in accepts:
        if n > N:
            break
        sub_num = n
    N -= sub_num
    interim += 1

print(interim + dfs(N, 0))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
L.sort()
if (N > 59049):
  N = N - 59049
  k = 1
else:
  k = 0
while (N > 0):
  for i in range(len(L)-1):
    if (N <= 11 or 18 <= N): 
      if (L[i] <= N < L[i+1]):
        N = N-L[i]
        k += 1
        i = 0
    else:
        k += N-10
        N = 0
print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
a = [9**i for i in range(1, 6)]
b = [6**i for i in range(1, 7)]
ab = a+b
ab.sort(reverse=True)
while N >= 6:
    for i in ab:
        if N >= i:
            N = N - i
            ans += 1
            break
print(ans+N)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
a = [9**i for i in range(1, 6)]
b = [6**i for i in range(1, 7)]
ab = a+b
ab.sort(reverse=True)
while N >= 6:
    for i in ab:
        if N >= i:
            N = N - i
            ans += 1
            break
print(ans+N)
print(ans)
print(N)

Submission status: Wrong Answer

Solution code:
def withdrow(rest,num,cost):
    
    ans1 = float('inf')
    ans2 = float('inf')
    
    if rest < len(cost):
        return num + cost[rest]
    else:
        for i in range(1,10):
            if rest < 6**i:
                ans1 = withdrow(rest-6**(i-1), num+1,cost)
                break

    if rest < len(cost):
        return num + cost[rest]
    else:
        for i in range(1, 10):
            if rest < 9**i:
                ans2 = withdrow(rest-9**(i-1), num+1,cost)
                break

    return min(ans1, ans2)

N = int(input())

cost = [0,1,2,3,4,5,1,2,3,1,2,3,4,5,2,3,4,2,3,4,5,6,7,4]

ans = withdrow(N, 0, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
def withdrow(rest,num):
    
    ans1 = 999
    ans2 = 999
    
    if rest < 6:
        return num + rest
    else:
        for i in range(1,10):
            if rest < 6**i:
                ans1 = withdrow(rest-6**(i-1), num+1)
                break

    if rest < 9:
        return num + rest
    else:
        for i in range(1, 10):
            if rest < 9**i:
                ans2 = withdrow(rest-9**(i-1), num+1)
                break

    return min(ans1, ans2)

N = int(input())

cost = [0,1,2,3,4,5,1,2,3,1,2,3,4,5,2,3,4,2,3,4,5,6,7,4]

ans = withdrow(N, 0)
print(ans)

Submission status: Wrong Answer

Solution code:
def withdrow(rest,num):
    
    ans1 = 999999
    ans2 = 999999
    
    if rest < 6:
        return num + rest
    
    for i in range(1,9):
        if rest < 6**i:
            ans1 = withdrow(rest-6**(i-1), num+1)
            break

    if rest < 9:
        return num + rest
    
    for i in range(1, 8):
        if rest < 9**i:
            ans2 = withdrow(rest-9**(i-1), num+1)
            break

    return min(ans1, ans2)

N = int(input())

ans = withdrow(N, 0)
print(ans)

Submission status: Wrong Answer

Solution code:
def withdrow(rest,num):
    
    ans1 = 999999
    ans2 = 999999
    
    rest1 = rest
    rest2 = rest
    
    num1 = num
    num2 = num
    
    if rest1 < 6:
        return num2 + rest1
    
    for i in range(1,9):
        if rest1 < 6**i:
            rest1 -= 6**(i-1)
            num1 += 1
            ans1 = withdrow(rest1, num1)
            break

    if rest2 < 9:
        return num2 + rest2
    
    for i in range(1, 8):
        if rest2 < 9**i:
            rest2 -= 9**(i-1)
            num2 +=1
            ans2 = withdrow(rest2, num2)
            break

    return min(ans1, ans2)

N = int(input())

ans = withdrow(N, 0)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
n6=0
n9=0
while 1:
    if n<=5:
        count+=n
        break
    for i in range (1,100):
        if 6**i>n:
            n6=6**(i-1)
            break
    for j in range (1,100):
        if 9**j>n:
            n9=9**(j-1)
            break
    if n6>=n9:
        n-=n6
        count+=1
    else:
        n-=n9
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import time
N = int(input())
num_list = [1]
for i in range(1, 7):
	if N > 6**i:
		num_list.append(6**i)
for i in range(1, 6):
	if N > 9**i:
		num_list.append(9**i)
		
ans = 100
i = 1

while i < ans:
	ans = min(map(lambda nums: N - sum(nums) + i if N > sum(nums) else 100, itertools.combinations_with_replacement(num_list, i)))
	i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

mico=n

for i in range(n):
    co=0
    six=i
    while six>0:
        co+=six%6
        six//=6
    nin=n-i
    while nin>0:
        co+=nin%9
        nin//=9
    mico=min(mico,co)

print(mico)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())



def c(nn,step,mi):
    if nn<=5:
        step+=nn
        return min(mi,step)
    elif step>=mi:
        return mi
    else:
        mmi=mi
        nin=9**(int(math.log(nn,9)))
        mmi=c(nn-nin,step+1,mmi)
        six=6**(int(math.log(nn,6)))
        mmi=c(nn-six,step+1,mmi)
        return mmi

print(c(n,0,n))

Submission status: Wrong Answer

Solution code:
import math

n=int(input())



def c(nn,step,mi):
    if nn<=5:
        step+=nn
        return min(mi,step)
    else:
        mmi=mi
        nin=9**(int(math.log(nn,9)))
        mmi=c(nn-nin,step+1,mmi)
        six=6**(int(math.log(nn,6)))
        mmi=c(nn-six,step+1,mmi)
        return mmi

print(c(n,0,n))