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())
ans=0

while(1):
    if n<6:
            break
    else:

        if n==12 or n==13 or n==14:
            ans+=n%6+2
            n=0
            break
        else:
            count9=9
            count6=6
            while(count9<=n):
                count9*=9
            while(count6<=n):
                count6*=6

            if count9/9>count6/6:
                n-=count9/9
            else:
                n-=count6/6
            ans+=1

print(int(ans+n))

Submission status: Wrong Answer

Solution code:
N = int(input())
number = N
n = 0
while number >= 18:
    n6 = 0
    n9 = 0
    num = number 
    while num > 0:
        num //= 6
        n6 += 1
    num = number 
    while num > 0:
        num //= 9
        n9 += 1
    x = max(6**(n6 -1),9**(n9 - 1))
    number -= x
    n += 1
else:
    if number >= 12:
        number -= 12
        n += 2
    if number >= 9:
        number -= 9
        n += 1
    if number >= 6:
        number -= 6
        n += 1
    n += number 
    print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
while n >= 15:
    i = 1
    while True:
        if 9**i <= n:
            i += 1
        else:
            a.append([9,i-1])
            break
        
    n -= 9**(i-1)
    if n < 15:
        break
    
    i = 1
    while True:
        if 6**i <= n:
            i += 1
        else:
            a.append([6,i-1])
            break
    n -= 6**(i-1)
    if n < 15:
        break

