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

lst = []
for i in range(7):
    lst.append(6 ** i)
for j in range(1, 5):
    lst.append(9 ** j)
lst.sort()

DP = [_ for _ in range(N + 1)]
DP[0] = 0

for i in lst:
    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:
import math

line = input().split()
N = int(line[0])


all_numbers = []
all_numbers.append(1)

for i in range(1, 7):
    all_numbers.append(math.pow(6, i))

for i in range(1, 6):
    all_numbers.append(math.pow(9, i))


all_numbers.sort()
all_numbers.reverse()

count = 0

for i in all_numbers:
    div, mod = divmod(N, i)
    count += div
    N = mod

print(int(count))

Submission status: Wrong Answer

Solution code:
def func(n, k):
    i6 = 1
    i9 = 1
    while(i6*6 <= n):
        i6*=6
    while(i9*9 <= n):
        i9*=9
    n6 = n - i6
    n9 = n - i9
    if i6 == 1 and i9 == 1:
        return k+n
    elif n6 == 0 or n9 == 0:
        return k+1
    else:
        return func(min(n6, n9), k+1)

N = int(input())
print (func(N, 0))

Submission status: Wrong Answer

Solution code:
n = int(input())
money_list = (59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1)
ans = 0
for i in money_list:
  while n >= i:
    if 46656*2 <= n:
      n -= 46656
      ans += 1
    elif 12 <= n <=14:
      n -= 6
      ans += 1
    else:
      n -= i
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
a.append(1)
for i in range(1,7):
    a.append(pow(6,i))
    a.append(pow(9,i))
a.reverse()
# print(a)
c = 0
d = 1
while(n):
    if n ==0:
        break
    if n <= 14 and n >= 12:
        d +=1
    if a[d] <= n:
        n-=a[d]
        # print(n,a[d],c+1)
        c += 1
    else:
        d += 1

print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())               
ans = 0                        
                               
def num(x,y):                  
    base = x                   
    while x <= y:              
        x = x * base           
    return x // base           
a = N                          
while a >= 6:                  
    ans += 1                   
    n6 = num(6,a)              
    n9 = num(9,a)              
    if a >= 12 and a <= 14:    
        a = a - n6             
    elif n6 < n9:              
        a = a -n9              
    else:                      
        a = a - n6             
                               
print(ans + a)

Submission status: Wrong Answer

Solution code:
n = int(input())

# def get_small(target, num_list, start):


num_list = []

for i in range(1, 7):
    num_list.append(pow(6, i))
    if i <= 5:
        num_list.append(pow(9, i))

num_list = sorted(num_list)
cnt = 0
is_break = True
while is_break :
    for i in range(len(num_list)):
        if n <= 35:
            is_break = False
            break
        if num_list[i] > n and i == 0:
            is_break = False
            break
        elif num_list[i] > n:
            n -= num_list[i-1]
            cnt += 1
            break

if 33 <= n:
    n -=9*3
    n -= 6
    cnt+=4
elif 30 <= n:
    n -=9*2
    n -=6*2
    cnt+=4
elif 27 <= n:
    n -= 9*3
    cnt += 3
elif 24 <= n:
    n -= 9*2
    n -= 6
    cnt += 3
elif 21 <= n:
    n -= 9
    n -= 6*2
    cnt += 3
elif 18 <= n:
    n -= 9*2
    cnt += 2
elif 15 <= n:
    n -= 9
    n -= 6
    cnt += 2
elif 12 <= n:
    n -= 6*2
    cnt += 2
elif 9 <= n:
    n -= 9
    cnt += 1
elif 6 <= n:
    n -= 6
    cnt += 1

print(cnt+n)

Submission status: Wrong Answer

Solution code:
from math import log


def min_withdraw(n):
    if n < 6:
        return n
    elif n < 9:
        return (n - 6) + 1
    else:
        exp_nine = int(log(n, 9))
        exp_six = int(log(n, 6))
        return 1 + min(min_withdraw(n - (6 ** exp_six)), min_withdraw(n - (9 ** exp_nine)))
    
    
if __name__ == '__main__':
    n = int(input())
    print(min_withdraw(n))

Submission status: Wrong Answer

Solution code:
N = int(input())
k = 0
nine = [9** (i+1) for i in range(5)]
six = [6 ** (i+1) for i in range(6)]
nine.extend(six)
nine.sort()
while(N>5):
 for i in range(len(nine)-1):
  if nine[i] <= N and nine[i+1] > N:
   N -= nine[i]
   k += 1

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

