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:
import bisect as bi

N = int(input())

li6 = [6 ** i for i in range(7)]
li9 = [9 ** i for i in range(6)]

def s69(n):
  if n < 6:
    return n
  else:
    s6 = li6[bi.bisect_left(li6, n)-1]
    s9 = li9[bi.bisect_left(li9, n)-1]
    return min(n // s6 + s69(n % s6), n // s9 + s69(n % s9))
#    return min(n // s6 + s69(n % s6), 1 + s69(n-s9))
  
print (s69(N))

Submission status: Wrong Answer

Solution code:
import bisect as bi

N = int(input())

li6 = [6 ** i for i in range(7)]
li9 = [9 ** i for i in range(6)]

def s69(n):
  if n < 6:
    return n
  else:
    s6 = li6[bi.bisect_left(li6, n)-1]
    s9 = li9[bi.bisect_left(li9, n)-1]
#    return min(n // s6 + s69(n % s6), n // s9 + s69(n % s9))
    return min(n // s6 + s69(n % s6), 1 + s69(n-s9))
  
print (s69(N))

Submission status: Wrong Answer

Solution code:
N = int(input())

a = 0
li= [1]
for i in range(1,12):
  if 6 ** i < 1000000:
    li.append(6 ** i)
  if 9 ** i < 1000000:
    li.append(9 ** i)
li.sort(reverse=True)
    
for i in range(len(li)):
  a += N //li[i]
  N = N % li[i]
print (a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

N = int(input())
nL = []
Flag=0
i=1
while Flag==0:
  nTmp = 9 ** i
  if nTmp < 100000:
    nL.append(nTmp)
    i += 1
  else:
    Flag = 1

i=1
Flag=0
while Flag==0:
  nTmp = 6 ** i
  if nTmp < 100000:
    nL.append(nTmp)
    i += 1
  else:
    Flag = 1
nL.append(1)
nL.sort(reverse=True)

# print(nL)

nCnt = 0
Flag=0
nLen = len(nL)
i=0
while Flag==0:
  TmpN = nL[i]
  if TmpN > N:
    if i < nLen:
      i += 1
      continue
    else:
      Flag=1
      break
  N -= TmpN
#  print(N)
  nCnt += 1
  if N==0:
    Flag=1

print(nCnt)

Submission status: Wrong Answer

Solution code:
MAX = 100000
N = int(input())

out = [1]

for i in range(1, MAX):
    tmp = 6 ** i
    if tmp > MAX:
        break
    out.append(tmp)

for i in range(1, MAX):
    tmp = 9 ** i
    if tmp > MAX:
        break
    out.append(tmp)

ans = 0
while N > 0:
    limit = max([x for x in out if x <= N])
    N -= limit
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = N
if N == 6 or N == 9:
  ans = 1
else:
  for i in range(N):
    count = 0
    t=i
    while t>0:
      count+=t%6
      t=math.floor(t//6)

    t = N-i

    while t>0:
      count += t%9
      t=math.floor(t/9)

    if ans>count:
      ans = count

print(ans)

Submission status: Wrong Answer

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

ans = 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

  if ans>count:
    ans = count

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[1, 6, 36, 216, 1296, 7776, 46656]
b=[1, 9, 81, 729, 6561, 59049]
def ab_cal(num,arr):
  i=len(arr)-1
  cnt1=0
  while num>0:
    if arr[i]<=num:
      num-=arr[i]
      cnt1+=1
    else:
      i-=1
  return cnt1

ans = 10**9
for i in range(1,n-1):
  cnt=ab_cal(i,a)+ab_cal(n-i,b)
  ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l9=list(9**i for i in range(1,3))
l6=list(6**j for j in range(1,8))
l=sorted(l9+l6)
dp=[_ for _ in range(100010)]
for k in l:
    for m in range(k,n+1):
        dp[m]=min(dp[m-k]+1,dp[m])
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
l9=list(9**i for i in range(1,3))
l6=list(6**j for j in range(1,8))
l=sorted(l9+l6)
dp=[_ for _ in range(100010)]
for k in l:
    for m in range(k,n+1):
        dp[m]=min(dp[m-k]+1,dp[m])
    print(dp)
print(dp[n])

Submission status: Wrong Answer

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

ans = 0
while N>0:
  if math.floor(math.log(N,9)) > 0 or math.floor(math.log(N,6)) > 0:
    print(max(9**(math.floor(math.log(N,9))), 6**(math.floor(math.log(N,6)))))
    N -= max(9**(math.floor(math.log(N,9))), 6**(math.floor(math.log(N,6))))
  else:
    N -= 1
  ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [1]
i = 6
while i < 100000:
    x.append(i)
    i *= 6
i = 9
while i < 100000:
    x.append(i)
    i *= 9

dp = [0] * 100001
dp[1] = 1
for i in range(2, 100001):
    tmp = []
    for xx in x:
        if i - xx >= 1:
            tmp.append(dp[i-xx]+1)
    dp[i] = min(tmp)
print(dp[n])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ans = n
for i in range(n):
    cc = 0
    t = i
    while (t > 0):
        cc += t % 6
        t = math.floor(t/6)
    t = n - i
    while (t > 0):
        cc += t % 9
        t = math.floor(t/9)
    ans = min(ans, cc)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

n = int(input())
dp = [i for i in range(n+1)]

yen = [6 ** i for i in range(1, 8) if 6 ** i <= n]
yen += [9 ** i for i in range(1, 7) if 9 ** i <= n]

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

dp[-1]

Submission status: Wrong Answer

Solution code:
# ABC099C - Strange Bank
# DP ver.
def main():
    n = int(input())
    dp = [i for i in range(n + 1)]  # initialize with using only ¥1
    cand = [6 ** i for i in range(1, 6) if 6 ** i <= n]  # max: 10 ** 5
    cand += [9 ** i for i in range(1, 6) if 9 ** i <= n]
    for i in range(n + 1):
        for j in cand:
            if j > n:
                break
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + 1)
    print(dp[-1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC099C - Strange Bank
def main():
    n = int(input())
    # initialize dp table with using only ¥1
    dp = [i for i in range(n + 1)]
    for i in range(n + 1):
        for p in (6, 9):
            while p <= n:
                for j in range(1, n + 1):
                    if i - p >= 0:
                        dp[i] = min(dp[i], dp[i - p] + 1)
                p *= p
    print(dp[-1])
    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

check_list = [1]

check = 6
while check <= 100000:
    check_list.append(check)
    check = check * 6

check = 9
while check <= 100000:
    check_list.append(check)
    check = check * 9

check_list.sort(reverse=True)

ans = 0
while N != 0:
    for subst in check_list:
        if subst <= N:
            N -= subst
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
six = [6**i for i in range(8)]
nine = [9**i for i in range(7)]
combined  = list(set(six) | set(nine))
combined.sort(reverse=True)
revsix = sorted(six,reverse=True)
s = 0
while n:
    div  = -1
    for i in combined:
        if n%i == 0:
            div = i
            break
    if n//div < 5 and div !=- 1:
        s+=(n//i)
     #   print(i,n//i)
        n=0
    else:
        flag = 1
        for i in revsix:
            if n%i == 1 or n%i == 2:
                n-=1
                s+=1
                flag = 0
        if flag:
             for i in combined:
                if n>=i:
    #                print(i)
                    n-=i
                    s+=1
                    break
    #print("left=",n)
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 100000
for i in range(N):
    n = i
    m = N - n
    count = 0
    while n > 9:
        k = 1
        while n > 9 ** k:
            k += 1
        n -= 9 ** (k - 1)
        count += 1
    m += n
    while m > 6:
        k = 1
        while m > 6 ** k:
            k += 1
        m -= 6 ** (k - 1)
        count += 1
    count += m
    ans = min(ans, count)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
hoge=[]
for i in range(10):
  hoge.append(6**i)
  hoge.append(9**i)
hoge=list(set(hoge))
hoge.sort()
count=0
print
while 1:
  ans=1
  for i in range(len(hoge)):
    huga=n-hoge[i]
    if(huga>=0):
      ans=max(ans,hoge[i])
  n-=ans
  count+=1
  if(n==0):
    print(count)
    exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
li = [1,6,6**2,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5]
dp = [100000]*100001
dp[1] = 1
for i in range(1,100001):
  for s in li:
    if i+s <= 100000:
      dp[i+s] = min(dp[i]+1,dp[i+s])
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())

cnt=0

while n>0:
    mindiff=100000
    for i in range(100000):
        diff=n-9**i
        if diff<0:
            break
        mindiff=min(diff,mindiff)
    for i in range(100000):
        diff=n-6**i
        if diff<0:
            break
        mindiff=min(diff,mindiff)
    n=mindiff
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

cnt=0

while n>0:
    mindiff=100000
    for i in range(100000):
        diff=n-9**i
        if diff<0:
            break
        mindiff=min(diff,mindiff)
    for i in range(100000):
        diff=n-6**i
        if diff<0:
            break
        mindiff=min(diff,mindiff)
    n=mindiff
    print(n)
    cnt+=1
print(cnt)

Submission status: Wrong Answer

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

for i in range(n//9):
    cnt = 0
    k = i
    while k != 0:
        cnt += k % 9
        k = k // 9
    j = (n-i*9) // 6
    k = j
    while k != 0:
        cnt += k % 6
        k = k // 6
    ans = min(ans, cnt+(n-i*9-j*6))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
base = n % 3
m = (n // 3) * 3
ans = n
if m % 9 == 0:
    i = m//9
    j = 0
    while i >= 0:
        cnt = 0
        k = i
        while k != 0:
            cnt += k % 9
            k = k // 9
        k = j
        while k != 0:
            cnt += k % 6
            k = k // 6
        ans = min(ans, cnt)
        i -= 2
        j += 3
else:
    j = m//6
    i = 0
    while j >= 0:
        cnt = 0
        k = i
        while k != 0:
            cnt += k % 9
            k = k // 9
        k = j
        while k != 0:
            cnt += k % 6
            k = k // 6
        ans = min(ans, cnt)
        i += 2
        j -= 3
if n < 6:
    print(n)
else:
    print(ans+base)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = [0] * (N + 1)
dp[0] = 0
print(dp)
for i in range(1, N + 1):
    cnt = i
    for j in range(1, 7):
        q = 6 ** j
        if i >= q:
            cnt = min(cnt, dp[i - q] + 1)
            print(i,cnt)
    for j in range(1, 6):
        q = 9 ** j
        if i >= q:
            cnt = min(cnt, dp[i - q] + 1)
    dp[i] = cnt
print(dp)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst_69=[]
count_num=0
for i in range(7):
    if 6**i <=n:
        lst_69.append(6**i)
    if 9**i <=n:
        lst_69.append(9**i)
a=sorted(lst_69,reverse=True)
for i in a:
    if n-i>=0:
        n-=i
        count_num+=1
for j in a:
    if n-j>=0:
        n-=j
        count_num+=1
for k in [1]*n:
    if n-k>=0:
        n-=j
        count_num+=1
print(count_num)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst_69=[]
count_num=0
for i in range(n):
    if 6**i <=n:
        lst_69.append(6**i)
    if 9**i <=n:
        lst_69.append(9**i)
a=sorted(lst_69,reverse=True)
for i in a:
    if n-i>=0:
        n-=i
        count_num+=1
for j in a:
    if n-j>=0:
        n-=j
        count_num+=1
for k in [1]*n:
    if n-k>=0:
        n-=j
        count_num+=1
print(count_num)

Submission status: Wrong Answer

Solution code:
N = int(input())

d_list = [1]

a = 1
while True:
  if 6**a <= N:
    d_list.append(6**a)
    a += 1
  else:
    break
a = 1
while True:
  if 9**a <= N:
    d_list.append(9**a)
    a += 1
  else:
    break
d_list.sort(key=lambda x:-x)
rest = N
cnt = 0
while True:
  if rest < 6:
    cnt += rest
    print(cnt)
    break
  else:
    for num in d_list:
      if rest >= num:
        cnt += 1
        rest -= num
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

d_list = [1]

a = 1
while True:
  if 6**a <= N:
    d_list.append(6**a)
    a += 1
  else:
    break
a = 1
while True:
  if 9**a <= N:
    d_list.append(9**a)
    a += 1
  else:
    break
d_list.sort(key=lambda x:-x)
rest = N
cnt = 0
while True:
  if rest < 6:
    cnt += rest
    print(cnt)
    break
  else:
    for num in d_list:
      if rest >= num:
        print(num)
        cnt += 1
        rest -= num
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

d_list = [1]

a = 1
while True:
  if 6**a <= N:
    d_list.append(6**a)
    a += 1
  else:
    break
a = 1
while True:
  if 9**a <= N:
    d_list.append(9**a)
    a += 1
  else:
    break
d_list.sort(key=lambda x:-x)
rest = N
cnt = 0
while True:
  if rest < 6:
    cnt = rest
    print(cnt)
    break
  else:
    for num in d_list:
      if rest >= num:
        cnt += 1
        rest -= num
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

def mod(mod, n):
    i = 0
    if n < mod:
        return 0, n
    while n >= mod**i:
        a, b = i, n-mod**i
        i += 1
    return a, b

def draw(remain, c):
    c6, re6 = mod(6, remain)
    c9, re9 = mod(9, remain)
    #print('roop', remain)
    #print(c)
    #print(c6, re6)
    #print(c9, re9)
    if c6 == 0:
        c += re6
        return c
    if c9 == 0:
        c += re9
        return c
    c_6 = c + draw(re6, c) + 1
    c_9 = c + draw(re9, c) + 1
    return min(c_6, c_9)

print(draw(N, 0))

Submission status: Wrong Answer

Solution code:
n = int(input())

money = []
for i in range(2,10):
    if 6**i <= 100000:
        money.append(6**i)
    if 9**i <= 100000:
        money.append(9**i)
money.sort(reverse=True)
#print(money)

m = len(money)
res = 0
ret = n
for i in range(m):
    if ret == 0:
        break
    if ret >= money[i]:
        x = ret // money[i]
        ret %= money[i]
        res += x

y = float("inf")
total = 0
for i in range(9):
    for j in range(6):
        if 9*i+6*j > ret:
            break
        total = i + j + ret - (9*i+6*j)
        if total <= y:
            y = total
res += y
print(res)

Submission status: Wrong Answer

Solution code:
from math import log10
# 引き出したいお金の額を入力する
N = int(input())

# 整数aの累乗のうち、整数N以下かつ最も大きいものを返す関数を定義
def func(N, a):
    index = int(log10(N) / log10(a))
    return a ** index

# 引き出し回数を再帰的に求める関数を定義
def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    elif N < 9:
        times = 1 + (N - 6)
        return times
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return 1 + N1
        else:
            return 1 + N2

print(search_times_re(N))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
dp = [10**15] * 1000000
dp[1] = 1
for i in range(1,N + 1):
    dp[i + 1] = min (dp[i] + 1 , dp[i + 1])
    for k in range(1,7):
        dp[i + 6 ** k ] = min (dp[i] + 1 ,dp[i + 6 ** k ])
    for k in range(1, 7):
        dp[i + 9 ** k] = min(dp[i] + 1, dp[i + 9 ** k])
print(dp[N])

Submission status: Wrong Answer

Solution code:
from math import log
# 引き出したいお金の額を入力する
N = int(input())

# 整数aの累乗のうち、整数N以下かつ最も大きいものを返す関数を定義
def func(N, a):
    index = int(log(N) / log(a))
    return a ** index

# 引き出し回数を再帰的に求める関数を定義
def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    elif N < 9:
        times = 1 + (N - 6)
        return times
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return 1 + N1
        else:
            return 1 + N2

print(search_times_re(N))

Submission status: Wrong Answer

Solution code:
from math import log
# 引き出したいお金の額を入力する
N = int(input())

# 整数aの累乗のうち、整数N以下かつ最も大きいものを返す関数を定義
def func(N, a):
    index = int(log(N) / log(a))
    return a ** index

# 引き出し回数を再帰的に求める関数を定義
def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return N1 + 1
        else:
            return N2 + 1

print(search_times_re(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = [1]
i = 1
while N > 6**i:
    if 9**i < N:
        xs.append(9**i)
    xs.append(6**i)
    i += 1
X = sorted(xs)

# N円のときの最小回数
dp = [10000000000] * 1008000
dp[1] = 1
for i in range(N):
    for x in X:
        dp[i+x] = min(dp[i]+1, dp[i+x])
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = [1]
i = 1
while N > 6**i:
    if 9**i < N:
        xs.append(9**i)
    xs.append(6**i)
    i += 1
X = sorted(xs)
print(X)

# N円のときの最小回数
dp = [10000000000] * 1008000
dp[1] = 1
for i in range(N):
    for x in X:
        dp[i+x] = min(dp[i]+1, dp[i+x])
print(dp[N])

Submission status: Wrong Answer

Solution code:
def generate_options(limit=100000):
    options = [1]

    p = 6
    q = p
    while q <= limit:
        options.append(q)
        q *= p

    p = 9
    q = p
    while q <= limit:
        options.append(q)
        q *= p

    options.sort()
    return options


def solve(n):
    options = generate_options()
    m = []
    i = 0
    while n:
        m.append(min([i + n // o for o in options if n % o == 0]))
        while n < options[-1]:
            options.pop()
        n -= options[-1]
        i += 1
    return min(m)


n = int(input())
print(solve(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [i for i in range(n+1)]

dp[1] = 1
for i in range(1,n):
    j,l = 1,1
    while i + 6**j <= n:
        dp[i+6**j] = min(dp[i+6**j], dp[i]+1)
        j += 1
    while i + 9**l <= n:
        dp[i+9**l] = min(dp[i+9**l], dp[i]+1)
        l += 1
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
ans=0
for i in range(12)[::-1]:
  j=(max(n//w[i],0))
  n-=j*w[i]
  ans+=j
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [float("INF")] * 100010
dp[0] = 0


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9


ans = dp[n]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())


dp = [x for x in range(100010)]


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9


ans = dp[n]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

m=[1,6,6**2,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5]
m.sort()
cnt=[0]*(N+1)
for i in range(1,N+1):
    #print('i',i)
    for l in m:
        #print('l',l)
        formararr=[]
        if i>=l:
            formararr.append(cnt[i-l])
            cnt[i]=min(formararr)+1
print(cnt[N])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	
	DP = [i for i in range(100010)]
	
	for i in range(1, 100001):
		for j in range(1, i):
			step = 6**j
			if step >= i:
				break
			tmp = 1 + DP[i-step]
			DP[i] = min(DP[i], tmp)
			
	for i in range(1, 100001):
		for j in range(1, i):
			step = 9**j
			if step >= i:
				break
			tmp = 1 + DP[i-step]
			DP[i] = min(DP[i], tmp)
	
	print(DP[N])
			
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
nlist = [1, 6, 9, 6**2, 9**2, 6**3, 9**3, 6**4, 9**4, 6**5, 6**6, 9**5]
ans = 0
i = 0
while(n):
  if n >= nlist[11-i]:
    n = n - nlist[11-i]
    ans += 1
  else:
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
a = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
a.sort(reverse=True)
ans = 0
for k in a:
    ans += N//k
    N -= (N//k)*k
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
a = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
a.sort()
ans = 0
while N:
    if bisect_left(a, N) <= 1:
        print(ans + N)
        break
    else:
        N -= a[bisect_left(a, N) - 1]
        ans += 1

Submission status: Wrong Answer

Solution code:
table = [1]+[10**10 for i in range(10**6)]
six = [6 ** i for i in range(1,8)]
nine = [9 ** i for i in range(1,7)]
for i in range(10**5):
    table[i+1] = min(table[i+1],table[i]+1)
    for x in six:
        table[i + x] = min(table[i + x], table[i]+1 )
    for y in nine:
        table[i+y] = min(table[i+y], table[i]+1)
print(table[int(input())-1])

Submission status: Wrong Answer

Solution code:
table = [1]+[10**10 for i in range(10**6)]
six = [6 ** i for i in range(1,7)]
nine = [9 ** i for i in range(1,5)]
for i in range(10**5):
    table[i+1] = min(table[i+1],table[i]+1)
    for x in six:
        table[i + x] = min(table[i + x], table[i]+1 )
    for y in nine:
        table[i+y] = min(table[i+y], table[i]+1)
print(table[int(input())-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
ans=0
for i in range(11,0,-1):
  ans+=(n//w[i])
  n-=ans*w[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[1]
for i in range(1,7):
    l.append(6**i)
for i in range(1,6):
    l.append(9**i)
l.sort(reverse=True)
i=0
c=0
while n>0:
    if l[i]<=n:
        for j in range(5,0,-1):
            if n>=l[i]*j:
                n=n-l[i]*j
                c+=j
                break
        i+=1

    else:
        i+=1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

cnt = 0
for s in seed:
  cnt += n // s
  n %= s

print(s)

Submission status: Wrong Answer

Solution code:
def f(N,x):
    ret=0
    while N>=x:
        ret+=N%x
        N=N//x
    return(ret+N)

N=int(input())
ans=[]
for i in range(1,N+1):
    ans.append(f(i,6)+f(N-i,9))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [200000] * 200000
dp[0] = 0

for i in range(N+1):
    for j in range(i+1):
        tmp = 6**j
        if tmp > N:
            break
        dp[i+tmp] = min(dp[i]+1, dp[i+tmp])
    for j in range(i+1):
        tmp = 9**j
        if tmp > N:
            break
        dp[i+tmp] = min(dp[i]+1, dp[i+tmp])

print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [200000] * 200000
dp[0] = 0

for i in range(N):
    for j in range(i+1):
        tmp = 6**j
        if tmp > N:
            break
        dp[i+tmp] = min(dp[i]+1, dp[i+tmp])
    for j in range(i+1):
        tmp = 9**j
        if tmp > N:
            break
        dp[i+tmp] = min(dp[i]+1, dp[i+tmp])

print(dp[N])

Submission status: Wrong Answer

Solution code:
def ninebeki(n):
    cnt=0
    while n>9**cnt:
        cnt+=1
    return cnt-1
def sixbeki(n):
    cnt=0
    while n>6**cnt:
        cnt+=1
    return cnt-1

def resolve():
    n=int(input())
    cnt=0
    q=ninebeki(n)
    r=sixbeki(n)
    l=[9**i for i in range(1,q+1)]
    l+=[6**i for i in range(1,r+1)]
    l.append(1)
    l.sort()
    d=[n for i in range(n+1)]
    d[0]=0
    for c in l:
        for i in range(c,n+1):
            d[i]=min(d[i],d[i-c]+1)
    print(d[n])
resolve()

Submission status: Wrong Answer

Solution code:
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())
i_6 = math.ceil(math.log(N, 6))
i_9 = math.ceil(math.log(N, 9))

dp = [9999999] * (N + 1)
dp[0] = 0

for i in range(N):
    for j in range(i_6):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(i_9):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())

i_6 = math.ceil(math.log(N, 6))
i_9 = math.ceil(math.log(N, 9))

dp = [9999999] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for j in range(i_6):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(i_9):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())

i_6 = math.floor(math.log(N, 6))
i_9 = math.floor(math.log(N, 9))

dp = [99999] * (N + 1)
dp[0] = 0

for i in range(N):
    if dp[i] < dp[i + 1]:
        dp[i + 1] = dp[i] + 1

    for j in range(1, i_6 + 1):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(1, i_9 + 1):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())
if not N:
    print(0)
    sys.exit(0)

i_6 = math.floor(math.log(N, 6))
i_9 = math.floor(math.log(N, 9))

dp = [99999] * (N + 1)
dp[0] = 0

for i in range(N):
    if dp[i] < dp[i + 1]:
        dp[i + 1] = dp[i] + 1

    for j in range(1, i_6 + 1):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(1, i_9 + 1):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())
i_6 = math.floor(math.log(N, 6))
i_9 = math.floor(math.log(N, 9))

dp = [99999] * (N + 1)
dp[0] = 0

for i in range(N):
    if dp[i] < dp[i + 1]:
        dp[i + 1] = dp[i] + 1

    for j in range(1, i_6 + 1):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(1, i_9 + 1):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])

Submission status: Wrong Answer

Solution code:
## TLEなのはわかってるが、保存用

import numpy as np
from collections import deque
#from copy import deepcopy

N = int(input())

## 6^6 < 1e5 < 6^7
## 9^5 < 1e5 < 9^6
## に注目すると大きい金額から引き出してみる全探索で良さそう

## 各引き出し方は多くともそれぞれ5or8回まで 


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

if N < 6:
  print(N)
  exit()

dq = deque()
dq.append((N,0,[[0,0],[0,0]])) ## [rest money, n_draw, draw_lst]
## draw_lst = [[次にどれを引き出すか, それを今まで何回引き出したか],[]]

loop_cnt = 0
while dq:
  loop_cnt += 1
  rest, cnt, draw_lst = dq.popleft()
  #print((rest,cnt,draw_lst))
  if rest < 6:
    solver.append(rest + cnt)
    continue
  ## 与えられた6のべき乗を引き出す
  if draw_lst[0][1] < 4:
    rest_afterdraw_6 = rest - drawable_6[draw_lst[0][0]]
    if rest_afterdraw_6 >= 0:
      new_draw_lst = [[draw_lst[0][0],draw_lst[0][1]+1],draw_lst[1]]
      dq.append((rest_afterdraw_6,cnt+1,new_draw_lst))
      #print((rest_afterdraw_6,cnt+1,new_draw_lst))
  ## 次に低い6のべき乗を引き出すようにシフトする
  if draw_lst[0][0] < 5:
    new_draw_lst = [[draw_lst[0][0]+1,0],draw_lst[1]]
    dq.append((rest,cnt,new_draw_lst))
    #print((rest,cnt,new_draw_lst))
  ## 与えられた9のべき乗を引き出す
  if draw_lst[1][1] < 4:
    rest_afterdraw_9 = rest - drawable_9[draw_lst[1][0]]
    if rest_afterdraw_9 >= 0:
      new_draw_lst = [draw_lst[0],[draw_lst[1][0],draw_lst[1][1]+1]]
      dq.append((rest_afterdraw_9,cnt+1,new_draw_lst))
      #print((rest_afterdraw_9,cnt+1,new_draw_lst))
  ## 次に低い9のべき乗を引き出すようにシフトする
  if draw_lst[1][0] < 5:
    new_draw_lst = [draw_lst[0],[draw_lst[1][0]+1,0]]
    dq.append((rest,cnt,new_draw_lst))
    #print((rest,cnt,new_draw_lst))

print(min(solver))
print('n_loop =', loop_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

L =[1,6**1,6**2,6**3,6**4,6**5,6**6,9**1,9**2,9**3,9**4,9**5]
X = [0]*N
for i in range(N):
    X[i] = i+1

for i in range(N):
    for l in L:
        if i+l < N:
            X[i+l] = min(X[i] + 1, X[i+l])
        
print(X[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

L =[1,6**1,6**2,6**3,6**4,6**5, 6**6, 9**1,9**2,9**3,9**4,9**5]
X = [1000]*N
X[0] = 1
for i in range(N):
    for l in L:
        if i+l < N:
            X[i+l] = min(X[i] + 1, X[i+l])
        
print(X[-1])