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:
def main(n):
  if n<6:
    print(n)
    exit()
  l=[6**i for i in range(7)]
  l[6:6]=[9**i for i in range(1,6)]
  l.sort()
  if n in l:
    print(1)
    exit()
  ans=n
  from collections import deque
  todo=deque([[1,li] for li in l[1:]])
  while len(todo)>0:
    d=todo.popleft()
    d[0]+=1
    t=d[1]
    for li in [li for li in l if li<=n-d[1]]:
      if t+li==n:
        ans=min(ans,d[0])
      d[1]=t+li
      todo.append(d)
  print(ans)

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  n=int(input())
  main(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
#dp[j] = j￥を引き出すために必要な操作の最小回数
dp = [float('inf')]*(10**5+1)
dp[0] = 0
import math

for i in range(1,10**5+1):
    for j in range(int(math.log(i,9)+0.00001)+1):
        dp[i] = min(dp[i], dp[i-9**j]+1)

    for k in range(int(math.log(i,6))+1):
        dp[i] = min(dp[i],dp[i-6**k]+1)
 
print(dp[n])
print(dp[n-3:n+1])

Submission status: Wrong Answer

Solution code:
n = int(input())
#dp[j] = j￥を引き出すために必要な操作の最小回数
dp = [float('inf')]*(10**5+1)
dp[0] = 0
import math
for i in range(1,10**5+1):
    for j in range(int(math.log(i,9)+1)):
        dp[i] = min(dp[i], dp[i-9**j]+1)
    for k in range(int(math.log(i,6)+1)):
        dp[i] = min(dp[i],dp[i-6**k]+1)
    dp[i] = min(dp[i], dp[i-1]+1)
print(dp[n])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)
n = int(input())
import math
ans = float('inf')
def dfs(i,j):
    global ans
    if j == 0:
        ans = min(ans, i)
    
    else:
        dfs(i+1, j-9**int(math.log(j,9)))
        dfs(i+1, j-6**int(math.log(j,6)))
dfs(0,n)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1


def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            break
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 9):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(2, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1

def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            break
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 7):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(2, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [0] * (N+1)

dp[0] = 0

pow6 = [6**i for i in range(int(N**(1/6))+2)]
pow9 = [9**i for i in range(int(N**(1/9))+2)]


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

print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [0] * (N+1)

dp[0] = 0

pow6 = [6**i for i in range(int(N**(1/6))+2)]
pow9 = [9**i for i in range(int(N**(1/9))+2)]


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

print(dp[N])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc099/tasks
# 15:00-


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

    ans = 0

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

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


print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc099/tasks
# 15:00-


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

    ans = 0

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

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


print(main())

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
dp=[sys.maxsize]*(n+1)
def beki(arg):
  res=0
  t=1
  while t < n:
    t=t*arg
    res+=1
  return res

dp[0]=0
a = beki(9)
b = beki(6)

for i in range(n):
  dp[i+1]=min(dp[i+1],dp[i]+1)
  for j in range(1,a):
    if i+9**j > n:
      break
    dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
  for j in range(1,b):
    if i+6**j > n:
      break
    dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[1]
for i in range(1,8):
    l.append(6**i)
for i in range(1,7):
    l.append(9**i)
l=sorted(l,reverse=True)
ans=0
for i in range(len(l)):
    if l[i]<=n:
        c,n = divmod(n,l[i])
        ans+=c
print(ans)

Submission status: Wrong Answer

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

b6 = math.floor(math.log(n, 6))
b9 = math.floor(math.log(n, 9))

dp = [[0] * (n + 1) for _ in range(1 + 1 + b6 + b9)]

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

for i in range(1, n + 1):
    for j in range(1, b9 + 1):
        dp[j + b6 + 1][i] = dp[b6 + j][i]
        if i >= 9 ** j:
            dp[j + b6 + 1][i] = min([
                dp[j + b6 + 1][i], 
                dp[j + b6 + 1][i - (9 ** j)] + 1
            ])

print(dp[-1][n])

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
ary = []
i = 1
ary.append(1)
while 9**i < n:
    ary.append(9**i)
    i += 1

i = 1
while 6**i < n:
    ary.append(6**i)
    i += 1
ary.sort()

dp = [100002] * (n+1)
dp[0] = 0

for i in range(1,n+1):
    tmp = dp[i] + 1
    for j, aa in enumerate(ary):
        if i >= aa:
            tmp = min(tmp, dp[i-aa] + 1)
        else:
            break
    dp[i] = tmp
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())

