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

count = 0

def cal(N,num):
    if N >= num:
        for i in range(1,999):
            if N < num ** i:
                return num ** (i-1)
                break

    return -1


while N >= 6:
    res_6 = cal(N,6)
    res_9 = cal(N,9)

    if res_9 != -1 and N >= res_9 and res_9 > res_6:
        N -= res_9
        count += 1
    if res_6 != -1 and N >= res_6:
        N -= res_6
        count += 1
count += N
print(count)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
ans = 100000
for i in range(N):
  a = i
  b = N -i
  da = 0
  db = 0
  while a > 0:
    da += a % 9
    a /= 9
  while b > 0:
    db += b % 6
    b /= 6
  ans = min(ans, da+db)
print ans

Submission status: Wrong Answer

Solution code:

N = int(input())

ans = 0
list = [1]
for i in range(1, 7):
    list.append(9**i)
    list.append(6**i)
list.sort()
#print(list)
for j in range(N):
    for i in range(12):
        if N in range(list[i],list[i+1]):
            N = N - list[i]
            #print(list[i])
            ans += 1
            #print(N)
            if N == 0:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 0)]
MAX_CNT = 9999999
min_cnt = MAX_CNT

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) + 1 < min_cnt:
            min_cnt = cnt + int(N - v) + 1
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) + 1 < min_cnt:
            min_cnt = cnt + int(N - v) + 1

if min_cnt == MAX_CNT:
    print(N)
else:
    print(min_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())


def hoge(kind, target):
    i = 0
    while kind**i <= target:
        i += 1
    rest = target - kind**(i - 1)
    return i - 1, rest


target = N
count = 0
while target >= 36:
    six_i, six_rest = hoge(6, target)
    nine_i, nine_rest = hoge(9, target)
    if six_rest < nine_rest:
        target = six_rest
    else:
        target = nine_rest
    count += 1

Min = float("inf")
for i in range(target // 9 + 1):
    temp = target - i * 9
    for j in range(temp // 6 + 1):
        k = temp - j * 6
        Min = min(Min, i + j + k)

print(count + Min)

Submission status: Wrong Answer

Solution code:
N = int(input())
num = 0
drawlist = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6,
            9, 9**2, 9**3, 9**4, 9**5]
drawlist.sort()
drawlist.reverse()
while N:
    for d in drawlist:
        if N >= d:
            N = N - d
            num = num + 1
            break
print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    N = int(input())
    b= []
    i=0
    while(6**i<N):
        b.append(6**i)
        i+=1
    i=1
    while(9**i<N):
        b.append(9**i)
        i+=1
    b.sort()
    x = np.zeros(N)
    for itms in b:
        for vol in range(N):
            dif = vol-itms
            if (dif+1 >= 0):
                if (dif==-1):
                    x[vol]=1
                elif(x[vol]==0 or x[vol]>x[dif]+1):
                    x[vol] = x[dif]+1
    print(int(x[N-1]))

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())


def hoge(kind, target):
    i = 0
    while kind**i <= target:
        i += 1
    rest = target - kind**(i - 1)
    return i - 1, rest


target = N
count = 0
while target >= 36:
    six_i, six_rest = hoge(6, target)
    nine_i, nine_rest = hoge(9, target)
    if six_rest < nine_rest:
        target = six_rest
    else:
        target = nine_rest
    count += 1

Min = float("inf")
for i in range(target // 9 + 3):
    temp = target - i * 9
    for j in range(temp // 6 + 1):
        k = temp - j * 6
        Min = min(Min, i + j + k)

print(count + Min)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 0)]
MAX_CNT = 9999999
min_cnt = MAX_CNT

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) + 1 < min_cnt:
            min_cnt = cnt + int(N - v) + 1
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) + 1 < min_cnt:
            min_cnt = cnt + int(N - v) + 1

if min_cnt == MAX_CNT:
    print(N)
else:
    print(min_cnt)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 0)]
MAX_CNT = 9999999
min_cnt = MAX_CNT

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v) + 1
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v) + 1

if min_cnt == MAX_CNT:
    print(N)
else:
    print(min_cnt)

Submission status: Wrong Answer

