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:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()

def calc(x,n):
	tmp = 0
	while x > 0:
		tmp += x%n
		x //= n
	return tmp

ans = INF
for i in range(0,N,6):
	tmp = calc(i,6)+calc(N-i,9)
	ans = min(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")

kalanbaba = 1
MOD = 10**9 + 7
# I = lambda:list(map(int,input().split()))

n = int(input())
from math import log
count = 0
l9 = int(log(n,9))
l6 = int(log(n,6))
a = [0]*100001
a[1:7] = [1,2,3,4,5,6]
for i in range(7,100000+1):
	l6 = int(log(i,6))
	l9 = int(log(i,9))
	kk = i//6
	kkk = i//9
	f = kkk + i%9
	f = kkk + (i%9)%6 + (i%9 >= 6)
	a[i] = min((1 if l9 > 0 else 10**9) + a[i - 6**l6] , (1 if l9 > 0 else 10**9) + a[i - 9**l9] , kk + i%6 , f)
print(a[n])

Submission status: Wrong Answer

Solution code:
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")

kalanbaba = 1
MOD = 10**9 + 7
# I = lambda:list(map(int,input().split()))

n = int(input())
from math import log
count = 0
l9 = int(log(n,9))
l6 = int(log(n,6))
while l9 > 0 or l6 > 0:
	count += 1
	lll = 6**l6
	kkk = 9**l9
	if n - lll != 0 and n - kkk != 0 and -1*9**int(log(n - lll,9)) + n - lll == 0:
		count += 1
		n = 0
		break
	elif 6**l6 > 9**l9:
		n -= 6**l6
	else:
		n -= 9**l9
	if n == 0:
		break
	l9 = int(log(n,9))
	l6 = int(log(n,6)) 
print(count + n)

Submission status: Wrong Answer

Solution code:
kalanbaba = 1
MOD = 10**9 + 7
# I = lambda:list(map(int,input().split()))

n = int(input())
from math import log
count = 0
l9 = int(log(n,9))
l6 = int(log(n,6))
while l9 > 0 or l6 > 0:
	count += 1
	if 6**l6 > 9**l9:
		n -= 6**l6
	else:
		n -= 9**l9
	if n == 0:
		break
	l9 = int(log(n,9))
	l6 = int(log(n,6)) 
print(count + n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in [6,9]:
    j = 1
    while i**j<100000:
        a.append(i**j)
        j += 1
a.sort()
dp = [i for i in range(n+1)]
dp[0]= 0
for c in a:
    for i in range(c+1,n+1):
        dp[i] = min(dp[i-c]+1, dp[i])
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [1]
for i in [6,9]:
    j = 1
    while i**j<100000:
        a.append(i**j)
        j += 1
a.sort()
a.reverse()
ans = 0
for i in a:
    ans += n//i
    n -= n//i * i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

hikidasi = [1]

for i in range(1,10000):
    if 6**i > 100000:
        break
    else:
        hikidasi.append(6**i)

for j in range(1,10000):
    if 9**j > 100000:
        break
    else:
        hikidasi.append(9**j)

hikidasi.sort()
hikidasi = hikidasi[::-1]
# print(hikidasi)

ans = 0
while True:
    for money in hikidasi:
        if N >= money:
            # print(money)
            N -= money
            ans += 1
            break
        
    if N == 0:
        print(ans)
        sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

def six(x):
    n=0
    s=6
    while n<1:
        if s<x:
            s*=6
        elif s==x:
            n=1
            return s
        else:
            n=1
            return s/6

def nine(x):
    n=0
    s=9
    while n<1:
        if s<x:
            s*=9
        elif s==x:
            n=1
            return s
        else:
            n=1
            return s/9
        
def ade(x):
    return max(six(x),nine(x))

ans=0

while n>0:
    
    if 12<=n and n<=14:
        ans+=n-10
        n=0
    else:
        n-=ade(n)
        ans+=1
    

print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
l = [1]
for i in range(1, 7):
  l.append(6 ** i)
for j in range(1, 6):
  l.append(9 ** j)
l = sorted(l)
while n != 0:
  for k in range(len(l)):
    if n < l[k]:
      n -= l[k - 1]
      ans += 1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
sys.setrecursionlimit(N*10)

memo = dict()
INF = N

def withdraw(ammount):
    if ammount == 0:
        return 0
    if ammount in memo:
        return memo[ammount]

    answer = ammount

    def calc(unit_base):
        unit = unit_base
        _answer = answer
        while unit < ammount:
            _answer = min(_answer, withdraw(ammount-unit)+1)
            unit *= unit_base
        return _answer

    answer = min(answer, calc(6))
    answer = min(answer, calc(9))

    memo[ammount] = answer
    return answer

print(withdraw(N))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
sys.setrecursionlimit(N*10)

memo = dict()
INF = N

def withdraw(ammount):
    if ammount == 0:
        return 0
    if ammount in memo:
        return memo[ammount]

    answer = INF
    answer = ammount

    unit = 6
    while unit < ammount:
        answer = min(answer, withdraw(ammount-unit)+1)
        unit *= 6

    unit = 9
    while unit < ammount:
        answer = min(answer, withdraw(ammount-unit)+1)
        unit *= 9

    memo[ammount] = answer
    return answer

print(withdraw(N))

Submission status: Wrong Answer

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

INF = 999999999
n = int(input())

coins = [1]

s = 9
while s<n:
    coins.append(s)
    s *= 9

s = 6
while s<n:
    coins.append(s)
    s *= 6

coins.sort(reverse=True)

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

for i in range(1,n+1):
    for c in coins:
        if i-c>=0:
            dp[i] = min(dp[i], dp[i-c]+1)

print(dp[-1])

Submission status: Wrong Answer

Solution code:
ans = N = int(input())
for i in range(N):
  a_,n6,n9 = 0,i,N-i
  while (n6>0): a_ += n6%6; n6 = n6//6
  while (n9>0): a_ += n9%9; n9 = n9//9
  ans = min(ans, a_)
print(ans)

Submission status: Wrong Answer

Solution code:
ans,N = 0,int(input())
coins = sorted([6**i for i in range(7)] + [9**i for i in range(4)], reverse=True)
for c in coins:
  a_ = N // c
  ans += a_ 
  N -= a_*c
print(ans)

Submission status: Wrong Answer

Solution code:
ans,N = 0,int(input())
coins = sorted([6**i for i in range(6)] + [9**i for i in range(6)], reverse=True)
for c in coins:
  a_ = N // c
  ans += a_ 
  N -= a_*c
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N=input()

ans=float("inf")


for n in range(256):
	for m in range(256):
		cnt=0
		num=copy.deepcopy(N)
		for i in range(8,-1,-1):
			if n & 1<<i:
				val9=9**i
				if num/val9>=1:
					tmp=min( num/val9, 8)
					cnt+=num/val9
					num=num-val9*tmp
			if m & 1<<i:
				val6=6**i
				if num/val6>=1:
					tmp=min( num/val6, 5)
					cnt+=num/val6
					num=num-val6*tmp
#	print n,m,cnt
	cnt+=num
	ans=min(ans,cnt)

print ans

Submission status: Wrong Answer

Solution code:
N=input()

ans=0
for i in range(10,0,-1):
	#print "i,N::",i,N
	if 9**i<=N:
		a=9**i
		ans+=N/a
		N=N%a
	if 6**i<=N:
		a=6**i
		ans+=N/a
		N=N%a

ans+=N
print ans

Submission status: Wrong Answer

Solution code:
n = int(input())

nums = []
for i in range(n):
    num = 0
    k=0
    while 6**k <= i:
        num += int(i/(6**k))%6
        k+=1
    k=0
    while 9**k <= n-i:
        num += int((n-i)/(9**k))%9
        k+=1
    
    nums.append(num)

print(min(nums))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
#N = 44852
#candidates = [1, 6, 36, 216, 1296, 7776, 46656,
#              9, 81, 729, 6561, 59049]
candidates = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776,
              46656, 59049]
cnt = 0
while True:
    if N == 0:
        break
    for i, cand in enumerate(candidates):
#        print(N, cand)
        if N-cand < 0:
            now_draw = candidates[i-1]
            candidates = candidates[:i]
            N -= now_draw
            cnt += 1
            break
        if i == len(candidates) - 1:
            now_draw = candidates[-1]
            N -= now_draw
            cnt += 1
            break
            
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
#N = 44852
#candidates = [1, 6, 36, 216, 1296, 7776, 46656,
#              9, 81, 729, 6561, 59049]
candidates = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776,
              46656, 59049]