ar = [1,6,9,36,81,729,1296,6561,7776,46656,59049]

dp = [float('inf')]*101000
dp[0] = 0

for i in range(1, n+1):
    mins = float('inf')
    for a in ar:
        if i >= a:
            # i円の最小操作回数 = min(i-1円の最小操作回数+1, i-ar[j]円の最小操作回数+1
            mins = min(mins, min(dp[i-1] + 1, dp[i-a]+1))
    dp[i] = mins
print(dp[n])

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def dfs(R, cnt):
    if R < 6:
        return cnt + R
    elif R < 9:
        return cnt + 1 + (R-6)
    else:
        c_6 = dfs(R-6, cnt+1)
        c_9 = dfs(R-9, cnt+1)
        return min(c_6, c_9)


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

    A = []
    i = 2
    while True:
        if 6**i <= 100000:
            A.append(6**i)
            i += 1
        else:
            break
    i = 2
    while True:
        if 9**i <= 100000:
            A.append(9**i)
            i += 1
        else:
            break
    A.sort(reverse=True)

    ans = 0
    for a in A:
        while True:
            if a <= N:
                N -= a
                ans += 1
            else:
                break
    ans += dfs(N, 0)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [1, 6, 9]

tmp = 6
while tmp < N:
    tmp *= 6
    L.append(tmp)
tmp = 9
while tmp < N:
    tmp *= 9
    L.append(tmp)

L.sort(reverse=True)


DP = [float('inf')] * 100001
DP[0]
for i in range(1, 6):
    DP[i] = i
DP[6] = 1

for i in range(7, N+1):
    for l in L:
        if l <= i:
            DP[i] = min(DP[i], DP[i-l] + 1)

print(DP[N])

Submission status: Wrong Answer

Solution code:
import math

def fn6(num):
    ans=0
    while num >= 6:
        num -= pow(6,int(math.log(num,6)))
        ans += 1
    ans+=num
    return ans

def fn9(num):
    ans=0
    while num >= 9:
        num -= pow(9,int(math.log(num,9)))
        ans += 1
    ans+=num
    return ans

n = int(input())
min = n

for i in range(n+1):
    ans = fn6(i) + fn9(n-i)
    if ans < min:
        min = ans

print(int(min))

Submission status: Wrong Answer

Solution code:
import math

def fn6(num):
    if num < 6:
        return num
    else:
        a = math.floor(math.log(num,6))
        ret = 1
        ret += fn6(num-math.pow(6,a))
        return ret

def fn9(num):
    if num < 9:
        return num
    else:
        a = math.floor(math.log(num,9))
        ret = 1
        ret += fn9(num-math.pow(9,a))
        return ret

n = int(input())
min = n

for i in range(n):
    ans = fn6(i) + fn9(n-i)
    if ans < min:
        min = ans

print(int(min))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, log

def main():
    N = int(readline())
    dp = [i for i in range(N+1)]
    for i in range(N):
        dp[i+1] = min(dp[i+1], dp[i]+1)
        log9 = floor(log(N-i, 9))
        for e in range(1, log9+1):
            dp[i+9**e] = min(dp[i+9**e], dp[i]+1)
        log6 = floor(log(N-i, 6))
        for e in range(1, log6+1):
            dp[i+6**e] = min(dp[i+6**e], dp[i]+1)
    
    print(dp[N])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

