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())
payable = [1] + [6**(int(x)+1) for x in range(7)] + [9**(int(x)+1) for x in range(6)]
payable.sort(reverse=True)
ans = 0
while n > 0:
    for value in payable:
        if value > n:
            payable.remove(value)
        else:
            break
    n -= max(payable)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
payable = [1] + [6**(int(x)+1) for x in range(6)] + [9**(int(x)+1) for x in range(5)]
payable.sort()
ans = 0
while n > 0:
    for value in payable:
        if value > n:
            payable.remove(value)
    n -= max(payable)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [0] * (10 ** 5 + 10)
dp[0] = 0
for i in range(1, 10 ** 5):
    dp[i] = 10 ** 5 + 1
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 6

    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 9

print(dp[N])

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
result = 10**18
for six in itertools.product(range(6), repeat=6):
    ans = 0
    SUM = 0
    for i in range(1, 7):
        SUM += (6**i) * six[i-1]
    if SUM <= N:
        ans += sum(six)
        rem = N-SUM
        for j in range(1, 6):
            if rem > 9**(6-j):
                ans += rem // (9**(6-j))
                rem -= (rem // (9**(6-j))) * (9**(6-j))
        ans += rem
        result = min(ans, result)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())


def dfs(remain, count):
    if 6 > remain:
        return count + remain
    count9 = dfs(remain - 9, count + 1) if remain - 9 > 0 else count + remain
    count6 = dfs(remain - 6, count + 1) if remain - 6 > 0 else count + remain
    return count9 if count9 < count6 else count6


count = 0
while n >= 6:
    m_9 = 1
    while 9 ** m_9 <= n:
        m_9 += 1
    m_6 = 1
    while 6 ** m_6 <= n:
        m_6 += 1
    if 2 == m_9 and 2 == m_6:
        count += dfs(n, 0)
        n = 0
    else:
        candidates = [9 ** (m_9 - 1), 6 ** (m_6 - 1)]
        n -= max(candidates)
        count += 1
print(count + n)

Submission status: Wrong Answer

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

# 整数bをa進数で表現した時の各桁の和
# (ex. 7,6 => (6**1)*1 + (6**0)*1 => 1+1=2
def func(n,a):
    x = 0
    while n > 0:
        x += n%a
        n //= a
    return x

def main():
    N = int(input())
    mi = N
    for i in range(N):
        mi = min(mi, func(i,6) + func(N-i,9))
    print(mi)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
a = [0] * 12
for i in range(1, 7):
  a[2*(i-1)] += max((9**(i-1)), (6**i))
  a[2*(i-1)-1] += min((9**(i-1)), (6**i))