cnt = 0
while True:
    if N == 0:
        break
    for i, cand in enumerate(candidates):
        print(N, cand)
        if N-cand < 0:
            now_draw = candidates[i-1]
            candidates = candidates[:i]
            N -= now_draw
            cnt += 1
            break
        if i == len(candidates) - 1:
            now_draw = candidates[-1]
            N -= now_draw
            cnt += 1
            break
            
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

#N = int(input())
N = 44852
#candidates = [1, 6, 36, 216, 1296, 7776, 46656,
#              9, 81, 729, 6561, 59049]
candidates = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776,
              46656, 59049]
cnt = 0
while True:
    if N == 0:
        break
    for i, cand in enumerate(candidates):
        print(N, cand)
        if N-cand < 0:
            now_draw = candidates[i-1]
            candidates = candidates[:i]
            N -= now_draw
            cnt += 1
            break
        if i == len(candidates) - 1:
            now_draw = candidates[-1]
            N -= now_draw
            cnt += 1
            break
            
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

r0 = N
r = 0
count6 = 0
count9 = 0

while (r0 != 0):
    while (1):
        if r0 >= 6**(count6+1):
            count6 += 1
        else:
            break

    while (1):
        if r0 >= 9**(count9+1):
            count9 += 1
        else:
            break

    if 9**count9 > 6**count6:
        r += 1
        r0 = r0 - 9**count9
    elif 9**count9 < 6**count6:
        r += 1
        r0 = r0 - 6**count6
    elif count9 == 0 and count6 == 0:
        r += 1
        r0 = r0 - 1
    count9 = 0
    count6 = 0