Solution code:
def how_many(n, i):
    B = 1
    while True:
        a = n - i**B

        if a < 0:
            B -= 1
            return B
            break
        if i ==1:
            break

        B += 1


N = int(input())
A = [9, 6, 1]
ans = 0

for i in A:
    B = how_many(N, i)
    # print(N, i)
    if B != None:
        if B != 0:
            ans += 1
            # print(type((B)))
            N -= i ** int(B)
            # print("B", B)
    if 0 < N < 6:
        ans += N
        break
print(ans)

Submission status: Wrong Answer

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

count=0
if N < 6:
    print(N)
else:
    while (1):
        n9 = math.log(N, 9)
        n6 = math.log(N, 6)
        print(n9,n6)
        n9,nn=math.modf(n9)
        n6,nj=math.modf(n6)
        if math.pow(9, nn)>math.pow(6, nj):
            N -= math.pow(9, nn)
        else:
            N -= math.pow(6, nj)
        count+=1
        if N < 6:
            print(int(count + N))
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
num = 0
drawlist = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6,
            9, 9**2, 9**3, 9**4, 9**5]
drawlist.sort()
drawlist.reverse()
while N:
    for d in drawlist:
        if N >= d:
            print(d)
            N = N - d
            num = num + 1
            break
print(num)

Submission status: Wrong Answer

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

def f(N):
    if N<6:
        return N-1
    for i in range(2,10):
        if N-pow(6,i)<0:
            a6 = pow(6,i-1)
            break
    for i in range(1,10):
        if N-pow(9,i)<0:
            a9 = pow(9,i-1)
            break
    return N-max(a6,a9)

m=0
while n!=0:
    n = f(n)
    m += 1
    
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt=0
nine = [9**i for i in range(6)]
six = [6**i for i in range(7)]
mix = sorted(list(set(nine + six)),reverse=True)
n -= n%3
for money in mix:
    cnt += int(n/money)
    n -= money*int(n/money)
print(cnt+n%3)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(sys.stdin.readline())

queue = [(N, 1)]
MAX_CNT = 9999999
min_cnt = MAX_CNT

while queue:
    N, cnt = queue.pop()
    if N >= 9:
        v = math.pow(9, math.floor(math.log(N, 9)))
        if N - v >= 6 and cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)
    if N >= 6:
        v = math.pow(6, math.floor(math.log(N, 6)))
        if cnt < min_cnt:
            queue.append((N - v, cnt + 1))
        elif cnt + (N - v) < min_cnt:
            min_cnt = cnt + int(N - v)

if min_cnt == MAX_CNT:
    print(N)
