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:
if __name__ == '__main__':
    N = int(input()) #引き出したい金額

    res = N #全部1円で引き出したときの回数
    for A in range(N):
        temp = 0
        tot = A
        while tot > 0:
            temp += tot % 6
            tot = tot // 6

        tot = N - A
        while tot > 0:
            temp += tot % 9
            tot = tot // 9
        if(res > temp):
            res = temp

    print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(6):
	a = 9**(i+1)
	if N<a:
		nine = i
		N = N-(9**i)
		break

for i in range(7):
	a = 6**(i+1)
	if N<a:
		six = i
		N = N-(6**i)
		one = N
		break

out = one + six + nine
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for s in range(0,n+1):
    a.append(1)
for l in range(0,7):
    if l == 0:
        a[1]=2
    else:
        if 6**l<=n:
            a[6**l]=l
        else:
            pass
        if 9**l<=n:
            a[9**l]=l
        else:
            pass
for i in range(1,n+1):
    if a[i]>=2:
        for j in range(0,7):
            if i+6**j<=n:
                if a[i+6**j]>=2:
                    a[i+6**j]=min(a[i+6**j],a[i]+1)
                else:
                    a[i+6**j]=a[i]+1
            else:
                break
        for k in range(0,6):
            if i + 9**k<=n:
                if a[i+9**k]>=2:
                    a[i+9**k]=min(a[i+9**k],a[i]+1)
                else:
                    a[i+9**k]=a[i]+1
            else:
                break
    else:
        pass