def calc(n, i):
    if n == 0:
        return i
    elif n < 6:
        return i + n
    elif n < 9:
        return i + (n - 6 + 1)
    else:
        return min(
            calc(n - 6**int(math.log(n,6)), i+1),
            calc(n - 9**int(math.log(n,9)), i+1)
        )
    
print(calc(N, 0))

Submission status: Wrong Answer

Solution code:
# https://beta.atcoder.jp/contests/abc099/tasks/abc099_c
# C - Strange Bank

# C_Strange_Bank.py

N = int(input())
n = 0
N_divided_9 = N
N_divided_6 = N
num_division_9 = 0
num_division_6 = 0

while (N_divided_9 / 9) >= 1 :
    N_divided_9 = N_divided_9 / 9
    num_division_9 += 1
#print(num_division_9)

while (N_divided_6 / 6) >= 1 :
    N_divided_6 = N_divided_6 / 6
    num_division_6 += 1
#print(num_division_6)


l = [1]
for i in range(1, num_division_9+1):
    l.append(9**i)
for i in range(1, num_division_6+1):
    l.append(6**i)

l.sort(reverse = True)
#print(l)

total = 0
for num in l:
    num_division = N // num
    #print("N_left, num, num_division:", N, num, num_division)
    N -= num_division * num
    total += num_division
    #print("num, N_left, total_zantei:", num, N, total)

print(total)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product

sys.setrecursionlimit(50000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@lru_cache(maxsize=None)
def r(N):
    # print(N)
    if N == 1:
        return 1
    elif N == 0:
        return 0
    a = 1
    b = 6**int(math.floor(math.log(N, 6)))
    c = 9**int(math.floor(math.log(N, 9)))
    if c >= 9:
        ac = r(N - c) + 1
    else:
        ac = sys.maxsize
    if b >= 6:
        ab = r(N - b) + 1
    else:
        ab = sys.maxsize
    aa = N
    return min(aa, ab, ac)


@mt
def slv(N):
    return r(N)


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 1 6^ 9^

n = int(input())

# その数までのリストを持っておく

lis = [1]
head = 6
val = 6
while True:
    if n < head:
        break
    lis.append(head)
    head = val * head

head = 9
val = 9
while True:
    if n < head:
        break
    lis.append(head)
    head = val * head

# print(lis)

count = 0
while True:
    if n == 0:
        break
    if n < 20:
        six_per = int(n / 6)
        nine_per = int(n / 9)
        if six_per > nine_per:
            n = n - six_per * 6
            count += six_per
            count += n
        else:
            n = n - nine_per * 9
            count += nine_per
            count += n
        break

    tmp = 0
    for i in reversed(sorted(lis)):
        if n >= i:
            tmp = i
            count += 1
            break
    n -= tmp
    # print(n)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

availableValues = sorted(
    [
        1,
        6,
        36,
        216,
        1296,
        7776,
        46656,
        9,
        81,
        729,
        6561,
        59049,
    ],
    reverse=True)

count = 0

while N > 0:
    for i in availableValues:
        if i <= N:
            N -= i
            count += 1
            break

print(count)

Submission status: Wrong Answer

Solution code:
n = input()
l = []
count = 0

for i in xrange(0,10):
	x = 9 ** i
	if x > 100000:
		break
	l.append(x)

for i in xrange(1,10):
	x = 6 ** i
	if x > 100000:
		break
	l.append(x)

l.sort()
l.reverse()

i = 0

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

print count

Submission status: Wrong Answer

Solution code:
values=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049,9999999]
a=int(input())
count=0
while(a>0):
	for i in range(0,len(values)):
		if(values[i]>a):
			break
	count+=1
	a=a-values[i-1]
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

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

    draws = [1]

    for beki in range(1, 99999):
        over = 0

        if 6 ** beki > 100000:
            over += 1
        else:
            draws.append(6 ** beki)

        if 9 ** beki > 100000:
            over += 1
        else:
            draws.append(9 ** beki)

        if over == 2:
            break

    draws.sort(reverse=True)

    ans = 0
    idx = 0

    while N != 0:
        if draws[idx] > N:
            idx += 1
            continue
        else:
            if 12 <= N <= 17:
                N -= 6
                ans += 1
            else:
                N -= draws[idx]
                ans += 1


    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N=int(input())
