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())
can=set()

can.add(1)
i=0
ans=0
while ans<=100000:
  ans=6**i
  can.add(ans)
  i+=1
j=0
ans=0
while ans<=100000:
  ans=9**j
  can.add(ans)
  j+=1

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

for k in range(2,N+1):
  mini=1000000
  for item in can:
    if k-item>=1:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
limit = 10**5

lst = [1]
v1,v2 = 9,6
while v1 <= limit:
    lst.append(v1)
    v1 *= 9
while v2 <= limit:
    lst.append(v2)
    v2 *= 6
lst.sort()

cnt = 0
val = 0

while val != n:
   tmp = lst[bisect.bisect_right(lst,n-val)-1] 
   val += tmp
   cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(2)]
dp[0][0] = 0
dp[1][0]= 0
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(1,nine+1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[0][j] = min(dp[0][j],dp[0][j-9**i] + 1)
for i in range(1,six+1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[1][j] = min(dp[1][j],dp[0][j-9**i] + 1)
        if j - 6**i >= 0:
            dp[1][j] = min(dp[1][j],dp[1][j-6**i] + 1)
ans = dp[1][N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[1][N-i]+i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(2)]
dp[0][0] = 0
dp[1][0]= 0
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(nine,0,-1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[0][j] = min(dp[0][j],dp[0][j-9**i] + 1)
for i in range(six,0,-1):
    for j in range(N+1):
        if j - 6**i >= 0:
            dp[1][j] = min(dp[1][j],dp[1][j-6**i] + 1)
        if j - 9**i >= 0:
            dp[1][j] = min(dp[1][j],dp[0][j-9**i] + 1)
ans = dp[1][N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[1][N-i]+i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(2)]
dp[0][0] = 0
dp[1][0]= 0
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(1,nine+1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[0][j] = min(dp[0][j],dp[0][j-9**i] + 1)
for i in range(1,six+1):
    for j in range(N+1):
        if j - 6**i >= 0:
            dp[1][j] = min(dp[1][j],dp[1][j-6**i] + 1)
        if j - 9**i >= 0:
            dp[1][j] = min(dp[1][j],dp[0][j-9**i] + 1)
ans = dp[1][N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[1][N-i]+i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(3)]
dp[0][0] = 0
dp[2][0]= 0
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(nine,0,-1):
    dp[1][9**i] = 1
    x= (9**i)
    for j in range(x,N+1):
        dp[1][j] = min(dp[1][j],dp[1][j-x]+1)
for i in range(1,six+1):
    dp[2][6**i] = 1
    x= (6**i)
    for j in range(N+1):
        if j >= 9:
            dp[2][j] = min(dp[2][j],dp[2][j-x]+1)
        if j >= x:
            dp[2][j] = min(dp[2][j],dp[1][j-x]+1)
print(dp)
ans = dp[2][N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[2][N-i]+i)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def chmin(a, b):
    if a > b:
        a = b
        return a
    else:
        return a

n = int(input())

dp = [10**5] * n
dp[0] = 1

p = int(math.log(n, 6))
q = int(math.log(n, 9))

for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + 1)
    for j in range(1, p + 1):
        if i - 6 ** j < 0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i - 6 ** j] + 1)
    for k in range(1, q + 1):
        if i - 9 ** k < 0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i - 9 ** k] + 1)

print(dp[n - 1])

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    dp = [0] * (10 ** 5 + 1)
    dp[1] = 1

    x = [1]
    x.extend([6 ** x for x in range(1, 7)])
    x.extend([9 ** x for x in range(1, 5)])


    for i in range(2, 10 ** 5 + 1):
        tmp = []
        for v in x:
            if i >= v:
                tmp.append(dp[i - v] + 1)

        dp[i] = min(tmp)

    print(dp[N])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import log

def n_number(num:int , n:int)->list:
    #n進数に直す
    ans = []
    while num > 0:
        ans.append(num%n)
        num = num // n
    return ans[::-1]


def main():
    N = int(input())
    ans = N
    for six in range(1,N + 1):
        ans = min(ans,sum(n_number(six,6)) + sum(n_number(N - six,9)))
    print(ans)
    return
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
list=sorted(list, reverse=True)
N=44852
count=0
for i in list:
    if i <= N:
        N=N-i
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
list=sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
      print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
list=sorted(list, reverse=True)
print(list)
N=128
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
        print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
