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

l = [1]
for i in [6, 9]:
  j = 1
  while i**j <= n:
    l.append(i**j)
    j += 1
l.sort(reverse=True)

count, i = 0, 0
while n > 0:
  if n >= l[i]:
    n -= l[i]
    count += 1
  else: i += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

pow6 = [6**i for i in range(1,8)]
pow9 = [9**i for i in range(1,7)]

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

print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
actions = 0

while N > 6:
  pow = 1
  while True:
    if (9 ** pow > N):
      break
    pow += 1

  if pow - 1 != 0:
    N = N - (9  ** (pow - 1))
    actions += 1

  pow = 1

  while True:
    if (6 ** pow > N):
      break
    pow += 1

  if pow - 1 != 0:
    N = N - (6  ** (pow - 1))
    actions += 1


print(actions + N)

Submission status: Wrong Answer

Solution code:
N=int(input())
INF=10**10
dp=[INF]*(N+1)
dp[0]=0
for i in range(N+1):
    if i<N: dp[i+1]=min(dp[i+1],dp[i]+1)
    j=1
    while i+6**j<N:
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
        j+=1
    j=1
    while i+9**j<N:
        dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
        j+=1
print(dp[N])

Submission status: Wrong Answer

Solution code:
N=int(input())
INF=10**10
dp=[INF]*(N+1)
dp[0]=0
for i in range(N+1):
    if i<N: dp[i+1]=min(dp[i+1],dp[i]+1)
    j=1
    while i+6**j<N:
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
        j+=1
    j=1
    while i+9**j<N:
        dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
        j+=1

print(dp[N])

Submission status: Wrong Answer

Solution code:
from functools import *
@lru_cache(maxsize=None)
def f(x):
  if x==1:return 1
  s=10000000000000000
  for u in [1]+[6**i for i in range(1,11)]+[9**i for i in range(1,11)]:
    if x-u>=1:
      s=min(s,f(x-u)+1)
  return s
for i in range(1,100001):f(i)
print(f(int(input())))

Submission status: Wrong Answer

Solution code:
from functools import *
@lru_cache(maxsize=None)
def f(x):
  if x==1:return 1
  s=1000000000
  for u in [1]+[6**i for i in range(1,11)]+[9**i for i in range(1,11)]:
    if x-u>=1:
      s=min(s,f(x-u)+1)
  return s
for i in range(1,100001):f(i)
print(f(int(input())))

Submission status: Wrong Answer

Solution code:
from functools import *
@lru_cache(maxsize=None)
def f(x):
  if x==1:return 1
  s=1000000000
  for u in [1]+[6**i for i in range(1,11)]+[9**i for i in range(1,11)]:
    if x-u>=1:
      s=min(s,f(x-u))
  return s
for i in range(1,100001):f(i)
print(f(int(input())))

Submission status: Wrong Answer

Solution code:
from functools import *
@lru_cache(maxsize=None)
def f(x):
  if x==1:return 1
  s=1000000000
  for u in [1,6,9]:
    if x-u>=1:
      s=min(s,f(x-u))
  return s
for i in range(1,100001):f(i)
print(f(int(input())))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [0] * (10**5+1)
for i in range(N):
  l[i+1] = l[i]+1
  for j in range(1, N):
    if i+6**j <= N:
      l[i+6**j] = l[i]+1
    else:
      break
  for j in range(1, N):
    if i+9**j <= N:
      l[i+9**j] = l[i]+1
    else:
      break
  if l[N] > 0:
    break
  print(l)
print(l[N])

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
while 1:
#   print(n)
  if n<6:
    break
  roku=0
  kyu=0
  i=1
  j=1
  while 1:
    if 9**i>n:
      if 9**(i-1) != 0:
        kyu=9**(i-1)
      break
    i+=1
  while 1:
    if 6**j>n:
      if 6**(j-1) != 0:
        roku=6**(j-1)
      break
    j+=1
  if n-kyu <= n-roku:
    n = n - kyu
    # print('9の'+str(i-1)+'乗の'+str(kyu))
  else:
    n = n - roku
    # print('6の'+str(j-1)+'乗の'+str(roku))
  count+=1