print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())

r0 = N
r = 0
count6 = 0
count9 = 0

while (r0 != 0):
    while (1):
        if r0 >= 6**(count6+1):
            count6 += 1
        else:
            break

    while (1):
        if r0 >= 9**(count9+1):
            count9 += 1
        else:
            break

    if 9**count9 > 6**count6:
        r += 1
        r0 = r0 - 9**count9
        print(str(9) + " - " + str(count9))
    elif 9**count9 < 6**count6:
        r += 1
        r0 = r0 - 6**count6
        print(str(6) + " - " + str(count6))
    elif count9 == 0 and count6 == 0:
        r += 1
        r0 = r0 - 1
        print(1)
    count9 = 0
    count6 = 0

print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = float("inf")
for i in range(n):
    rec = 0
    k = i
    while k > 0:
        rec += k % 6
        k = k // 6
    k = n - i
    while k > 0:
        rec += k % 9
        k = k // 9
    num = min(num, rec)

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
yen = [6**2, 6**3, 6**4, 6**5, 6**6, 9**2, 9**3, 9**4, 9**5]
yen.sort()
yen.reverse()

ans = 0

while n>=36 :
    for i in range(len(yen)):
        if n - yen[i] >= 0:
            ans = ans + 1
            n = n - yen[i]
            break

if n < 6:
    ans = ans + n
elif n in {6, 9}:
    ans = ans + 1
elif n in {7, 10, 12, 15, 18}:
    ans = ans + 2
elif n in {8, 11, 13, 16, 19, 21, 24, 27}:
    ans = ans + 3
elif n in {14, 17, 20, 22, 25, 28, 30, 33}:
    ans = ans + 4
elif n in {23, 26, 29, 31, 34}:
    ans = ans + 5
elif n in {32, 35}:
    ans = ans + 6
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
yen = [6**2, 6**3, 6**4, 6**5, 6**6, 9**2, 9**3, 9**4, 9**5]
yen.sort()
yen.reverse()

ans = 0

while n>=36 :
    for i in range(len(yen)):
        if n - yen[i] >= 0:
            ans = ans + 1
            n = n - yen[i]
            break

if n < 6:
    ans = ans + n
elif n in {6, 9}:
    ans = ans + 1
elif n in {7, 10, 12, 15, 18}:
    ans = ans + 2
elif n in {8, 11, 13, 16, 19, 21, 24, 27}:
    ans = ans + 3
elif n in {14, 17, 20, 22, 25, 28, 30, 34}:
    ans = ans + 4
elif n in {21, 23, 26, 29, 31, 35}:
    ans = ans + 5
elif n in {32}:
    ans = ans + 6
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
yen = [6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5, 12]
yen.sort()
yen.reverse()

