TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
import functools
sys.setrecursionlimit(10**6)

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


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

    if n in six_ps or n in nine_ps:
        return 1

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

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

    return min(six_tmp, nine_tmp)


# -*- coding: utf-8 -*-
N = int(input())
INF = 10**6

dp = [INF] * (N + 100)
dp[0] = 0

for n in range(1, N + 1):
    dp[n] = dp[n - 1] + 1

    power = 6
    while n - power >= 0:
        dp[n] = min(1 + dp[n - power], dp[n])
        power *= 6

    power = 9
    while n - power >= 0:
        dp[n] = min(1 + dp[n - power], dp[n])
        power *= 9

print(dp[N])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
INF = 10 ** 20

W,N = map(int,input().split())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(W+1)
dp[0] = 0
 
for coin in coin_list:
    for i in range(coin,W+1):
        dp[i] = min(dp[i], dp[i-coin]+1)
 
print(dp[W])

INF = 10 ** 20

N = int(input())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(W+1)
dp[0] = 0
 
for coin in coin_list:
    for i in range(coin,W+1):
        dp[i] = min(dp[i], dp[i-coin]+1)
 
print(dp[W])

INF = 10 ** 20

N = int(input())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(N+1)
dp[0] = 0
 
for coin in coin_list:
    for i in range(coin,N+1):
        dp[i] = min(dp[i], dp[i-coin]+1)
 
print(dp[N])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
ans = 0
a = [0] * 12
for i in range(1, 7):
  print(i)
  a[2*(i-1)] += max((9**(i-1)), (6**i))
  a[2*(i-1)-1] += min((9**(i-1)), (6**i))
print(a)
for i in a:
  if (n//i) != 0:
    ans += n//i
    n -= n//i * i

print(ans)

import bisect as bi

def ref(n):
  if n < 6:
    return n
  else:
    s6 = l6[bi.bisect(l6, n)-1]
    s9 = l9[bi.bisect(l9, n)-1]
    return min(n//s6 + ref(n%s6), 1+ref(n-s9))

l6 = [6**i for i in range(7)]
l9 = [9**i for i in range(6)]
print (ref(int(input())))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
i=1
count=0
n6=1
n9=1
l=[1]
while True:
    if 9**i>n:
        n9=i-1
        break
    i+=1
i=1
while True:
    if 6**i>n:
        n6=i-1
        break
    i+=1
for i in range(n6):
    l.append(6**(i+1))
for i in range(n9):
    l.append(9**(i+1))
l.sort(reverse=True)
for i in l:
    count+=n//i
    n%=i
    print(count)
print(count)


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)

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = N

for i in range(N+1):
    temp = 0
    six_pay = i
    while six_pay:
        temp += six_pay%6
        six_pay //= 6
    nine_pay = N - i
    while nine_pay:
        temp += nine_pay%9
        nine_pay //= 9
    if temp < answer:
        answer = temp

print(answer)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

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

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def get_num_draw(n, x):
    res = 0
    while n > 0:
        res += n % x
        n = n // x
    return res


def main():
    N = NI()
    ans = 10**10
    for i in range(0, N+1, 6):
        ans = min(get_num_draw(N-i, 9) + get_num_draw(i//6, 6), ans)
    print(ans)


if __name__ == "__main__":
    main()

Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
ans = 0

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

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

print(ans)


n = int(input())

dp = [0]

for i in range(1, n+1):
    dp.append(100000)
    power = 1
    while (i - power >= 0):
        dp[i] = min(dp[i], 1 + dp[i - power])
        power *= 6

    power = 9
    while (i - power >= 0):
        dp[i] = min(dp[i], 1 + dp[i - power])
        power *= 9

print(dp[n])
    


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n):
    if dp[i] == float("Inf"):
        pass
    else:
        for j in range(1,n//6):
            if i + 6**j > n:
                break
            dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
        for j in range(1,n//9):
            if i + 9**j > n:
                break
            dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
ans = n
for i in range(max(0, n-5), n+1):
    ans = min(ans, dp[i]+n-i)
print(ans)
print(dp)

n = int(input())
dp = [float("Inf")]*(n+1)
for i in range(min(6, n+1)):
    dp[i] = i
for i in range(n):
    for j in range(1,n//6+1):
        if i + 6**j > n:
            break
        dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
    for j in range(1,n//9+1):
        if i + 9**j > n:
            break
        dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
print(dp[-1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

def f(n):
  X6 = []
  X9 = []
  for i in range(1, 10):
    if n >= 6**i:
      X6.append(6**i)
    if n >= 9**i:
      X9.append(9**i)
  return X6, X9


def main():
  input = sys.stdin.readline
  N = int(input())
  X6, X9 = f(N)
  X = [1] + X6 + X9
  dp = [0 for _ in range(N+1)]
  for i in range(1, N+1):
    can = []
    for x in X:
      can.append(dp[i-x] + 1)
    dp[i] = min(can)
  print(dp[N])

if __name__ == '__main__':
  main()

import sys
from itertools import count, takewhile

def dfs(n, d={}):
  if n < 6:
    return n
  if n in d:
    return d[n]

  max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))
  max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))
  d[n] = min(dfs(n-max9), dfs(n-max6)) + 1
  return d[n]


def main():
  input = sys.stdin.readline
  N = int(input())
  print(dfs(N))
  
if __name__ == '__main__':
  main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
def f(x):
  ans=0
  while x >0:
    ans+=x%6
    x = x//6
  return ans
def g(x):
  ans=0
  while x >0:
    ans+=x%9
    x = x//9
  return ans
ans = n
for i in range(n+1):
  ans = min(ans,f(n-i),g(i))
print(ans)



n=int(input())
def f(x):
    ans=0
    while x>0:
        ans+=x%6
        x=x//6
    return ans
def g(x):
    ans=0
    while x>0:
        ans+=x%9
        x=x//9
    return ans
ans=n
for i in range(n+1): 
  ans=min(ans,f(i)+g(n-i))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

n=int(input())
INF=10**7
w=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp=[INF]*100001
dp[0]=0
for i in range(100001):
  for j in w:
    if i+j>100000:continue
    dp[i+j]=min(dp[i]+1,dp[i+j])
print(dp[n])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(9):
  if i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1

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


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

N = int(input())
INF = 10**6
dp = [INF] * (max(9, N)+1)
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  for j in range(1, 6):
    dp[i+j] = min(dp[i+j], dp[i] + j)
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])


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


N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(10):
  if i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  while i+9*n > N:
    dp[i+9*n] = min(dp[i+9*n], dp[i] + 1)
    n += 1
  while i+6*m > N:
    dp[i+6*m] = min(dp[i+6*m], dp[i] + 1)
    m += 1
print(dp[N])
    


N = int(input())
INF = 10**6
dp = [INF] * (max(9, N))
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
for i in range(N):
  n = m = 1
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])


