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())
INF = float('inf')
dp = [INF] * (N+1)
dp[0] = 0

for n in range(N + 1):
    power = 0
    while pow(6, power) < N:
        dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
        power += 1

    power = 0
    while pow(9, power) < N:
        dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
        power += 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n
for k in range(0,n):
    count = 0
    for i in range(0,7):
        num6 = k//(6**i)%6
        count += num6

    for i in range(0,6):
        num9 = (n-k)//(9**i)%9
        count += num9

    if count < ans: 
        ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    ans = 0
    withdraw = [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
    withdraw.sort()
    if N % 3 != 0:
        ans += N % 3
        N -= N % 3
    while 0 < N:
        for d in withdraw[::-1]:
            if 12 <= N < 18 and N % 6 == 0 and N % 9 != 0:
                ans += N//6
                N = 0
                break
            if d <= N:
                ans += 1
                N -= d
                break
        else:
            ans += N
            N = 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    ans = 0
    withdraw = [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
    withdraw.sort()
    if N % 3 != 0:
        ans += N % 3
        N -= N % 3
    while 0 < N:
        for d in withdraw[::-1]:
            if 12 <= N < 36 and N % 6 == 0 and N % 9 != 0:
                ans += N//6
                N = 0
                break
            if d <= N:
                ans += 1
                N -= d
                break
        else:
            ans += N
            N = 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

s = 6
m = 9
Can = [1]
count = 2
while s < 10**5:
    Can.append(s)
    s = 6**count
    count += 1

count = 2
while m < 10**5:
    Can.append(m)
    m = 9**count
    count += 1

DP = [1]
for i in range(1,n):
    dp_can = []
    for num in Can:
        if num > i:
            continue
        dp_can.append(DP[i-num]+1)
    DP.append(min(dp_can))

print(DP[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
n=10
s=10
while N>=6:
  if N-max(6**s,9**n)>=0:
    N-=max(6**s,9**n)
    print(n,s,N)
    ans+=1
  else:
    bl=int(6**s<9**n)
    n-=bl
    s-=1-bl
  if n==0 and s==0:
    break
print(N)
print(ans+N)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=N
for i in range(0,N,1):
    n=(i%9 + (N-i)%6)

    n9=0
    num9=i//9
    while num9:
        n9+=num9%9
        num9//=9

    n6=0
    num6=(N-i)//6
    while num6:
        n6+=num6%6
        num6//=6
    #print(n9,n6)
    count=min(n9+n6+n,count)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=N
for i in range(0,N,3):
    n=(i%9 + (N-i)%6)

    n9=0
    num9=i//9
    while num9:
        n9+=num9%9
        num9//=9

    n6=0
    num6=(N-i)//6
    while num6:
        n6+=num6%6
        num6//=6
    #print(n9,n6)
    count=min(n9+n6+n,count)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=N
for i in range(0,N,3):
    n9=0
    num9=i//9
    while num9:
        n9+=num9%9
        num9//=9
    n6=(N-i)%6
    num6=(N-i)//6
    while num6:
        n6+=num6%6
        num6//=6
    #print(n9,n6)
    count=min(n9+n6,count)
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
count=N
for i in range(0,N,9):
    n9=0
    num9=i//9
    while num9:
        n9+=num9%9
        num9//=9
    n6=(N-i)%6
    num6=(N-i)//6
    while num6:
        n6+=num6%6
        num6//=6
    #print(n9,n6)
    count=min(n9+n6,count)
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
lst=set()
lst.add(1)
i=1
while 6**i<N:
    lst.add(6**i)
    i+=1
i=1
while 9**i<N:
    lst.add(9**i)
    i+=1

lst=sorted(list(lst))
count=0
while N:
    N-=lst[bisect.bisect_right(lst,N)-1]
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
lst=set()
lst.add(1)
i=1
while 6**i<N:
    lst.add(6**i)
    i+=1
i=1
while 9**i<N:
    lst.add(9**i)
    i+=1

lst=sorted(list(lst))
print(lst)
count=0
while N:
    N-=lst[bisect.bisect_right(lst,N)-1]
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math

if __name__ == '__main__':
    N=int(input())
    count=0

    power_of_nine=int(math.log(N,9))
    power_of_six=int(math.log(N,6))

    i=power_of_nine
    j=power_of_six
    upper=max(9**i,6**j)
    while i>=1 or j>=1:
        if N-upper>=0:
            N-=upper
            count+=1
        else:
            if upper==9**i:
                i-=1
            else:
                j-=1
            upper = max(9 ** i, 6 ** j)

    print(count+N)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
c=0
#ただのDPやんけ
#0~N
dp=[100000000000000]*(n+1)
for i in range(1,min(6,n+1)):
    dp[i]=i
#print(dp)
for i in range(n+1):
    for j in range(1,7):
        if i+6**j<=n:
            dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
    for j in range(1,6):
        if i+9**j<=n:
            dp[i+9**j]=min(dp[i+9**j],dp[i]+1)

print(dp[n])

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
c=0
while n>=15:
    c+=1
    n-=max(9**int(math.log(n,9)),6**int(math.log(n,6)))
    #print(n)
if n==12:
    print(c+2)
elif n==13:
    print(c+3)
elif n==14:
    print(c+4)
elif n>=9:
    print(c+1+(n-9))
elif n>=6:
    print(c+1+(n-6))
else:
    print(c+n)

Submission status: Wrong Answer

Solution code:
N = int(input())

num = [[0, N]]
ans = N
cnt = 0

while len(num) > 0:
    cnt, remain_money = num.pop(0)
    if remain_money < 6:
        ans = min(ans, cnt + remain_money)
    else:
        for n in [6, 9]:
            i = n
            while True:
                if remain_money < i * n:
                    num.append([cnt + 1, remain_money - i])
                    break
                i *= n

print(ans)

Submission status: Wrong Answer

Solution code:

args = int(input())

ans = float('inf')
for i in range(args+1):
    count = 0

    args_six = i
    while args_six >= 6:
        count += args_six % 6
        args_six //= 6
    count += args_six

    args_nine = args - i
    while args_nine >= 9:
        count += args_nine % 6
        args_nine //= 9
    count += args_nine
    ans = min(ans, count)

print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))




#ABC99 C
n = int(input())

memo = 1
li3 = []
while(memo<=n):
    li3.append(memo)
    memo *= 6
li3.append(memo)   

memo = 1
while(memo<=n):
    li3.append(memo)
    memo *= 9
li3.append(memo)  

li3 = sorted(li3,reverse = True)


i = 0
cnt = 0
while(n >0):
    if li3[i] <= n:
        n-=li3[i]
        cnt += 1
        
    else:
        i+= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
dp = [float("inf")]*(N + 1)
dp[0] = 0
pull_list_9 = [9**i for i in range(1, 6)]
pull_list_6 = [6**i for i in range(1, 7)]
pull_list = np.array(pull_list_9 + pull_list_6 + [1])
p_s = sorted(pull_list)
for i in range(1, N + 1):
  for j in p_s:
    if i - j < 0:
      break
      dp[i] = min(dp[i], dp[i-j] + 1)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
import math

n = int(input())

#引き出せる金額の準備
a1 = [1]
a6 = [6**x for x in range(1, int(math.log(n, 6))+1)]
a9 = [9**x for x in range(1, int(math.log(n, 9))+1)]
b = a1+a6+a9
b.sort()

# n円引き出すための引き出し回数
dp = [-1] *(n+1)
dp[0]  = 0

# 探索キューを初期値ゼロで用意
d = deque([0])

# キューがなくなるまでループ
for _ in range(10**12):
    # キューが無いなら終了
    if len(d) == 0:
        break
        
    # キューから取り出し
    tmp = d.pop()
    
    # +1回で引き出せる範囲をDPにメモ
    for x in b:
        if tmp+x > n:
            break
        if dp[tmp+x] == -1:
            dp[tmp+x] = dp[tmp]+1
            d.appendleft(tmp+x)

print(dp[n])

Submission status: Wrong Answer

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

dp = ['inf']*(N+1)

init = 6 if N > 5 else N+1
for n in range(init):
	dp[n] = n

for n in range(6,N+1):
	cnd = [dp[n-1]+1]
	for i in range(1,6):
		if n > 6**i-1:
			cnd.append(dp[n-6**i]+1)
	for j in range(1,5):
		if n > 9**j-1:
			cnd.append(dp[n-9**j]+1)
	dp[n] = min(cnd)
	
print(dp[N])

Submission status: Wrong Answer

Solution code:
from collections import deque
import math

n = int(input())

#引き出せる金額の準備
a1 = set([1])
a6 = set([6**x for x in range(1, int(math.log(n, 6))+1)])
a9 = set([9**x for x in range(1, int(math.log(n, 9))+1)])
a = a1 | a6 | a9
b = list(a)
b.sort()

# n円引き出すための引き出し回数
dp = [-1] *(n+1)
dp[0]  = 0

# 探索キューを初期値ゼロで用意
d = deque([0])

# キューがなくなるまでループ
for _ in range(10**12):
    # キューが無いなら終了
    if len(d) == 0:
        break
        
    # キューから取り出し
    tmp = d.pop()
    
    # +1回で引き出せる範囲をDPにメモ
    for x in b:
        if tmp+x > n:
            break
        if dp[tmp+x] != -1:
            continue
        dp[tmp+x] = dp[tmp]+1
        d.appendleft(tmp+x)

print(dp[n])

Submission status: Wrong Answer

Solution code:
from collections import deque
import math

n = int(input())

#引き出せる金額の準備
a1 = set([1])
a6 = set([6**x for x in range(1, int(math.log(n, 6))+1)])
a9 = set([9**x for x in range(1, int(math.log(n, 9))+1)])
a = a1 | a6 | a9
b = list(a)
b.sort()

# n円引き出すための引き出し回数
dp = [-1] *(n+1)
dp[0]  = 0

# 探索キューを初期値ゼロで用意
d = deque([0])

# キューがなくなるまでループ
for _ in range(10**7):
    # キューが無いなら終了
    if len(d) == 0:
        break
        
    # キューから取り出し
    tmp = d.pop()
    
    # +1回で引き出せる範囲をDPにメモ
    for x in b:
        if tmp+x > n:
            break
        if dp[tmp+x] != -1:
            continue
        dp[tmp+x] = dp[tmp]+1
        d.appendleft(tmp+x)

print(dp[n])

Submission status: Wrong Answer

Solution code:
from collections import deque
import math

n = int(input())

#引き出せる金額の準備
a1 = set([1])
a6 = set([6**x for x in range(1, int(math.log(n, 6))+1)])
a9 = set([9**x for x in range(1, int(math.log(n, 9))+1)])
a = a1 | a6 | a9
b = list(a)
b.sort()

dp = [-1] *(n+1)
dp[0]  = 0

# 探索キューを初期値ゼロで用意
d = deque([0])
for _ in range(10**7):
    if len(d) == 0:
        break
    tmp = d.pop()
    for x in b:
        if tmp+x > n:
            break
        if dp[tmp+x] != -1:
            continue
        dp[tmp+x] = dp[tmp]+1
        d.appendleft(tmp+x)
        
print(dp[n])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
ary = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
N = int(input())
ans = 0
while N > 0:
    i = bisect_left(ary, N)
    if 11 < N < 15:
        N -= 6
    elif i < len(ary) and ary[i] == N:
        N -= ary[i]
    else:
        N -= ary[i-1]
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
li = sorted([1]+[6**i for i in range(1,10)]+[9**i for i in range(1,8)])
ans = N%3
N -= ans
while N >= 36:
    a = bisect_right(li,N)
    N -= li[a-1]
    ans += 1
if N == 3:
    ans += 3
elif N <= 9:
    ans += 1
elif N <= 18:
    ans += 2
elif N <= 33:
    ans += 3
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
li = sorted([1]+[6**i for i in range(1,10)]+[9**i for i in range(1,8)])
print(li)
ans = N%3
N -= ans
while N >= 36:
    a = bisect_right(li,N)
    N -= li[a-1]
    ans += 1
if N == 3:
    ans += 3
elif N <= 9:
    ans += 1
elif N <= 18:
    ans += 2
elif N <= 33:
    ans += 3
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

from functools import lru_cache

@lru_cache(maxsize=1000)
def f(n):
    if n < 6:
        return n
    else:
        # Nを6系の最大値、9系の最大値で割れば良い
        max_9 = 1
        for _ in range(1000):
            if max_9*9 < n:
                max_9 *= 9
            else:
                break            
        next_9 = n - max_9
        
        max_6 = 1
        for _ in range(1000):
            if max_6*6 < n:
                max_6 *= 6
            else:
                break     
        next_6 = n - max_6
        return min([f(next_9)+1, f(next_6)+1])

print(f(n))

Submission status: Wrong Answer

Solution code:
n=int(input())

#from functools import lru_cache
#@lru_cache(maxsize=1000)

def f(n):
    if n < 6:
        return n
    else:
        # Nを6系の最大値、9系の最大値で割れば良い
        max_9 = 1
        for _ in range(1000):
            if max_9*9 < n:
                max_9 *= 9
            else:
                break            
        next_9 = n - max_9
        
        max_6 = 1
        for _ in range(1000):
            if max_6*6 < n:
                max_6 *= 6
            else:
                break     
        next_6 = n - max_6
        return min([f(next_9)+1, f(next_6)+1])

print(f(n))

Submission status: Wrong Answer

Solution code:
nums = []
for i in range(7 + 1):
    nums.append(6**i)
    nums.append(9**i)
nums = sorted(list(set(nums)))
# print(nums)
N = int(input())
from bisect import bisect_right
counter = 0
while N != 0:
    index = bisect_right(nums, N)
    if nums[index - 1] == 9 and N - nums[index - 1] >= 5:
        N -= 6
        # print(6, N)
    else:
        N -= nums[index - 1]
        # print(nums[index - 1], N)

    counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
import math
if sys.platform =='ios':
  sys.stdin=open('Untitled.txt')
input = sys.stdin.readline


N = int(input())
dp = [float("INF") for _ in range(N+1)]
dp[0] = 0

MAX_JOU = math.ceil(math.log(N, 6))

a_six = [6**x for x in range(MAX_JOU)]
a_nine = [9**x for x in range(MAX_JOU)]

for i in range(N+1):
    if (i-1 >= 0):
            dp[i] = min(dp[i], dp[i-1]+1)
    for six in a_six:
        if (i-six >= 0):
            dp[i] = min(dp[i], dp[i-six]+1)
    for nine in a_nine:
        if (i-nine >= 0):
            dp[i] = min(dp[i], dp[i-nine]+1)

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[10**5]*n
dp[0]=1
for i in range(n):
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=6
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=9
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[10**5]*n
dp[0]=0
for i in range(n):
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=6
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=9
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
enable = set()

k = 0
while(6**k <= N):
    enable.add(6**k)
    k += 1
k = 0
while(9**k <= N):
    enable.add(9**k)
    k += 1


enable = list(enable)
enable.sort()

ans = 10**9
l = len(enable)
for i in range(l):
    n = N
    tmp = 0
    while(n != 0):
        id = bisect.bisect_right(enable, n) - 1
        if id != 0 and n % enable[id] > 1 and n % enable[id] < 6:
            id -= 1
        n -= enable[id]
        tmp += 1
    enable.pop()

    ans = min(tmp, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
enable = set()

k = 0
while(6**k <= N):
    enable.add(6**k)
    k += 1
k = 0
while(9**k <= N):
    enable.add(9**k)
    k += 1


enable = list(enable)
enable.sort()

ans = 0

while(N != 0):
    id = bisect.bisect_right(enable, N) - 1
    if id != 0 and N % enable[id] > 1 and N % enable[id] < 6:
        id -= 1

    N -= enable[id]
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
import sys
sys.setrecursionlimit(10**6)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(stdin.readline().rstrip())

li = prime_factorize(n)

lin = []

for i in range(1,11):
    lin.append(6**i)
    lin.append(9**i)
lin.sort()
k = n
point = 0
def tansaku(n):
    global point
    point += n//(lin[bisect.bisect(lin,n)-1])
    n = n%(lin[bisect.bisect(lin,n)-1])
    if n < 6:
        point += n
    else:
        tansaku(n)

tansaku(n)
print(point)

Submission status: Wrong Answer

Solution code:
N = int(input())
import math 
m = math.floor(math.log(N,6)) #max 8
n = math.floor(math.log(N,9)) #max 7
s = [1]
for i in range(1,m+1):
    s.append(6**i)
for j in range(1,n+1):
    s.append(9**j)
s.sort()
l = len(s)
dp = [ N for i in range(N+1)]
dp[0] = 0
for i in range(N+1):
    for j in range(l):
        c = s[j]
        if c > i:
            break
        K = min(i//c,8)
        for k in range(K+1):
            dp[i] = min(dp[i],dp[i-c*k]+k)
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
import math 
m = math.floor(math.log(N,6)) #max 8
n = math.floor(math.log(N,9)) #max 7
s = [1]
for i in range(1,m+1):
    s.append(6**i)
for j in range(1,n+1):
    s.append(9**j)
s.sort()
l = len(s)
inf = N
dp = [[ inf for i in range(N+1)] for j in range(l+1)]
for i in range(l+1):
    dp[i][0] = 0
for i in range(1,l+1):
    c = s[i-1]
    for j in range(1,N+1):
        r = 5
        if c%2 == 1:
            r = 8
        if c == 1:
            r = 5
        K = min(j // c,r)
        for k in range(K+1):
            dp[i][j] = min(dp[i][j],dp[i-1][j-k*c] + k)
ans = dp[l][N]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import math 
m = math.floor(math.log(N,6)) #max 8
n = math.floor(math.log(N,9)) #max 7
s = [1]
for i in range(1,m+1):
    s.append(6**i)
for j in range(1,n+1):
    s.append(9**j)
s.sort()
l = len(s)
inf = N
dp = [[ inf for i in range(N+1)] for j in range(l+1)]
for i in range(l+1):
    dp[i][0] = 0
for i in range(1,l+1):
    c = s[i-1]
    for j in range(1,N+1):
        K = min(j // c,8)
        for k in range(K+1):
            dp[i][j] = min(dp[i][j],dp[i-1][j-k*c] + k)
ans = dp[l][N]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import math 
m = math.floor(math.log(N,6)) #max 8
n = math.floor(math.log(N,9)) #max 7
s = [1]
for i in range(1,m+1):
    s.append(6**i)
for j in range(1,n+1):
    s.append(9**j)
s.sort()
l = len(s)
inf = 100
dp = [[ inf for i in range(N+1)] for j in range(l+1)]
for i in range(l+1):
    dp[i][0] = 0
for i in range(1,l+1):
    c = s[i-1]
    for j in range(1,N+1):
        K = j // c
        for k in range(K):
            dp[i][j] = min(dp[i][j],dp[i-1][j-k*c] + k)
ans = dp[l][N]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
if N < 6:
	print(N)
	sys.exit()
elif N < 9:
	print(1+(N-6))
	sys.exit()

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = float("inf")

for i in reversed(range(N//9)):
	t = N - 9*i
	t_6, t_1 = divmod(t, 6)

	time_9 = Base_10_to_n(i, 9)
	time_6 = Base_10_to_n(t_6, 6)

	ans = min(ans, sum(list(map(int, time_9))) + sum(list(map(int, time_6))) + t_1)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = float("inf")

for i in reversed(range(N//9)):
	t = N - 9*i
	t_6, t_1 = divmod(t, 6)

	time_9 = Base_10_to_n(i, 9)
	time_6 = Base_10_to_n(t_6, 6)

	ans = min(ans, sum(list(map(int, time_9))) + sum(list(map(int, time_6))) + t_1)

print(ans)

Submission status: Wrong Answer

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

dp = [10 ** 9 + 7] * N
dp[0] = 0
for n in range(N):
    pow = 1
    while pow <= n:
        dp[n] = min(dp[n], dp[n-pow] + 1)
        pow *= 6
    pow = 1
    while pow <= n:
        dp[n] = min(dp[n], dp[n-pow] + 1)
        pow *= 9

print(dp[-1] + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(1,7):
  lst.append(9**i)
for j in range(1,8):
  lst.append(6**j)
m=n
cnt=0
for l in range(100000):
  for k in range(13):
    m=min(abs(m-lst[k]),m)
  if m<6:
    cnt+=1
    break
  else:
    cnt+=1
print(cnt+m)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(1,7):
  lst.append(9**i)
for j in range(1,8):
  lst.append(6**j)
m=n
cnt=0
for l in range(100000):
  for k in lst:
    m=min(abs(m-k),m)
  if m<6:
    cnt+=1
    break
  else:
    cnt+=1
print(cnt+m)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(1,7):
  lst.append(9**i)
for j in range(1,8):
  lst.append(6**j)
m=n
cnt=0
while m>5:
  for k in lst:
    m=min(abs(m-k),m)
  cnt+=1
print(cnt+m)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(1,7):
  lst.append(9**i)
for j in range(1,8):
  lst.append(6**j)
m=100000
cnt=0
while m>5:
  for k in lst:
    m=min(abs(m-k),m)
  cnt+=1
print(cnt+m)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(1,7):
  lst.append(9**i)
for j in range(1,8):
  lst.append(6**j)
m=100000
cnt=0
while m<6:
  for k in lst:
    m=min(abs(m-k),m)
  cnt+=1
print(cnt+m)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[]
for i in range(7):
  lst.append(9**i)
for j in range(8):
  lst.append(6**j)
m=100000
cnt=0
while m<6:
  for k in lst:
    m=min(abs(m-k),m)
  cnt+=1
print(cnt+m)

Submission status: Wrong Answer

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

import math

lim6 = int(math.floor(math.log(N, 6)))
candidates6 = [int(math.pow(6, i))
               for i in range(1, lim6+1)]

lim9 = int(math.floor(math.log(N, 9)))
candidates9 = [int(math.pow(9, i))
               for i in range(1, lim9+1)]


# DP
counts = [i for i in range(N + 1)]
for c in candidates6 + candidates9:
    for i in range(c, N+1):
        counts[i] = min(counts[i], counts[i-c] + 1)

print(counts[N])

Submission status: Wrong Answer

Solution code:
N = int(input())

import math

lim6 = int(math.floor(math.log(N, 6)))
candidates6 = [int(math.pow(6, i))
               for i in range(1, lim6+1)]

lim9 = int(math.floor(math.log(N, 9)))
candidates9 = [int(math.pow(9, i))
               for i in range(1, lim9+1)]


# DP
counts = [i for i in range(N + 1)]
for c in candidates6 + candidates9:
    for i in range(c, N+1):
        counts[i] = min(counts[i], counts[i-c] + 1)

print(counts[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
import math as m

N = int(input())

ans = []

def dfs(d,num):
  if num == N:
    ans.append(d)
    return
  
  a = (int)(m.log(N - num,6))
  b = (int)(m.log(N - num,9))
  
  if a > 0:
  	dfs(d+1,num + (int)(pow(6,a)))
  if b > 0:
  	dfs(d+1,num + (int)(pow(9,b)))
    
  if a == 0 and b == 0:
    ans.append(d + N - num)
    return

dfs(0,0)

print(np.min(ans))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
add_num = 1
draw_money = []
while add_num <= 10 ** 5:
    draw_money.append(add_num)
    add_num *= 6
    
add_num = 1
while add_num <= 10 ** 5:
    draw_money.append(add_num)
    add_num *= 9

#重複を削除
draw_money = list(set(draw_money))
ans = 0

draw_money.sort()
##print(draw_money)
index = bisect.bisect_right(draw_money, n)
while n != 0:
    index = bisect.bisect_right(draw_money, n)
  ###  print("{} - {} = {}".format(n, draw_money[index - 1],n - draw_money[index-1]))
    n -= draw_money[index - 1]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-08 02:12:52(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    count = 0
    for _ in range(n):
        if n < 6:
            count += n
            break
        elif n >= 15 or 12 > n >= 6:
            n -= max(6 ** math.floor(math.log(n, 6)), 9 ** math.floor(math.log(n, 9)))
            count += 1
        elif 15 > n >= 12:
            n -= 6
            count += 1

    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-08 02:12:52(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    count = 0
    for _ in range(n):
        if n < 6:
            count += n
            break
        elif n >= 15 or 12 > n >= 6:
            n -= max(6 ** math.floor(math.log(n, 6)), 9 ** math.floor(math.log(n, 9)))
            count += 1
        elif 15 > n >= 12:
            n -= 6
            count += 1

        print(n)
    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

Solution code:
print("hello world")

Submission status: Wrong Answer

Solution code:
import bisect

six=[1, 6, 36, 216, 1296, 7776, 46656]
nin=[1, 9, 81, 729, 6561, 59049]
N=int(input())

def find_lt(a,x):
    i = bisect.bisect_right(a,x)
    if i:
        return a[i-1]
    raise ValueError

ans=0
while N!=0:
    s=find_lt(six,N)
    n=find_lt(nin,N)
    N-=max(s,n)
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# WIP (The fucking code)
N = int(input())


def search_range(target_yen, remaining):
    x = 1
    exp_val = target_yen ** x
    while remaining > exp_val:
        x += 1
        exp_val = target_yen ** x
    if remaining == exp_val:
        x += 1
    return x - 1


n_operation = 0
remaining = N
inf = float('inf')
while remaining > 0:
    power_9 = search_range(9, remaining)
    power_6 = search_range(6, remaining)
    canditate = None
    if power_9 == 0 and power_6 == 0:
        canditate = [inf, inf, remaining]
    elif power_9 == 0:
        canditate = [inf, remaining - 6**power_6, remaining]
    elif power_6 == 0:
        canditate = [remaining - 9**power_9, inf, remaining]
    else:
        canditate = [remaining - 9**power_9, remaining - 6**power_6, remaining]

    # Update remaining
    remaining = min(canditate)
    argmin_cand = canditate.index(remaining)
    target_power = remaining if argmin_cand == 2 else 1
    n_operation += target_power
    if argmin_cand == 2:
        break

print(n_operation)

Submission status: Wrong Answer

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


def search_range(target_yen, remaining):
    x = 1
    exp_val = target_yen ** x
    while remaining > exp_val:
        x += 1
        exp_val = target_yen ** x
    return x - 1


n_operation = 0
remaining = N
inf = float('inf')
while remaining > 0:
    power_9 = search_range(9, remaining)
    power_6 = search_range(6, remaining)
    canditate = None
    if power_9 == 0 and power_6 == 0:
        canditate = [inf, inf, remaining]
    elif power_9 == 0:
        canditate = [inf, remaining - 6**power_6, remaining]
    elif power_6 == 0:
        canditate = [remaining - 9**power_9, inf, remaining]
    else:
        canditate = [remaining - 9**power_9, remaining - 6**power_6, remaining]

    # Update remaining
    remaining = min(canditate)
    argmin_cand = canditate.index(remaining)
    target_power = remaining if argmin_cand == 2 else 1
    print(canditate, argmin_cand, target_power, remaining)
    n_operation += target_power
    if target_power == remaining:
        break

print(n_operation)

Submission status: Wrong Answer

Solution code:
import math
cash = [1]
n = int(input())
ans = [float('inf')] * (n + 1)
for i in range(1, math.ceil(math.log(n, 6))):
    cash.append(6 ** i)
for i in range(1, math.ceil(math.log(n, 9))):
    cash.append(9 ** i)
cash.sort()
ans[0] = 0
for i in range(1, n + 1):
    for j in cash:
        if i - j < 0:
            break
        else:
            ans[i] = min(ans[i], ans[i - j] + 1)
print(ans[n])

Submission status: Wrong Answer

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

ans = []
for i in range(n+1):
    cnt6 = i
    cnt9 = n - i

    ans6 = 0
    ans9 = 0
    
    list6 = [6, 36, 216, 1296, 7776, 46656]
    list9 = [9, 81, 729, 6561, 59049]
    
    while cnt6 > 0:
        if cnt6 in list6:
            ans6 = 1
            break
        else:
            sho = 6**math.floor(math.log(cnt6, 6))
            ans6 += cnt6//sho
            cnt6= cnt6%sho
        
    while cnt9 > 0:
        if cnt9 in list9:
            ans9 = 1
            break
        else:
            sho2 = 9**math.floor(math.log(cnt9, 9))
            ans9 += cnt9//sho2
            cnt9 = cnt9%sho2

    ans.append(ans6+ans9)

print(min(ans))

Submission status: Wrong Answer

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

ans = []
for i in range(n+1):
    cnt6 = i
    cnt9 = n - i
    ans6 = 0
    ans9 = 0
    
    while cnt6 > 0:
        sho = 6**math.floor(math.log(cnt6, 6))
        ans6 += cnt6//sho
        cnt6= cnt6%sho
        
    while cnt9 > 0:
        sho2 = 9**math.floor(math.log(cnt9, 9))
        ans9 += cnt9//sho2
        cnt9 = cnt9%sho2
        
    ans.append(ans6+ans9)
        
print(min(ans))

Submission status: Wrong Answer

Solution code:
# Strange Bank

N = int(input())
N_max = 100000

dp = ['inf']*2*N_max
for n in range(6):
	dp[n] = n

for n in range(6,N+1):
	cnd = [dp[n-1]+1]
	for i in range(1,7):
		if n > 6**i-1:
			cnd.append(dp[n-6**i]+1)
	for j in range(1,5):
		if n > 9**j-1:
			cnd.append(dp[n-9**j]+1)
	dp[n] = min(cnd)
	
print(dp[N])

Submission status: Wrong Answer

Solution code:
n = int(input())

import math
def bank(n):
    ans = 1
    list_six = [6**i for i in range(math.floor(math.log(n, 6)+1))]
    list_nine = [9**i for i in range(math.floor(math.log(n, 9)+1))]
    
    if n in list_six or n in list_nine:
        pass
    elif n == 12 or n == 13 or n == 14:
        ans += bank(n-6)
    elif n > 1:
        ans += bank(n - max(list_six[-1], list_nine[-1]))
        
    return ans

print(bank(n))