print(yen)
ans = 0

while n>5 :
    for i in range(len(yen)):
        if n - yen[i] >= 0:
            print("n is:{0}, yen[{1}] is:{2}".format(n, i, yen[i]))
            if yen[i] == 12:
                ans = ans + 2
            else :
                ans = ans + 1
            n = n - yen[i]
            print("rest is:{0}".format(n))
            break

print(ans+n)

Submission status: Wrong Answer

Solution code:
n = int(input())
yen = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5]
yen.sort()
yen.reverse()
ans = 0

while n>0 :
    for i in range(len(yen)):
        if n - yen[i] >= 0:
            ans = ans + 1
            n = n - yen[i]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0
while 0 < n:
    can_pulls = {1}
    for std_n in (6, 9):
        m = 0
        while std_n**(m+1) <= n:
            m += 1
        can_pulls.add(std_n**m)
    n -= max(can_pulls)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0
while n:
    can_pulls = {1}
    for std_num in range(6, 9):
        m = 0
        while std_num**m <= n:
            m += 1
        can_pulls.add(std_num**(m-1))
    n -= max(can_pulls)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

maxdata=0
chkflg=True
i=0
cnt=0
while chkflg:

    if n>=9**i:
        maxdata=9**i
        i+=1

    elif n>=6**i:
        maxdata=6**i
        i+=1 
    
    else:
        chkflg=False
    

    if chkflg==False:
        
        n-=maxdata
        chkflg=True
        maxdata=0
        cnt+=1
        i=0
        
    if n<=5:
     
        cnt+=n
        break
        
print(cnt)

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())

withdraw_list = []
withdraw_list.append(1)
# 6
count = 0
while (1):
    count += 1
    if 6**count <=10**5:
        withdraw_list.append(6**count)
    else:
        break
count = 0
while (1):
    count += 1
    if 9**count <=10**5:
        withdraw_list.append(9**count)
    else:
        break
withdraw_list.sort()
withdraw_list.reverse()
# print(withdraw_list)

wi_cou = 0
while (1):
    for i in range(len(withdraw_list)):
        if n == 14:
            wi_cou +=4
            n = 0
            break
        if n == 13:
            wi_cou += 3
            n = 0
            break
        if withdraw_list[i] <= n:
            n -= withdraw_list[i]
            wi_cou += 1
            # print(withdraw_list[i])
            break

    if n == 0:
        break

print(wi_cou)

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())

withdraw_list = []
withdraw_list.append(1)
# 6
count = 0
while (1):
    count += 1
    if 6**count <=10**5:
        withdraw_list.append(6**count)
    else:
        break
count = 0
while (1):
    count += 1
    if 9**count <=10**5:
        withdraw_list.append(9**count)
    else:
        break
withdraw_list.sort()
withdraw_list.reverse()
# print(withdraw_list)

wi_cou = 0
while (1):
    for i in range(len(withdraw_list)):
        if withdraw_list[i] <= n:
            n -= withdraw_list[i]
            wi_cou += 1
            # print(withdraw_list[i])
            break

    if n == 0:
        break

print(wi_cou)

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())

withdraw_list = []
withdraw_list.append(1)
# 6
count = 0
while (1):
    count += 1
    if 6**count <=10**5:
        withdraw_list.append(6**count)
    else:
        break
count = 0
while (1):
    count += 1
    if 9**count <=10**5:
        withdraw_list.append(9**count)
    else:
        break
withdraw_list.sort()
withdraw_list.reverse()
print(withdraw_list)

wi_cou = 0
while (1):
    for i in range(len(withdraw_list)):
        if withdraw_list[i] <= n:
            n -= withdraw_list[i]
            wi_cou += 1
            # print(withdraw_list[i])
            break

    if n == 0:
        break

print(wi_cou)

Submission status: Wrong Answer

Solution code:
from math import log
N = int(input())
n = 0

while N >= 15:
    n += 1
    a = int(log(N, 6))
    b = int(log(N, 9))
    A = 6**a
    B = 9**b
    
    if A > B:
        N -= A
    elif B > A:
        N -= B

if N == 6 or N == 9:
    print(n + 1)
elif N == 7 or N == 10 or N == 12:
    print(n + 2)
elif N == 8 or N == 11 or N == 13:
    print(n + 3)
elif N == 14:
    print(n + 4)