a.sort(reverse=True)
for i in a:
  if (n//i) != 0:
    ans += n//i
    n -= n//i * i

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
a = [0] * 12
for i in range(1, 7):
  print(i)
  a[2*(i-1)] += max((9**(i-1)), (6**i))
  a[2*(i-1)-1] += min((9**(i-1)), (6**i))
print(a)
for i in a:
  if (n//i) != 0:
    ans += n//i
    n -= n//i * i

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
j = 0
cnt = 0

while n >= 6:
  while 9**i <= n:
    i += 1

  while 6**j <= n:
    j += 1
    
  n -= max(9**(i-1), 6**(j-1))
  print(n)
  i = 0
  j = 0
  cnt += 1
  
print(cnt + n)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


N = int(input())

dp = [float('inf')]*(N+1)
dp[0] = 1

six_count = 1
nine_count = 1

for i in range(1,N):

    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 6

    power = 1
    while power <= N:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 9

print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


N = int(input())

dp = [float('inf')]*(N+1)
dp[0] = 1

six_count = 1
nine_count = 1

for i in range(1,N):

    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[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


N = int(input())

dp = np.zeros(N,dtype=np.int)
dp[0] = 1

six_count = 1
nine_count = 1

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

    if i == pow(6,six_count):
        six_count = six_count + 1
    if i == pow(9,nine_count):
        nine_count = nine_count + 1

    b = float('inf')
    c = float('inf')
    if i>=6:
        for _ in range(six_count):
            b = min(b,dp[i-pow(6,_)]+1)

    if i>=9:
        for _ in range(nine_count):
            c = min(c,dp[i-pow(9,_)]+1)

    dp[i] = min(a,b,c)

print(dp[N-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []

for i in range(1, N + 1):
    count = 0
    n_f = N - i
    n_s = i
    while n_f != 0:
        count += n_f % 6
        n_f //= 6
    while n_s != 0:
        count += n_s % 9
        n_s //= 9
    ans.append(count)

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
m6 = [6 ** i for i in reversed(range(7))]
m9 = [9 ** i for i in reversed(range(6))]
ans = []

for i in range(1, N + 1):
    count = 0
    n_f = N - i
    n_s = i
    while n_f != 0:
        for j in m6:
            if n_f - j >= 0:
                n_f -= j
                count += 1
                break
            else:
                continue
    while n_s != 0:
        for j in m9:
            if n_s - j >= 0:
                n_s -= j
                count += 1
                break
            else:
                continue
    ans.append(count)

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [1]
tmp = 6
while tmp < 10**5:
    A.append(tmp)
    tmp *= 6
tmp = 9
while tmp < 10**5:
    A.append(tmp)
    tmp *= 9

Ans = [float("inf")] * (10**5)
Ans[0] = 1

for i in range(1,10**5):
    tmp = float("inf")
    for j in A:
        if i-j >= 0:
            if tmp > Ans[i-j] + 1:
                tmp = Ans[i-j] + 1
    Ans[i] = tmp
print(Ans[N-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [1]
tmp = 6
while tmp < 10**5:
    A.append(tmp)
    tmp *= 6
tmp = 9
while tmp < 10**5:
    A.append(tmp)
    tmp *= 9
A = sorted(A)[::-1]

ans = 0
while N != 0:
    flag = 0
    for i in A:
        if flag == 0:
            if i <= N:
                ans += 1
                N -= i
                flag = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
m = [1]
l = [1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 3, 2, 3, 4, 2, 3, 4, 2]

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

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

m.sort(reverse=True)

if N <= 5:
    ans += N
else:
    while N != 0:
        if N <= 18:
            ans += l[N - 1]
            N = 0
        else:
            for i in m:
                if i <= N:
                    ans += 1
                    N -= i
                    break
                else:
                    continue

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
m = [1]

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

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

m.sort(reverse=True)

if N <= 5:
    ans += N
else:
    while N != 0:
        if N <= 5:
            ans += N // 3 + N % 3
            N = 0
        else:
            for i in m:
                if i <= N:
                    ans += max(N // i, 1)
                    N %= i
                    break
                else:
                    continue

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li=[6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp = [i for i in range(100010)]
for a in li:
    for x in range(a,N+1):
        print(dp[x],dp[x-a]+1)
        dp[x] = min(dp[x],dp[x-a]+1)
print(dp[N])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
dp = [mod for i in range(2*n)]
dp[0] = 0
p_6 = []
p_9 = []
tmp = 1
while tmp < n:
    p_6.append(tmp)
    tmp *= 6
tmp = 1
while tmp < n:
    p_9.append(tmp)
    tmp *= 9


for i in range(n):
    for j in p_6:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
    for k in p_9:
        if i+k <= n:
            dp[i+k] = min(dp[i+k],dp[i]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
dp = [mod for i in range(2*n)]
dp[0] = 0
p_6 = []
p_9 = []
tmp = 1
while tmp < n:
    p_6.append(tmp)
    tmp *= 6
tmp = 1
while tmp < n:
    p_9.append(tmp)
    tmp *= 9
for i in range(n):
    for j in p_6:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
    for k in p_9:
        if i+j <= n:
            dp[i+k] = min(dp[i+k],dp[i]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
a={1}
for i in range(1,8):
	a.add(6**i)
	a.add(9**i)
a=list(a)
a.sort()
n=int(input())
ans=0
j=len(a)-1
while n>0:
	if n>=a[j]:
		n-=a[j]
		ans+=1
	else:
		j-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=1
N=1
lst=[]
cnt=0
for i in range(16668):
  S*=6
  N*=9
  lst.append(S)
  lst.append(N)
lst.sort()
while n>5:
  for i in range(len(lst)):
    if lst[i]>n:
      n-=lst[i-1]
      cnt+=1
      break
print(cnt+n)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
S=1
N=1
lst=[]
cnt=0
for i in range(16668):
  S*=6
  N*=9
  lst.append(S)
  lst.append(N)
lst.sort()
if n<6:
  print(n)
  sys.exit()
while n>5:
  for i in range(len(lst)):
    if lst[i]>n:
      n-=lst[i-1]
      cnt+=1
      break
print(cnt+n)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=6
N=9
lst=[]
cnt=0
for i in range(16667):
  S*=6
  N*=9
  lst.append(S)
  lst.append(N)
lst.sort()
while n>5:
  for i in range(len(lst)):
    if lst[i]>n:
      n-=lst[i-1]
      cnt+=1
      break
print(cnt+n)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=6
N=9
lst=[]
cnt=0
for i in range(16667):
  S*=6
  N*=9
  lst.append(S)
  lst.append(N)
while n>5:
  for i in range(len(lst)):
    if lst[i]>n:
      n-=lst[i-1]
      cnt+=1
      break
print(cnt+n)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    loop = 1
    d = []
    while True:
        d.append(9 ** loop)
        d.append(6 ** loop)
        loop += 1
        if 6 ** loop > n:
            break
    d.sort(reverse=True)
    cnt = 0
    for v in d:
        t = n // v
        cnt += t
        n -= (t * v)
    print(cnt + n)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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

ans = 0
while dp[N] == 0:
    nextDP = [0] * (N+1)
    nextDP[0] = 1
    for i in range(N):
        if dp[i] == 1:
            nextDP[i+1] = 1
            j = 1
            while i + 6**j < N:
                nextDP[i+6**j] = 1
                j += 1
            j = 1
            while i + 9**j < N:
                nextDP[i+9**j] = 1
                j += 1
    dp = nextDP
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def nsin(X,n):
    if(int(X/n)):
        return nsin(int(X/n),n)+str(X%n)
    return str(X)

s = nsin(int(input()),9)
score = 0

for i in range(len(s)-1):
    score += int(s[i])//4 + int(s[i])%4

print(score + (int(s[-1])//6 + int(s[-1])%6))

Submission status: Wrong Answer

Solution code:
def jyou(n, maxNum):
    i = 1
    result = 0

    if n == 1:
        return 1

    while True:
        val = n ** i
        if val > maxNum:
            break

        i += 1
        result = val

    return result


N = int(input())
dp = [[0 for _ in range(3)] for _ in range(110000)]

nums = [9,6,1]

index = 0
isMatch = False
while True:
    for i,e in enumerate(nums):
        for k in range(3):
            maxNum = N - dp[index][k] 
            result = jyou(e, maxNum)
            nextVal = dp[index][k] + result

            dp[index + 1][i] = max(dp[index + 1][i], nextVal) 

            if nextVal == N:
                isMatch = True
                break
        if isMatch:
            break

    if isMatch:
        break
    index += 1
        
print(index + 1)

Submission status: Wrong Answer

Solution code:
"""
ある銀行では、お金の引き出しを難しくするために、一回の操作で引き出せる金額が
以下のいずれかとなっています。 
1 円 
6 円、 6 2 ( = 36 ) 円、 6 3 ( = 216 ) 円、 . . . 
9 円、 9 2 ( = 81 ) 円、 9 3 ( = 729 ) 円、 . . . 
この銀行からちょうど N 円を引き出すには少なくとも何回の操作が
必要か求めてください。 

ただし、一度引き出したお金を再び預け入れてはならないとします。

1 ≤ N ≤ 100000 
N は整数

127
→4

1 円、 9 円、 36 ( = 6 2 ) 円、 81 ( = 9 2 ) 円を引き出す操作をそれぞれ
 1 回ずつ行うことで、合計 4 回の操作で 127 円を引き出すことができます。
 
"""
def jyou(n, maxNum):
    i = 1
    result = 0

    if n == 1:
        return 1

    while True:
        val = n ** i
        if val > maxNum:
            break

        i += 1
        result = val

    return result


N = int(input())
dp = [[0 for _ in range(3)] for _ in range(1000000)]

nums = [9,6,1]

index = 0
isMatch = False
while True:
    for i,e in enumerate(nums):
        for k in range(3):
            maxNum = N - dp[index][k] 
            result = jyou(e, maxNum)
            nextVal = dp[index][k] + result

            dp[index + 1][i] = max(dp[index + 1][i], nextVal) 

            if nextVal == N:
                isMatch = True
                break
        if isMatch:
            break

    if isMatch:
        break
    index += 1
        
print(index + 1)

Submission status: Wrong Answer

Solution code:
def jyou(n, maxNum):
    i = 1
    result = 0

    if n == 1:
        return 1

    while True:
        val = n ** i
        if val > maxNum:
            break

        i += 1
        result = val

    return result


N = int(input())
dp = [[0 for _ in range(3)] for _ in range(100000)]

nums = [9,6,1]

index = 0
isMatch = False
while True:
    for i,e in enumerate(nums):
        for k in range(3):
            maxNum = N - dp[index][k] 
            result = jyou(e, maxNum)
            nextVal = dp[index][k] + result

            dp[index + 1][i] = max(dp[index + 1][i], nextVal) 

            if nextVal == N:
                isMatch = True
                break
        if isMatch:
            break

    if isMatch:
        break
    index += 1
        
print(index + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
low_numbers = [1]

max_9_p = 1
while 9 ** max_9_p <= n:
    low_numbers.append(9 ** max_9_p)
    max_9_p += 1

max_6_p = 1
while 6 ** max_6_p <= n:
    low_numbers.append(6 ** max_6_p)
    max_6_p += 1

low_numbers.sort(reverse=True)
print(low_numbers)
ans_list = []

for i in range(len(low_numbers)):
    n_ = n
    ans = 0
    for m in low_numbers[i:]:
        c = n_ // m
        ans += c
        n_ %= m
    ans_list.append(ans)

print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
low_numbers = [1]

max_9_p = 1
while 9 ** max_9_p <= n:
    low_numbers.append(9 ** max_9_p)
    max_9_p += 1

max_6_p = 1
while 6 ** max_6_p <= n:
    low_numbers.append(6 ** max_6_p)
    max_6_p += 1

low_numbers.sort(reverse=True)
ans = 0
for m in low_numbers:
    c = n // m
    ans += c
    n %= m

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
low_numbers = [1]

max_9_p = 0
while True:
    max_9_p += 1
    if 9 ** max_9_p <= n:
        low_numbers.append(9 ** max_9_p)
    else:
        break

max_6_p = 0
while True:
    max_6_p += 1
    if 6 ** max_6_p <= n:
        low_numbers.append(6 ** max_6_p)
    else:
        break

low_numbers.sort(reverse=True)
ans = 0

for m in low_numbers:
    c = n // m
    ans += c
    n %= m

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

ans = N
for i in range(N // 9 + 1):
    nine = i * 9
    six = N - nine
    tmp_ans = 0
    print(nine, six)
    while nine > 0:
        tmp_ans += nine % 9
        nine = nine // 9
    while six > 0:
        tmp_ans += six % 6
        six = six // 6
    ans = min(tmp_ans, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

ans = N
for i in range((N - 1) // 9 + 1):
    nine = i * 9
    six = N - nine
    tmp_ans = 0
    while nine > 0:
        tmp_ans += nine % 9
        nine = nine // 9
    while six > 0:
        tmp_ans += six % 6
        six = six // 6
    ans = min(tmp_ans, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

nine = [9 ** i for i in range(1, 20) if 9 ** i <= 10 ** 5]

ans = N
for i in range(N // 9):
    nine = i * 9
    six = N - nine
    tmp_ans = 0
    while nine > 0:
        tmp_ans += nine % 9
        nine = nine // 9
    while six > 0:
        tmp_ans += six % 6
        six = six // 6
    ans = min(tmp_ans, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


def withdraw_greedy(deposit):
    acc = deposit
    m_nine = 1
    while acc > 0:
        tmp_acc = acc // 9
        if tmp_acc < 1:
            break
        acc = tmp_acc
        m_nine *= 9

    acc = deposit
    m_six = 1
    while acc > 0:
        tmp_acc = acc // 6
        if tmp_acc < 1:
            break
        acc = tmp_acc
        m_six *= 6

    withdraw_m = max(1, m_six, m_nine)
    return deposit - withdraw_m


ans = 0
rest = N
s = 0
while rest > 0:
    withdraw_m = withdraw_greedy(rest)
    s = rest - withdraw_m
    rest = withdraw_m
    ans += 1
    # print('ans:', ans, 'withdraw:', withdraw_m, 's:', s)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


def withdraw_greedy(deposit):
    acc = deposit
    m_nine = 1
    while acc > 0:
        tmp_acc = acc // 9
        if tmp_acc < 1:
            break
        acc = tmp_acc
        m_nine *= 9

    acc = deposit
    m_six = 1
    while acc > 0:
        tmp_acc = acc // 6
        if tmp_acc < 1:
            break
        acc = tmp_acc
        m_six *= 6

    withdraw_m = max(1, m_six, m_nine)
    return deposit - withdraw_m


ans = 0
rest = N
s = 0
while rest > 0:
    withdraw_m = withdraw_greedy(rest)
    s = rest - withdraw_m
    rest = withdraw_m
    ans += 1
    # print('ans:', ans, 'withdraw:', withdraw_m, 's:', s)

print(ans, s)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = 0
y = 0
b = [6]
c = [9]
count = 0
while b[x] <= 100000:
    b += [6**(x+2)]
    x += 1
while c[y] <= 100000:
    c += [9**(y+2)]
    y += 1
d = sorted([1]+b[0:len(b)-1]+c[0:len(c)-1])[::-1]
for i in range(len(d)):
    while n >= d[i]:
        n -= d[i]
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [1]
i = 6
while i < n:
  a.append(i)
  i *= 6
i = 9
while i < n:
  a.append(i)
  i *= 9
t = [float("inf")] * (n + 1)
t[0] = 0
for i in range(n):
  for j in a:
    if i + j <= n and t[i + j] > t[i] + 1:
      t[i + j] = t[i] + 1
print(t[n])

Submission status: Wrong Answer

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

n = int(input())

dp = [0] * (n+1)

for i in range(0, n+1):
  dp[i] = i
  six = 6
  nine = 9
  while True:
    six *= 6
    if six > i:
      six /= 6
      break
  if i - six >= 0:
    dp[i] = min(dp[i], dp[i-int(six)]+1)
  while True:
    nine *= 9
    if nine > i:
      nine /= 9
      break
  if i - six >= 0:
    dp[i] = min(dp[i], dp[i-int(nine)]+1)
#print(*dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
l=sorted([1,6,6**2,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5])
le=len(l)
for i in range(le):
  ans+=N//l[le-1-i]
  N=N%l[le-1-i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python


def get_all_values(N, v):
    all_values = []

    current = v
    while current < N:
        all_values.append(current)
        current *= v

    return all_values


def get_min_number(memo, all_values, N):
    if N in memo:
        return memo[N]

    if N in all_values:
        return 1
    elif N < 6:
        return N
    else:
        min_number = min(
            [get_min_number(memo, all_values, N - v) + 1 for v in all_values if N - v >= 0]
        )
        memo[N] = min_number
        return min_number


def solve(N):
    # Get all values and sort in descent order
    all_values = [1] + get_all_values(N, 6) + get_all_values(N, 9)
    sorted_all_values = list(reversed(sorted(all_values)))

    # Recursively get minimum number
    memo = {}
    ans = get_min_number(memo, sorted_all_values, N)

    return ans


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

    # Solve
    ans = solve(N)

    # Answer
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())

six=[6**i for i in range(1, 7)]
nine=[9**i for i in range(0, 6)]
Cash=sorted(six+nine, reverse=True)

ans=0
i=0
while i<len(Cash):
    c=Cash[i]
    num=n//c
    n-=num*c
    ans+=num
    print(num, c, n)
    if n==0:
        break
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
x = [6**i for i in range(1,8)]
y = [9**i for i in range(1,8)]
l = sorted([1] + x + y)

cnt = 0
while n != 0:
    cnt += 1
    ind = bisect.bisect_right(l, n)
    n -= l[ind-1]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N
for n9 in range(N//9):
    a = N - 9*n9
    c = 0
    while a >= 6:
        c += a % 6
        a = a // 6
    c2 = 0
    while n9 >= 9:
        c2 += n9 % 9
        n9 = n9 // 9
    cost = a + c + c2 + n9
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [1]
for i in range(1, 9):
    if 6**i < 100000:
        l.append(6**i)
    if 9**i < 100000:
        l.append(9**i)

l.sort()
i = -1
count = 0
while n != 0:
    if n // l[i] > 0:
        count += n // l[i]
        n = n % l[i]
    i -= 1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
i=1
count=0
n6=1
n9=1
l=[1]
while True:
    if 9**i>n:
        n9=i-1
        break
    i+=1
i=1
while True:
    if 6**i>n:
        n6=i-1
        break
    i+=1
for i in range(n6):
    l.append(6**(i+1))
for i in range(n9):
    l.append(9**(i+1))
l.sort(reverse=True)
for i in l:
    count+=n//i
    n%=i
    print(count)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
# counts of i yen will be given as cnt[i]
cnt = list(range(n+1))
options = [1]

p = 1
while 9**p < n:
    options.append(9**p)
    p += 1
p = 1
while 6**p < n:
    options.append(6**p)
    p += 1

options = sorted(options)
for i in range(n+1):
    for j in options:
        if i>=j:
            """If (i-j) yen could be withdrawn at less than (i-j) times,
            i yen will be done by additional j yen-withdrawal.
            """
            cnt[i] = min(cnt[i], cnt[i-j]+1)

print(cnt[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
# counts of i yen will be given as cnt[i]
cnt = [i for i in range(n+1)]
options = [1]

p = 1
while 9**p < n:
    options.append(9**p)
    p += 1
p = 1
while 6**p < n:
    options.append(6**p)
    p += 1

for i in range(n+1):
    for j in options:
        if i>=j:
            """If (i-j) yen could be withdrawn at less than (i-j) times,
            i yen will be done by additional j yen-withdrawal.
            """
            cnt[i] = min(cnt[i], cnt[i-j]+1)

print(cnt[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for k in range(n):
    six = 0
    nine = 0
    for i in range(1,n):
        if 6 ** i <= n:
            six = 6**i
        else:
            break
    for j in range(1,n):
        if 9 ** j <= n:
            nine = 9**j
        else:
            break
    if 12 <= n <= 14:
        ans += (2 +(n % 6))
        break
    if n < 6:
        ans += n
        break
    n = n - max(six, nine)
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for k in range(n):
    six = 0
    nine = 0
    for i in range(1,n):
        if 6 ** i <= n:
            six = 6**i
        else:
            break
    for j in range(1,n):
        if 9 ** j <= n:
            nine = 9**j
        else:
            break
    if 12 <= n <= 14:
        ans += (2 +n % 6)
        break
    if n < 6:
        ans += n
        break
    n = n - max(six, nine)
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for k in range(n):
    
    six = 0
    nine = 0
    for i in range(1,n):
        if 6 ** i <= n:
            six += 1
        else:
            break
    for j in range(1,n):
        if 9 ** j <= n:
            nine += 1
        else:
            break
    if n < 6:
        ans += n
        break
    n = n - max(6 **six, 9**nine)
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
i=1
count=0
n6=1
n9=1
l=[1]
while True:
    if 9**i>n:
        n9=i-1
        break
    i+=1
i=1
while True:
    if 6**i>n:
        n6=i-1
        break
    i+=1
for i in range(n6):
    l.append(6**(i+1))
for i in range(n9):
    l.append(9**(i+1))
l.sort(reverse=True)
for i in l:
    count+=n//i
    n%=i
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
# 100000以下の引き出せるお金の候補を作る
# 9**5 = 59049
# 6**6 = 46656

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

li.append(6**6)
li.append(1)
li.sort(reverse=True)

# print(li)

cnt = 0
while n != 0:
  for j in li:
    if n - j >= 0:
#       print(n, j, cnt)
      n -= j
      cnt += 1
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=n%3
n-=n%3
if n%9==3:
  if n==3:
    x+=3
    n=0
  else:
    x+=2
    n-=12
elif n%9==6:
  x+=1
  n-=6
while n>0:
  a=6
  while True:
    if a*6>n:
      break
    else:
      a*=6
  b=9
  while True:
    if b*9>n:
      break
    else:
      b*=9
  n-=max(a,b)
  x+=1
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=n%3
n-=n%3
if n%9==3:
  x+=2
  n-=12
elif n%9==6:
  x+=1
  n-=6
while n>0:
  a=6
  while True:
    if a*6>n:
      break
    else:
      a*=6
  b=9
  while True:
    if b*9>n:
      break
    else:
      b*=9
  n-=max(a,b)
  x+=1
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=0
while n>=6:
  a=6
  while True:
    if a*6>n:
      break
    else:
      a*=6
  b=9
  while True:
    if b*9>n:
      break
    else:
      b*=9
  n-=max(a,b)
  x+=1
print(x+n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [9**i for i in range(1,6)]
b = [6**i for i in range(1,7)]
c = a+b
p = 100000
a = 1
cnt = 0
while n>6:
    for i in c:
        if p>n//i>0:
            p = n//i
            a = max(i,a)
    n =n%a
    cnt +=1

print(cnt + n)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [1]
def under_nums(N,m):
    nums = []
    i = 1
    while m**i <= N:
        nums.append(m**i)
        i += 1
    return nums
all_nums = nums+under_nums(N,6)+under_nums(N,9)
all_nums.sort(reverse=True)
#print(all_nums)
cnt = 0
idx = 0
money = N
a = []
while money > 0:
    while money >= all_nums[idx]:
        #print(all_nums[idx])

        money -= all_nums[idx]
        a.append(all_nums[idx])
        #print("money="+str(money))
        cnt += 1
    idx += 1
print(cnt)
# print(a)
# print(sum(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [1]
def under_nums(N,m):
    nums = []
    i = 1
    while m**i <= N:
        nums.append(m**i)
        i += 1
    return nums
all_nums = nums+under_nums(N,6)+under_nums(N,9)
all_nums.sort(reverse=True)
print(all_nums)
cnt = 0
idx = 0
money = N
a = []
while money > 0:
    while money >= all_nums[idx]:
        #print(all_nums[idx])

        money -= all_nums[idx]
        a.append(all_nums[idx])
        #print("money="+str(money))
        cnt += 1
    idx += 1
print(cnt)
# print(a)
# print(sum(a))

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = [1]
upper = 10 ** 5

for i in range(1, 10):
  if (6 ** i < upper):
    lst.append(6 ** i)
  if (9 ** i < upper):
    lst.append(9 ** i)

lst.sort()
cnt = 0
while N != 0:
  for i in range(len(lst)):
    if (N < lst[i]):
      N -= lst[i-1]
      cnt += 1
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect as bi

li6 = [6 ** i for i in range(7)]
li9 = [9 ** i for i in range(6)]

def s69(n):
  if n < 6:
    return n
  else:
    s6 = li6[bi.bisect_left(li6, n)-1]
    s9 = li9[bi.bisect_left(li9, n)-1]
#    return min(n // s6 + s69(n % s6), n // s9 + s69(n % s9))
    return min(n // s6 + s69(n % s6), 1 + s69(n-s9), n // s9 + s69(n % s9))
  
print (s69(int(input())))