N = int(input())
INF = 10**6
dp = [INF] * (max(9, N)+1)
dp[0] = 0
for i in range(N):
  n = m = 0
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,k=map(int,input().split())
h=list(map(int,input().split()))
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])

n=int(input())
dp=[10**5]*n
dp[0]=0
for i in range(n+1):
    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])


n=int(input())
dp=[10**5]*n
dp[0]=0
for i in range(n+1):
    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])


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


n=int(input())
dp=[10**5]*(n+1)
dp[0]=0
for i in range(n+1):
    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])


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
    

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

arr6 = []
for i in range(10):
	arr6.append(6**i)

arr9 = []
for i in range(10):
	arr9.append(9**i)


ans = float("inf")
for i in range(n+1):
	count = 0
	tmp = i
	while tmp > 0:
		t = 0
		while arr6[t] <= tmp:
			t+=1

		tmp -= arr6[t-1]
		count += 1

	tmp = n-i
	while tmp > 0:
		t = 0
		while arr9[t] <= tmp:
			t += 1
		tmp -= arr9[t-1]
		count += 1

	ans = min(ans,count)

print ans


import numpy as np
N = int(input())

coin = [6**n for n in range(10) if 6**n <= N]
coin += [9**n for n in range(10) if 9**n <= N]

dp = np.zeros(N+1, dtype=np.int32)
dp += 10**9
dp[0] = 0

for c in coin:
  for _ in range(9):
    dp[c:] = np.minimum(dp[:-c] + 1, dp[c:])

answer = dp[-1]
print(answer)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

lis = [1, 6, 36, 216, 1296, 7776, 46656,
     9, 81, 729, 6561, 59049]
m = len(c)

dp = [float('inf') for _ in range(n+1)]
dp[0] = 0

for j in range(1,n+1):
    temp = []
    for i in range(m):
        if j < c[i]:
            continue
        else:
            temp.append(dp[j-lis[i]]+1)
    dp[j] = min(temp)

print(dp[n])


n = int(input())

lis = [1, 6, 36, 216, 1296, 7776, 46656,
     9, 81, 729, 6561, 59049]