else:
    print(n + N)

Submission status: Wrong Answer

Solution code:
def dfs(n):
    if n < 6:
        return n
    elif n < 9:
        return 1 + dfs(n - 6)
    
    six_max = 1
    nine_max = 1
    while six_max * 6 < n:
        six_max *= 6
    
    while nine_max * 9 < n:
        nine_max *= 9
    
    return min(dfs(n - nine_max), dfs(n - six_max)) + 1

print(dfs(int(input())))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
 
def Nsinpou(x, base):
    #配列を返す Nsin[0]が上位桁
    if x == 0: return [0]
    Nsin = []
    for i in range((round(math.log(x,base)//1)+1)):
        ithdigit = x%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin
 
ans = N
for i in range(N+1):
    coins = sum(Nsinpou(i,6)) + sum(Nsinpou(N-i,9))
    if coins < ans:
        ans = coins
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
 
def Nsinpou(x, base):
    #配列を返す Nsin[0]が上位桁 ex. 56(base=6) => [1,3,2]
    if x == 0: return [0] #log_n(0)の回避
    Nsin = []
    for i in range((int(math.log(x,base)//1)+1)):
        ithdigit = x%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin
 
ans = N #最大でも1円玉N枚
for i in range(N+1): #分け方全探索
    coins = sum(Nsinpou(i,6)) + sum(Nsinpou(N-i,9))
    if coins < ans:
        ans = coins
    
print(ans)

Submission status: Wrong Answer

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

def Nsinpou(x, base):
    #配列を返す Nsin[0]が上位桁
    if x == 0: return [0]
    Nsin = []
    for i in range((int(math.log(x,base)//1)+1)):
        ithdigit = x%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin

ans = N
for i in range(N+1):
    coins = sum(Nsinpou(i,6)) + sum(Nsinpou(N-i,9))
    if coins < ans:
        ans = coins
    
print(ans)

Submission status: Wrong Answer

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

def nsin(N, base):
    if N == 0: return [0]
    Nsin = []
    for i in range((int(math.log(N,base)//1)+1)):
        ithdigit = N%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin

ans = N
for i in range(N+1):
    coins = sum(nsin(i,6)) + sum(nsin(N-i,9))
    if coins < ans: ans = coins

print(ans)

Submission status: Wrong Answer

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

def nsin(N, base):
    if N == 0: return [0]
    Nsin = []
    for i in range((int(math.log(N,base)//1)+1)):
        ithdigit = N%(base**(i+1)) // (base ** i)
        Nsin.append(ithdigit)
    Nsin.reverse()
    return Nsin

ans = N
for i in range(N):
    coins = sum(nsin(i,6)) + sum(nsin(N-i,9))
    if coins < ans: ans = coins

print(ans)

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
from collections import deque

def nearest_num_six(n):
    temp = 1
    if n < 6:
        return n -1
    else:
        while n > temp:
            temp *= 6
        return n - temp // 6

def nearest_num_nine(n):
    temp = 1
    if n < 9:
        return n -1
    else:
        while n > temp:
            temp *= 9
        return n - temp // 9

def any_one(lists):
    if 1 in lists:
        return True
    else:
        return False

def main():
    #入力
    N = int(input())
    q = deque([N])
    cnt = 0
    j = 1

    while not any_one(q):
        for i in range(j):
            n = q.popleft()
            q.append(nearest_num_six(n))
            q.append(nearest_num_nine(n))
        cnt += 1
        j *= 2

    print(cnt+1)
        

    





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
from collections import deque

def nearest_num_six(n):
    temp = 1
    if n < 6:
        return n -1
    else:
        while n > temp:
            temp *= 6
        return n - temp // 6

def nearest_num_nine(n):
    temp = 1
    if n < 9:
        return n -1
    else:
        while n > temp:
            temp *= 9
        return n - temp // 9

def any_one(lists):
    if 1 in lists:
        return True
    else:
        return False

def main():
    #入力
    N = int(input())
    q = deque([N])
    cnt = 0
    j = 1

    while not any_one(q):
        print(q)
        for i in range(j):
            n = q.popleft()
            q.append(nearest_num_six(n))
            q.append(nearest_num_nine(n))
        cnt += 1
        j *= 2

    print(cnt+1)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def nearest_num(n):
    temp1 = 1
    temp2 = 1

    while n >= temp1:
        temp1 *= 6
    if n < 6:
        diff1 = n
    else:
        diff1 = n - temp1 // 6

    while n >= temp2:
        temp2 *= 9
    if n < 9:
        diff2 = n
    else:
        diff2 = n - temp2 // 9

    if diff1 > diff2:
        return diff2
    else:
        return diff1

def main():
    #入力
    N = int(input())

    cnt = 0

    while True:
        a = nearest_num(N)
        if a == N:
            break
        else:
            N = a
            cnt += 1

    print(a + cnt)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import time
start=time.monotonic()
dif=[6,9,36,81,216,729,1296,6561,7776,46656,59049]
n=int(input())
kaisu=n
sta=[(n,0)]
while len(sta)>0:
	p=sta.pop()
	for i in dif:
		if p[0]-i>=0 and p[1]+1<kaisu:
			kaisu=min(kaisu,p[1]+1+p[0]-i)
			sta.append((p[0]-i,p[1]+1))
	if time.monotonic()-start>1.9:
		break
print(kaisu)

Submission status: Wrong Answer

Solution code:
# your code goes here

N=int(input())
a = 0

while N >= 6:
	i = 0
	while 9 <= N:
		
		if  9**i <= N and N < 9**(i+1):
			break
		i = i +1
	



	j = 0
	while 6 <= N:

		if  6**j <= N and N < 6**(j+1):
	 		break
		j = j +1

	if 6 ** j <= 9 ** i:
		a = a + 1
		N = N-9**i
	else:
		a = a + 1
		N = N-6**j


print(a + N)

Submission status: Wrong Answer

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

N = int(input())

num_list = [1]

for i in [6, 9]:
    j = 1
    while True:
        if i ** j <= 100000:
            num_list.append(i ** j)
        else:
            break
        j += 1

num_list.sort(reverse=True)

sum1 = 0
cnt = 0
for num in num_list:
    if sum1 + num <= N:
        cnt += (N - sum1) // num
        sum1 += num * ((N - sum1) // num)

print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
c = 0
def croku(N):
    roku =[0,1] + [6**i for i in range(1,7)]
    c = 0
    while N != 0:
        N = N - roku[bisect_right(roku,N)-1]
        c += 1
    return c

def ckyu(N):
    kyu = [0,1] + [9**i for i in range(1,6)]
    c = 0
    while N != 0:
        N = N - kyu[bisect_right(kyu,N)-1]
        c += 1
    return c

K = 10**5
for i in range(1,N+1):
    K = min(K, croku(i) + ckyu(N-i))
print(K)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
c = 0
roku = [6**i for i in range(1,7)]
kyu = [9**i for i in range(1,6)]
able = sorted([0,1] + roku + kyu)
while N != 0:
    N = N - able[bisect_right(able,N)-1]
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
c = 0
roku = [6**i for i in range(1,7)]
kyu = [9**i for i in range(1,6)]
able = sorted([0,1] + roku + kyu)
print(able)
while N != 0:
    N = N - able[bisect_right(able,N)-1]
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
def reverse(a):
    if a==[]:
        return []
    else:
        return [a[-1]]+reverse(a[:-1])
for i in range(7):
	list.append(6**i)
for j in range(1,6):
	list.append(9**j)
list.sort()
list=(reverse(list))
s=0
while len(list)>1:
	s=s+n//(int(list[0]))
	n=n-((n//(list[0]))*list[0])
	if len(list)>1:
		list=list[1:]
	if len(list)==1:
		s=s+list[0]
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5]
l.sort()

cnt = 0
while N > 0:
    for i in range(11):
        if l[i] > N:
            N -= l[i-1]
            cnt += 1
            break
            
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N
for i in range(N):
	count = 0
	temp = i
	while temp > 0:
		count += int(temp % 9)
		temp = int(temp / 9)
	temp = N - i
	while temp > 0:
		count += int(temp % 6)
		temp = int(temp / 6)
	if count < ans:
		ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N
for i in range(1, N + 1):
	count = 0
	t = i
	while t > 0:
		count += int(t % 9)
		t = int(t / 9)
	t = N - i
	while t > 0:
		count += int(t % 6)
		t = int(t / 6)
	if count < ans:
		ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
input_num = int(input())

combinations = [(pow1, pow2, pow3, pow4, pow5, pow6)
                for pow1 in range(0, 6)
                for pow2 in range(0, 6)
                for pow3 in range(0, 6)
                for pow4 in range(0, 6)
                for pow5 in range(0, 6)
                for pow6 in range(0, 6)]

num_withdraw_list = []
for combination in combinations:
    pow1, pow2, pow3, pow4, pow5, pow6 = combination
    withdraw6 = 6 ** 1 * pow1 + 6 ** 2 * pow2 + \
                6 ** 3 * pow3 + 6 ** 4 * pow4 + \
                6 ** 5 * pow5 + 6 ** 6 * pow6

    if withdraw6 > input_num:
        continue
    else:
        rest = input_num - withdraw6
        num_withdraw = sum(combination)
        for i in reversed(range(1, 5)):
            withdraw_i = rest // 9 ** i
            rest -= 9 ** i * withdraw_i
            num_withdraw += withdraw_i
        num_withdraw += rest
        num_withdraw_list.append(num_withdraw)

print(min(num_withdraw_list))

Submission status: Wrong Answer

Solution code:
def times(money, mod):
  ans = 0
  x = 1
  while( x * mod <= money):
    x *= mod
  while(money > mod):
    ans += money // x
    money = money % x
    x = x // mod
  return(ans + money)

a = []
b = []
for i in range(100001):
  a.append(times(i,6))
  b.append(times(i,9))

c = []
n = int(input())
for i in range(n+1):
  c.append(a[i]+b[n-i])
print(min(c))

Submission status: Wrong Answer

Solution code:
def times(money, mod):
  ans = 0
  x = 1
  while( x * mod < money):
    x *= mod
  while(money > mod):
    ans += money // x
    money = money % x
    x = x // mod
  return(ans + money)

a = []
b = []
for i in range(100001):
  a.append(times(i,6))
  b.append(times(i,9))

c = []
n = int(input())
for i in range(n):
  c.append(a[i]+b[n-i])
print(min(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [1,]
b = []
i = 6
while i <= N:
    b.append(i)
    i *= 6
c = []
i = 9
while i <= N:
    c.append(i)
    i *= 9
L = sorted(a + b + c)
x = 0
i = 1
while N > 0:
    if N >= L[-i]:
        N -= L[-i]
        x += 1
    else:
        i += 1
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(range(1,6))
b = []
i = 6
while i < N:
    b.append(i)
    i *= 6
c = []
i = 9
while i < N:
    c.append(i)
    i *= 9
L = sorted(a + b + c)
x = 0
i = 1
while N > 0:
    if N >= L[-i]:
        N -= L[-i]
        x += 1
    else:
        i += 1
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = N%3
b = []
c = []
d = N // 3
while d > 0:
    e = d % 3
    b.append(e==2)
    c.append(e==1)
    d = d // 3
print(a+sum(b)+sum(c))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
s6 = [pow(6,i) for i in range(1,20)]
s9 = [pow(9,i) for i in range(1,20)]
cost = [-1]*(max(n+1,12))
for x in range(12):
  if x < 6:
    cost[x] = x
  elif x < 9:
    cost[x] = (x//6) + (x%6)
  else:
    cost[x] = (x//9) + (x%9)
    
def get_cost(x):
  if 0 <= cost[x]:
    return cost[x]
  div6 = bisect.bisect_right(s6,x)-1
  if cost[x - (x//s6[div6])*s6[div6]] < 0:
    get_cost(x - (x//s6[div6])*s6[div6])
  div9 = bisect.bisect_right(s9,x)-1
  if cost[x - (x//s9[div9])*s9[div9]] < 0:
    get_cost(x - (x//s9[div9])*s9[div9])
  cost[x] = min((x//s6[div6])+cost[x - (x//s6[div6])*s6[div6]],(x//s9[div9])+cost[x - (x//s9[div9])*s9[div9]])
  return cost[x]
print(get_cost(n))

Submission status: Wrong Answer

Solution code:
N = int(input())

m = [1]
n1 = 1
while 6**n1 <= 100000:
    m.append(6**n1)
    n1 += 1
n2 = 1
while 9**n2 <= 100000:
    m.append(9**n2)
    n2 += 1
m.sort()

ans = 0
while N > 0:
    for i in m:
        if i > N:
            N -= m[m.index(i)-1]
            ans += 1
            break

print(ans)