# n 円を引き出すための最小の引き出し回数

table = [i for i in range(0, N  + 1)]  # 1円ずつ引き出した場合

for base in (6, 9):  
  unit = base  # 引き出し単位
  while unit <= N:
    for i in range(N + 1):
      table[i] = min(
        table[i],
        table[i - unit] + 1
      )
    
    unit *= base

print(table[N])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

#dp[i+1]:i円引き出すまでの回数

I = math.floor(math.log(N, 6))
J = math.floor(math.log(N, 9))

INF = float('inf')
dp = [INF for n in range(N+1)]
dp[0] = 0

for n in range(N):
    t_min = dp[n] + 1
    for i in range(1,I+1):
        if n+1 < 6**i:
            break
        t_min = min(t_min, dp[n-6**i+1]+1)
    for j in range(1,J+1):
        if n+1 < 9**j:
            break
        t_min = min(t_min, dp[n-9**j+1]+1)
    dp[n+1] = t_min

print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)
print(AA)
        
INF = float("inf")
dp=[INF]*(N+1)
dp[0]=0

for i in range(N+1):
    for j in AA:
        if i>=j:
            dp[i]=min(dp[i-j]+1,dp[i])
        else:
            dp[i]=dp[i]
    
#print(dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)
        
INF = float("inf")
dp=[INF]*(N)
dp[0]=1

for i in range(N):
    for j in AA:
        if i>=j:
            dp[i]=min(dp[i-j]+1,dp[i])
        else:
            dp[i]=dp[i]
    
#print(dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)
        
INF = float("inf")
dp=[INF]*(N)
dp[0]=1

for i in range(N):
    for j in AA:
        dp[i]=min(dp[i-j]+1,dp[i])
    
#print(dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [6**x for x in range(1,7)] + [9**x for x in range(1,6)]
l.sort(reverse = True)

cnt = float("inf")
for j in range(1,2**11):
  bs = format(j,"011b")
  nl = []
  for k in range(11):
    if bs[k] == "1":
      nl.append(l[k])

  c = 0   
  NN = N 
  for i in range(len(nl)):
    if  NN//nl[i] > 0:
      c += NN//nl[i]  
      NN = NN%nl[i] 
  c += NN    
  if c == 0:
    c = float("inf")  
  cnt = min(cnt,c)    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = list(range(N+1))
price = []
base = 1
while base<=100000:
    base *= 6
    price.append(base)
base = 1
while base<=100000:
    base *= 9
    price.append(base)

for i in range(2,N+1):
    for p in price:
        if p < i:
             temp = dp[i-p]
             if temp < dp[i-1] and temp+1 < dp[i]:
                 dp[i] = temp+1
print(dp[N])

Submission status: Wrong Answer

Solution code:
l_6 = []
_ = 1
while 6**_ < 100000:
    l_6.append(6**_)
    _ += 1
l_6.sort(reverse = 1)

l_9= []
_ = 1
while 9**_ < 100000:
    l_9.append(9**_)
    _ += 1
l_9.sort(reverse = 1)
print(l_6, l_9)

n = int(input())

w = 0
z = []
for i in range(n+1):
    x = i
    for j in range(len(l_6)):
        while l_6[j] <= x:
            x -= l_6[j]
            w += 1
    else:
        w += x
    
    y = n-i
    for k in range(len(l_9)):
        while l_9[k] <= y:
            y -= l_9[k]
            w += 1
    else:
        w += y

    z.append(w)
    w = 0

print(min(z))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = [1] + [pow(6,i) for i in range(1,15)] + [pow(9,i) for i in range(1,10)]
l.sort(reverse=True)
ans = 0

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

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)