m = len(c)

dp = [float('inf') for _ in range(n+1)]
dp[0] = 0

for j in range(1,n+1):
    temp = []
    for i in range(m):
        if j < lis[i]:
            continue
        else:
            temp.append(dp[j-lis[i]]+1)
    dp[j] = min(temp)

print(dp[n])


n = int(input())
lis = [1, 6, 36, 216, 1296, 7776, 46656,9, 81, 729, 6561, 59049]
lis.sort(reverse=True)
dp = [10 ** 10 for i in range(n+1)]
dp[0] = 0
for i in range(n):
  for num in lis:
    try:
      dp[i+num] = min(dp[i+num],dp[i]+1)
    except:
      continue
print(dp[n])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())

def solve():
    inf=10**7
    dp=[inf]*(n+1)
    dp[0]=0
    
    for i in range(1,n+1):
        power=1
        while power<=i:
            dp[i]=min(dp[i],dp[i-power]+1)
            power*=6
    #print(dp)

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

print(solve())

n=int(input())

def solve():
    inf=10**7
    dp=[inf]*(n+1)
    dp[0]=0
    
    for i in range(1,n+1):
        power=1
        while power<=i:
            dp[i]=min(dp[i],dp[i-power]+1)
            power*=6
    #print(dp)

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

print(solve())

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
dp = [int(i) for i in range(10 ** 5 + 1)]

for i in [6,9]:
    v = i
    while v < 10 ** 5:
        for j in range(len(dp)):
            if j+v <= 10 ** 5:
                dp[j+v] =min(dp[j]+1,dp[j+v])
        v *= i  
        
print(dp[10**5])

n = int(input())

max_range = 10 ** 5
dp = [int(i) for i in range(max_range + 1)]

for i in [6,9]:
    check = i
    while check < max_range:
        for j in range(max_range + 1):
            if j - check >= 0:
                dp[j] = min(dp[j],dp[j-check] + 1)

        check =  check *
        
print(dp[n])

n = int(input())
max_n = 10 ** 5
dp = [int(i) for i in range(max_n + 1)]

for i in (6,9):
    v = i
    while v < max_n:
        for j in range(len(dp)):
            if j + v < max_n:
                dp[j+v] = min(dp[j+v],dp[j]+1)
        v *= i
        
dp[n]

n = int(input())

max_range = 10 ** 5
dp = [int(i) for i in range(max_range + 1)]

for i in [6,9]:
    check = i
    while check < max_range:
        for j in range(max_range + 1):
            if j - check >= 0:
                dp[j] = min(dp[j],dp[j-check] + 1)

        check =  check * i
        
print(dp[n])

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
l_6 = []
_ = 1
while 6**_ < 100000:
    l_6.append(6**_)
    _ += 1
l_6.sort(reverse = 1)

l_9= []
_ = 1
while 9**_ < 100000:
    l_9.append(9**_)
    _ += 1
l_9.sort(reverse = 1)
print(l_6, l_9)

n = int(input())

w = 0
z = []
for i in range(n+1):
    x = i
    for j in range(len(l_6)):
        while l_6[j] <= x:
            x -= l_6[j]
            w += 1
    else:
        w += x
    
    y = n-i
    for k in range(len(l_9)):
        while l_9[k] <= y:
            y -= l_9[k]
            w += 1
    else:
        w += y

    z.append(w)
    w = 0

print(min(z))

n = int(input())

dp = [0] + [100000]*n

ptn = [1]
_ = 1
while 6**_ < 100000:
    ptn.append(6**_)
    _ += 1

_ = 1
while 9**_ < 100000:
    ptn.append(9**_)
    _ += 1

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n_max = 100000

bs = [(6 ** i, 6) for i in range (1, 10)]
bs.extend([(9 ** i, 9) for i in range (1, 10)])
bs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))
bms = []
s = 5
for b, i in bs:
    s += b * (i - 1)
    bms.append((b, i, s))

#print(bs)


#m = 44852
m = int(input())

stack = [(m, 0, len(bms) - 1)]

result = 10000
while stack:
    m, n, bms_i = stack.pop()
    steps += 1
    b, i, s = bms[bms_i]
    #print(m, n, bms_i, b, i, s)

    if n > result:
        #print("skip!", m, n, bms_i)
        continue
    if m > s:
        continue
    if bms_i < 0:
        if m <= 6 and m + n < result:
            result = m + n
        #    print('get result!', result)
        continue

    for j in range(i):
        next_m = m - b * j
        if next_m >= 0 and n + j < result:
            stack.append((next_m, n + j, bms_i - 1))