LIST=[1679616,531441,279936,59049,46656,7776,6561,1296,729,216,81,36,9,6,1]
count=0
for x in LIST:
	count+=int(N/x)
	N=N-x*int(N/x)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
money_list = (59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1)
ans = 0
for i in money_list:
  while n >= i:
    if 12 <= n <=14:
      n -= 6
      ans += 1
    else:
      n -= i
      ans += 1

print(ans)

Submission status: Wrong Answer

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

def solve():
    n = int(input())
    li = [1]
    li.extend([6 ** i for i in range(1, 15) if 6 ** i < n])
    li.extend([9 ** i for i in range(1, 15) if 9 ** i < n])
    li.sort(reverse=True)

    cnt = 0
    s = set([n])
    bf = False
    while not bf:
        ts = set(s)
        for e in li:
            for c in s:
                if c - e == 0:
                    bf = True
                    break
                if c - e > 0:
                    ts.add(c - e)
            if bf:
                break
        if not bf:
            s = ts
        cnt += 1
    print(cnt)


if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
kingaku = int(input())

kaisu = 0

while(1):
    if kingaku > 9**5:
        kingaku -= 9**5
        kaisu += 1

    if kingaku > 6**6:
        kingaku -= 6**6
        kaisu += 1


    if kingaku > 9**4:
        kingaku -= 9**4
        kaisu += 1


    if kingaku > 6**5:
        kingaku -= 6**5
        kaisu += 1


    if kingaku > 9**3:
        kingaku -= 9**3
        kaisu += 1


    if kingaku > 6**4:
        kingaku -= 6**4
        kaisu += 1


    if kingaku > 9**2:
        kingaku -= 9**2
        kaisu += 1


    if kingaku > 6**3:
        kingaku -= 6**3
        kaisu += 1


    if kingaku > 9**1:
        kingaku -= 9**1
        kaisu += 1


    if kingaku > 6**2:
        kingaku -= 6**2
        kaisu += 1


    if kingaku > 6**1:
        kingaku -= 6**1
        kaisu += 1


    if kingaku > 9**0:
        kingaku -= 9**0
        kaisu += 1

    if kingaku == 1:
        kaisu += 1
        break

print(kaisu)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product