def rec(n, dp):
	if n == 1:
		return 1
	if dp[n] < float('inf'):
		return dp[n]
	pow6 = 6
	pow9 = 9
	dp[n] = min(n, dp[n])
	while n > pow6:
		dp[n] = min(dp[n], rec(n-pow6, dp) + 1)
		pow6 *= 6
	while n > pow9:
		dp[n] = min(dp[n], rec(n-pow9, dp) + 1)
		pow9 *= 9
	return dp[n]

def resolve():
	n = int(input())
	dp = [float('inf')]*(n+1)
	print(rec(n, dp))
resolve()

Submission status: Wrong Answer

Solution code:
N=int(input());t=[0]+[N]*N
for i in range(2,N+1):
 x,a,b=t[i-1],6,9
 while a<=i:x=min(x,t[i-a],(t[i-b]if b<=i else N));a*=6;b*=9
 t[i]=x+1
print(t[N])

Submission status: Wrong Answer

Solution code:
N=int(input());t=[0]+[N]*N
for i in range(2,N+1):
 x,a,b=t[i-1],6,9
 while a<=i:x=min(x,t[i-a],t[i-b]if b<=i else N);a*=6;b*=9
 t[i]=x+1
print(t[N])

Submission status: Wrong Answer

Solution code:
n = int(input())
choice = [1]
for i in range(1,7):
    choice.append(6**i)
    choice.append(9**i)
dp = [float('INF')]*(10**5)
dp[0],dp[5],dp[8] = 1,1,1
for i in range(1,10**5):
    for j in choice:
        if i<j:
            continue
        else:
            dp[i] = min(dp[i],dp[i-j]+1)
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
def to_n(X, n):
    X_dumy = X
    out = 0
    while X_dumy>0:
        out += (X_dumy%n)
        X_dumy = int(X_dumy/n)
    return out
  
n = int(input())
ans = 10 ** 6
for i in range(n):
  tmp = 0
  res = n
  if not i % 9:
    tmp += to_n(i,9)
    res -= i
  tmp += to_n(res,6)
  ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*(n+1)
six=0
nine=0
for i in range(1,n+1):
  if i>6**(six+1):
    six+=1
  if i>9**(nine+1):
    nine+=1
  a[i]=min(a[i-1],a[i-6**six],a[i-9**nine])+1
print(a[n])

Submission status: Wrong Answer

Solution code:
def readints():
    return list(map(int, input().split()))


N, = readints()
DEPTH_LIMIT = 900
INF = 10**9
memo = [None]*(N+1)
memo[0] = 0


def solve(n, depth):
    global INF
    global DEPTH_LIMIT
    global memo
    if DEPTH_LIMIT < depth:
        return INF
    # print(n, depth)
    if memo[n] != None:
        return memo[n]
    ret = INF
    i = 1
    while i <= n:
        ret = min(ret, solve(n-i, depth+1)+1)
        i *= 6
    i = 1
    while i <= n:
        ret = min(ret, solve(n-i, depth+1)+1)
        i *= 9
    memo[n] = ret
    return memo[n]


print(solve(N, 0))

Submission status: Wrong Answer

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

lim_6 = int(math.log(n,6))
lim_9 = int(math.log(n,9))
target_ls = []
for i in range(lim_6+1):
    target_ls.append(6**i)
for i in range(lim_9+1):
    target_ls.append(9**i)
target_ls = list(set(target_ls))

dp = [float('inf')] * (n+1)
dp[0] = 0
for i in range(n):
    for j in target_ls:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i] + 1)
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [10**5]*(10**5+1)
dp[0] = 0
for i in range(n+1):
  if i >= 1:
    dp[i] = min(dp[i-1]+1,dp[i])
  if i >= 6:
    dp[i] = min(dp[i-6]+1,dp[i])
  if i >= 9:
    dp[i] = min(dp[i-9]+1,dp[i])
  if i >= 36:
    dp[i] = min(dp[i-36]+1,dp[i])
  if i >= 81:
    dp[i] = min(dp[i-81]+1,dp[i])
  if i >= 729:
    dp[i] = min(dp[i-729]+1,dp[i])
  if i >= 1296:
    dp[i] = min(dp[i-1296]+1,dp[i]) 
  if i >= 6561:
    dp[i] = min(dp[i-6561]+1,dp[i])
  if i >= 7776:
    dp[i] = min(dp[i-7776]+1,dp[i])
  if i >= 46656:
    dp[i] = min(dp[i-46656]+1,dp[i])
  if i >= 59049:
    dp[i] = min(dp[i-59049]+1,dp[i])