print(result)


n_max = 100000

bs = [(6 ** i, 6) for i in range (1, 10)]
bs.extend([(9 ** i, 9) for i in range (1, 10)])
bs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))
bms = []
s = 5
for b, i in bs:
    s += b * (i - 1)
    bms.append((b, i, s))

#print(bs)


#m = 44852
m = int(input())

stack = [(m, 0, len(bms) - 1)]

result = 10000
while stack:
    m, n, bms_i = stack.pop()
    b, i, s = bms[bms_i]
    #print(m, n, bms_i, b, i, s)

    if n > result:
        #print("skip!", m, n, bms_i)
        continue
    if m > s:
        continue
    if bms_i < 0:
        if m <= 6 and m + n < result:
            result = m + n
        #    print('get result!', result)
        continue

    for j in range(i):
        next_m = m - b * j
        if next_m >= 0 and n + j < result:
            stack.append((next_m, n + j, bms_i - 1))

print(result)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
arr = [1]
for i in range(1, 10):
    if 6 ** i < 100000:
        arr.append(6 ** i)
    if 9 ** i < 100000:
        arr.append(9 ** i)

arr.sort(reverse=True)

n = 44852
#n = 127
# n=3


def wari(k, l=0):
    # print(k)
    if k == 0:
        return l
    i = 0
    while k < arr[i]:
        i += 1
    a = int(k / arr[i])
    b = k % arr[i]
    wari1 = wari(b, a+l)

    if i < len(arr)-1:
        c = int(k / arr[i+1])
        d = k % arr[i+1]
        wari2 = wari(d, c+l)
        if wari1 < wari2:
            return wari1
        else:
            return wari2
    return wari1


print(wari(n))




n = 44852
# n = 127
# n=3

def wari(n):
    res = n
    for i in range(n):
        cc = 0
        t = i
        while t > 0:
            cc += t % 6
            t = t // 6
        t = n - i
        while t > 0:
            cc += t % 9
            t = t // 9
        if res > cc:
            res = cc
    return res

print(wari(n))




n = int(input())

def sol(n):
    res = n
    for i in range(n+1):
        cc = 0
        t = i
        while t > 0:
            cc += t % 6
            t = t // 6
        t = n - i
        while t > 0:
            cc += t % 9
            t = t // 9
        if res > cc:
            res = cc
    return res

print(sol(n))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect as bi

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

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


