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=N
def func1():
    global ans
    for i in range(N+1):
        cnt=0
        t=i
        while(t>0):
            cnt+=t%6
            t/=6
            t=int(t)
        t=N-i
        while(t>0):
            cnt+=t%9
            t/=9
            t=int(t)
        print(cnt)
        if(ans>cnt):
            ans=cnt
    return ans

func1()
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
k = a
for i  in range(a+1):
  al = 0
  t = i
  while t > 0:
    al += t%6
    t //=6
  t = a - i
  while t > 0:
    al += t%9
    t //=9
  if al < k:
    k = al

print(al)

Submission status: Wrong Answer

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

def main():
    n = int(input())
    li = dp(n)
    print(li)
    print(li[n])

def dp(n):
    inf=float('inf')
    dp = [inf for i in range(n+1)]
    dp[0] = 0
    money_list = get_money_list()
    for i in range(1, n + 1):
        for pay in money_list:
            if pay > i:
                continue
            else:
                dp[i] = min(dp[i - pay] + 1, dp[i])
    return dp

def create_list(n):
    i = 1
    money_list = []
    while i < 100000:
        money_list.append(i)
        i = i * n
    return money_list

def get_money_list():
    li = create_list(9)
    li.extend(create_list(6))
    li = list(set(li))
    li.sort(key=int, reverse=True)
    return li

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=n
for i in range(n):
  cc=0
  t=i
  while t>0:
    cc=cc+t%6
    t=t//6
  t=n-i
  while t>0:
    cc=cc+t%9
    t=t//9
  if ans>cc:
    ans=cc
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=cc+t%6
    t=t//6
  t=n-i
  while t>0:
    cc=cc+t%9
    t=t//9
  ans=min(ans,cc)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from itertools import product

N = int(input())

values = sorted([9**i for i in range(1, math.ceil(math.log(N, 9)))] +
                [6**i for i in range(math.ceil(math.log(N, 6)))])
dp = [N] * (N + 1)
dp[0] = 0
for i, v in product(range(1, N + 1), values):
    if i - v >= 0:
        dp[i] = min(dp[i - v] + 1, dp[i])
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
#num = [1]
#print("a")
"""
#memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
"""

def ninep(N):
    if N <9:
        return N
    ans = 0
    while N > 0:
        ans += N % 9
        N =N // 9
    return ans


def sixp(N):
    if N <6:
        return N
    ans = 0
    while N > 0:
        ans += N % 6
        N = N // 6
    return ans


ans = 1000000
for i in range(N):
    ans = min(ans,ninep(i) + sixp(N - i))
#`    print(ninep(i), sixp(N - i),i)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
#num = [1]
#print("a")
"""
#memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
"""

def ninep(N):
    if N <9:
        return N
    ans = 0
    while N > 0:
        ans += N % 9
        N =N // 9
    return ans


def sixp(N):
    if N <6:
        return N
    ans = 0
    while N > 0:
        ans += N % 6
        N = N // 6
    return ans


ans = 100000
for i in range(N):
    ans = min(ans,ninep(i) + sixp(N - i))
#`    print(ninep(i), sixp(N - i),i)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
#num = [1]
print("a")
"""
#memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
"""

def ninep(N):
    if N <9:
        return N
    ans = 0
    while N > 0:
        ans += N % 9
        N =N // 9
    return ans


def sixp(N):
    if N <6:
        return N
    ans = 0
    while N > 0:
        ans += N % 6
        N = N // 6
    return ans


ans = 100000
for i in range(N):
    ans = min(ans,ninep(i) + sixp(N - i))
#`    print(ninep(i), sixp(N - i),i)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
#num = [1]
print("a")
"""
#memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
"""

def ninep(N):
    if N <9:
        return N
    ans = 0
    while N > 0:
        ans += N % 9
        N =N // 9
    return ans


def sixp(N):
    if N <6:
        return N
    ans = 0
    while N > 0:
        ans += N % 6
        N = N // 6
    return ans


ans = 100000
for i in range(N):
    ans = min(ans,ninep(i) + sixp(N - i))
    print(ninep(i), sixp(N - i),i)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


def get_rest(base, target):
    i = 0
    while base**i < target:
        i += 1
    return target - base**(i - 1)


def greedy(base, target):
    count = 0
    rest = target
    while rest >= base:
        rest = get_rest(base, rest)
        count += 1
    return count + rest


Min = float("inf")
for i in range(N + 1):
    Min = min(Min, greedy(6, i) + greedy(9, N - i))

print(Min)

Submission status: Wrong Answer

Solution code:
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(2**16)
s = int(input())