sys.setrecursionlimit(50000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@lru_cache(maxsize=None)
def r(N):
    # print(N)
    if N == 1:
        return 1
    elif N == 0:
        return 0
    a = 1
    b = 6**int(math.floor(math.log(N, 6)))
    c = 9**int(math.floor(math.log(N, 9)))
    if c > 0:
        ac = r(N - c) + 1
    else:
        ac = sys.maxsize
    if b > 0:
        ab = r(N - b) + 1
    else:
        ab = sys.maxsize
    aa = N
    return min(aa, ab, ac)


@mt
def slv(N):
    return r(N)


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = int(input())

b = [1,6,9,36,81,216,729,1296,6561,7776,46659,59049]
c = 0
al = 0
for i in range(len(b)):
  c = 0
  if b[11- i] <= a:
    c = a // b[11-i]
    a %= b[11-i]
    al += c
    if a == 0:
      break

print(al)

Submission status: Wrong Answer

Solution code:
def N_dev6(N):
    ans = 0
    while True:
        N = N/6
        if N >= 1:
            ans += 1
        else:
            break
    return ans

def N_dev9(N):
    ans = 0
    while True:
        N = N/9
        if N >= 1:
            ans += 1
        else:
            break
    return ans

def deep(N):
    if N <= 5:
        result = N
    else:
        N_sub6 = N - 6**N_dev6(N)
        N_sub9 = N - 9**N_dev9(N)
        result = 1 + min(deep(N_sub6),deep(N_sub9))
    return result

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [1]
for i in range(1, 7):
    lst.append(6 ** i)
for j in range(1, 5):
    lst.append(9 ** j)
DP = [100000 for _ in range(N + 1)]
DP[0] = 0

for i in lst:
    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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    li = [1]
    li.extend([6 ** i for i in range(1, 15) if 6 ** i < n])
    li.extend([9 ** i for i in range(1, 15) if 9 ** i < n])
    li.sort(reverse=True)

    cnt = 0
    s = set([n])
    bf = False
    while not bf:
        ts = set(s)
        for e in li:
            for c in s:
                if c - e == 0:
                    bf = True
                    break
                ts.add(c - e)
            if bf:
                break
        s = ts
        cnt += 1
    print(cnt)


if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
towithdraw = int(input())

possible = []

for i in range(0, 9):
    possible.append(9**i)
for i in range(1, 9):
    possible.append(6 ** i)

poss = sorted(possible)
#print(poss)
number = 0

#while towithdraw != 0:
#    for i in reversed(range(0,len(poss))):
#        while(poss[i]<=towithdraw):
#            towithdraw -= poss[i]
#            # print(poss[i])
#            number += 1
#print(number)


while towithdraw != 0:
    for i in reversed(range(0,len(poss))):
        number += towithdraw // poss[i]
        towithdraw %= poss[i]
print(number)

Submission status: Wrong Answer

Solution code:
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

n = int(input())
count = 0
k = 0
while n > 0:
	if n == 14:
		count += 4
		n = 0
	elif n == 13:
		count += 3
		n = 0
	elif n == 12:
		count += 2
		n = 0
	elif n == 116:
		count += 6
		n = 0
	elif n == 115:
		count += 5
		n = 0
	elif n == 114:
		count += 4
		n = 0
	elif n >= cost[k]:
		n = n-cost[k]
		count += 1
	else:
		k += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()

l = []
for i in range(1,6):
  l.append(9**i)
for i in range(7):
  l.append(6**i)
l.sort(reverse=True)

cache = {n:n for n in l}
def f(n):
  if n in cache:
    return cache[n]
  ret = 100000
  for i in l:
    if i <= n:
      ret = min(ret, f(n-i)+1)
  cache[n] = ret
  return ret
print(f(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 0
j = 0
a = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
b = a.sort(reverse=True)
while N > 0:
  if a[j] > N:
    j += 1
  if a[j] == N:
    N = 0
    i += 1
    print(i)
  if a[j] < N:
    N = N-a[j]
    i += 1

Submission status: Wrong Answer

Solution code:
N = int(input())

count = 0

while N>= 6:

    six_jousu = 1
    nine_jousu = 1
    while N >= 6**six_jousu:
        six_jousu += 1

    while N >= 9**nine_jousu:
        nine_jousu += 1

    N = N-max(6**(six_jousu-1), 9**(nine_jousu-1))
    count += 1

count = count + N
print(count)

Submission status: Wrong Answer

Solution code:
from math import log

n = int(input())

ans = 0
while n > 0 :
    a = 6**int(log(n,6))
    b = 9**int(log(n,9))
    if n - max(a,b) < 6 :
        break
    n -= max(a,b)
    ans += 1

ans += min(n//6+n%6, n//9+n%9)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

M = 100000

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

# for i in range(10):
#     val = 9 ** i
#     if val <= M:
#         print(val)
#         c.append(val)
#
# for i in range(10):
#     val = 6 ** i
#     if val <= M:
#         print(val)
#         c.append(val)

count = 0
rest = N

for i in c:
    if rest // i > 0:
        count += rest // i
        # print(str(i) + ', ' + str(rest // i) + ' times, rest = ' + str(rest % i))
        rest = rest % i

    if rest == 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

calc_list = [729,216,81,36,9,6,1]
res = 0

for i in range(len(calc_list)):
    if n == 1:
        res += 1
        break
    if n > calc_list[i]:
        #print("n",n,"cal",calc_list[i])
        res += int(n/calc_list[i])
        n = n%calc_list[i]

        #print("n",n)
        #print(res)

print(res)

Submission status: Wrong Answer

Solution code:

ar = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
n = int(input())
c = 0
b = 0
for z in range(100):
    for i in range(len(ar)):
        if n - ar[i] < 0:
            if n - ar[i-1] > ar[i-2] * 2:
                n -= ar[i - 2]
            else:
                n -= ar[i-1]
            c += 1
            #print(n, ar[i - 1])
            if n == 0:
                b = 1
                break
            break
    if b == 1:
        break
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())

M = 100000

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

# for i in range(10):
#     val = 9 ** i
#     if val <= M:
#         print(val)
#         c.append(val)
#
# for i in range(10):
#     val = 6 ** i
#     if val <= M:
#         print(val)
#         c.append(val)

count = 0
rest = N

for i in c:
    if rest // i > 0:
        count += rest // i
        print(str(i) + ', ' + str(rest // i) + ' times, rest = ' + str(rest % i))
        rest = rest % i

    if rest == 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [1]
result = 0

i = 6
while True:
	arr.append(i)
	i *= 6
	if i>N:
		break

i = 9
while True:
	arr.append(i)
	i *= 9
	if i>N:
		break

arr.sort()
arr.reverse()

while N>14:
	for i in arr:
		if i<=N:
			N -= i
			result += 1
			break
if N>=12:
	result += 2		# 6を2回
	N -= 12
elif N>=6:
	result += 1		# 6を1回
	N -= 6

print(result + N)

Submission status: Wrong Answer

Solution code:
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

n = int(input())
count = 0
k = 0
while n > 0:
	if n == 14:
		count += 4
		n = 0
	elif n == 13:
		count += 3
		n = 0
	elif n == 12:
		count += 2
		n = 0
	elif n >= cost[k]:
		n = n-cost[k]
		count += 1
	else:
		k += 1
print(count)

Submission status: Wrong Answer

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

for i in range(100):
    if 9 ** i <= 100000:
        l.append(9 ** i)
        
ll = list(set(l))
ll = list(reversed(list(sorted(ll))))
#ll = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

count = 0
for i in range(len(ll)):
    if n == 0:
        break
    elif n < ll[i]:
        continue
    else:
        m = n // ll[i]
        count = count + n // ll[i]
        n = n - ll[i] * m
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
mi = 100000
for q in range(11120):
    a = 0
    n = q*9
    pn = N-n
    if(n>N) : break;
    for i in range(4,0,-1):
        if(n >= 9**i) :
            a += n//(9**i)
            n%=(9**i)
    for i in range(5,0,-1):
        if(pn >= 6**i) :
            a += pn//(6**i)
            pn%=(6**i)
    a += pn;
    mi = min(mi,a)
print(mi)

Submission status: Wrong Answer

Solution code:
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

print(cost)
n = int(input())
count = 0
k = 0
while n > 0:
	if n == 14:
		count += 4
		n = 0
	elif n == 13:
		count += 3
		n = 0
	elif n == 12:
		count += 2
		n = 0
	elif n >= cost[k]:
		print(cost[k],n)
		n = n-cost[k]
		count += 1
	else:
		k += 1
print(count)

Submission status: Wrong Answer

Solution code:
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

n = int(input())
count = 0
k = 0
while n > 0:
	if n == 14:
		count += 4
		n = 0
	elif n == 13:
		count += 3
		n = 0
	elif n == 12:
		count += 2
		n = 0
	elif n == 11:
		count += 2
		n = 0
	elif n >= cost[k]:
		n = n-cost[k]
		count += 1
	else:
		k += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
possible = [1]
i=1
while i <= 100000:
  i = i*6
  possible+=[i]
i=1
while i <= 100000:
  i = i*9
  possible+=[i]
possible.sort(reverse =1)
ans =0
while n:
  for i in range(len(possible)):
    if n==12:
      ans+=2
      n=0
    elif n==13:
      ans+=2
      n=1
    elif n==14:
      ans+=2
      n=2
    elif possible[i] <=n:
      n-=possible[i]
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    dp = [[False]*(n+1)]
    dp[0][0] = True
    way = [1] + [6**i for i in range(1,9) if 6**i <= n] + [9**i for i in range(1,7) if 9**i <= n]
    while True:
        newline = [False] * (n+1)
        for w in way:
            for i in range(0, n+1):
                if i - w < 0: continue
                if newline[i]: continue
                if dp[len(dp)-1][i-w]: newline[i] = True
                if newline[n]: return len(dp)
        dp.append(newline)

print(solve())

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def solve():
    n = int(input())
    dp = deque([[False]*(n+1)])
    dp[0][0] = True
    way = [1] + [6**i for i in range(1,9) if 6**i <= n] + [9**i for i in range(1,7) if 9**i <= n]
    while True:
        newline = [False] * (n+1)
        for w in way:
            for i in range(0, n+1):
                if i - w < 0: continue
                if dp[0][i-w]: newline[i] = True
                if newline[n]:
                    return len(dp)
        dp.appendleft(newline)

print(solve())

Submission status: Time Limit Exceeded

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

def count(val1, val2):
    num = 1
    while True:
        if val1 < (val2 ** num):
            res = 0
            if num > 1:
                res = val2 ** (num-1)

            break  
        num += 1

    return res


N = int(input())
ans = N

for i in range(0,N+1):
    n = i
    m = N - i
    res = 0

    while True:
        num = count(n, 9)
        if num == 0:
            break
        n -= num
        res += 1

    while True:
        num = count(m, 6)
        if num == 0:
            break
        m -= num
        res += 1

    res += n + m
    ans = min(ans, res)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**9

if __name__ == "__main__":
    n = int(input())
    m = [1]
    dp = [INF]*201010
    t = 6
    q = 9
    while t<=n:
        m.append(t)
        t*=6
    while q<=n:
        m.append(q)
    for i in m:
        dp[i] = 1
    
    for i in range(1,n):
        for j in m:
            dp[i+j] = min(dp[i+j],dp[i]+1)
    print(dp[n])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
six = [6**i for i in range(7)]
nine = [9**i for i in range(6)]
L = []
for s in six:
  L.append(s)
for s in nine[1:]:
  L.append(s)
L.sort(reverse=True)
ans = 0
for l in L:
  while N > 0:
    ans += N // l
    N %= l
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

#初期化
#コイン1円
dp=[i for i in range(n+1)]

#コイン6円
i=1
while 6**i<=n:
    dp[6**i]=1
    i+=1
#コイン6円
i=1
while 9**i<=n:
    dp[9**i]=1
    i+=1

for i in range(1,n+1):
    for j in range(i):
        dp[i]=min(dp[i],dp[j]+dp[i-j])
    #if i%1000==0:
        #print(i)
print(dp[-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def drawal(x):
  if(x <= 5):
    return x
  else:
    def drawal9(y):
      i = 0
      while 9** (i+ 1)<= y:
        i+= 1
      return drawal(y- 9** i)+ 1
    def drawal6(z):
      i = 0
      while 6** (i+ 1)<= z:
        i+= 1
      return drawal(z- 6** i)+ 1
    return min(drawal9(x), drawal6(x))

print(drawal(N))

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
def DFS(n, t):
    tmp = 10**5
    if t<=5:
        for i in range(9):
            nxt = n-i*(9**(6-t))
            if nxt<0:
                continue
            tmp = min(tmp, DFS(nxt, t+1)+i)
        return tmp
    elif t<=11:
        for i in range(6):
            nxt = n-i*(6**(12-t))
            if nxt<0:
                continue
            tmp = min(tmp, DFS(nxt, t+1)+i)
        return tmp
    else:
        if n<6:
            return n
        else:
            return 10**5
print(DFS(n, 1))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
q = deque([(0, 0, 0)])
while q:
    now, cnt, stat = q.popleft()
    if now>n:
        continue
    if now==n:
        print(cnt)
        break
    for i in range(1, 8):
        if stat<=i:
            q.append((now+6**i, cnt+1, i))
    for i in range(1, 7):
        if stat<=i+7:
            q.append((now+9**i, cnt+1, i+7))
    q.append((now+1, cnt+1, 14))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())

d = deque([0])
table = [-1]*(N+1)
table[0] = 0
while d:
    i = d.popleft()
    j = 6
    k = 9
    if (i < N):
        if table[i+1] == -1:
            table[i+1] = table[i] + 1
        d.append(i+1)

    while i + j <= N:
        if table[i+j] == -1:
            table[i+j] = table[i] + 1
            d.append(j)
        j *= 6
    while i + k <= N:
        if table[i+k] == -1:
            table[i+k] = table[i] + 1
            d.append(k)
        k *= 9
    if table[N] != -1:
        break
print(table[N])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())

d = deque([0])
table = [-1]*(N+1)
table[0] = 0
while d:
    i = d.popleft()
    j = 6
    k = 9
    if (i < N):
        if table[i+1] == -1:
            table[i+1] = table[i] + 1
        d.append(i+1)

    while i + j <= N:
        if table[i+j] == -1:
            table[i+j] = table[i] + 1
            d.append(j)
        j *= 6
    while i + k <= N:
        if table[i+k] == -1:
            table[i+k] = table[i] + 1
            d.append(k)
        k *= 9
print(table[N])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())

d = deque([0])
table = [-1]*(N+1)
table[0] = 0
while d:
    i = d.popleft()
    j = 6
    k = 9
    if (i < N):
        if table[i+1] == -1:
            table[i+1] = table[i] + 1
        else:
            table[i+1] = min(table[i+1], table[i] + 1)
        d.append(i+1)

    while i + j <= N:
        if table[i+j] == -1:
            table[i+j] = table[i] + 1
            d.append(j)
        else:
            table[i+j] = min(table[i]+1, table[i+j])
        j *= 6
    while i + k <= N:
        if table[i+k] == -1:
            table[i+k] = table[i] + 1
            d.append(k)
        else:
            table[i+k] = min(table[i]+1, table[i+k])
        k *= 9
print(table[N])