print(s69(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(li6, n) - 1]
        s9 = li9[bi.bisect(li9, n) - 1]
        return min(n // s6 + s69(n % s6), 1 + s69(n - s9))


print(s69(int(input())))



import bisect as bi

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(li6, n) - 1]
        s9 = li9[bi.bisect(li9, n) - 1]
        return min(n // s6 + s69(n % s6), 1 + s69(n - s9))


print(s69(int(input())))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())

l1 = 2 ** 30
p6 = [1] * 6
p9 = [1] * 5
for i in range(1,7):
    p6[i] = p6[i-1] * 6
    if i < 6 : p9[i] = p9[i-1] * 9

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

for i in range(1,N+1):
    for j in p6:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
    for j in p9:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
print(dp[N])

N = int(input())

l1 = 2 ** 30
p6 = [1] * 7
p9 = [1] * 6
for i in range(1,7):
    p6[i] = p6[i-1] * 6
    if i < 6 : p9[i] = p9[i-1] * 9

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

for i in range(1,N+1):
    for j in p6:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
    for j in p9:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
print(dp[N])

Verdicts: Runtime Error

Accepted
Problem: 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.

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


N = int(input())
def six(n):
  i = 0
  while n%6 == 0:
    n = n//6
    i += 1
  return i

def nine(n):
  i = 0
  while n%9 == 0:
    n = n//9
    i += 1
  return i

def ans(n):
  if n-6**six(n)==0:
    return 1
  elif n-9**nine(n)==0:
    return 1
  else:
    return max(six(n)+ans(n-6**six(n)),nine(n)+ans(n-9**nine(n)))

ans(44852)
    
    

N = int(input())
a = [1,6,36,216,1296,7776,46656]
b = [1,9,81,729,6561,59049]
def ans(n):
  if n<=0:
    return 1000
  elif n in a or n in b:
    return 1
  else:
    return(min(ans(n-1),ans(n-6),ans(n-36),ans(n-216),ans(n-1296),ans(n-7776),ans(n-46656),ans(n-9),ans(n-81),ans(n-729),ans(n-6561),ans(n-59049))+1)
m = 1
while m <= N:
  ans(m)
print(ans(N))
  

N = int(input())
a = [1,6,36,216,1296,7776,46656]
b = [1,9,81,729,6561,59049]
def six(n):
  i = 0
  if n < a[i]:
    return i-1
  else:
    i += 1
def nine(n):
  i = 0
  if n < b[i]:
    return i-1
  else:
    i += 1
def ans(n):
  if n in a or n in b:
    return 1
  else:
    return(min(six(n)+ans(n-6**six(n)),(nine(n)+ans(n-9**nine(n))
                                        
print(ans(44852))

N = int(input())
def cn(X, n):
    if (int(X/n)):
        return cn(int(X/n), n)+str(X%n)
    return str(X%n)
def su(n):
  ans = 0
  for chara in n:
    ans += int(chara)
  return ans
lis = []
i = 0
while i <= N:
  lis.append(su(cn(i,6))+su(cn(N-i,9)))
  i += 1
print(min(lis))

Verdicts: Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for i in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)

N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for j in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):


N = int(input())


dp = [10 ** 5] * N
six = [6 ** x for x in range(8)]
nine = [9 ** x for x in range(6)]


dp[0] = 1


for i in range(1, N):
    
    for s in six:
        if i + s >= N:
            break
        dp[i + s] = min(dp[i + s], dp[i] + 1)
    
    for n in nine:
        if i + n >= N:
            break
        dp[i + n] = min(dp[i + n], dp[i] + 1)


print(dp[N - 1])




N = int(input())


dp = [10 ** 5] * (N + 1)


six = []
c = 0
while True:
    w = 6 ** c
    if w > N:
        break
    six.append(w)
    c += 1
nine = []
c = 0
while True:
    w = 9 ** c
    if w > N:
        break
    nine.append(w)
    c += 1


dp[0] = 0


for i in range(N + 1):
    
    for s in six:
        if i + s > N:
            break
        dp[i + s] = min(dp[i + s], dp[i] + 1)
    
    for n in nine:
        if i + n > N:
            break
        dp[i + n] = min(dp[i + n], dp[i] + 1)


print(dp[N])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = input().split()
cand = [1]
for i in range(1,6):
  for j in range(1,7):
    cand.append(6**j)
    cand.append(9**i)
import bisect  
count = 0
cand.sort()
while n > 0:
	index = bisect.bisect_left(cand, n)
    if index != 0
      n = n - cand[index-1]
      count += 1
    else:
      n -= 1
      count += 1
print(count)
    


  

n = int(input())
cand = [1]
for i in range(1,7):
    cand.append(6**i)
for j in range(1,6):
  cand.append(9**j)
cand.sort()
dp = []
for c in cand:
  hoge = []
  for i in range(n+1):
    if i % c == 0:
      hoge.append(i//c)
    else:
      hoge.append(i)
  dp.append(hoge)
for a in range(1,12):
  for b in range(1,n+1):
    if b >= cand[a]:
    	dp[a][b] = min(dp[a-1][b],dp[a][b - cand[a]] + 1)
    else:
      dp[a][b]  = dp[a-1][b]
      
print(dp[-1][n])
      

      

     
    

  

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())

res = 100000

for i in range(N+1):
  t = i
  cc = 0
  while t>0:
    cc += t%6
    t = int(t/6)
  t = N-i
  while t>0:
    cc += t%9
    t = int(t/9)
  if res > cc:
    res = cc

print(cc)
  

N = int(input())

res = 100000

for i in range(N+1):
  cc = 0
  t = i
  while t>0:
    cc += t%6
    t = int(t/6)
  t = N-i
  while t>0:
    cc += t%9
    t = int(t/9)
  if res > cc:
    res = cc

print(res)
  

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

dp = [N] * (N + 1)
dp[0] = 0
for i in range(N):
    dp[i + 1] = min(dp[i + 1], dp[i] + 1)
    six = 6
    nine = 9
    for p in range(20):
        if i + six <= N:
            dp[i + six] = min(dp[i + six], dp[i] + 1)
        if i + nine <= N:
            dp[i + nine] = min(dp[i + nine], dp[i] + 1)
        six *= six
        nine *= nine

print(dp[N])

import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

dp = [N] * (N + 1)
dp[0] = 0
for i in range(N):
    dp[i + 1] = min(dp[i + 1], dp[i] + 1)
    six = 6
    nine = 9
    for p in range(10):
        if i + six <= N:
            dp[i + six] = min(dp[i + six], dp[i] + 1)
        if i + nine <= N:
            dp[i + nine] = min(dp[i + nine], dp[i] + 1)
        six *= 6
        nine *= 9

print(dp[N])


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a))
print(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))