else:
    print(min_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

def hikidashi(n):
    if 35 >= n:
        tmp1 = n//9 + (n%9)//6 + (n%9)%6
        tmp2 = n//6 + n%6

        if tmp1 == tmp2:
            if n >= 9:
                return 9
            elif n >= 6:
                return 6
            else:
                return 1
        elif tmp1 > tmp2:
            return 6
        else:
            return 9
    

    else:
        count = 0
        while True:
            tmp = pow(9, count)
            if tmp > n:
                break
            n9 = tmp
            count += 1

        count = 0
        while True:
            tmp = pow(6, count)
            if tmp > n:
                break
            n6 = tmp
            count += 1
        return max(n6, n9)


result = 0
while N != 0:
    result += 1
    N = N - hikidashi(N)

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
while 6<=N:
    i = 0
    j = 0
    while N-(9**i)>=0:
        i+=1
    while N-(6**j)>=0:
        j+=1
    N -= max(9**(i-1),6**(j-1))
    cnt += 1
print(cnt+N)

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
while n>=0:
  if n<=5:
    count+=n
    print(count)
    exit()
  elif n<=8:
    count+=n-5
    print(count)
    exit()
  else:
    i=1
    next1=0
    while 6**i<=n:
      next1=6**i
      i+=1
    j=1
    next2=0
    while 9**j<=n:
      next2=9**j
      j+=1
    if next1>next2:
      n=n-next1
    else:
      n=n-next2
    count+=1

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(1, 7):
    cashs.append(6 ** i)

cashs.append(1)
cashs = sorted(cashs, reverse=True)


cnt = 0
for money in cashs:
    cnt += N // money
    N = N % money
    

print (cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
list1 = []
i = 1
j = 1

while 9**i <= N:
    list1.append(9**i)
    i += 1

while 6**j <= N:
    list1.append(6**j)
    j += 1

list1.append(1)
list2 = sorted(list1, reverse=True)

for i in list2:
    if i <= N:
        q = N // i
        N = N - i * q
        count += q

print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

count = 0

for i in range(12):
  count += int(n/p[i][0])*p[i][1]
  n = n%p[i][0]

print(count + n)

Submission status: Wrong Answer

Solution code:
# your code goes here



def max_6_9(N):
	t_9 = 0
	t_6 = 0
	
	while 6**t_6 <= N :
		t_6 += 1
	while 9**t_9 <= N :
		t_9 += 1
	if 12 <= N <= 14:
		return 6
	else:
		return max(6**(t_6-1), 9**(t_9-1))

def main(N, count):
	
	if N == 0 :
		return count
	else:
		N -= max_6_9(N)
		count += 1
	
	return main(N, count)
	

N = int(input())
count = 0
print(main(N, count))

Submission status: Wrong Answer

Solution code:
kingaku = int(input())

kaisu = 0

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


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

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

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

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

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

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

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



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


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



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


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

    if kingaku == 1:
        kaisu += 1
        break

print(kaisu)

Submission status: Wrong Answer

Solution code:
N = int(input())
base6 = []
base9 = []
result = 0

tmp = N
while tmp>=6:
	base6.append(tmp%6)
	tmp = int(tmp/6)
base6.append(tmp)	# arrの6進数のリスト

tmp = N
while tmp>=9:
	base9.append(tmp%9)
	tmp = int(tmp/9)
base9.append(tmp)	# arrの9進数のリスト

if len(base6) > len(base9):
	base9.extend([0 for i in range(len(base6)-len(base9))])

for i in range(len(base6)):
	if base6[i] > base9[i]:
		result += base9[i]
	else:
		result += base6[i]

print(result-1)

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 (6561*2) <= n <= (7776+6561):
      n -= 6561
      ans += 1
    elif (729*2) <= n <= (1296+729):
      n -= 729
      ans += 1
    elif 12 <= n <= 14:
      n -= 6
      ans += 1
    else:
      n -= i
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import functools
sys.setrecursionlimit(10**6)

# N = int(input())
MAXN = 10**5
six_ps = [6**i for i in range(1, 7)]
nine_ps = [9**i for i in range(1, 6)]


@functools.lru_cache(maxsize=None)
def rec(n):
    if n < 6:
        return n

    if n in six_ps or n in nine_ps:
        return 1

    six_tmps = [1 + rec(n - six_p) if six_p < n else MAXN for six_p in six_ps]
    six_tmp = min(six_tmps)

    nine_tmps = [
        1 + rec(n - nine_p) if nine_p < n else MAXN for nine_p in nine_ps
    ]
    nine_tmp = min(nine_tmps)

    return min(six_tmp, nine_tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
pay = []
for i in range(1, 10):
    if 6 ** i < 100000:
        pay.append(6 ** i)
    if 9 ** i < 100000:
        pay.append(9 ** i)
pay.sort(reverse=True)


def func(n, times):
    for i in pay:
        if i <= n:
            global ans
            n -= i
            times += 1
            if ans > times + n:
                ans = times + n
            if n >= 6 and times < ans:
                func(n, times)


func(n, 0)
print(ans)

Submission status: Wrong Answer

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

def f(N):
    if N<6:
        return N-1
    for i in range(2,10):
        if N-pow(6,i)<0:
            a6 = pow(6,i-1)
            break
    for i in range(1,10):
        if N-pow(9,i)<0:
            a9 = pow(9,i-1)
            break
    return N-max(a6,a9)

m=0
while n!=0:
    n = f(n)
    print(n)
    m += 1
    
print(m)

Submission status: Wrong Answer

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

def strbank(N):
    if N == 0:
        return 0
    else:
        m = math.floor(math.log(N, 6))
        n = math.floor(math.log(N, 9))
        a = 6**m
        b = 9**n
        ans = min(N//a + strbank(N % a), N//b + strbank(N % b))
        return ans

h = strbank(N)
print(h)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
x = 0
i = 1
j = 1

while i <= 100000:
    i = i*6
    s.append(i)

while j <= 100000:
    j = j*9
    s.append(j)

while N % 3 != 0:
    N -= 1
    x += 1

s.sort()
s.reverse()

a = len(s)

for k in range(a):
    l = s[k]
    while N >= l:
        N -= l
        x += 1
        if l >= 9:
            if s[k+1] * 2 == N:
                l = s[k+1]
while N != 0:
    N -= 1
    x += 1

print(x)

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

        if 12 <= N <= 14:
            N -= 6
            ans += 1
        else:
            N -= draws[idx]
            ans += 1

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
pay = []
for i in range(1, 10):
    if 6 ** i < 100000:
        pay.append(6 ** i)
    if 9 ** i < 100000:
        pay.append(9 ** i)
pay.sort(reverse=True)


def func(n, times):
    for i in pay:
        if i <= n:
            global ans
            n -= i
            times += 1
            if ans > times + n:
                ans = times + n
            if n > 6 and times < ans:
                func(n, times)


func(n, 0)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def hikidashi(n):
    if 36 > n:
        if n//9 + n%9 == n//6 + n%6:
            if n >= 9:
                return 9
            elif n >= 6:
                return 6
            else:
                return 1
        elif n//9 + n%9 > n//6 + n%6:
            return 6
        else:
            return 9
    


    else:
        count = 0
        while True:
            tmp = pow(9, count)
            if tmp > n:
                break
            n9 = tmp
            count += 1

        count = 0
        while True:
            tmp = pow(6, count)
            if tmp > n:
                break
            n6 = tmp
            count += 1
        return max(n6, n9)


result = 0
while N != 0:
    result += 1
    N = N - hikidashi(N)

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
k = 0
while(N > 5):
 if N >= 59049:
  N -= 59049
  k += 1
 elif N >= 46656:
  N -= 46656
  k += 1
 elif N >= 7776:
  N -= 7776
  k += 1
 elif N >= 6561:
  N -= 6561
  k += 1
 elif N >= 1296:
  N -= 1296
  k += 1
 elif N >= 729:
  N -= 729
  k += 1
 elif N >= 216:
  N -= 216
  k += 1
 elif N >= 81:
  N -= 81
  k += 1
 elif N >= 36:
  N -= 36
  k += 1
 elif N >= 9:
  N -= 9
  k += 1
 elif N >= 6:
  N -= 6
  k += 1

print(k + N)

Submission status: Wrong Answer

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

import os
import sys

def main():
    n = int(input())
    l1 = lis(n, 9)
    l2 = lis(n, 6)
    l1.extend(l2)
    l1 = list(set(l1))
    l1.sort(key=int, reverse=True)
    print(sum(minus(n, l1)))

def lis(n, i):
    count = 0
    res = []
    oi = i
    while i < n:
        res.append(i)
        i = i * oi
        count = count + 1
    return res

def minus(n, l):
    minus_count = 0
    for i in l:
        while n > i:
            if n - i > 0:
                n = n - i
                minus_count = minus_count + 1
            else:
                break
    return minus_count, n

if __name__ == '__main__':
    main()

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.sort()
a.reverse()
# print(a)
c = 0
d = 1
while(n):
    if n ==0:
        break
    if n <= 14 and n >= 12:
        d =11
    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())
list_six_nine = [6**i for i in range(10)]
list_six_nine.extend([9**i for i in range(10)])
list_six_nine.sort()

ans = 0
while n != 0:
    minus = 0
    for i in range(19):
        if n < list_six_nine[i+1]:
            minus = list_six_nine[i]
            break
    n -= minus
    ans += 1
print(ans)

Submission status: Wrong Answer

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

import os
import sys

def main():
    n = int(input())
    l1 = lis(n, 9)
    l2 = lis(n, 6)
    l1.extend(l2)
    l1 = list(set(l1))
    l1.sort(key=int, reverse=True)
    print(minus(n, l1))

def lis(n, i):
    count = 0
    res = []
    oi = i
    while i < n:
        res.append(i)
        i = i * oi
        count = count + 1
    return res

def minus(n, l):
    minus_count = 0
    for i in l:
        while n > i:
            if n - i > 0:
                n = n - i
                minus_count = minus_count + 1
            else:
                break
    return minus_count, n

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
while n>=0:
  if n<=5:
    count+=n
    print(count)
    exit()
  elif n<=8:
    count+=n-5
    print(count)
    exit()
  else:
    i=1
    next=0
    while 6**i<=n:
      next=6**i
      i+=1
    j=1
    while 9**j<=n:
      if 9**j>next:
        next=9**j
      j+=1
    n=n-next
    count+=1

Submission status: Wrong Answer

Solution code:
def abc099_c():
    n = int(input())
    if n == 3:
        return 3
    count = n % 3
    n -= count

    vals = [6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049][::-1]
    while n:
        for val in vals:
            if n >= val and n - val != 3:
                n -= val
                count += 1
                break

    return count


print(abc099_c())

Submission status: Wrong Answer

Solution code:
N_MAX = 100000

pull_list = [1]

n = 9
while n <= N_MAX:
    pull_list.append(n)
    n *= 9

n = 6
while n <= N_MAX:
    pull_list.append(n)
    n *= 6

pull_list.sort()
pull_list.reverse()

n = int(input().rstrip())

nokori = n
count = 0
while 0 < nokori:
    for pull in pull_list:
        if pull <= nokori:
            nokori -= pull
            count += 1
            break

print(count)

Submission status: Wrong Answer

Solution code:
def c_strange_bank(N):
    import bisect
    # 1,6**k,9**k の形であり、Nの最大値10**5以下の整数
    money = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
    money_odd = [1,  9, 81,  729,  6561,  59049]
    money_even = [6, 36, 216, 1296, 7776, 46656]

    ans = 0
    while N != 0:
        if 1 <= N <= 5:
            ans += N
            break
        elif N in [6, 7, 8, 12, 13, 14]:
            N -= 6
        elif N in [9, 10, 11, 15, 16, 17, 18]:
            N -= 9
        else:
            idx = bisect.bisect_right(money, N) - 1
            N -= money[idx]
        ans += 1
    return ans

N = int(input())
print(c_strange_bank(N))

Submission status: Wrong Answer

Solution code:
N = int(input())

F = [1]
F += [pow(6,i) for i in range(1,7)]
F += [pow(9,i) for i in range(1,6)]

F = sorted(F)[::-1]
ans = 0
while(N>36):
    for f in F:
        if N-f>=0:
            N-=f
            ans+=1
            break
            
#36達していれば36以上の値を使うに越したことはない(6の乗数は9の倍数でも6の倍数でもある)
if N<6:
    ans += N
else:
    Nsub = N
    min_count = 36
    for nine in range(0,4):
        count = 0
        for six in range(0,6):
            if N-(nine*9)-(six*6)>=0:
                count = nine+six+(N-(nine*9)-(six*6))
                #print(nine,six,N-(nine*9)-(six*6))
                if count<min_count:
                    min_count = count
    ans += min_count
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = 0

while N >= 6:

    p = 0
    M = N
    while M >= 6:
        M = (M - M % 6)/6
        p += 1

    q = 0
    L = N
    while L >= 9:
        L =(L - L % 9)/9
        q += 1

    N = min(N - 6 ** p, N - 9 ** q)
    x += 1

x += N
print(x)

Submission status: Wrong Answer

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

l = []
p = 0
while True:
    power = pow(9, p)
    if power > n:
        break
    else:
        l.append(power)
    p += 1
p = 0
while True:
    power = pow(6, p)
    if power > n:
        break
    else:
        l.append(power)
    p += 1
l = list(set(l))
l.sort()
l.reverse()
print(l)

for i in l:
    d = n // i
    n -= d * i
    ans += d
    print(i, d)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a,b,cnt=0,0,0
def nine():
    global a
    for i in range(N):
        if 9**i<=N:
            a=9**i
        else:
            break
def six():
    global b
    for i in range(N):
        if 6**i<=N:
            b=6**i
        else:
            break

for i in range(N):
    if N>=6:
        nine()
        six()
        N-=max(a,b)
        cnt+=1
    else:
        cnt+=N
        break
print(cnt)

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 - 9**int(math.log(n,9)), i+1),
            calc(n - 6**int(math.log(n,6)), i+1)
        )
    
print(calc(N, 0))

Submission status: Wrong Answer

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

num=1
while 6**num <= 100000:
    arr.append(6**num)
    num+=1

num=1
while 9**num <= 100000:
    arr.append(9**num)
    num+=1

#print(sorted(arr)[::-1])
#arr=[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
count=0
for i in sorted(arr)[::-1][:-3]:
    if n<i:
        pass
    else:
        count+=n//i
        n=n%i
        #print(count,n)

outs=[]
if n<6:
    print(count+n)
elif n<9:
    print(count+n-5)
else:
    for i in range(4):
        for j in range(6):
            if 9*i+6*j>n:
                pass
            else:
                tmp=n-9*i-6*j
                outs.append(i+j+tmp)
    print(count+min(outs))

Submission status: Wrong Answer

Solution code:
N = int(input())

count = 0

numbers = sorted([9**5, 9**4, 9**3, 9**2, 9, 6**6, 6**5, 6**4, 6**3, 6**2, 6], reverse=True)

def search(n):
    for i in numbers:
        if i <= n:
            return i

for i in range(100):
    if 1 <= N <= 5:
        count += N
        break
    elif N == 0:
        break
    else:
        count += N // search(N)
        N %= search(N)
        

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

def hikidashi(n):
    if 36 > n:
        if n%9 == n%6:
            if n >= 9:
                return 9
            elif n >= 6:
                return 6
            else:
                return 1
        elif n%9 > n%6:
            return 6
        else:
            return 9
    


    else:
        count = 0
        while True:
            tmp = pow(9, count)
            if tmp > n:
                break
            n9 = tmp
            count += 1

        count = 0
        while True:
            tmp = pow(6, count)
            if tmp > n:
                break
            n6 = tmp
            count += 1
        return max(n6, n9)


result = 0
while N != 0:
    result += 1
    N = N - hikidashi(N)

print(result)

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)-1, -1, -1):
        if n <= 35:
            is_break = False
            break
        if num_list[i] < n:
            n -= num_list[i]
            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:
n = int(input())

limit = 100000
inputList = [1]

nine = 9
while nine <= limit:
    inputList.append(nine)
    nine = nine * 9

six = 6
while six <= limit:
    inputList.append(six)
    six = six * 6

inputList.sort(reverse=True)

zan = n
r = 0
for i in inputList:
    tmp = zan//i
    if tmp != 0:
        r = r + tmp
        zan = zan % i

print(r)

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 =11
    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 = n
pay = []
for i in range(1, 10):
    if 6 ** i < 100000:
        pay.append(6 ** i)
    if 9 ** i < 100000:
        pay.append(9 ** i)
pay.sort(reverse=True)


def func(n, times):
    for i in pay:
        if i < n:
            global ans
            n -= i
            times += 1
            if ans > times + n:
                ans = times + n
            if n > 6:
                func(n, times)


func(n, 0)
print(ans)

Submission status: Wrong Answer

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

import os
import sys

def main():
    n = int(input())
    l1 = lis(n, 9)
    l2 = lis(n, 6)
    print(l1)
    print(l2)
    l1.extend(l2)
    l1 = list(set(l1))
    l1.sort(key=int, reverse=True)
    print(minus(n, l1))

def lis(n, i):
    count = 0
    res = []
    oi = i
    while i < n:
        res.append(i)
        i = i * oi
        count = count + 1
    return res

def minus(n, l):
    minus_count = 0
    for i in l:
        while n > i:
            if n - i > 0:
                n = n - i
                minus_count = minus_count + 1
            else:
                break
        print(i, n)
    return minus_count, n

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

l = [1] + [6**x for x in range(1, 7)] + [9**x for x in range(1, 6)]
l.sort(reverse=True)

cnt = 0
for price in l:
    cnt += n // price
    n -= (n // price) * price
    if n == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
num=[9**5,6**6,6**5,9**4,6**4,729,216,81,36,9,6]
for i in num:
    if n//i<=0:
        continue
    elif n%i==0:
        ans=ans+n//i
        n=0
        break
    elif n//i>=1:
        ans=ans+n//i
        n=n%i
print(ans+n)