print(dp[n])

Submission status: Wrong Answer

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

print(dp[n-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
six=[1]
nine=[]
for i in range(1,N):
  six.append(6**i)
  nine.append(9**i)
  if 6**i>N:
    break
six=np.array(six)
nine=np.array(nine)
L=np.concatenate([six,nine])    
now=N
count=0
dp=np.ones(N+L.max()+1)*np.inf
dp[1]=1
#dp[i+1]　iをちょうど引き出すのに必要な最小回数
for i in range(1,N):
  dp[i+1]=(dp[i-L+1]+1).min()

  
print(int(dp[N]))
#print(len(L))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
six=[1]
nine=[]
for i in range(1,N):
  six.append(6**i)
  nine.append(9**i)
  if 6**i>N:
    break
six=np.array(six)
nine=np.array(nine)
L=np.concatenate([six,nine])    
now=N
count=0
dp=np.ones(N+L.max()+1)
dp[1]=1
#dp[i+1]　iをちょうど引き出すのに必要な最小回数
for i in range(1,N):
  now=np.inf
  for l in L:
    if i-l+1>=1:
      now=min((dp[i-l+1]+1),now)
    dp[i+1]=now
  
print(int(dp[N]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
six=[0]
nine=[0]
for i in range(1,N):
  six.append(6**i)
  nine.append(9**i)
  if 6**i>N:
    break
six=np.array(six)
nine=np.array(nine)
    
now=N
count=0
while now>0:
  sub=max(1,six[six<=now].max(),nine[nine<=now].max())
  now-=sub
  count+=1
  
print(count)
#print(six, nine)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

n = int(input())
min_time = n

for i in range(n):
    v6, v9 = i, n-i
    count = 0
    while v6 > 0:
        count += v6 % 6
        v6 //= 6
    while v9 > 0:
        count += v9 % 9
        v9 //= 9
    min_time = min(min_time, count)

print(min_time)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [1]
for i in range(8):
    lis.append(6**(i+1))
    lis.append(9**(i+1))
lis.sort()
lis.reverse()
cnt = 0
i = 0
while n > 0:
    if lis[i] <= n:
        n -= lis[i]
        cnt += 1
    else:
        i += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    dp = [None]*n
    dp[0] = 1
    nl = list(sorted([6**i for i in range(10) if (6**i)<=n]+[9**i for i in range(1, 10) if (9**i)<=n]))
    for i in range(1, n):
        d = 10**15
        for j in nl:
            if j > i:
                break
            d = min(d, 1+dp[i-j])
        dp[i] = d
    print(dp[n-1])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    dp = [None]*n
    dp[0] = 1
    nl = list(sorted([6**i for i in range(10) if 6**i<=n]+[9**i for i in range(1, 10) if 9**i<=n]))
    for i in range(1, n):
        d = 10**12
        for j in nl:
            if j > i:
                break
            d = min(d, 1+dp[i-j])
        dp[i] = d
    print(dp[n-1])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    dp = [None]*n
    dp[0] = 1
    nl = list(sorted([6**i for i in range(7) if 6**i<=n]+[9**i for i in range(1, 6) if 9**i<=n]))
    for i in range(1, n):
        d = 10**12
        for j in nl:
            if j > i:
                break
            d = min(d, 1+dp[i-j])
        dp[i] = d
    print(dp[n-1])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    yen = [6 ** i for i in range(1, 7)]
    yen += [9 ** i for i in range(1, 6)]
    yen.sort(reverse=True)

    def MIN(a, b):
        if a > b:
            return b
        else:
            return a

    @lru_cache(maxsize=None)
    def dfs(x, n, m):
        n += 1
        for y in yen:
            if n >= m:
                return n
            if y > x:
                continue
            if x - y < 6:
                return n + x - y
            m = MIN(dfs(x - y, n, m), m)
        return m

    print(dfs(N, 0, 10 ** 9))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1, n+1):
    j = n-i

    a = j
    p = 0
    while a>0:
        p += a%6
        a = a//6

    b = i
    q = 0
    while b>0:
        q += b%9
        b = b//9

    ans = min(ans, p+q)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
min_count = 10*6
for i in range(n):
    m = i
    result = 0
    while m > 0:
        result += m % 6
        m //= 6
    m = n-i
    while m > 0:
        result += m %9
        m //= 9
    min_count = min(result, min_count)
print(min_count)

Submission status: Wrong Answer

Solution code:
NUM=[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

N = int(input())

count=0
for val in NUM:
    if N>=val:
        #print(val, N//val)
        count+=N//val
        N=N%val
print(count)

Submission status: Wrong Answer

Solution code:
NUM=[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

N = int(input())

count=0
for val in NUM:
    if N>=val:
        print(val, N//val)
        count+=N//val
        N=N%val
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = sorted(
    [1] + [6, 36, 216, 1296, 7776, 46656] + [9, 81, 729, 6561, 59049], reverse=True
)

ret_lst = []
for x in lst:
    while N >= x:
        N -= x
        ret_lst.append(x)
if ret_lst.count(9) >= 1 and ret_lst.count(1) >= 5:
    print(len(ret_lst) - 2)
else:
    print(len(ret_lst))

Submission status: Wrong Answer

Solution code:
#99c
import math

N = int(input()) #<=100000

#引き算を足し算で下から求める

#直で引き出せる一覧のsetを作る。
single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,1 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,1 + int(math.log(N,9)))}
#print(single_withdraw_set)

#何回で引き出せるかのdict。この後の計算でマイナス値を参照するので、あらかじめ作っておく。
withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0

#最低の引き出し回数を1円から計算していく
for i in range(1,N+1):
    if i in single_withdraw_set:
        #1回で引き出せるsetにあるなら当然1回
        withdraw_dict[i] = 1
    else:
        #なければ (現状の値 - 1回で引き出し可能な値)の中で1番少ない値 + 1 
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[N])

Submission status: Wrong Answer

Solution code:
def resolve():
    N=int(input())
    nine=[1]
    i=1
    while 9**i<=N:
        nine.append(9**i)
        i+=1
    i=1
    while 6**i<=N:
        nine.append(6**i)
        i+=1

    nine.sort(reverse=True)

    cnt=0
    i=0
    while N>0:
        cnt+=N//nine[i]
        N-= nine[i]*(N//nine[i])
        i+=1

    print(cnt)
resolve()

Submission status: Wrong Answer

Solution code:
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = A = list(map(int, input().split()))

lst = []
k = 6
for i in range(6):
    lst.append(k)
    k *= 6
lst.append(12)
k = 9
for i in range(5):
    lst.append(k)
    k *= 9
lst.sort(reverse=1)
pt = len(lst) # 1円以外で出せるパターン数

ans = 0
for i in range(pt):
    while N > lst[i]:
        ans += 1
        if (i == pt - 2):
            ans += 1
     #   print(ans, end=": ")
     #   print(N, end= " - ")
     #   print(lst[i], end=" = ")
        N -= lst[i]
     #   print(N)
ans += N
print(ans)

Submission status: Wrong Answer

Solution code:
k = [1]
N = int(input())
ans = 0
for i in range(1,10**5):
  if 6**i > N:
    break
  else:
    k.append(6**i)
for i in range(1,10**5):
  if 9**i > N:
    break
  else:
    k.append(9**i)
k.sort()
k.reverse()
for i in range(10**5):
  for j in range(len(k)):
    if k[j]<=N:
      N -= k[j]
      ans += 1
      if N == 0:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
import sys

# N
n = int(input())

res = n

for i in range(n):
    cc = 0
    t = i
    while(t > 0):
        cc += t % 6
        t //= 6
    t = n - i
    while(t > 0):
        cc += t % 9
        t //= 9
    if (res > cc):
        res = cc
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
l = 0

def main(n):
  x, y = n, n
  a, b = 0, 0
  while x >= 1:
    x = x / 6
    a += 1
  while y >= 1:
    y = y / 9
    b += 1
  a, b = a - 1, b - 1
  #print(a, b)
  if 6 ** a > 9 ** b:
    return 6 ** a
  else:
    return 9 ** b

  
while N > 5:
  if main(N) % 9 == 0:
    l = 1
  N = N - main(N)
  count += 1
  #print("N", N)
count += N
#print(l)
if (N == 5) or (N == 4):
  if l == 1:
    count -= 2
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [i for i in range(n + 1)]
for i in range(1, n + 1):
    pow = 6
    while i + pow <= n:
        dp[i + pow] = min(dp[i + pow], dp[i] + 1)
        pow *= 6
    pow = 9
    while i + pow <= n:
        dp[i + pow] = min(dp[i + pow], dp[i] + 1)
        pow *= 9
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
inf=float("inf")
DP=[inf]*(n+1)
DP[0]=0

for i in range(1,n+1):
    for P in (6,9):
        cnt=1
        while P**cnt<=i:
            DP[i]=min(DP[i-1]+1,DP[i-P**cnt]+1,DP[i])
            cnt +=1

print(DP[n])

Submission status: Wrong Answer

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = N
    for n in range(N):
        cnt = 0
        i = n

        while (i > 0):
            cnt += i % 6
            i //= 6

        j = N - n
        while (j > 0):
            cnt += j % 9
            j //= 9

        ret = min(cnt, ret)

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

def six_p(n) :
    temp = 0
    for i in reversed(range(7)) :
        temp += n//(6**i)
        n = n%(6**i)
    return temp

def nin_p(n) :
    temp = 0
    for i in reversed(range(6)) :
        temp += n//(9**i)
        n = n%(9**i)
    return temp

ans = 10**6
for i in range(N):
    ans = min(ans, six_p(i)+nin_p(N-i))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [0] * (n + 1)
for i in range(n):
     if i in range(6):
          dp[i+1] = i + 1
     else:
          j = 1
          k = 1
          a = [100000]
          b = [100000]
          while i + 1 - 6**j >= 0:
              a += [dp[i + 1 - 6**j]]
              j += 1
          while i + 1 - 9**k >= 0:
              b += [dp[i + 1 - 9**k]]
              k += 1
          dp[i + 1] = min(dp[i],min(a),min(b)) + 1
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [0] * (n + 1)
for i in range(n):
     if i in range(6):
          dp[i+1] = i + 1
     else:
          j = 1
          k = 1
          a = [100000]
          b = [100000]
          while i + 1 - 6**j > 0:
              a += [dp[i + 1 - 6**j]]
              j += 1
          while i + 1 - 9**k > 0:
              b += [dp[i + 1 - 9**k]]
              k += 1
          dp[i + 1] = min(dp[i],min(a),min(b)) + 1
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
while n > 0:
     
     n = min(min([n - (9**i) for i in range(6) if n - (9**i) >= 0]),min([n - (6**j) for j in range(9) if n - (6**j) >= 0]),n-1)
     ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=100001

for i in range(n):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    t=n-i
    while t>0:
        cnt+=t%9
        t//=9
    if ans>cnt:
        ans=cnt
print(ans)