print(n+count)

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
while 1:
  print(n)
  if n<6:
    break
  roku=0
  kyu=0
  i=1
  j=1
  while 1:
    if 9**i>n:
      if 9**(i-1) != 0:
        kyu=9**(i-1)
      break
    i+=1
  while 1:
    if 6**j>n:
      if 6**(j-1) != 0:
        roku=6**(j-1)
      break
    j+=1
  if n-kyu <= n-roku:
    n = n - kyu
    print('9の'+str(i-1)+'乗の'+str(kyu))
  else:
    n = n - roku
    print('6の'+str(j-1)+'乗の'+str(roku))
  count+=1
print(n+count)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[10000]*(n+1)
x[0]=1
a=[6**i for i in range(1,7)]
b=[9**i for i in range(1,6)]
c=[1]
c=a+b+c
c.sort()
for i in range(1,n+1):
    for j in c:
        if i-j>=0:
            x[i]=min(x[i],x[i-j]+1)
        else:
            break
print(x[n-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N
for i in range(N):
    x = 0
    y = i
    while y:
        x += y%6
        y //= 6
    y = N-i
    while y:
        x += y%9
        y //= 9
    ans = min(x, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    #kingakuwohozon
    dp = [0] * (N+1)

    for i in range(1, N+1):
        j = 0
        if (N - dp[i-1]) % 9 == 0 and (N - dp[i-1]) < 9 ** 2:
            ans = i + (N - dp[i-1]) / 9
            ans -= 1
            break
        elif (N - dp[i-1]) % 6 == 0 and (N - dp[i-1]) < 6 ** 2:
            ans = i + (N - dp[i - 1]) / 6
            ans -= 1
            break

        while True:
            if dp[i-1] + 9 ** j <= N:
                dp[i] = dp[i-1] + 9 ** j

            elif dp[i-1] + 6 ** j <= N:
                dp[i] = dp[i-1] + 6 ** j

            if dp[i-1] + 9 ** j > N or dp[i-1] + 6 ** j > N:
                break

            j += 1

        if dp[i] == N:
            ans = i
            break

    print(ans)
    #print(dp)

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    #kingakuwohozon
    dp = [0] * (N+1)

    for i in range(1, N+1):
        j = 0
        if (N - dp[i-1]) % 9 == 0 and (N - dp[i-1]) < 9 ** 2:
            ans = i + (N - dp[i-1]) / 9
            ans -= 1
            break
        elif (N - dp[i-1]) % 6 == 0 and (N - dp[i-1]) < 6 ** 2:
            ans = i + (N - dp[i - 1]) / 6
            ans -= 1
            break

        while True:
            if dp[i-1] + 9 ** j <= N:
                dp[i] = dp[i-1] + 9 ** j

            elif dp[i-1] + 6 ** j <= N:
                dp[i] = dp[i-1] + 6 ** j

            if dp[i-1] + 9 ** j > N or dp[i-1] + 6 ** j > N:
                break

            j += 1

        if dp[i] == N:
            ans = i
            break

    print(ans)
    print(dp)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

for i in range(10,0,-1):
  for j in range(N + 1):
    if dp[j] != INF:
      if j + 6 ** i < N:
        dp[j + 6 ** i] = min(dp[j + 6 ** i], dp[j] + 1)
      if j + 9 ** i < N:
        dp[j + 9 ** i] = min(dp[j + 9 ** i], dp[j] + 1)
        
ans = INF
for i in range(len(dp) - 1, -1, -1):
  money = dp[i] + N - i
  if ans > money:
    ans = money
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

for i in range(10,0,-1):
  for j in range(N):
    if dp[j] != INF:
      if j + 6 ** i < N:
        dp[j + 6 ** i] = min(dp[j + 6 ** i], dp[j] + 1)
      if j + 9 ** i < N:
        dp[j + 9 ** i] = min(dp[j + 9 ** i], dp[j] + 1)
        
ans = INF
for i in range(len(dp) - 1, -1, -1):
  money = dp[i] + N - i
  if ans > money:
    ans = money
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = [6**i for i in range(7)]
b = [9**i for i in range(1,6)]
c = sorted(a+b)
N = int(input())
import bisect
ans = 0
while N > 0:
    if N == 14 or N == 13 or N == 12:
        N -= 6
    else:
        N -= c[bisect.bisect_right(c,N)-1]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

INF = float("inf")

dp = [INF]*100010
dp[0] = 0

pow6 = [6**i for i in range(1,7)]
pow9 = [9**i for i in range(1,6)]

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

print(dp[n])

Submission status: Wrong Answer

Solution code:
N = int(input())
#初期化
dp=[0]*N
for i in range(10):
  if 6**i-1 < N:
    dp[6**i-1] = 1
for i in range(10):
  if 9**i-1 < N:
    dp[9**i-1] = 1

#dp
for k in range(1,N):
  dp_list = []
  for j in range(10):
    if k >= 6**j:
      dp_list.append(dp[k-6**j])
    if k >= 9**j:
      dp_list.append(dp[k-9**j])
  
  dp[k] = 1+min(dp_list)
  
  if k == (5 or 6**2-1 or 6**3-1 or 6**4-1 or 6**5-1 or 6**6-1 or 6**7-1 or 8 or 9**2-1 or 9**3-1 or 9**4-1 or 9**5-1 or 9**6-1):
    dp[k] = 1

print(dp[N-1]%1000000007)

Submission status: Wrong Answer

Solution code:
N = int(input())
#初期化
dp=[0]*N
for i in range(10):
  if 6**i-1 <= N:
    dp[6**i-1] = 1
for i in range(10):
  if 9**i-1 <= N:
    dp[9**i-1] = 1

#dp
for k in range(1,N):
  dp_list = []
  for j in range(10):
    if k >= 6**j:
      dp_list.append(dp[k-6**j])
    if k >= 9**j:
      dp_list.append(dp[k-9**j])
  
  dp[k] = 1+min(dp_list)

print(dp[N-1]%1000000007)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
L = {1}
m = 6
n = 9
while m <= N:
    L.add(m)
    m *= 6
while n <= N:
    L.add(n)
    n *= 9
L = list(L)
L.sort()
# print(L)

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

for i in range(1, N+1):
    x = bisect_right(L, i)
    for j in range(x):
        dp[i] = min(dp[i], dp[i % L[j]]+i//L[j])

# print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
L = [1]
m = 6
n = 9
while m < N:
    L.append(m)
    m *= 6
while n < N:
    L.append(n)
    n *= 9
L.sort()
# print(L)

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

for i in range(1, N+1):
    x = bisect_right(L, i)
    for j in range(x):
        dp[i] = min(dp[i], dp[i-L[j]]+1)

# print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
L = [1]
m = 6
n = 9
while m < N:
    L.append(m)
    m *= 6
while n < N:
    L.append(n)
    n *= 9
L.sort()
# print(L)

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

for i in range(1, N+1):
    x = bisect_right(L, i)
    l = L[:x]
    for j in range(len(l)):
        dp[i] = min(dp[i], dp[i-l[j]]+1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


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

    i = 1
    r = 6
    k = 9
    G = [1]
    while r < N:
        G.append(k)
        G.append(r)
        k *= 9
        r *= 6

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

    for i in range(N):
        c = number[i]
        for g in G:
            if i+g <=N:
                number[i+g] =min(c+1,number[i+g])
    print(number[N])



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 6**6 < 10**5 < 6**7
# 9**5 < 10**5 < 9**6

def solve(n):
    if n < 6:
        return n
    elif n < 9:
        return n - 5
    else:
        now_6 = 6
        while now_6 * 6 < n:
            now_6 *= 6

        now_9 = 9
        while now_9 * 9 < n:
            now_9 *= 9
        
        ans = float('inf')
        for i in range(n // now_6 + 1):
            cnt = i + (n - now_6*i) // now_9 + solve((n - now_6*i) % now_9)
            if cnt < ans:
                ans = cnt
        
        return ans

print(solve(int(input())))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
i = 0
 
while N > 0:
    n = int(math.log(N, 6))
    m = int(math.log(N, 9))
    #print(m)
    N =min(N-1, abs(N-6**n), abs(N-9**m))
    #print(N)
    i += 1
print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=0
b=0
c=0
ans_9=0
ans_6=0
ans_1=0
for i in range(n):
    if n>=9**i:
        a = n-9**i
        ans_9=1
    else:
        break


for j in range(a):
    if a>=6**j:
        b = a-6**j
        ans_6=1
    else:
        break


for k in range(b):
    if b>=9*k:
        c=b-9*k
        ans_9+=k
    else:
        break

for l in range(c):
    if c>=6*l:
        ans_1=c-6*l
        ans_6+=l
    else:
        break

print(ans_6+ans_9+ans_1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=0
b=0
c=0
ans_9=0
ans_6=0
ans_1=0
for i in range(n+1):
    if n>=9**i:
        a = n-9**i
        ans_9=1
    else:
        break


for j in range(a+1):
    if a>=6**j:
        b = a-6**j
        ans_6=1
    else:
        break


for k in range(b):
    if b>=9*k:
        c=b-9*k
        ans_9+=k
    else:
        break

for l in range(c+1):
    if c>=6*l:
        ans_1=c-6*l
        ans_6+=l
    else:
        break

print(ans_6+ans_9+ans_1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=0
b=0
c=0
ans_9=0
ans_6=0
ans_1=0
for i in range(n+1):
    if n>=9**i:
        a = n-9**i
        ans_9=1


for j in range(a+1):
    if a>=6**j:
        b = a-6**j
        ans_6=1


for k in range(b):
    if b>=9*k:
        c=b-9*k
        ans_9+=k

for l in range(c+1):
    if c>=6*l:
        ans_1=c-6*l
        ans_6+=l

print(ans_6+ans_9+ans_1)

Submission status: Wrong Answer

Solution code:
#解説見ながら

n = int(input())

ans = n

for i in range(n) :
    c = 0
    a = n-i
    while a>0 :
        c += a%6
        a = a//6
    a = i
    while a>0 :
        c += a%9
        a = a//9
    if c<ans :
        ans = c

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [0] * 100500

import math
dp[1] = 1
for i in range(2, N+1):
    dp[i] = dp[i-1] + 1
    for j in range(math.floor(math.log(i, 6)) + 1):
        dp[i] = min(dp[i], dp[i - 6 ** j] + 1)
    for k in range(math.floor(math.log(i, 9) + 0.00001) + 1):
        dp[i] = min(dp[i], dp[i - 9 ** k] + 1)


print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [0] * 100500

import math
dp[1] = 1
for i in range(2, N+1):
    dp[i] = dp[i-1] + 1
    for j in range(math.floor(math.log(i, 6)) + 1):
        dp[i] = min(dp[i], dp[i - 6 ** j] + 1)
    for k in range(math.floor(math.log(i, 9)) + 1):
        dp[i] = min(dp[i], dp[i - 9 ** k] + 1)


print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [0] * 100500

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


print(dp[N])

Submission status: Wrong Answer

Solution code:
n = int(input())
def f(x):
  ans=0
  while x >0:
    ans+=x%6
    x = x//6
  return ans
def g(x):
  ans=0
  while x >0:
    ans+=x%9
    x = x//9
  return ans
ans = n
for i in range(n+1):
  ans = min(ans,f(n-i),g(i))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [float('inf')]*(N+1)
dp[0] = 0
for i in range(N+1):
    if i+1 <= N:
        dp[i] = min(dp[i],dp[i-1]+1)
    for j in range(1,N+1):
        if i < 6**j:
            break
        dp[i] = min(dp[i-6**j]+1,dp[i])
    for k in range(1,N+1):
        if i < 9**k:
            break
        dp[i] = min(dp[i-9**k]+1,dp[i])
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [1]
b = [6,6**2,6**3,6**4,6**5,6**6]
c = [9,9**2,9**3,9**4,9**5]
list = a+b+c
list.sort(reverse = True)
a = 0
for i in range(12):
  a += N//list[i]
  N -= list[i]*(N//list[i])
print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[1]
i=1
while 6**i<=10**5:
    x.append(6**i)
    i+=1
i=1
while 9**i<=10**5:
    x.append(9**i)
    i+=1
x=sorted(x,reverse=True)
m=len(x)
ans=0

for i in range(m-3):
    z=n//x[i]
    ans+=z
    n-=x[i]*z
aa=n
for i in range(6):
    for j in range(4):
        if n-6*i-9*j>=0:
            aa=min(aa,i+j+n-6*i-9*j)

print(ans+aa)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(1, 7):
    all_procedure.append(6 ** i)

all_procedure.sort()

num = len(all_procedure)

counter = 0
while n >= 15:
    l = 0
    r = num - 1
    while l + 1 != r:
        mid = (l + r) // 2
        if n == all_procedure[mid]:
            counter += 1
            n -= all_procedure[mid]
            break
        elif n < all_procedure[mid]:
            r = mid
        elif mid < n:
            l = mid

    n -= all_procedure[l]
    counter += 1
if n % 9 + n // 9 > n % 6 + n // 6:
    print(counter + n // 6 + n % 6)
else:
    print(counter + n // 9 + n % 9)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

m_6 = math.floor(math.log(N, 6))
m_9 = math.floor(math.log(N, 9))

# for a_9 in range(m_9, 0, -1):
#     for a_6 in range(m_6, 0, -1):
#         print(a_6, a_9, N - 6**a_6 - 9**a_9)

rest = N
cnt = 0
for i in range(m_6, 0, -1):
    a = rest // (9 ** i)
    cnt += a
    rest -= a * 9 ** i
    b = rest // (6 ** i)
    cnt += b
    rest -= b * 6 ** i

cnt += rest

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[6**i for i in range(1,8)]+[9**i for i in range(7)]
r.sort(reverse=True)
cnt=0
while n>=6:
    for k in r:
        if k<=n:
            n-=k
            cnt+=1
            break
print(cnt+n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
inf=100000
dp=[inf for _ in range(N+1)]
dp[0]=0
dp[1]=1
for n in range(N+1):
    num=100000
    i=0
    j=0
    while n>9**i:
        i+=1
    while n>6**j:
        j+=1
    for k in range(i):
        num=min(num,dp[n-9**k]+1)
    for k in range(j):
        num=min(num,dp[n-6**k]+1)
    num=min(num,dp[n-1]+1)
    dp[n]=min(dp[n],num)
print(dp[N])

Submission status: Wrong Answer

Solution code:
n = int(input())

# a進法でのnの桁和
def func(n,a):
    res = 0
    while n > 0:
        res += n%a
        n //= a
    return res

mini = n

for i in range(n):
    tmp = func(i,6) + func(n-i,9)
    mini = min(mini,tmp)
print(mini)

Submission status: Wrong Answer

Solution code:
def f(a,x):
    l=[]
    while x!=0:
        l.append(x%a)
        x//=a
    return sum(l)

def main():
    N=int(input())
    MIN=100000
    for k in range(N):
        MIN=min(MIN,f(9,k)+f(6,(N-k)))
    return MIN

if __name__=="__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())

# a進法でのnの桁和
def func(n,a):
    res = 0
    while n > 0:
        res += n%a
        n //= a
    return res

mini = 10**6

for i in range(n):
    tmp = func(i,6) + func(n-i,9)
    mini = min(mini,tmp)
print(mini)

Submission status: Wrong Answer

Solution code:
n = int(input())

# a進法でのnの桁和
def func(n,a):
    res = 0
    while n > 0:
        res += n%a
        n //= a
    return res

mini = 10**5

for i in range(n):
    tmp = func(i,6) + func(n-i,9)
    mini = min(mini,tmp)
print(mini)

Submission status: Wrong Answer

Solution code:
def f(a,x):
    l=[]
    while x!=0:
        l.append(x%a)
        x//=a
    return sum(l)

def main():
    N=int(input())
    MIN=1000
    for k in range(N):
        MIN=min(MIN,f(9,k)+f(6,(N-k)))
    return MIN

if __name__=="__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
m = int(input())

def shin6(n):
    amari = []
    while True:
        if n >= 6:
            amari.append(n%6)
            n = n//6
        else:
            amari.append(n)
            break
    gyaku = amari[::-1]
    return gyaku

def shin9(n):
    amari = []
    while True:
        if n >= 9:
            amari.append(n%9)
            n = n//9
        else:
            amari.append(n)
            break
    gyaku = amari[::-1]
    return gyaku

li = [12,13,14,30,31,32]
li2 = [2,3,4,5,6,7]
cnt = 0
#msg = f"{m}="
while m>0:# and m not in li:
    s6 = shin6(m)
    s9 = shin9(m)
    #print(s6,s9)
    l1 = len(s6)
    l2 = len(s9)
    if 6**(l1-1)>9**(l2-1):
        m -= 6**(l1-1)
        #print(6,6**(l1-1),9**(l2-1))
        #msg += f"+{6**(l1-1)}"
    else:
        m -= 9**(l2-1)
        #print(9,6**(l1-1),9**(l2-1))
        #msg += f"+{9**(l2-1)}"
    cnt += 1
    #print(m,cnt)
"""
if m in li:
    cnt += li2[li.index(m)]
"""

print(cnt)

Submission status: Wrong Answer

Solution code:
m = int(input())

def shin6(n):
    amari = []
    while True:
        if n >= 6:
            amari.append(n%6)
            n = n//6
        else:
            amari.append(n)
            break
    gyaku = amari[::-1]
    return gyaku

def shin9(n):
    amari = []
    while True:
        if n >= 9:
            amari.append(n%9)
            n = n//9
        else:
            amari.append(n)
            break
    gyaku = amari[::-1]
    return gyaku

li = [12,13,14,30,31,32]
li2 = [2,3,4,5,6,7]
cnt = 0
#msg = f"{m}="
while m>0 and m not in li:
    s6 = shin6(m)
    s9 = shin9(m)
    #print(s6,s9)
    l1 = len(s6)
    l2 = len(s9)
    if 6**(l1-1)>9**(l2-1):
        m -= 6**(l1-1)
        #print(6,6**(l1-1),9**(l2-1))
        #msg += f"+{6**(l1-1)}"
    else:
        m -= 9**(l2-1)
        #print(9,6**(l1-1),9**(l2-1))
        #msg += f"+{9**(l2-1)}"
    cnt += 1
    #print(m,cnt)

if m in li:
    cnt += li2[li.index(m)]

print(cnt)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

dp = [n] * (n+1)

dp[0] = 0
dp[1] = 1

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

for i in range(1, n+1):
    dp[i] = min(dp[i-1]+1, dp[i])
    for x in range(1, p+1):
        y = pow(6, x)
        if i - y >= 0:
            dp[i] = min(dp[i-y] + 1, dp[i])
    for x in range(1, q+1):
        y = pow(9, x)
        if i - y >= 0:
            dp[i] = min(dp[i-y] + 1, dp[i])

print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())

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

inf=float('inf')
dp=[inf for _ in range(100000+1)]
dp[1]=1

for x in range(1,100001):
  for b in a:
    if b<=x:
      dp[x]=min(dp[x],dp[x-b]+1)
      
print(dp[n])

Submission status: Wrong Answer

Solution code:
N = int(input())

patterns = []
patterns.append(1)

f = 6
a = 6
while a <= N:
    patterns.append(a)
    a *= f

f = 9
a = 9
while a <= N:
    patterns.append(a)
    a *= f

dp = [float('inf')] * (N + 1)
dp[0] = 0
for n in range(1, N + 1):
    for p in patterns:
        if n - p < 0:
            break

        dp[n] = min(dp[n - p] + 1, dp[n])


print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
money = []
for i in range(n):
    if 6**i>n:
        break
    money.append(6**i)
for j in range(1,n):
    if 9**j>n:
        break
    money.append(9**j)
money.sort()
print(money)

ans = {}
for i in range(len(money)):
    if n//money[-(i+1)]>0:
        ans.setdefault(money[-(i+1)],n//money[-(i+1)])
    n = n%money[-(i+1)]

#print(ans)
print(sum(ans.values()))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

ans = [-1]*n

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

Submission status: Wrong Answer

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

ans = [-1]*n

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

Submission status: Wrong Answer

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

ans = [-1]*n

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

Submission status: Wrong Answer

Solution code:
import math
power_6 = [6 ** i for i in range(int(math.log(100000, 6)) + 1)]
power_9 = [9 ** i for i in range(int(math.log(100000, 9)) + 1)]
p = list(set(power_6 + power_9))
p.sort(reverse=True)

N = int(input())

remainder = ""
idx = 0
cnt = []
while N != 0:
  cnt.append(N // p[idx])
  N = N % p[idx]
  idx += 1
print(sum(cnt))

Submission status: Wrong Answer

Solution code:
import sys
from math import log, floor

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    ans = 1000000
    d_9 = [pow(9, i) for i in range(1, floor(log(n, 9)) + 1)]
    d_6 = [pow(6, i) for i in range(1, floor(log(n, 6)) + 1)]
    D = sorted(d_9 + d_6, reverse=True)
    for i in range(2 ** len(D)):
        DD = []
        for j in range(len(D)):
            if ((i >> j) & 1):
                DD.append(D[j])
        nn = n
        tmp = 0
        for d in DD:
            tmp += nn // d
            nn %= d
        tmp += nn
        ans = min(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

# dp[i] := i円引き出すのに必要な最小操作回数
dp = [float('inf')] * (N + 1)
dp[0] = 0
operates = [1, 6, 36, 216, 9, 81, 729]
for i in range(N):
    for ope in operates:
        if i + ope > N:
            continue
        dp[i + ope] = min(dp[i + ope], dp[i] + 1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
def sinsuuton(X, n): #10進数の Xをn進数に
    if (int(X/n)):
        return sinsuuton(int(X/n), n)+str(X%n)
    return str(X%n)
def sinsuutoo10(X,n): #n進数のX(str)を10進数に
    return sum([ X[-i-1]*n**i for i in range(len(X)) ])
n=int(input())
ans=98754
for i in range(1,n):
    t=i
    now=0
    t6= sinsuuton(t, 6)
    now+= sum([int(i) for i in t6])
    t=n-i
    t9= sinsuuton(t, 9)
    now+= sum([int(i) for i in t9])
    ans=min(ans,now)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
cnt = 0
d = {n:0}
q = deque([n])
while q and (q[0] > -10000):
    t = q.popleft()
    cnt = d[t]
    # print(t)
    a = 1
    b = 1
    while 6**a <= t:
        a += 1
    while 9**b <= t:
        b += 1
    a -= 1
    b -= 1
    # print(a,b)
    if t-6**a in d:
        if d[t-6**a] <= cnt+1:
            continue
        else:
            d[t-6**a] = cnt+1
            q.append(t-6**a)
    else:
        d[t-6**a] = cnt+1
        q.append(t-6**a)
    if t-9**b in d:
        if d[t-9**b] <= cnt+1:
            continue
        else:
            d[t-9**b] = cnt+1
            q.append(t-9**b)
    else:
        d[t-9**b] = cnt+1
        q.append(t-9**b)
    # print(q)
print(d[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
cnt = 0
d = {n:0}
q = deque([n])
while q and (q[0] > -5):
    t = q.popleft()
    cnt = d[t]
    # print(t)
    a = 1
    b = 1
    while 6**a <= t:
        a += 1
    while 9**b <= t:
        b += 1
    a -= 1
    b -= 1
    # print(a,b)
    if t-6**a in d:
        if d[t-6**a] <= cnt+1:
            continue
        else:
            d[t-6**a] = cnt+1
            q.append(t-6**a)
    else:
        d[t-6**a] = cnt+1
        q.append(t-6**a)
    if t-9**b in d:
        if d[t-9**b] <= cnt+1:
            continue
        else:
            d[t-9**b] = cnt+1
            q.append(t-9**b)
    else:
        d[t-9**b] = cnt+1
        q.append(t-9**b)
    # print(q)
print(d[0])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

dp = [10**18] * (100000 + 10)
dp[0] = 0

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

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


print(dp[n])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

dp = [10**18] * (n+1)
dp[0] = 0

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

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

print(dp[-1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

dp = [10**18] * (n+1)
dp[0] = 0

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

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

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
m=99999999999999
from math import log
for i in range(0,n+1):
    t6=i
    t9=n-i
    c=0
    while(t6>0):
        k=int(log(t6,6))
        a=t6//(6**k)
        c+=a
        t6=t6%(6**k)
    while (t9 > 0):
        k = int(log(t9, 9))
        a = t9 // (9 ** k)
        c += a
        t9 = t9 % (9 ** k)
    if c<m:
        m=c
print(m)

Submission status: Wrong Answer

Solution code:
from itertools import product

n = int(input())
n = 9 ** 6 - 1

pow6 = [pow(6, i + 1) for i in range(6)]
pow9 = [pow(9, i) for i in range(6)][::-1]

ans = n
for l in product(range(6), repeat=6):
    cnt = sum(l)
    num = n - sum(pi * li for pi, li in zip(pow6, l))
    if num >= 0:
        tmp = 0
        while num > 0:
            if pow9[tmp] > num:
                tmp += 1
            elif pow9[tmp] <= num:
                num -= pow9[tmp]
                cnt += 1
        ans = min(ans, cnt)
print(ans)