list=sorted(list, reverse=True)
N=127
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
        print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
      print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**j)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i < N:
    N=N-i
    count+=1
  if i == N:
    count+=1
    print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i < N:
    N=N-i
    count+=1
  if i == N:
    count+=1
    print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
      break
      print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
    if N == 0:
      print(count)

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1

Submission status: Wrong Answer

Solution code:
n = int(input())

INF = 10**9

dp = [INF] * (n+1)
dp[1] = 1

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

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())

Submission status: Wrong Answer

Solution code:
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [pow(9, i) for i in range(11, 0, -1)]
A.extend([pow(6, i) for i in range(11, 0, -1)])
A.sort(reverse=True)
ans = 0
index = 0
while index < len(A):
    if A[index] <= N:
        N -= A[index]
        ans += 1
    else:
        index += 1
print(ans+N)

Submission status: Wrong Answer

Solution code:
# ボトムアップ 貰う DP
N = int(input())

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

# 貰う DP --- dp[n] に遷移を集める
for n in range(1, N+1):
  p6 = 1
  for p6 in range(1, N, p6*6):
    dp[n] = min(dp[n], dp[n-p6]+1)
  p9 = 1
  for p9 in range(1, N, p9*9):
    dp[n] = min(dp[n], dp[n-p9]+1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
n = int(input())
MAXN = 110000

f_inf = float('inf')
dp = [f_inf] * (MAXN+n)

dp[0] = 0

for i in range(1, n+2):
    for j in range(6):
        dp[i] = min(dp[i], dp[i-pow(6, j)]+1)
    for k in range(6):
        dp[i] = min(dp[i], dp[i-pow(9, k)]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
MAXN = 110000

f_inf = float('inf')
dp = [f_inf] * (MAXN+n)

dp[0] = 0

for i in range(1, n+2):
    for j in range(5):
        dp[i] = min(dp[i], dp[i-pow(6, j)]+1)
    for k in range(5):
        dp[i] = min(dp[i], dp[i-pow(9, k)]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
import sys

l6 = [6, 36, 216, 1296, 7776,59049]
l9 = [9, 81, 729, 6561,46656]

l = []
l.extend(l6)
l.extend(l9)
l.sort(reverse=True)

count = 0

N = int(input())
N_copy = N

while 1:
    index = 0
    while 1:
        if l[index]<=N_copy:
            N_copy = N_copy - l[index]
            count = count + 1
            if N_copy==0:
                print(count)
                sys.exit()
        else:
            index = index + 1
            if index==len(l):
                break

    count = count + (N_copy)
    print(count)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

l6 = [6, 36, 216, 1296, 7776,59049]
l9 = [9, 81, 729, 6561,7776,46656]

l = []
l.extend(l6)
l.extend(l9)
l.sort(reverse=True)

count = 0

N = int(input())
N_copy = N

while 1:
    index = 0
    while 1:
        if l[index]<=N_copy:
            N_copy = N_copy - l[index]
            count = count + 1
            if N_copy==0:
                print(count)
                sys.exit()
        else:
            index = index + 1
            if index==len(l):
                break

    count = count + (N_copy)
    print(count)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

l6 = [6, 36, 216, 1296, 7776,59049]
l9 = [9, 81, 729, 6561,7776,46656]

l = []
l.extend(l6)
l.extend(l9)
l.sort(reverse=True)
print(l)
count = 0

N = int(input())
N_copy = N

while 1:
    index = 0
    while 1:
        if l[index]<=N_copy:
            N_copy = N_copy - l[index]
            count = count + 1
            if N_copy==0:
                print(count)
                sys.exit()
        else:
            index = index + 1
            if index==len(l):
                break

    count = count + (N_copy)
    print(count)
    sys.exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[10]*(n+1)
dp[0]=0
for i in range(n):
    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])

Submission status: Wrong Answer

Solution code:
import sys
from math import log, floor

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

def main():
    bit6 = [0] * floor(log(n, 6) + 1)
    bit9 = [0] * floor(log(n, 9) + 1)
    b = n
    for i in range(floor(log(n, 9)), -1, -1):
        q, r = divmod(b, 9 ** i)
        bit9[i] = q
        b = r

    res = sum(bit6) + sum(bit9)

    for _ in range(n):
        i = 0
        while True:
            bit6[i] += 1
            if bit6[i] == 6:
                bit6[i] = 0
                i += 1
            else:
                break

        i = 0
        while True:
            bit9[i] -= 1
            if bit9[i] == -1:
                bit9[i] = 8
                i += 1
            else:
                break        

        res = min(res, sum(bit6) + sum(bit9))

    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import log, floor

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

def main():
    possible = set([0])
    cnt = 0
    while True:
        nex = set()
        for i in possible:
            for j in range(floor(log(n-i, 6)) + 1):
                nex.add(i + 6 ** j)
            for j in range(floor(log(n-i, 9)) + 1):
                nex.add(i + 9 ** j)
        possible = nex
        cnt += 1
        if n in possible:
            return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import log, floor

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

def main():
    r = n
    cnt = 0
    while r >= 15 or 0 < r <= 11:
        p6, p9 = floor(log(r, 6)), floor(log(r, 9))
        r -= max(6 ** p6, 9 ** p9)
        cnt += 1
    if 12 <= r <= 14:
        q, s = divmod(r, 6)
        cnt += q + s
    
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt9 = 0
cnt6 = 0
price = N
ans = 0

while price>=36:
    for i in range(30,0,-1):
        if(price//(9**i) >=1):
            kouho = 0
            ans +=1
            for j in range(30,0,-1):      
                if(price//(6**j) >=1):
                    kouho = 6**j
                    break
            price -= max(kouho,9**i)
            break

cnt = 36
for i in range(0,10):
    for j in range(0,10):
        if (i==0 and j ==0):
            continue
        q = price % (9*i+6*j)
        cnt = min(cnt,q+i+j,price) 

print(ans+cnt)

Submission status: Wrong Answer

Solution code:
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
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
count = 0
while n != 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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
N=int(input())
N_max=100000

d=set()
n=1
while n<=N_max:
    d.add(n)
    n*=6
n=1
while n<=N_max:
    d.add(n)
    n*=9

dp=[N_max+1 for _ in range(N_max+1)]
dp[0]=1
dp[1]=1
for i in range(2,N_max+1):
    for n in d:
        if i>=n:
            dp[i]=min(dp[i],dp[i-n]+1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
List9 = [9 ** i for i in range(1,6) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = [i for i in List9 if i <= n][-1]
    max6 = [i for i in List6 if i <= n][-1]
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Submission status: Wrong Answer

Solution code:
N = int(input())
List9 = [9 ** i for i in range(1,6) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = max([i for i in List9 if i <= n])
    max6 = max([i for i in List6 if i <= n])
    
    bigger = max(max9,max6)
    
    return recur(n - bigger,con + 1)
    
print(recur(N,0))

Submission status: Wrong Answer

Solution code:
N = int(input())
List9 = [9 ** i for i in range(1,6) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con


  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = max([i for i in List9 if i <= n])
    max6 = max([i for i in List6 if i <= n])
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N + 1
for t in range(N):
    cnt = 0
    v6 = t
    while v6 > 0:
        cnt += v6 % 6
        v6 //= 6
    v9 = N - t
    while v9 > 0:
        cnt += v9 % 9
        v9 //= 9
    ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N
for t in range(N):
    cnt = 0
    v6 = t
    while v6 > 0:
        cnt += v6 % 6
        v6 //= 6
    v9 = N - t
    while v9 > 0:
        cnt += v9 % 9
        v9 //= 9
    ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import math


class binary_tree():
    def __init__(self, m):
        self.c = 0
        self.a = m
        self.n = m

    def base_six(self, n, c):
        if n < 6:
            if self.a > c+n:
                self.a = c+n
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def base_nine(self, n, c):
        if n < 9:
            if self.a > c+n:
                self.a = c+n
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def find(self):
        self.base_six(self.n, self.c)
        self.base_nine(self.n, self.c)
        return self.a


if __name__ == "__main__":
    n = int(input())
    bt = binary_tree(n)
    print(bt.find())

Submission status: Wrong Answer

Solution code:
import math


class binary_tree():
    def __init__(self, m):
        self.c = 0
        self.a = m
        self.n = m

    def base_six(self, n, c):
        if n < 6:
            if self.a > c+n:
                self.a = c+n
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def base_nine(self, n, c):
        if n < 9:
            if self.a > c+n:
                self.a = c+n
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def find(self):
        self.base_six(self.n, self.c)
        self.base_nine(self.n, self.c)
        return self.a


n = int(input())
bt = binary_tree(n)
print(bt.find())

Submission status: Wrong Answer

Solution code:
import math


class binary_tree():
    def __init__(self, n):
        self.c = 0
        self.l = []
        self.n = n

    def base_six(self, n, c):
        if n < 6:
            self.l.append(c+n)
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def base_nine(self, n, c):
        if n < 9:
            self.l.append(c+n)
        else:
            i_s = int(math.log(n, 6))
            i_n = int(math.log(n, 9))
            self.base_six(n - 6 ** i_s, c + 1)
            self.base_nine(n - 9 ** i_n, c + 1)

    def find(self):
        self.base_six(n, self.c)
        self.base_nine(n, self.c)
        return min(self.l)


n = int(input())
bt = binary_tree(n)
print(bt.find())

Submission status: Wrong Answer

Solution code:
from collections import deque
from math import log

N = int(input())
queue = deque()
queue.append((N, 0))
while queue:
    n, d = queue.popleft()
    if n == 0:
        print(d)
        break
    x = 6**int(log(n, 6))
    queue.append((n-x, d+1))
    x = 9**int(log(n, 9))
    queue.append((n-x, d+1))

Submission status: Wrong Answer

Solution code:
#N = int(input())
N=44852
LIST=[10**9]*(10**7)
LIST[0]=1

i=1
c=1
while(6**i <= N):
    LIST[c]=6**i
    c+=1
    if(9**i <= N):
        LIST[c]=9**i
        c+=1
    i+=1
LIST=LIST[0:c]
LIST=list(sorted(LIST,reverse=True))
MIN=10**10

def calc(L,i,c):
    global MIN
    global N
    if(MIN<c):
        return
    if(N-L >= LIST[i]):
        calc(L+LIST[i],i,c+1)
        if(MIN<c):
            return
    if(len(LIST)-2>=i):
        calc(L,i+1,c)
        if(MIN<c):
            return
    if(N==L):
        MIN=min(MIN,c)
  

calc(0,0,0)
print(MIN)

Submission status: Wrong Answer

Solution code:
N = int(input())
#N=44852
LIST=[10**9]*(10**7)
LIST[0]=1

i=1
c=1
while(6**i <= N):
    LIST[c]=6**i
    c+=1
    LIST[c]=9**i
    c+=1
    i+=1
LIST=LIST[0:c]
LIST=list(sorted(LIST,reverse=True))

c=0
for i in range(len(LIST)):
    t=N//LIST[i]
    N-=t*LIST[i]
    c+=t
    if(N==0):
        break
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

dp[0] = 0

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

# 9 ^ i 円
nine = 9
while nine <= n:
    for i in range(n - nine):
        dp[i + nine] = min(dp[i + nine], dp[i] + 1)
    nine *= 9

# 1 円
for i in range(n):
    dp[i + 1] = min(dp[i + 1], dp[i] + 1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [float('inf') for _ in range(N+1)]
nums[1] = 1

for i, num in enumerate(nums):
  if i+1<=N:
    nums[i+1] = min(nums[i+1], nums[i]+1)
  
  i6 = 1
  while i+6**i6 <= N:
    nums[i+6**i6] = min(nums[i+6**i6],nums[i]+1)
    i6 += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if 12 <= N <= 14:
            N -= 6
            ans += 1
            break
        if i <= N:
            N -= i
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if 6 <= N <= 14:
            N -= 6
            ans += 1
            # print(6,N)
            break
        if i <= N:
            N -= i
            ans += 1
            # print(i,N)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if i <= N:
            N -= i
            ans += 1
            # print(i,N)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if i <= N:
            N -= i
            ans += 1
            print(i,N)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
def calc(c, p):
    res = 0
    while c:
        res += c % p
        c = c // p
    return res
ans = n
for i in range(n):
    cand = calc(i, 6) + calc(n - i, 9)
    ans = min(ans, cand)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=10**5

for i in range(N):
    cc=0
    t,s=i,N-i
    while t>0:
        cc+=t%6
        t//=6
    while s>0:
        cc+=s%9
        s//=9
    ans=min(ans,cc)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[59049,46656,7776,6561,1296,729,216,81,36,9,6,1]
dp=[0]*(n+1)
dp[1]=1
for i in range(2,n+1):
    for j in range(12):
        if i>=li[j]:
            k=i-li[j]
            break
    dp[i]=1+dp[k]        
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
ansa=[0]
ansb=[0]
ans=[]
cnt=0
x=0
y=0
for i in range(1,n+1):
    while 9**(x+1)<=i:
        x+=1
    for j in range(x,-1,-1):
        z=(math.floor(i/(9**j))%9)
        i-=(9**j)*z
        cnt+=z
    ansa.append(cnt)
    cnt=0    
    
for i in range(1,n+1):
    while 6**(y+1)<=i:
        y+=1
    for j in range(y,-1,-1):
        z=(math.floor(i/(6**j))%6)
        i-=(6**j)*z
        cnt+=z
    ansb.append(cnt)
    cnt=0
    
for i in range(n):
    ans.append(ansa[i]+ansb[n-i])
    
print(int(min(ans)))

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
ansa=[0]
ansb=[0]
ans=[]
cnt=0
x=0
y=0
for i in range(1,n+1):
    while 9**(x+1)<=i:
        x+=1
    for j in range(x,-1,-1):
        z=(math.floor(i/(9**j))%9)
        i-=(9**j)*z
        cnt+=z
    ansa.append(cnt)
    cnt=0    
    
for i in range(1,n+1):
    while 6**(y+1)<=i:
        y+=1
    for j in range(y,-1,-1):
        z=(math.floor(i/(6**j))%6)
        i-=(6**j)*z
        cnt+=z
    ansb.append(cnt)
    cnt=0
    
for i in range(n):
    ans.append(ansa[i]+ansb[n-i])
    
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[58509,46656,7776,6501,1296,729,216,81,36,9,6,1]
dp=[0]*(n+1)
dp[1]=1
for i in range(2,n+1):
    for j in range(12):
        if i>=li[j]:
            k=i-li[j]
            break
    dp[i]=1+dp[k]        
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
res = n
for i in range(n):
  t = i
  c = 0
  while t > 0:
    c += t % 9
    t //= 9
  t = n - i
  while t > 0:
    c += t % 6
    t //= 6
  if res > c:
    res = c
print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
roku = [0]+[6**_ for _ in range(10) if 6**_ <= n]
kyu = [0]+[9**_ for _ in range(10) if 9**_ <= n]

ma = 10**10
for i in range(n):
    six = i
    nine = n-i
    count = 0
    while True:
        if six == 0:
            break
        six -= roku[bisect.bisect(roku,six)-1]
        count += 1
    while True:
        if nine <= 0:
            break
        nine -= kyu[bisect.bisect(kyu,nine)-1]
        count += 1
    ma = min(ma,count)
print(ma)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
l=[1]
for i in range(1,int(math.log(N,6))+1):
    l.append(6**i)
for i in range(1,int(math.log(N,9))+1):
    l.append(9**i)
l.sort()
dp=[100000 for _ in range(N+1)]
dp[0] = 0
for i in range(len(l)):
    for j in range(l[i],N+1):
        dp[j] = min(dp[j],dp[j-l[i]]+1)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
l=[1]
for i in range(1,int(math.log(N,6))+1):
    l.append(6**i)
for i in range(1,int(math.log(N,9))+1):
    l.append(9**i)
l.sort()
dp=[10**15 for _ in range(N+1)]
dp[0] = 0
for i in range(len(l)):
    for j in range(l[i],N+1):
        dp[j] = min(dp[j],dp[j-l[i]]+1)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
l=[1]
for i in range(1,int(math.log(N,6))+1):
    l.append(6**i)
for i in range(1,int(math.log(N,9))+1):
    l.append(9**i)
l.sort()
dp=[10**10 for _ in range(N+1)]
dp[0] = 0
for i in range(len(l)):
    for j in range(l[i],N+1):
        dp[j] = min(dp[j],dp[j-l[i]]+1)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import floor
N = int(input())
res = N
for i in range(1, N+1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t = t // 6
    t = N - i
    while t > 0:
        cc += t % 9
        t = t // 9
    if res > cc:
        res = cc
print(floor(res))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
res = N
for i in range(1, N+1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t = t // 6
    t = N - i
    while t > 0:
        cc += t % 9
        t = t // 9
    if res > cc:
        res = cc
print(int(res))

Submission status: Wrong Answer

Solution code:
import math


n = int(input())


def log6(x):
    return math.log(x, 6)


def log9(x):
    return math.log(x, 9)

todo = [[n, 0]]
ans = 10**9
while todo:
    num, count = todo.pop()
    if count > ans:
        continue

    if num <= 5:
        ans = min(ans, count+num)
        continue

    #log6
    k = int(log6(num))
    todo.append([num-6**k, count+1])

    #log9
    t = int(log9(num))
    if t == 0:
        continue
    todo.append([num-9**t, count+1])

print(ans)