print(a[n]-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
six_list = [6 ** i for i in range(0,7)]
nine_list =[9 ** i for i in range(1,6)]
sn_list = sorted(six_list + nine_list)[::-1]
counter = 0
for i in sn_list:
    counter += N // i
    N = N % i
print (counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
six_list = [6 ** i for i in range(1,7)]
nine_list =[9 ** i for i in range(1,6)]
sn_list = sorted(six_list + nine_list)[::-1]
counter = 0
d = 1
while (N > 5):
    while(d < 0):
        sn_list.pop(0)
        for i in sn_list:
            d = N -i 
    N = N % sn_list[0]
    counter += N // sn_list[0]
counter += N
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = sorted([6**x for x in range(1, 9) if 6**x <= N] + [9**x for x in range(1, 9) if 9**x <= N])
dp = [i for i in range(0,N+1)]
for i in range(2, N+1):
    dp[i] = 1+dp[i-1]
    for c in arr:
        if i - c > 0:
            dp[i] = min([dp[i], 1+dp[i-c]])
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
i=1
x=[1]
while(6**i<n):
    x.append(6**i)
    i+=1
i=1
while(9**i<n):
    x.append(9**i)
    i+=1
x.sort()

dp=[0]
for i in range(1,n+1):
    k=n
    t=[]
    for j in x:
        if j<=i:
            k=min(dp[i-j]+1, k)
    dp.append(k)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
x = 100000
a3=0
a9=0
count=0
for j in range(x):
    
    for i in range (x):
        if a3 < n: 
            a3 = a3*3
        else:
            break
    for i in range (x):
        if a9 < n: 
            a9 = a9*3
        else:
            break
    if n !=0:
        n = n - max(a3, a9, 1)
        count+=1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

for i in range(1,n+1):
    tmp = float('inf')
    for j in range(int(math.log(i,6))+1):
        if dp[i-6**j]+1 < tmp:
            tmp = dp[i-6**j] + 1
    for j in range(int(math.log(i,9))+1):
        if dp[i-9**j]+1 < tmp:
            tmp = dp[i-9**j]+1
    dp[i] = tmp

print(dp[n])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

for i in range(1,n+1):
    tmp = float('inf')
    for j in range(int(math.log(i,6))+1):
        if dp[i-6**j]+1 < tmp:
            tmp = dp[i-6**j] + 1
    for j in range(int(math.log(i,9))+1):
        if dp[i-9**j]+1 < tmp:
            tmp = dp[i-9**j]+1
    dp[i] = tmp

print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[]
t=[]
p=0
def f9(n,p):
    while n>=9:
        n//=9
        p+=1
        f9(n,p)
    return p
def f6(n,p):
    while n>=6:
        n//=6
        p+=1
        f6(n,p)
    return p    
s.append((n,0))
while s:
    print(s)
    a=s[0][0]
    b=s[0][1]
    if a<6:
        t.append(b+a)
    else:
        p=0
        s.append((a-9**f9(a,p),b+1))
        p=0
        s.append((a-6**f6(a,p),b+1))
    s.pop(0)    
print(min(t))

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [0 for i in range(n)]
a = [1]
i = 1
_ = 6
while _ <= n:
    a.append(_)
    i += 1
    _ = 6 ** i
i = 1
_ = 9
while _ <= n:
    a.append(_)
    i += 1
    _ = 9 ** i
dp[0] = 1
len_a = len(a)
for i in range(n):
    target = []
    for j in range(len_a):
        if i + 1 >= a[j]:
            target.append(dp[i - a[j]])
    dp[i] = min(target) + 1
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [0 for i in range(n)]
a = [1]
i = 1
_ = 6
while _ <= n:
    a.append(_)
    i += 1
    _ = 6 ** i
i = 1
_ = 9
while _ <= n:
    a.append(_)
    i += 1
    _ = 9 ** i
dp[0] = 1
len_a = len(a)
for i in range(n):
    target = []
    for j in range(len_a):
        if i + 1 >= a[j]:
            target.append(dp[i - a[j]])
    dp[i] = min(target) + 1
print('answer', dp[n-1])

Submission status: Wrong Answer

Solution code:
def gen_multiples(n):
    count = 0
    while n**count <= 100000:
        yield n**count
        count+=1
        
N = int(input())
remainder = N
ops = 0
mult9 = list(gen_multiples(9))
mult6 = list(gen_multiples(6))

mult9.remove(1)
mult6.remove(1)
mult9.extend(mult6)
mult9.sort(reverse=True)
for w in [amount for amount in mult9 if amount <= N]:
    #print('{} times {} for {}, total = {}'.format(total//w,w,w*(total//w),total))
    ops += remainder//w
    remainder = remainder - w*(remainder//w)
print(ops + remainder)

Submission status: Wrong Answer

Solution code:
def func(a, b):
    c = 1
    d = 0
    while b//c != 0:
        d += (b//c) % a
        c *= a
    return d


n = int(input())
ans = 10**10
t = 0
while n > t:
    ans = min(ans, func(9, t)+func(6, n-t))
    t += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def func(a, b):
    c = 1
    d = 0
    while b//c != 0:
        d += (b//c) % a
        c *= a
    return d


n = int(input())
ans = 10**10
t = 0
while n > t:
    ans = min(ans, func(9, t)+func(6, n-t))
    t += 9
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
six = [1]
nine = [1]
res = 0
for i in range(1, n):
    num = 6 ** i
    if num > n:
        break
    six.append(num)

for j in range(1, n):
    num = 9 ** j
    if num > n:
        break
    nine.append(num)

print(six, nine)
while n != 0:
    six = list(filter(lambda x: x <= n, six))
    nine = list(filter(lambda x: x <= n, nine))
    n -= max(max(six), max(nine))
    res += 1

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
INF = 10**6

dp = [INF] * (N + 100)
dp[0] = 0

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

    power = 6
    while n - power > 0:
        dp[n] = min(1 + dp[n - power], dp[n])
        power *= 6

    power = 9
    while n - power > 0:
        dp[n] = min(1 + dp[n - power], dp[n])
        power *= 9

print(dp[N])

Submission status: Wrong Answer

Solution code:
N=int(input())

def num_6(A):
	i=0
	while True:
		if 6**i>A:
			return i-1
		i=i+1

def num_9(A):
	i=0
	while True:
		if 9**i>A:
			return i-1
		i=i+1

num_arr=[]
for i in range(N-1):
	num_6_max=num_6(i+1)
	num_9_max=num_9(N-(i+1))
	a6_num=[]
	a9_num=[]
	A=i+1
	B=N-(i+1)
	for j in range(num_6_max+1):
		a6_num.append(A//(6**(num_6_max-j)))
		A=A-(6**(num_6_max-j))*a6_num[j]
	for j in range(num_9_max+1):
		a9_num.append(B//(9**(num_9_max-j)))
		B=B-(9**(num_9_max-j))*a9_num[j]
	num_arr.append(sum(a6_num)+sum(a9_num))
if num_arr==[]:
	print(1)
else:
	print(min(num_arr))

Submission status: Wrong Answer

Solution code:
a=int(input())
p=0
def f9(n,b):
    while n>=9:
        n//=9
        b+=1
        return f9(n,b)
    return b
def f6(n,b):
    while n>=6:
        n//=6
        b+=1
        return f6(n,b)
    return b
while a:
    b,c=0,0
    s=max(1,9**f9(a,b),6**f6(a,c))
    a-=s
    p+=1
print(p)

Submission status: Wrong Answer

Solution code:
a=int(input())
p=0
def f9(n,b):
    while n>=9:
        n//=9
        b+=1
        return f9(n,b)
    return b
def f6(n,b):
    while n>=6:
        n//=6
        b+=1
        return f6(n,b)
    return b
while a:
    b,c=0,0
    s=max(1,9**f9(a,b),6**f6(a,c))
    print(s,a)
    a-=s
    p+=1
print(p)

Submission status: Wrong Answer

Solution code:
price=int(input())
count=0
while True:
    i=0
    if price>=81:
        while True:
            if price<9**i:
                i-=1
                price-=9**i
                count+=1
                break
            i+=1
    elif price>=36:
        while True:
            if price<6**i:
                i-=1
                price-=6**i
                count+=1
                break
            i+=1
    elif price>=9:
        price-=9
        count+=1
    elif price>=6:
        price-=6
        count+=1
    else:
        price-=1
        count+=1
    if price<=0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
m = input()
n = int(m)
x = 0

while n > 5:
    k = 9
    l = 6
    if (n - k) >= 0:
        while (n - 9 * k ) >= 0:
            k = k * 9
    if (n - l) >= 0:
        while (n - 6 * l ) >= 0:
            l = l * 6
    if n - k >= 0:
        if (n - k) < (n - l):
            n = n - k
        else:
            n = n - l
    else:
        n = n - l
    x = x + 1
    print(n)
x = x + n
print(x)

Submission status: Wrong Answer

Solution code:
list1 = [9**i for i in range(6)]
list2 = [6**i for i in range(1,7)]
list = sorted(list1+list2)
list.reverse()
count,sum,answer=[0,0,0]
n=int(input())
while sum < n:
    if n-sum>=list[count]:
        sum += list[count]
        answer += 1
        print(list[count])
    else:
        count += 1
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
wd = []
for i in range(1, 7):
    wd.append(6**i)
for i in range(1, 6):
    wd.append(9**i)
wd.append(1)

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

for i in range(len(wd)):
    for j in range(i, N+1):
        dp[j] = min(dp[j], dp[j-i]+1)

print(dp[N])

Submission status: Wrong Answer

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

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans = N

for i in range(N):
    tmp = 0
    a_6 = Base_10_to_n(i, 6)
    for j in a_6:
        tmp += int(j)
    a_9 = Base_10_to_n(N - i, 9)
    for k in a_9:
        tmp += int(k)
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
'''a = [1, 6, 9, 6**2, ....]

dp[i+1][n]: i番目までのaから総和をｎにする組み合わせのうち、
　　　　　　選ぶ整数の数の最小値 (個数制限なし)
0 <= i <= len(a)
0 <= n <= N
'''

maxN = int(1e5)
N = int(input())
a = [1]
for i in range(1,100):
    if 6**i <= N: a.append(6**i)
    if 9**i <= N: a.append(9**i)
    else: break
        
        
dp = [[0] + [maxN]*N]    # initial state :dp[0][n]

for i in range(len(a)):
    dp.append([0]*(N+1)) # dp[i+1]
    for n in range(N+1):
        if a[i] <= n:
            dp[i+1][n] = min(dp[i][n], dp[i+1][n-a[i]] + 1)
        else:
            dp[i+1][n] = dp[i][n]
          
print(dp[len(a)][N])

Submission status: Wrong Answer

Solution code:
global six
six = []
global nine
nine = []
ans = 1145141919810


def init():
	s = 6
	while (1):
		if s > 100000:
			break

		six.append(s)
		s *= 6

	n = 9
	while (1):
		if n > 100000:
			break

		nine.append(n)
		n *= 9

	six.reverse()
	nine.reverse()


def dfs(zan, did):
	global ans
	global six
	global nine
	if zan <= 6:
		res = did + zan
		if res < ans:
			ans = res

		return

	for val in six:
		if val > zan:
			continue

		dfs(zan - val, did + 1)
		break

	for val in nine:
		if val > zan:
			continue

		dfs(zan - val, did + 1)
		break


init()
n = int(input())
dfs(n, 0)

print(ans)

Submission status: Wrong Answer

Solution code:
def min(a, b):
    if(a < b):
        return a
    else:
        return b

dp = [0]
n = 1

for n in range(100000):
    dp.append(10000000)
    power = 1
    while(power <= n):
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 6
    power = 1
    while(power <= n):
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 9
        
N = int(input())
print(dp[N])

Submission status: Wrong Answer

Solution code:
def min(a, b):
    if(a < b):
        return a
    else:
        return b

dp = [0]
n = 1

for n in range(100000):
    dp.append(10000000)
    power = 1
    while(power <= n):
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 6
    power = 1
    while(power <= n):
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 9

N = int(input())
print(dp[N])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 0

c9 = int(math.pow(N, (1.0/9.0))+1)
c6 = int(math.pow(N, (1.0/6.0))+1)
while N >= 6:
	if 6**c6 >= 9**c9:
		if N>= 6**c6:
			N -= 6**c6
			ans+=1
		else:
			c6-=1
	else:
		if N>= 9**c9:
			N -= 9**c9
			ans+=1
		else:
			c9-=1

print(ans+N)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
m=0
for i in range(12):
    m+=n//a[11-i]
    n=n%a[11-i]
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [pow(10, 10)] * 100005
dp[0] = 0
dp[1] = 1
for n in range(100000):
    # for 6
    power = 1
    while n - power >= 0:
        dp[n] = min(dp[n], 1 + dp[n - power])
        power *= 6
    # for 9
    power = 1
    while n - power >= 0:
        dp[n] = min(dp[n], 1 + dp[n - power])
        power *= 9
print(dp[N])

Submission status: Wrong Answer

Solution code:
def solve(n, c):
  if n < 6:
    return n + c
  a = b = 2000000000
  if n % 6 == 0:
    a = solve(n // 6, c + 1)
  if n % 9 == 0:
    b = solve(n // 9, c + 1)
  return min(a, b)
print(solve(int(input()), 0))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 0

c = int(math.pow(N, (1.0/9.0))+1)

while c > 0:
	if N >= 9**c:
		N-=9**c
		ans+=1
		c+=1
	c-=1
	
c = int(math.pow(N, (1.0/6.0))+1)
while c > 0:
	if N >= 6**c:
		N-=6**c
		ans+=1
		c+=1
	c-=1
print(ans+N)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 0

c = int(math.pow(N, (1.0/9.0))+1)
while c > 0:
	if N >= 9**c:
		N-=9**c
		ans+=1
	c-=1
	
c = int(math.pow(N, (1.0/6.0))+1)
while c > 0:
	if N >= 6**c:
		N-=6**c
		ans+=1
	c-=1
print(ans+N)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
if __name__ == '__main__':
    a = [1]
    b = 6
    while b <= 100000:
        a.append(b)
        b *= 6
    b = 9
    while b <= 100000:
        a.append(b)
        b *= 9
    a.sort()
    index = len(a) - 1
    n = input()
    count = 0
    while n > 0 :
        if n - a[index] >= 0:
            count += 1
            n -= a[index]
        else:
            index -= 1
    print count

Submission status: Wrong Answer

Solution code:
#coding : utf8

numInt = int(input())
count = 0

while(numInt > 0):

    for i in range(1, numInt):
        if( (numInt/pow(6,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("6*" +str(i-1) +":" +str(pow(6,i-1)))
            # numInt = numInt - pow(6,(i-1))
            # count += 1
            sixCoins = pow(6,(i-1))
            break

    for i in range(1, numInt):
        if( (numInt / pow(9,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("9*" +str(i-1) +":" +str(pow(9,i-1)))
            # numInt = numInt - pow(9,(i-1))
            # count += 1
            nineCoins = pow(9,(i-1))
            break

    if(numInt < 6):
        # print("count : " + str(count))
        # print("numInt : " +str(numInt))
        count = count + numInt
        break

    if(sixCoins > nineCoins):
        numInt = numInt - sixCoins
        # print("numInt : " +str(numInt))
        # print("6"  +":" +str(sixCoins))
        count += 1
    else:
        numInt = numInt - nineCoins
        # print("numInt : " +str(numInt))
        # print("9"  +":" +str(nineCoins))
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#coding : utf8

numInt = int(input())
count = 0

while(numInt > 0):

    for i in range(1, numInt):
        if( (numInt/pow(6,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("6*" +str(i-1) +":" +str(pow(6,i-1)))
            # numInt = numInt - pow(6,(i-1))
            # count += 1
            sixCoins = pow(6,(i-1))
            break

    for i in range(1, numInt):
        if( (numInt / pow(9,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("9*" +str(i-1) +":" +str(pow(9,i-1)))
            # numInt = numInt - pow(9,(i-1))
            # count += 1
            nineCoins = pow(9,(i-1))
            break

    if(numInt < 6):
        print("count : " + str(count))
        print("numInt : " +str(numInt))
        count = count + numInt
        break

    if(sixCoins > nineCoins):
        numInt = numInt - sixCoins
        print("numInt : " +str(numInt))
        print("6"  +":" +str(sixCoins))
        count += 1
    else:
        numInt = numInt - nineCoins
        print("numInt : " +str(numInt))
        print("9"  +":" +str(nineCoins))
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#coding : utf8

numInt = int(input())
count = 0

while(numInt > 0):

    for i in range(1, numInt):
        if( (numInt/pow(6,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("6*" +str(i-1) +":" +str(pow(6,i-1)))
            # numInt = numInt - pow(6,(i-1))
            # count += 1
            sixCoins = pow(6,(i-1))
            break

    for i in range(1, numInt):
        if( (numInt / pow(9,i)) < 1):
            # print("numInt : " +str(numInt))
            # print("9*" +str(i-1) +":" +str(pow(9,i-1)))
            # numInt = numInt - pow(9,(i-1))
            # count += 1
            nineCoins = pow(9,(i-1))
            break

    if(numInt < 6):
        print("count : " + str(count))
        print("numInt : " +str(numInt))
        count = count + numInt
        break

    if(sixCoins > nineCoins):
        numInt = numInt - sixCoins
        print("numInt : " +str(numInt))
        print("6"  +":" +str(sixCoins))
        count += 1
    else:
        numInt = numInt - nineCoins
        print("numInt : " +str(numInt))
        print("9"  +":" +str(nineCoins))
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#coding : utf8

numInt = int(input())
count = 0

while(numInt > 0):

    for i in range(1, numInt):
        if( (numInt / pow(9,i)) < 1 ):
            numInt = numInt - pow(9,(i-1))
            count += 1
            break

    for i in range(1, numInt):
        if( (numInt/pow(6,i)) < 1):
            numInt = numInt - pow(6,(i-1))
            count += 1
            break

    if(numInt < 9 and numInt < 6):
        count = count + numInt
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [0 for i in range(max(n+1, 36))]

for i in range(35):
    j = i // 9
    cand = []
    for k in range(j+1):
       _i = i
       _i -= 9*k
       l = _i // 6
       for m in range(l+1):
           __i = _i
           __i -= 6*m
           cand.append(k+m+__i)
    dp[i] = min(cand)
nine_list = [pow(9, i) for i in range(1, 6)]
six_list = [pow(6, i) for i in range(1, 7)]
for i in range(35, n+1):
    for j in range(len(nine_list)):
        if nine_list[j] > i:
            max_nine = nine_list[j-1]
            break
    for j in range(len(six_list)):
        if six_list[j] > i:
            max_six = six_list[j-1]
            break
    dp[i] = min(dp[i-max_nine]+1, dp[i-max_six]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = []
for i in range(N+1):
    if i == 0:
        ans.append(0)
    else:
        x = int(math.log(i, 6))
        y = int(math.log(i, 9))
        s = min(ans[i - 6 ** x], ans[i - 9 ** y]) + 1
        ans.append(s)
print(ans[N])

Submission status: Wrong Answer

Solution code:
n = int(input())
divs = [6, 9]
x = n
cnt = 0
while x >= divs[0]:
    i = 0
    j = 1
    while True:
        a = divs[i % 2]
        if a ** j > x:
        #if divs[i % 2] ** j > x:
            beki = j
            if i % 2 == 0:
                beki -= 1
            b = divs[(i - 1) % 2]
            x -= b ** beki
            #x -= divs[(i - 1) % 2] ** beki
            cnt += 1
            break
        i += 1
        if i % 2 == 0:
            j += 1
z = cnt + x
print(z)

Submission status: Wrong Answer

Solution code:
n = int(input())
divs = [6, 9]
x = n
cnt = 0
while x > divs[0]:
    i = 0
    j = 1
    while True:
        a = divs[i % 2]
        if a ** j > x:
        #if divs[i % 2] ** j > x:
            beki = j
            if i % 2 == 0:
                beki -= 1
            b = divs[(i - 1) % 2]
            x -= b ** beki
            #x -= divs[(i - 1) % 2] ** beki
            cnt += 1
            break
        i += 1
        if i % 2 == 0:
            j += 1
z = cnt + x
print(z)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4]) + 1
    
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [float('inf')] * (10**5)
dp[0] = 1

for i in range(1, N):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4]) + 1

print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys
from math import log

N = int(input())

max_index9 = int(log(N, 9))
max_index6 = int(log(N, 6))

rest = N
count = 0

val_set = set()
for i in range(max_index9 + 1):
    val_set.add(9 ** i)

for i in range(max_index6 + 1):
    val_set.add(6 ** i)

val_list = list(val_set)
val_list.sort(reverse=True)

for val in val_list:
    count += rest // val
    rest %= val

    if rest <= 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
p = [1]
for j in [6, 9]:
  i = j
  while i < N:
    p.append(i)
    i *= j
c = [N] * (N+1)
c[1] = 1
for i in range(1, N+1):
  for j in p:
    if i+j <= N:
      c[i+j] = min(c[i+j], c[i]+1)
print c[N]

Submission status: Wrong Answer

Solution code:
#!/bin/python

import math
import os
import random
import re
import sys

def dp(N,minIdx):
    global yen
    if table.get(N) != None:
        return table.get(N)
    if N == 0:
        return 0
    if N < 0:
        return sys.maxint
    result = sys.maxint
    for i in range(minIdx,len(yen)):
        result = min(result,dp(N-yen[i],i))
    table[N] = 1+result
    return 1+result

def solution(N):
    return dp(N,0)
        
table = {}

if __name__ == '__main__':
    minVal = sys.maxint
    N = int(raw_input())
    yen = [59049,46656,7776,6561,1296,729,216,81,36,9,6,1]
    result = solution(N)

    print result

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())

count = 0
while n != 0:
    c6 = int(math.log(n, 6))
    c9 = int(math.log(n, 9))
    if 6 ** c6 >= 9 ** c9:
        n -= 6 ** c6
    elif 6 ** c6 < 9 ** c9:
        n -= 9 ** c9
    count += 1



print(count)

Submission status: Wrong Answer

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

# dp[i] = i円を引き出すのに必要な最低回数
# dp[i] = min(dp[i-6**p]+1,dp[i-9**q],dp[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(res)

Submission status: Wrong Answer

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

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1, N+1):
    count = 0
    t = i
    
    while (t>0):
        count += t%6
        t = int(t/6)
        
    t = N - i
        
    while (t>0):
        count += t%9
        t = int(t/9)
        
    if(result > count):
        result = count
           

print(result)

Submission status: Wrong Answer

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

for i in range(N):
    count = 0
    t = i
    
    while (t>0):
        count += t%6
        t = int(t/6)
        
    t = N - i
        
    while (t>0):
        count += t%9
        t = int(t/9)
        
    if(result > count):
        result = count
           

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

c1 = 1
c6 = 6
c9 = 9

num_6 = 0
cost_6 = 1
for i in range(100):
    cost_6 *= c6
    if n < cost_6:
        num_6 = i
        break

ans = n
count = 0
cost9 = 0
for i in range(num_6, 0, -1):
    cost = 1

    for j in range(i):
        cost *= c9

    while cost <= ans:
        if i == 1:
            cost9 += 1
        ans -= cost
        count += 1

    cost = 1
    for j in range(i):
        cost *= c6

    while cost <= ans:
        ans -= cost
        count += 1

new_ans = ans + count

if cost9 > 0:
    ans1 = ans - 3
    if ans1 > 0:
        new_ans = min(count + ans, count + ans1 + 1)
    

print(new_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

Ans = 0

L = [1,6,6**2,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5]

while True:
    if N >= max(L):
        a = N//max(L)
        N = N - a*max(L)    
        Ans += a
        L.remove(max(L))
    else:
        L.remove(max(L))
    if L == []:
        break
        
print(Ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def sol(n):
    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
    return res

print(sol(n))

Submission status: Wrong Answer

Solution code:
n = 44852
# n = 127
# n=3

def wari(n):
    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
    return res

print(wari(n))

Submission status: Wrong Answer

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

def wari(n):
    res = n
    for i in range(n):
        cc = 0
        t = i
        while t > 0:
            cc += t % 6
            t = math.floor(t / 6)
        t = n - i
        while t > 0:
            cc += t % 9
            t = math.floor(t / 9)
        if res > cc:
            res = cc
    return res

print(wari(n))

Submission status: Wrong Answer

Solution code:
N = int(input())
 
def count_test(N, a):
    ans = 0
    ans2 = 999999
    n = len(a)
    for d in a:
        n = n - 1
        tmp = N // d
        if tmp > 0:
            N = N % d
            ans += tmp
            ans2 = 999999
            for i in range(n):
                tmp2 = count_test(N, a[i +1:])
                if tmp2 < ans2:
                    ans2 = tmp2
                ans2 = ans2 + ans
    ans = ans +  N
    
    if ans > ans2:
        ans = ans2
    return ans
 
list = []
for i  in range(1, 6):
    list.append(9**i)
    list.append(6**i)
 
list.append(6**6)
 
a = sorted(list,reverse=True)
 
ans = 999999
for i in range(len(a)):
    tmp = count_test(N, a[i:])
#    print(tmp , '-',  a[i:])
    if ans > tmp:
        ans = tmp
 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
def count_test(N, a):
    ans = 0
    ans2 = 999999
    n = len(a)
    for d in a:
        n = n - 1
        tmp = N // d
        if tmp > 0:
            N = N % d
            ans += tmp
            ans2 = 999999
            for i in range(n):
                tmp2 = count_test(N, a[i +1:])
                if tmp2 < ans2:
                    ans2 = tmp2
                ans2 = ans2 + ans
    ans = ans +  N
    
    if ans > ans2:
        ans = ans2
    return ans
 
list = []
for i  in range(1, 6):
    list.append(9**i)
    list.append(6**i)
 
list.append(6**6)
 
a = sorted(list,reverse=True)
 
ans = 999999
for i in range(len(a)):
    tmp = count_test(N, a[i:])
    print(tmp , '-',  a[i:])
    if ans > tmp:
        ans = tmp
 
print(ans)

Submission status: Wrong Answer

Solution code:
n_max = 100000

bs = [(6 ** i, 6) for i in range (1, 10)]
bs.extend([(9 ** i, 9) for i in range (1, 10)])
bs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))
bms = []
s = 5
for b, i in bs:
    s += b * (i - 1)
    bms.append((b, i, s))

#print(bs)
#print(bms, len(bms))

#m = 44852
m = int(input())

stack = [(m, 0, len(bms) - 1)]
#print("search start!")
result = 10000
while stack:
    m, n, bms_i = stack.pop()
    b, i, s = bms[bms_i]
    #print(m, n, bms_i, b, i, s)

    if n > result:
#        print("skip!", m, n, bms_i)
        continue
    if bms_i < 0:
        if m < 6 and result > m + n:
            result = m + n
#            print('get result!', result)
        continue

    for j in range(0, i):
        next_m = m - b * j
        if next_m > 0 and n + j < result:
            stack.append((next_m, n + j, bms_i - 1))

print(result)