def s(a,b):return[s(a//b,b)+a%b,a][a<b]
n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))

def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a));n=int(input())print(min(c(i,6)+c(n-i,9)for i in range(n+1)))

def solve(n, c):
  if n < 6:
    return n + c
  a = b = 2000000000
  if n % 6 == 0:
    a = solve(n // 6, c + 1)
  if n % 9 == 0:
    b = solve(n // 9, c + 1)
  return min(a, b)
print(solve(int(input()), 0))

def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a));print(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))

s=lambda a,b:a*(a<b)or s(a//b,b)+a%b;n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))

s=lambda a,b:a if a<b else s(a//b,b)+a%b;n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)


N = int(input())
li = [1]

six = 1
while six <= N:
    six = six*6
    li.append(six)

nine = 1
while nine <= N:
    nine = nine*9
    li.append(nine)

INF = 10**10

dp = [INF for i in range(N+1)]
dp[0] = 0

for i in range(N):
    for num in li:
        if i+num <= N:
            dp[i+num] = min(dp[i+num], dp[i] + 1)
print(dp[N])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
d = tuple([1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)])
M = 10**6+1
B = [float("inf")]*M
B[0] = 0
for i in range(M):
  for j in d:
    if i+j < M:
      B[i+j] = min(B[i+j], B[i]+1)
n = int(input())
print(B[n])

d = tuple([1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)])
M = 10**5+1
B = [float("inf")]*M
B[0] = 0
for i in range(M):
  for j in d:
    if i+j < M:
      B[i+j] = min(B[i+j], B[i]+1)
n = int(input())
print(B[n])

Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
import sys
N = int(input())
# judge = True
ans = 0
temp = 9
temp_list = [1,2,3,4,5]
while 100000>temp:
    temp_list.append(temp)
    temp *=9 
temp = 6
while 100000>temp:
    temp_list.append(temp)
    temp *=6 
temp_list=sorted(temp_list)
# print(temp_list)
for i in range(1,len(temp_list)+1):
    if N%temp_list[-i] == 0:
        print(N//temp_list[-i])
        sys.exit() 
    else:
        judge = True
        while judge:
            if N - temp_list[-i] > 9 and (temp_list[-i] >5):
                # print(N)
                # print(temp_list[-i])
                N -= temp_list[-i]
                ans+=1
            else:
                judge = False
# print(N)
# print(N//9)
# print(N//6)
# print(N)
if N%9 < N%6:
    ans += N//9
    N = N%9
    # N -= 9*N//9
else:
    ans += N//6
    N = N%6
    # N -= 6*N//6
# print(N)
# print(ans)
print(N+ans)
# print(N)
# print(ans)
# print(ans+N)

# temp_9 = []
# temp_6 = []
# judge = True

# while judge:

#         if N -temp_9[-i] >=0:
#             N -= temp_9[-i]
#             print(N)
#     judge = False
# print(N) 

# # while N > temp:
# #     temp *= 9
# #     ans += 1    
# # N = N - temp/9
# # print(N)


import sys
N = int(input())
dp = [ 100000 for i in range(N+1)]
dp[0] = 0
for i in range(1,N+1):
    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 6
    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 9
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power += 1
print(dp[N])



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math

N = int(input())
memo = [0]*(N+1)
memo[0] = 0

for i in range(1,N+1):
	memo[i] = memo[i-1]+1
	for j in range(1,iny(math.log(i,6))+1):
		memo[i] = min(memo[i],memo[i-pow(6,j)]+1)
	for j in range(1,int(math.log(i,9))+1):
		memo[i] = min(memo[i],memo[i-pow(9,j)]+1)

print(memo[-1])


import math

N = int(input())
memo = [0]*(N+1)
memo[0] = 0

for i in range(1,N+1):
	memo[i] = memo[i-1]+1
	j = 1
	while pow(6,j) <= i:  
		memo[i] = min(memo[i],memo[i-pow(6,j)]+1)
		j += 1
	j = 1
	while pow(9,j) <= i:
		memo[i] = min(memo[i],memo[i-pow(9,j)]+1)
		j += 1

print(memo[-1])


Verdicts: Runtime Error

Accepted