print(len(a)+min((n//6+n%6),(n//9+n%9)))

Submission status: Wrong Answer

Solution code:
n = int(input())
#入力

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

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
iq = 0
ix = 0
ii = 0
while n >= 9:
    n = n - 9
    iq += 1
while n >= 6:
    n = n - 6
    ix += 1
while n >= 1:
    n = n - 1
    ii += 1

iiq = 0
while iq // 9 > 9:
    iiq = iiq + iq % 9
    iq = iq // 9
iiq = iiq + iq % 9
iiq = iiq + iq //9

iix = 0
while ix // 6 > 6:
    iix = iix + ix % 6
    ix = ix // 6
iix = iix + ix % 6
iix = iix + ix //6

print(ii + iiq + iix)

Submission status: Wrong Answer

Solution code:
n = int(input())
iq = 0
ix = 0
ii = 0
while n >= 9:
    n = n - 9
    iq += 1
while n >= 6:
    n = n - 6
    ix += 1
while n >= 1:
    n = n - 1
    ii += 1

iiq = 0
while iq // 9 >= 9:
    iiq = iiq + iq % 9
    iq = iq // 9
iiq = iiq + iq % 9
iiq = iiq + iq //9

iix = 0
while ix // 6 >= 6:
    iix = iix + ix % 6
    ix = ix // 6
iix = iix + ix % 6
iix = iix + ix //6

print(ii + iiq + iix)

Submission status: Wrong Answer

Solution code:
n = int(input())
iq = 0
ix = 0
ii = 0
while n >= 0:
    n = n - 9
    iq += 1
while n >= 0:
    n = n - 6
    ix += 1
while n >= 0:
    n = n - 1
    ii += 1

iiq = 0
while iq // 9 >= 9:
    iiq = iiq + iq % 9
    iq = iq // 9
iiq = iiq + iq % 9
iiq = iiq + iq //9

iix = 0
while ix // 6 >= 6:
    iix = iix + ix % 6
    ix = ix // 6
iix = iix + ix % 6
iix = iix + ix //6

print(ii + iiq + iix)

Submission status: Wrong Answer

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

for i in [6,9]:
    v = i
    while v < 10 ** 5:
        for j in range(len(dp)):
            if j+v <= 10 ** 5:
                dp[j+v] =min(dp[j]+1,dp[j+v])
        v *= i  
        
print(dp[10**5])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
max_n = 10 ** 5
dp = [int(i) for i in range(max_n + 1)]
 
for i in (6,9):
    v = i
    while v < max_n:
        for j in range(len(dp)):
            if j + v < max_n:
                dp[j+v] = min(dp[j+v],dp[j]+1)
        v *= i
        
print(dp[n])

Submission status: Wrong Answer

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

for i in (6,9):
    v = i
    while v < max_n:
        for j in range(len(dp)):
            if j + v < max_n:
                dp[j+v] = min(dp[j+v],dp[j]+1)
        v *= i
        
dp[n]

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def solve_iter():
        if total == N:
            return res
        if total > N:
            return 1000000
    N  = int(lines.pop(0))
    Variation = [1]
    for i in [9, 6]:
        n = i
        while( n < N ):
            Variation.append(n)
            n *= i
    Variation.sort(reverse=True)
    Answer = []
    count = 0
    total = 0
    for i in Variation:
        while(True):
            if ( total + i > N ):
                break
            total += i
            count += 1
            if ( total == N ):
                print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
money = [6**i for i in range(1, 7) if 6**i < 100000]
money9 = [9**i for i in range(1, 7) if 9**i < 100000]
money.extend(money9)
money.sort(reverse=True)
for i in range(len(money)):
    if n >= money[i]:
        quo = n // money[i]
        ans += quo
        n -= money[i] * quo
print(ans+n)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [1]
for i in range(N):
	if 6**(i+1) <=N:
		L.append(6**(i+1))
	if 9**(i+1) <= N:
		L.append(9**(i+1))
	if 9**(i+1) >N:
		break
L.sort(reverse =True)
dp = []
dp = [float("inf")]*(N+1)
#print(L)
dp[0] = 0
#ある金額から出発
for i in range(N+1):
	for l in L:
		if i+l <= N:
			dp[i+l] = min(dp[i+l], dp[i]+1)
#print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
class DynamicProgramming(object):

    def __init__(self, item_n: int, border: int, obj_coef: list, sbj_coef: list, initializer: int = 0):
        self.item_n = item_n
        self.border = border
        self.table = [[initializer for _ in range(self.item_n + 1)] for _ in range(self.border + 1)]

        if len(obj_coef) == self.item_n:  # to 1-base
            obj_coef = [0] + obj_coef
        self.obj_coef = obj_coef

        if len(sbj_coef) == self.item_n:
            sbj_coef = [0] + sbj_coef
        self.sbj_coef = sbj_coef

    def __str__(self):
        return "\n".join(list(map(lambda l:
                                  " ".join(list(map(str, l)))
                                  , self.table)))

    def __repr__(self):
        return "DynamicProgramming object:\n" + \
               "item_n: " + str(self.item_n) + ", border: " + str(self.border) + "\n" +\
               "table:\n" + self.__str__()

    def solve(self, expr: callable) -> list:
        for weight_lim in range(1, self.border + 1):
            for item_idx in range(1, self.item_n + 1):
                self.table[weight_lim][item_idx] = expr(weight_lim, item_idx)

        return self.table

    def knapsack_expr(self, weight_lim: int, item_idx: int) -> int:
        res = self.table[weight_lim][item_idx - 1]
        if weight_lim - self.sbj_coef[item_idx] >= 0:
            res = max(res, self.table[weight_lim - self.sbj_coef[item_idx]][item_idx - 1] + self.obj_coef[item_idx])
        return res

    def coin_expr(self, target, coin_idx) -> int:
        if self.sbj_coef[coin_idx] == 1:
            res = target
        else:
            res = self.table[target][coin_idx - 1]
            if target - self.sbj_coef[coin_idx] >= 0:
                res = min(res, self.table[target - self.sbj_coef[coin_idx]][coin_idx] + self.obj_coef[coin_idx])
        return res

    def fill_0_idx_with(self, value: int) -> "DynamicProgramming":
        self.table[0] = [value for _ in range(self.item_n + 1)]
        for i in range(1, self.border + 1):
            self.table[i][0] = value
        return self


if __name__ == '__main__':
    N = int(input())
    values = sorted(list(set([6 ** i for i in range(7)] + [9 ** i for i in range(6)])))
    values_len = len(values)
    dp = DynamicProgramming(values_len, N, [1 for _ in range(values_len)], values, initializer=int(10e5))
    print(dp.solve(dp.coin_expr)[N][values_len])

Submission status: Wrong Answer

Solution code:
# ABC 099 解4 
import math
def getInt(): return int(input())
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
def atmUnit(base, req):
    if req<=0: return 0
    else: 
        unit = base ** int(math.log10(req)/math.log10(base))
        return unit # 引き出せる最大の単位量
def atm9(req): return atmUnit(9, req)
def atm6(req): return atmUnit(6, req)
def atm(req):
    #db(('req',req))
    if req<=0: return 0,0,0
    u9 = atm9(req)
    c9 = req // u9
    #db (('unit9,count9',u9,c9))
    u6 = atm6(req)
    c6 = req // u6
    #db (('unit6,count6',u6,c6))
    remainMax = min(u9,u6)
    #db(('remainMax:',remainMax))
    minCount = 999999
    for i in range(c9+1):
        for j in range(c6+1):
            if req-i*u9-j*u6>=remainMax: continue
            if req-i*u9-j*u6<0: continue
            c = atm(req-i*u9-j*u6)[0]
            if minCount>i+j+c:
                minCount = i+j+c
                db(('min',minCount,u9,i,u6,j,c))
    return minCount,u9,u6
    
debug = False
N = getInt()
ans =atm(N)
db(ans)
print(ans[0])

Submission status: Wrong Answer

Solution code:
# ABC 099 解4 
import math
def getInt(): return int(input())
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
def atmUnit(base, req):
    if req<=0: return 0
    else: 
        unit = base ** int(math.log10(req)/math.log10(base))
        return unit # 引き出せる最大の単位量
def atm9(req): return atmUnit(9, req)
def atm6(req): return atmUnit(6, req)
def atm(req):
    db(('req',req))
    if req<=0: return 0
    u9 = atm9(req)
    c9 = req // u9
    db (('unit9,count9',u9,c9))
    u6 = atm6(req)
    c6 = req // u6
    db (('unit6,count6',u6,c6))
    c6 = c6 + atm(req-c6*u6)
    remainMax = min(u9,u6)
    #db(('remainMax:',remainMax))
    minCount = 999999
    for i in range(c9+1):
        for j in range(c6+1):
            if req-i*u9-j*u6>=remainMax: continue
            if req-i*u9-j*u6<0: continue
            minCount = min(minCount, i+j+atm(req-i*u9-j*u6))
    #db(minCount)
    return minCount
    
debug = False
N = getInt()
print(atm(N))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ans = N

for N1 in range(N):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = math.floor(N1/6)
    
    while N2 > 0:
        count += N2%9
        N2 = math.floor(N2/9)
    
    if ans > count:
        ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ans = N

for N1 in range(N):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = math.floor(N1/6)
        print(N1)
    print(count)
    
    while N2 > 0:
        count += N2%9
        N2 = math.floor(N2/9)
    
    if ans > count:
        ans = count

print(ans)

Submission status: Wrong Answer

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

for N1 in range(N):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = int(N1/6)
    
    while N2 > 0:
        count += N2%9
        N2 = int(N2/9)
    
    if ans > count:
        ans = count

print(ans)

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

#    print('{},{}:'.format(i,cc),end = ' ')

    t = n-i
    while t>0:
        cc += t%9
        t //= 9
    
#   print('{},{}:'.format(n-i,cc))
    ans = min(ans, cc)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [i for i in range(100001)]
for i in range(100001):
    for j in range(1, 6):
        try:dp[i+6**j] = min(dp[i+6**j], dp[i]+1)
        except:pass
    for j in range(1, 5):
        try:dp[i+9**j] = min(dp[i+9**j], dp[i]+1)
        except:pass
    dp[i] = min(dp[i], dp[i]+1)

print(dp[N])

Submission status: Wrong Answer

Solution code:
# ABC 099 not yet
import math
def getInt(): return int(input())
def db(x): 
    global debug
    if debug: print(x)
def atm(unit, req):
    if req<=0: return 0
    else: return unit ** int(math.log10(req)/math.log10(unit))
debug = False
N = getInt()
count = 0
n = N
while n>0:
    c9 = atm(9, n)
    c6 = atm(6, n)
    db(('c9,c6:',c9,c6))
    c99 = atm(9, n-c9)
    c96 = atm(6, n-c9)
    c69 = atm(9, n-c6)
    c66 = atm(6, n-c6)
    db(('c99,c96,c69,c66:', c99,c96,c69,c66))
    if c9>c6:
        if c6+c66>c9+c99 or c6+c66>c9+c96 or c6+c69>c9+c99 or c6+c69>c9+c96: 
            db(c6)
            n -= c6
        else:
            db(c9)
            n -= c9
    elif c6>c9: 
        if c9+c99>c6+c69 or c9+c99>c6+c66 or c9+c96>c6+c69 or c9+c96>c6+c66: 
            db(c9)
            n -= c9
        else:
            db(c6)
            n -= c6
    else: # ==1
        count += n
        break
    count += 1
    db(('left:',n,count))
print(count)

Submission status: Wrong Answer

Solution code:
# ABC 099 not yet
import math
def getInt(): return int(input())
def db(x): 
    global debug
    if debug: print(x)
def atm(unit, req):
    if req<=0: return 0
    else: return unit ** int(math.log10(req)/math.log10(unit))
debug = False
N = getInt()
count = 0
n = N
while n>0:
    c9 = atm(9, n)
    c6 = atm(6, n)
    db((c9,c6))
    if c9>c6:
        c99 = atm(9, n-c9)
        c96 = atm(6, n-c9)
        c66 = atm(6, n-c6)
        if c6+c66>c9+c99 or c6+c66>c9+c96: 
            db(c6)
            n -= c6
        else:
            db(c9)
            n -= c9
    elif c6>c9: 
        db(c6)
        n -= c6
    else: # ==0
        count += n
        break
    count += 1
    db((n,count))
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import *
import sys
sys.setrecursionlimit(1145141919)
N = int(input())

def find_n(x):
    n6 = int(floor(log(x, 6)))
    n9 = int(floor(log(x, 9)))
    return 6**n6, 9**n9

memo = np.ones(N + 1) * -1

def dp(n):
    if memo[n] != -1:
        return memo[n]
    if n == 0:
        return 0
    n6, n9 = find_n(n)
    dp6 = 1 + dp(n - n6)
    dp9 = 1 + dp(n - n9)
    memo[n] = min(dp6, dp9)
    return memo[n]

print(int(dp(N)))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import *
import sys
sys.setrecursionlimit(1145141919)
N = int(input())

def find_n(x):
    n6 = floor(log(x, 6))
    n9 = floor(log(x, 9))
    return 6**n6, 9**n9

memo = np.ones(N + 1) * -1

def dp(n):
    if memo[n] != -1:
        return memo[n]
    if n == 0:
        return 0
    n6, n9 = find_n(n)
    dp6 = 1 + dp(n - n6)
    dp9 = 1 + dp(n - n9)
    memo[n] = min(dp6, dp9)
    return memo[n]

print(int(dp(N)))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import *
import sys
sys.setrecursionlimit(1145141919)
N = int(input())

def find_n(x):
    n6 = floor(log(x, 6))
    n9 = floor(log(x, 9))
    return 6**n6, 9**n9

memo = np.ones(N + 1) * -1

def dp(n):
    if memo[n] != -1:
        return memo[n]
    if n == 0:
        return 0
    n6, n9 = find_n(n)
    if n < 6:
        dp1 = n
    else:
        dp1 = 10e8
    dp6 = 1 + dp(n - n6)
    dp9 = 1 + dp(n - n9)
    memo[n] = min(dp1, dp6, dp9)
    return memo[n]

print(int(dp(N)))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
def greed(N, a):
    num = 0
    while True:
        if N == 0:
            return num
        p = int(math.log10(N) / math.log10(a))
        N -= a**p
        num += 1
A = []
for n in range(N+1):
    A.append(greed(n, 6) + greed(N-n, 9))
print(min(A))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
def greed(N, a):
    num = 0
    while True:
        if N == 0:
            return num
        p = int(math.log(N) / math.log(a))
        N -= a**p
        num += 1
A = []
for n in range(N+1):
    A.append(greed(n, 6) + greed(N-n, 9))
print(min(A))

Submission status: Wrong Answer

Solution code:
dic = {0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 1,
7: 2,
8: 3,
9: 1,
10: 2,
11: 3,
12: 2,
13: 3,
14: 4,
15: 2,
16: 3,
17: 4,
18: 2,
19: 3,
20: 4,
21: 3,
22: 4,
23: 5,
24: 3,
25: 4,
26: 5,
27: 3,
28: 4,
29: 5,
30: 4,
31: 5,
32: 6,
33: 4,
34: 5,
35: 6,
36: 1,
37: 2,
38: 3,
39: 4,
40: 5,
41: 6,
42: 2,
43: 3,
44: 4,
45: 2,
46: 3,
47: 4,
48: 3,
49: 4,
50: 5,
51: 3,
52: 4,
53: 5,
54: 3,
55: 4,
56: 5,
57: 4,
58: 5,
59: 6,
60: 4,
61: 5,
62: 6,
63: 4,
64: 5,
65: 6,
66: 5,
67: 6,
68: 7,
69: 5,
70: 6,
71: 7,
72: 2,
73: 3,
74: 4,
75: 5,
76: 6,
77: 7,
78: 3,
79: 4,
80: 5,
81: 1,
82: 2,
83: 3,
84: 4,
85: 5,
86: 6,
87: 2,
88: 3,
89: 4,
90: 2,
91: 3,
92: 4,
93: 3,
94: 4,
95: 5,
96: 3,
97: 4,
98: 5,
99: 3,
100: 4,
101: 5,
102: 4,
103: 5,
104: 6,
105: 4,
106: 5,
107: 6,
108: 3,
109: 4,
110: 5,
111: 5,
112: 6,
113: 7,
114: 4,
115: 5,
116: 6,
117: 2,
118: 3,
119: 4,
120: 5,
121: 6,
122: 7,
123: 3,
124: 4,
125: 5,
126: 3,
127: 4,
128: 5,
129: 4,
130: 5,
131: 6,
132: 4,
133: 5,
134: 6,
135: 4,
136: 5,
137: 6,
138: 5,
139: 6,
140: 7,
141: 5,
142: 6,
143: 7,
144: 4,
145: 5,
146: 6,
147: 6,
148: 7,
149: 8,
150: 5,
151: 6,
152: 7,
153: 3,
154: 4,
155: 5,
156: 6,
157: 7,
158: 8,
159: 4,
160: 5,
161: 6,
162: 2,
163: 3,
164: 4,
165: 5,
166: 6,
167: 7,
168: 3,
169: 4,
170: 5,
171: 3,
172: 4,
173: 5,
174: 4,
175: 5,
176: 6,
177: 4,
178: 5,
179: 6,
180: 4,
181: 5,
182: 6,
183: 5,
184: 6,
185: 7,
186: 5,
187: 6,
188: 7,
189: 4,
190: 5,
191: 6,
192: 6,
193: 7,
194: 8,
195: 5,
196: 6,
197: 7,
198: 3,
199: 4,
200: 5,
201: 6,
202: 7,
203: 8,
204: 4,
205: 5,
206: 6,
207: 4,
208: 5,
209: 6,
210: 5,
211: 6,
212: 7,
213: 5,
214: 6,
215: 7,
216: 1,
217: 2,
218: 3,
219: 4,
220: 5,
221: 6,
222: 2,
223: 3,
224: 4,
225: 2,
226: 3,
227: 4,
228: 3,
229: 4,
230: 5,
231: 3,
232: 4,
233: 5,
234: 3,
235: 4,
236: 5,
237: 4,
238: 5,
239: 6,
240: 4,
241: 5,
242: 6,
243: 3,
244: 4,
245: 5,
246: 5,
247: 6,
248: 7,
249: 4,
250: 5,
251: 6,
252: 2,
253: 3,
254: 4,
255: 5,
256: 6,
257: 7,
258: 3,
259: 4,
260: 5,
261: 3,
262: 4,
263: 5,
264: 4,
265: 5,
266: 6,
267: 4,
268: 5,
269: 6,
270: 4,
271: 5,
272: 6,
273: 5,
274: 6,
275: 7,
276: 5,
277: 6,
278: 7,
279: 4,
280: 5,
281: 6,
282: 6,
283: 7,
284: 8,
285: 5,
286: 6,
287: 7,
288: 3,
289: 4,
290: 5,
291: 6,
292: 7,
293: 8,
294: 4,
295: 5,
296: 6,
297: 2,
298: 3,
299: 4,
300: 5,
301: 6,
302: 7,
303: 3,
304: 4,
305: 5,
306: 3,
307: 4,
308: 5,
309: 4,
310: 5,
311: 6,
312: 4,
313: 5,
314: 6,
315: 4,
316: 5,
317: 6,
318: 5,
319: 6,
320: 7,
321: 5,
322: 6,
323: 7,
324: 4,
325: 5,
326: 6,
327: 6,
328: 7,
329: 8,
330: 5,
331: 6,
332: 7,
333: 3,
334: 4,
335: 5,
336: 6,
337: 7,
338: 8,
339: 4,
340: 5,
341: 6,
342: 4,
343: 5,
344: 6,
345: 5,
346: 6,
347: 7,
348: 5,
349: 6,
350: 7,
351: 5,
352: 6,
353: 7,
354: 6,
355: 7,
356: 8,
357: 6,
358: 7,
359: 8,
360: 5,
361: 6,
362: 7,
363: 7,
364: 8,
365: 9,
366: 6,
367: 7,
368: 8,
369: 4,
370: 5,
371: 6,
372: 7,
373: 8,
374: 9,
375: 5,
376: 6,
377: 7,
378: 3,
379: 4,
380: 5,
381: 6,
382: 7,
383: 8,
384: 4,
385: 5,
386: 6,
387: 4,
388: 5,
389: 6,
390: 5,
391: 6,
392: 7,
393: 5,
394: 6,
395: 7,
396: 5,
397: 6,
398: 7,
399: 6,
400: 7,
401: 8,
402: 6,
403: 7,
404: 8,
405: 5,
406: 6,
407: 7,
408: 7,
409: 8,
410: 9,
411: 6,
412: 7,
413: 8,
414: 4,
415: 5,
416: 6,
417: 7,
418: 8,
419: 9,
420: 5,
421: 6,
422: 7,
423: 5,
424: 6,
425: 7,
426: 6,
427: 7,
428: 8,
429: 6,
430: 7,
431: 8,
432: 2,
433: 3,
434: 4,
435: 5,
436: 6,
437: 7,
438: 3,
439: 4,
440: 5,
441: 3,
442: 4,
443: 5,
444: 4,
445: 5,
446: 6,
447: 4,
448: 5,
449: 6,
450: 4,
451: 5,
452: 6,
453: 5,
454: 6,
455: 7,
456: 5,
457: 6,
458: 7,
459: 4,
460: 5,
461: 6,
462: 6,
463: 7,
464: 8,
465: 5,
466: 6,
467: 7,
468: 3,
469: 4,
470: 5,
471: 6,
472: 7,
473: 8,
474: 4,
475: 5,
476: 6,
477: 4,
478: 5,
479: 6,
480: 5,
481: 6,
482: 7,
483: 5,
484: 6,
485: 7,
486: 5,
487: 6,
488: 7,
489: 6,
490: 7,
491: 8,
492: 6,
493: 7,
494: 8,
495: 5,
496: 6,
497: 7,
498: 7,
499: 8,
500: 9,
501: 6,
502: 7,
503: 8,
504: 4,
505: 5,
506: 6,
507: 7,
508: 8,
509: 9,
510: 5,
511: 6,
512: 7,
513: 3,
514: 4,
515: 5,
516: 6,
517: 7,
518: 8,
519: 4,
520: 5,
521: 6,
522: 4,
523: 5,
524: 6,
525: 5,
526: 6,
527: 7,
528: 5,
529: 6,
530: 7,
531: 5,
532: 6,
533: 7,
534: 6,
535: 7,
536: 8,
537: 6,
538: 7,
539: 8,
540: 5,
541: 6,
542: 7,
543: 7,
544: 8,
545: 9,
546: 6,
547: 7,
548: 8,
549: 4,
550: 5,
551: 6,
552: 7,
553: 8,
554: 9,
555: 5,
556: 6,
557: 7,
558: 5,
559: 6,
560: 7,
561: 6,
562: 7,
563: 8,
564: 6,
565: 7,
566: 8,
567: 6,
568: 7,
569: 8,
570: 7,
571: 8,
572: 9,
573: 7,
574: 8,
575: 9,
576: 6,
577: 7,
578: 8,
579: 8,
580: 9,
581: 10,
582: 7,
583: 8,
584: 9,
585: 5,
586: 6,
587: 7,
588: 8,
589: 9,
590: 10,
591: 6,
592: 7,
593: 8,
594: 4,
595: 5,
596: 6,
597: 7,
598: 8,
599: 9,
600: 5,
601: 6,
602: 7,
603: 5,
604: 6,
605: 7,
606: 6,
607: 7,
608: 8,
609: 6,
610: 7,
611: 8,
612: 6,
613: 7,
614: 8,
615: 7,
616: 8,
617: 9,
618: 7,
619: 8,
620: 9,
621: 6,
622: 7,
623: 8,
624: 8,
625: 9,
626: 10,
627: 7,
628: 8,
629: 9,
630: 5,
631: 6,
632: 7,
633: 8,
634: 9,
635: 10,
636: 6,
637: 7,
638: 8,
639: 6,
640: 7,
641: 8,
642: 7,
643: 8,
644: 9,
645: 7,
646: 8,
647: 9,
648: 3,
649: 4,
650: 5,
651: 6,
652: 7,
653: 8,
654: 4,
655: 5,
656: 6,
657: 4,
658: 5,
659: 6,
660: 5,
661: 6,
662: 7,
663: 5,
664: 6,
665: 7,
666: 5,
667: 6,
668: 7,
669: 6,
670: 7,
671: 8,
672: 6,
673: 7,
674: 8,
675: 5,
676: 6,
677: 7,
678: 7,
679: 8,
680: 9,
681: 6,
682: 7,
683: 8,
684: 4,
685: 5,
686: 6,
687: 7,
688: 8,
689: 9,
690: 5,
691: 6,
692: 7,
693: 5,
694: 6,
695: 7,
696: 6,
697: 7,
698: 8,
699: 6,
700: 7,
701: 8,
702: 6,
703: 7,
704: 8,
705: 7,
706: 8,
707: 9,
708: 7,
709: 8,
710: 9,
711: 6,
712: 7,
713: 8,
714: 8,
715: 9,
716: 10,
717: 7,
718: 8,
719: 9,
720: 5,
721: 6,
722: 7,
723: 8,
724: 9,
725: 10,
726: 6,
727: 7,
728: 8}

import math
N = int(input())

def rec(N, num, A):
    if N <= 728:
        A.append(num + dic[N])
    else:
        p = int(math.log(N) / math.log(6))
        rec(N - 6**p, num+1, A)
        p = int(math.log(N) / math.log(9))
        rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

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

def rec(N, num, A):
    if N <= 5:
        A.append(num + N)
        return A
    elif N <= 8:
        A.append(num + N - 5)
        return A
    else:
        p = int(math.log(N) / math.log(6))
        rec(N - 6**p, num+1, A)
        p = int(math.log(N) / math.log(9))
        rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

Solution code:
import math
# import sys
# sys.setrecursionlimit(10000000)
N = int(input())

def rec(N, num, A):
    if N <= 5:
        num += N
        A.append(num)
        return A
    if N <= 8:
        num += N - 5
        A.append(num)
        return A
    p = int(math.log(N) / math.log(6))
    rec(N - 6**p, num+1, A)
    p = int(math.log(N) / math.log(9))
    rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10000000)
N = int(input())

def rec(N, num, A):
    if N <= 5:
        num += N
        A.append(num)
        return A
    if N <= 8:
        num += N - 5
        A.append(num)
        return A
    p = int(math.log(N) / math.log(6))
    rec(N - 6**p, num+1, A)
    p = int(math.log(N) / math.log(9))
    rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10000000)
N = int(input())

def rec(N, num, A):
    tmpmin = min(A)
    if num > tmpmin:
        return A
    if N <= 5:
        num += N
        A.append(num)
        return A
    if N <= 8:
        num += N - 5
        A.append(num)
        return A
    p = int(math.log(N) / math.log(6))
    rec(N - 6**p, num+1, A)
    p = int(math.log(N) / math.log(9))
    rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [100000])
print(min(A))

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(100000)
N = int(input())

def rec(N, num, A):
    if N <= 5:
        num += N
        A.append(num)
        return A
    if N <= 8:
        num += N - 5
        A.append(num)
        return A
    p = int(math.log(N) / math.log(6))
    rec(N - 6**p, num+1, A)
    p = int(math.log(N) / math.log(9))
    rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

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

def rec(N, num, A):
    if N <= 5:
        num += N
        A.append(num)
        return A
    if N <= 8:
        num += N - 5
        A.append(num)
        return A
    p = int(math.log(N) / math.log(6))
    rec(N - 6**p, num+1, A)
    p = int(math.log(N) / math.log(9))
    rec(N - 9**p, num+1, A)
    return A

A = rec(N, 0, [])
print(min(A))

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])
        dp[i] = selected[1] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 
    print(find_options(91414))

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])
        dp[i] = selected[1] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])
        dp[i] = dp[i-selected[0]] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])
        print(selected)
        dp[i] = dp[i-selected[0]] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, i - x], options), key=lambda x: dp[x[1]])
        dp[i] = dp[i-selected[0]] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if len(powers) == 0:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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