mi = float("inf")


@lru_cache(maxsize=None)
def ret(n):
    over_9 = math.floor(math.log(n, 9))
    over_6 = math.floor(math.log(n, 6))
    return (over_6, over_9)


@lru_cache(maxsize=None)
def divide(n, su):
    global mi
    if su > mi:
        return
    if n < 6:
        mi = min(mi, su+n)
        return
    over_6, over_9 = ret(n)
    for i in range(over_9, 0, -1):
        divide(n-(9**i), su+1)
    for i in range(over_6, 0, -1):
        divide(n-(6**i), su+1)


divide(s, 0)
print(mi)

Submission status: Wrong Answer

Solution code:
num = [i for i in range(0,100001)]

for j in range(1,100001):
        num[j] = j//6 + num[j%6]

for i in range(1,2):
        for j in range(9*i,9*2):
                num[j] = min(num[j],i+num[j-9*i])
for j in range(9*2,100001):
        num[j] = min(num[j],(j//(9*2))*2+num[j%(9*2)])

for j in range(1,100001):
        num[j] = min(num[j],j//(6**2)+num[j%(6**2)])

for i in range(1,2**2):
        for j in range((9**2)*i,(9**2)*(2**2)):
                num[j] = min(num[j],i+num[j-(9**2)*i])
for j in range((9**2)*(2**2),100001):
        num[j] = min(num[j],(j//((9**2)*(2**2)))*4 + num[j%((9**2)*(2**2))])

for j in range(216,648):
        num[j] = min(num[j],1+num[j-216])
for j in range(432,648):
        num[j] = min(num[j],2+num[j-216*2])
for j in range(648,100001):
        num[j] = min(num[j],(j//648)*3 + num[j%648])

for i in range(1,8):
        for j in range(729*i,729*8):
                num[j] = min(num[j],i+num[j-729*i])
for j in range(729*8,100001):
        num[j] = min(num[j],(j//(729*8))*8+num[j%(729*8)])

for i in range(1,9):
        for j in range((6**4)*i,(6**4)*9):
                num[j] = min(num[j],i+num[j-(6**4)*i])
for j in range((6**4)*9,100001):
        num[j] = min(num[j],(j//((6**4)*9))*9+num[j%((6**4)*9)])

for i in range(1,2**4):
        for j in range((9**4)*i,100001):
                num[j] = min(num[j],i+num[j-(9**4)*i])



MoneyYouCanGet = [6**5,6**6,9**5]

for i in MoneyYouCanGet:
        for j in range(1,100001):
                k = 1
                while k*i<j:
                        num[j] = min(num[j],k+num[j-k*i])
                        k += 1

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

Submission status: Wrong Answer

Solution code:
num = [i for i in range(0,100001)]

for j in range(1,100001):
        num[j] = j//6 + num[j%6]

for i in range(1,2):
        for j in range(9*i,9*2):
                num[j] = min(num[j],i+num[j-9*i])
for j in range(9*2,100001):
        num[j] = min(num[j],(j//9*2)*2+num[j%(9*2)])

for j in range(1,100001):
        num[j] = min(num[j],j//36+num[j%36])

for j in range(81,324):
        num[j] = min(num[j],1+num[j-81])
for j in range(162,324):
        num[j] = min(num[j],2+num[j-162])
for j in range(243,324):
        num[j] = min(num[j],3+num[j-243])
for j in range(324,100001):
        num[j] = min(num[j],(j//324)*4 + num[j%234])

for j in range(216,648):
        num[j] = min(num[j],1+num[j-216])
for j in range(432,648):
        num[j] = min(num[j],2+num[j-216*2])
for j in range(648,100001):
        num[j] = min(num[j],(j//648)*3 + num[j%648])

for i in range(1,8):
        for j in range(729*i,729*8):
                num[j] = min(num[j],i+num[j-729*i])
for j in range(729*8,100001):
        num[j] = min(num[j],(j//(729*8))*8+num[j%(729*8)])

for i in range(1,9):
        for j in range((6**4)*i,(6**4)*9):
                num[j] = min(num[j],i+num[j-(6**4)*i])
for j in range((6**4)*9,100001):
        num[j] = min(num[j],(j//((6**4)*9))*9+num[j%((6**4)*9)])

for i in range(1,2**4):
        for j in range((9**4)*i,100001):
                num[j] = min(num[j],i+num[j-(9**4)*i])



MoneyYouCanGet = [6**5,6**6,9**5]

for i in MoneyYouCanGet:
        for j in range(1,100001):
                k = 1
                while k*i<j:
                        num[j] = min(num[j],k+num[j-k*i])
                        k += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())

res = 100000

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

print(cc)

Submission status: Wrong Answer

Solution code:
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(2**16)
s = int(input())

lis = []
ed = set()
mi = float("inf")

@lru_cache(maxsize=None)
def ret(n):
    over_9 = math.floor(math.log(n, 9))
    over_6 = math.floor(math.log(n, 6))
    return (over_6, over_9)

@lru_cache(maxsize=None)
def divide(n, su):
    if n == 0:
        mi = min(mi, su + n)
        return
    global mi
    if su > mi:
        return
    if n<6:
        global lis
        mi = min(mi, su+n)
    over_6, over_9 = ret(n)
    for i in range(over_9, 0, -1):
        divide(n-(9**i), su+1)
    for i in range(over_6, 0, -1):
        divide(n-(6**i), su+1)


divide(s, 0)
print(mi)

Submission status: Wrong Answer

Solution code:
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(2**16)
s = int(input())

lis = []
ed = set()
mi = float("inf")

@lru_cache(maxsize=None)
def ret(n):
    over_9 = math.floor(math.log(n, 9))
    over_6 = math.floor(math.log(n, 6))
    return (over_6, over_9)

@lru_cache(maxsize=None)
def divide(n, su):
    if n==0:
        return
    global mi
    if su > mi:
        return
    if n<6:
        global lis
        mi = min(mi, su+n)
    over_6, over_9 = ret(n)
    for i in range(over_9, 0, -1):
        divide(n-(9**i), su+1)
    for i in range(over_6, 0, -1):
        divide(n-(6**i), su+1)


divide(s, 0)
print(mi)

Submission status: Wrong Answer

Solution code:
from itertools import count
m = int(input())

n = 0
while m > 6:
    max_i9 = 0
    m9 = 0
    for i in count(1):
        if 9 ** i > m:
            max_i9 = i - 1
            m9 = 9 ** max_i9
            break

    max_i6 = 0
    m6 = 0
    for i in count(1):
        if 6 ** i > m:
            max_i6 = i - 1
            m6 = 6 ** max_i6
            break

    #print(n, m, m9, m6, max(m9, m6))
    if m9 > m6:
        m -= m9
    else:
        m -= m6
    n += 1

print(n + m)

Submission status: Wrong Answer

Solution code:
num = [i for i in range(0,100001)]

for j in range(1,100001):
        num[j] = j//6 + num[j%6]

for j in range(1,100001):
        num[j] = min(num[j],j//9+num[j%9])

for j in range(1,100001):
        num[j] = min(num[j],j//36+num[j%36])

for j in range(81,324):
        num[j] = min(num[j],1+num[j-81])
for j in range(162,324):
        num[j] = min(num[j],2+num[j-162])
for j in range(243,324):
        num[j] = min(num[j],3+num[j-243])
for j in range(324,100001):
        num[j] = min(num[j],(j//324)*4 + num[j%234])

for j in range(216,648):
        num[j] = min(num[j],1+num[j-216])
for j in range(432,648):
        num[j] = min(num[j],2+num[j-216*2])
for j in range(648,100001):
        num[j] = min(num[j],(j//648)*3 + num[j%648])

for i in range(1,8):
        for j in range(729*i,729*8):
                num[j] = min(num[j],i+num[j-729*i])
for j in range(729*8,100001):
        num[j] = min(num[j],(j//(729*8))*8+num[j%(729*8)])

for i in range(1,9):
        for j in range((6**4)*i,(6**4)*9):
                num[j] = min(num[j],i+num[j-(6**4)*i])
for j in range((6**4)*9,100001):
        num[j] = min(num[j],(j//((6**4)*9))*9+num[j%((6**4)*9)])

for i in range(1,2**4):
        for j in range((9**4)*i,100001):
                num[j] = min(num[j],i+num[j-(9**4)*i])



MoneyYouCanGet = [6**5,6**6,9**5]

for i in MoneyYouCanGet:
        for j in range(1,100001):
                k = 1
                while k*i<j:
                        num[j] = min(num[j],k+num[j-k*i])
                        k += 1

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
memo = [0]*(N+1)
memo[0] = 0

for i in range(1,N+1):
	memo[i] = memo[i-1]+1
	for j in range(1,int(math.log(i,6))+1):
		memo[i] = min(memo[i],memo[i-pow(6,j)]+1)
	for j in range(1,int(math.log(i,9))+1):
		memo[i] = min(memo[i],memo[i-pow(9,j)]+1)

print(memo[-1])

Submission status: Wrong Answer

Solution code:
N=int(raw_input())
M=[999999 for i in range(N+1)]
possible=sorted([1]+[6**i for i in range(1,10) if 6**i<=N]+[9**i for i in range(1,10) if 9**i<=N])
M[0]=0
for p in possible:
    M[p]=1

for m in range(N+1):
    tmp=999999
    for p in possible:
        if m-p>0:
            tmp=min(tmp, M[m-p]+1)
    if tmp!=999999:
        M[m]=tmp

print M[N]

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N
for i in range(N):
    cc = 0
    num_6 = i
    num_9 = N - i
    while num_6 > 0:
        cc += (num_6 % 6)
        num_6 //= 6
    while num_9 > 0:
        cc += (num_9 % 9)
        num_9 //= 9
    if ans > cc:
        ans = cc

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N

for A in range(N):
    counter = 0
    temp = A
    while temp > 0:
        q, r = divmod(temp, 6)
        counter += r
        temp = q
        
    temp = N - A
    while temp > 0:
        q, r = divmod(temp, 9)
        counter += r
        temp = q

    if counter < ans:
        ans = counter

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
sixs = [6,36,216,1296,7776,46656]
nines = [9,81,729,6561,59049]
lis = [0] + [100000 for i in range(170000)]
for i in range(0,100001):
 for j in sixs:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
 for j in nines:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
print(lis[n])

Submission status: Wrong Answer

Solution code:
num = [i for i in range(0,100001)]

for j in range(1,100001):
        num[j] = j//6 + num[j%6]

for j in range(1,100001):
        num[j] = min(num[j],j//9+num[j%9])

for j in range(1,100001):
        num[j] = min(num[j],j//36+num[j%36])

for j in range(81,324):
        num[j] = min(num[j],1+num[j-81])
for j in range(162,324):
        num[j] = min(num[j],2+num[j-162])
for j in range(243,324):
        num[j] = min(num[j],3+num[j-243])
for j in range(324,100001):
        num[j] = min(num[j],(j//324)*4 + num[j%234])

for j in range(216,648):
        num[j] = min(num[j],1+num[j-216])
for j in range(432,648):
        num[j] = min(num[j],2+num[j-216*2])
for j in range(648,100001):
        num[j] = min(num[j],(j//648)*3 + num[j%648])

for i in range(1,8):
        for j in range(729*i,729*8):
                num[j] = min(num[j],i+num[j-729*i])
for j in range(729*8,100001):
        num[j] = min(num[j],(j//(729*8))*8+num[j%(729*8)])

for i in range(1,9):
        for j in range((6**4)*i,(6**4)*9):
                num[j] = min(num[j],i+num[j-(6**4)*i])
for j in range((6**4)*9,100001):
        num[j] = min(num[j],(j//((6**4)*9))*9+num[j%((6**4)*9)])

MoneyYouCanGet = [9**4,6**5,6**6,9**5]

for i in MoneyYouCanGet:
        for j in range(1,100001):
                k = 1
                while k*i<j:
                        num[j] = min(num[j],k+num[j-k*i])
                        k += 1

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

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 = int(t/6)
    t = n-i
    while(t>0):
        cc+=t%9
        t = int(t/9)
    if res > cc:
        res =cc
print(res)

Submission status: Wrong Answer

Solution code:
num = [i for i in range(0,100001)]

for j in range(1,100001):
        num[j] = j//6 + num[j%6]

for j in range(1,100001):
        num[j] = min(num[j],j//9+num[j%9])

for j in range(1,100001):
        num[j] = min(num[j],j//36+num[j%36])

for j in range(81,324):
        num[j] = min(num[j],1+num[j-81])
for j in range(162,324):
        num[j] = min(num[j],2+num[j-162])
for j in range(243,324):
        num[j] = min(num[j],3+num[j-243])
for j in range(324,100001):
        num[j] = (j//324)*4 + num[j%234]

for j in range(216,648):
        num[j] = min(num[j],1+num[j-216])
for j in range(432,648):
        num[j] = min(num[j],2+num[j-216*2])
for j in range(648,100001):
        num[j] = (j//648)*3 + num[j%648]

for i in range(1,8):
        for j in range(729*i,729*8):
                num[j] = min(num[j],i+num[j-729*i])
for j in range(729*8,100001):
        num[j] = (j//(729*8))*8+num[j%(729*8)]

for i in range(1,9):
        for j in range((6**4)*i,(6**4)*9):
                num[j] = min(num[j],i+num[j-(6**4)*i])
for j in range((6**4)*9,100001):
        num[j] = (j//((6**4)*9))*9+num[j%((6**4)*9)]

MoneyYouCanGet = [9**4,6**5,6**6,9**5]

for i in MoneyYouCanGet:
        for j in range(1,100001):
                k = 1
                while k*i<j:
                        num[j] = min(num[j],k+num[j-k*i])
                        k += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
out = 0

l = []
for i in range(1, 7):
    a = 6 ** i
    b = 9 ** i
    l.append(a)
    l.append(b)
l.sort(reverse=1)
l = l[1:]
o = 0
for a in l:
    f = 0
    while n > a and f != 1:
        n -= a
        o+=1
        if n < 15 and a == 9:
            f = 1
print(o+n)

Submission status: Wrong Answer

Solution code:
N = int(input())

result = 100000000000

def calc(x, base):
    r = 0
    while x:
        x, m = divmod(x, base)
        r += m
    return r

for i in range(N):
    result = min(result, calc(i, 6) + calc(N - i, 9))

print(result)

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/=6
        t = int(t)
    t = n-i
    while(t>0):
        cc+=t%9
        t/=9
        t=int(t)
    if res > cc:
        res =cc
print(res)

Submission status: Wrong Answer

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


def main():
    six = []
    i = 0
    while True:
        n = 6 ** i
        if n > 100000:
            break
        six.append(n)
        i += 1
    nine = []
    i = 0
    while True:
        n = 9 ** i
        if n > 100000:
            break
        nine.append(n)
        i += 1

    N = int(input())

    queue = [[N, 0]]
    while len(queue):
        n, k = queue.pop(0)
        if n < 0:
            continue
        elif n == 0:
            print(k)
            break
        else:
            while n < six[-1]:
                six.pop(-1)
            while n < nine[-1]:
                nine.pop(-1)

            queue.append([n - six[-1], k + 1])
            queue.append([n - nine[-1], k + 1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
record = {0:0}
lst = [0] + [-1]*(N)
def max_6(x):
	i = 1
	while x >= i:
		i *= 6
	return i//6

def max_9(x):
	i = 1
	while x >= i:
		i *= 9
	return i//9

def count_money(x, c=0):
	if lst[x] != -1:
		return lst[x] + c
	else:
		i = max_6(x)
		j = max_9(x)
		if i > j:
			a = count_money(x-i,c+1)
			b = count_money(x-j,c+1)
		else:
			a = count_money(x-j,c+1)
			b = count_money(x-i,c+1)
		if a > b:
			ans = b
		else:
			ans = a
		lst[x] = ans
		return ans

print(count_money(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
record = {0:0}
lst = [0] + [-1]*(N)
def max_6(x):
	i = 1
	while x >= i:
		i *= 6
	return i//6

def max_9(x):
	i = 1
	while x >= i:
		i *= 9
	return i//9

def count_money(x, c=0):
	if lst[x] != -1:
		return lst[x] + c
	else:
		i = max_6(x)
		j = max_9(x)
		if i > j:
			a = count_money(x-i,c+1)
			b = count_money(x-j,c+1)
		else:
			a = count_money(x-j,c+1)
			b = count_money(x-i,c+1)
		if a > b:
			ans = b
		else:
			ans = a
		lst[x] = ans
		print(lst)
		return ans

print(count_money(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
s=1000
for i in range(1,6):
    for k in range(1,6):
        for j in range (30):
            for m in range(30):
                for n in range(30):
                    if N == j*9**i +m*6**k + n*1:
                        if s > j+m+n:
                            s = j+m+n
print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

N = input()
count = 0
while N > 0:
    n = int(math.log(N,9))
    s = int(math.log(N,6))
    if n > 0 or s > 0:
        
        if 9 ** n >= 6 ** s:
            if (N - 9 ** n) < 6:
                if N % 6 + int(N /6) < N - 9 ** n + 1:
                    count = count + N % 6 + int(N /6)
                    break
                else:
                    N = N - 9 ** n
            else:
                N = N - 9 ** n
        else:
            N = N - 6 ** s
        count = count + 1
    else:
        count = count + N
        break
print count

Submission status: Wrong Answer

Solution code:
import math
n=int(raw_input())
a=[10**6]*(n+1)
a[0]=0
for i in xrange(1,min(6,n+1)):
    a[i]=i
for i in xrange(6,n+1):
    fac9=int(math.log(i,9))
    fac6=int(math.log(i,6))
    if 9**fac9==i or 6**fac6==i:
        a[i]=1
    else:
        while(fac9>=0):
            a[i]=min(a[i],1+a[i-9**fac9])
            fac9-=1
        while(fac6>=0):
            a[i]=min(a[i],1+a[i-6**fac6])
            fac6-=1

print a[n]