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):
N = int(input())


def get_rest(base, target):
    i = 0
    while base**i < target:
        i += 1
    return target - base**(i - 1)


def greedy(base, target):
    count = 0
    rest = target
    while rest >= base:
        rest = get_rest(base, rest)
        count += 1
    return count + rest


Min = float("inf")
for i in range(N + 1):
    Min = min(Min, greedy(6, i) + greedy(9, N - i))

print(Min)


N = int(input())


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


def search(count, target):
    if target <= 5:
        return count + target
    six_rest = hoge(6, target)
    nine_rest = hoge(9, target)
    return min(search(count + 1, six_rest), hoge(count + 1, nine_rest))


print(search(0, N))


N = int(input())


def count(base, total):
    count = 0
    exp = 1
    while exp * base <= total:
        exp *= base
    remain = total
    while exp != 1:
        count += remain // exp
        remain %= exp
        exp //= base
    count += remain
    return count


Min = float("inf")
for i in range(N + 1):
    c = 0
    c += count(6, i)
    c += count(9, N - i)
    Min = min(Min, c)
print(Min)


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())
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):
    count = 0
    t = i
    while(t):
        count += t % 6
        t = int(t/6)
    t = n-i
    while(t):
        count += t % 9
        t = int(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())
wd = []
for i in range(1, 7):
    wd.append(6**i)
for i in range(1, 6):
    wd.append(9**i)
wd.append(1)

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

for i in range(len(wd)):
    for j in range(i, N+1):
        dp[j] = min(dp[j], dp[j-i]+1)

print(dp[N])

N = int(input())
wd = []
for i in range(1, 7):
    wd.append(6**i)
for i in range(1, 6):
    wd.append(9**i)
wd.append(1)

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

for i in wd:
    for j in range(i, N+1):
        dp[j] = min(dp[j], dp[j-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 = int(input())
count = 0
itr = 1

while(N >= 9 or N >= 6):
    itr = 1
    flag = 0
    itr2 = 0
    while(N >= 9**itr or N >= 6**itr):
        itr += 1
        if N < 9**itr and flag == 0:
            itr2 = itr-1
            flag = 1
    if flag == 1:
        if 9**itr2 > 6**(itr-1):
            N = N - 9**itr2
            print(N, 9**itr2, 9)
        else:
            N = N - 6**(itr-1)
            print(N, 6**(itr-1), 6)
    else:
        if 9**(itr-1) > 6**(itr-1):
            N = N - 9**(itr-1)
            print(N, 9**(itr-1), 9)
        else:
            N = N - 6**(itr-1)
            print(N, 6**(itr-1), 6)
    count += 1
    if N == 0:
        break
if N > 0:
    count += N
print(count)


from itertools import count, takewhile

def calc(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(calc(N-max9), calc(N-max6))+1
    #print(N, ':', d[N])
    return d[N]

print(calc(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):
import copy
import itertools

N = int(input())
six_nines = set()


for i in range(1,6):
  a = 6**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)
  a = 9**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)

comb_six_nines = copy.copy(six_nines)


for comb in itertools.combinations(six_nines,2):
  if comb[0]+comb[1] <= N and comb[0]+comb[1] not in comb_six_nines:
    comb_six_nines.add(comb[0]+comb[1])


#comb_six_nines.sort(reverse=True)
#comb_six_nines.append(1)
six_nines = list(six_nines)
six_nines.sort(reverse=True)
six_nines.append(1)

#print(comb_six_nines)
print(six_nines)


ans = 0
while N != 0:
  for comb in six_nines:
    if N >= comb:
      print(N,comb)
      if N 
      N -= comb
      ans += 1

print(ans)

#99c
import math

N = int(input()) #<=100000




single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}
#print(single_withdraw_set)


withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0


for i in range(1,N+1):
    if i in single_withdraw_set:
        
        withdraw_dict[i] = 1
    else:
        
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[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())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if 6 <= N <= 14:
            N -= 6
            ans += 1
            # print(6,N)
            break
        if i <= N:
            N -= i
            ans += 1
            # print(i,N)
            break
print(ans)

N = int(input())
bank = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
while N != 0:
    for i in bank:
        if i <= N:
            N -= i
            ans += 1
            print(i,N)
            break
print(ans)

import sys
sys.setrecursionlimit(10**7)
N = int(input())
memo = [-1]*(N+1)
def rec(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    m = 1
    while m <= n:
        res = min(res,rec(n-m)+1)
        m *= 6
    m = 1
    while m <= n:
        res = min(res,rec(n-m)+1)
        m *= 9
    memo[n] = res
    return memo[n]

print(rec(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):
N = int(input())
import sys
sys.setrecursionlimit(100000)
dp = [-1] * (N + 1)
def rec(n):
    if n == 0:
        return 0
    if dp[n] != -1:
        return dp[n]
    res = n
    i = 0
    while n >= i ** 6:
        pow6 = i ** 6
        res = min(res, rec(n - pow6) + 1)
        i += 1

    j = 0
    while n >= j ** 9:
        pow9 = j ** 9
        res = min(res, rec(n - pow9) + 1)
        i += 1

    dp[n] = res
    return dp[n]
print(rec(N))

import sys
sys.setrecursionlimit(10**6)
N = int(input())
dp = [-1] * (N + 1)

def rec(n):
    if n == 0:
        return 0
    if dp[n] != -1:
        return dp[n]
    res = n
    i = 0
    while n >= 6 ** i:
        pow6 = 6 ** i
        res = min(res, rec(n - pow6) + 1)
        i += 1
    j = 0
    while n >= 9 ** j:
        pow9 = 9 ** j
        res = min(res, rec(n - pow9) + 1)
        j += 1
    dp[n] = res
    return res
print(rec(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())
done = []

arr =  [N]
ans = 0
stop = 0
  

while arr:

  a = arr.pop(0)

  done.append(a)

  Next = []
  if a-1 >= 0:
    Next.append(a-1)
  if a-6 >= 0:
    Next.append(a-6)
  if a-36 >= 0:
    Next.append(a-36)
  if a-216 >= 0:
    Next.append(a-216)
  if a-1296 >= 0:
    Next.append(a-1296)
  if a-7776 >= 0:
    Next.append(a-7776)
  if a-46656 >= 0:
    Next.append(a-46656)
  if a-9 >= 0:
    Next.append(a-9)
  if a-81 >= 0:
    Next.append(a-81)
  if a-729 >= 0:
    Next.append(a-729)
  if a-6561 >= 0:
    Next.append(a-6561)
  if a-59049 >= 0:
    Next.append(a-59049)
    
  for i in Next:
    if i in done:
      continue
    elif i in arr:
      continue
    else:
      arr.append(i)
      if i == 0:
        stop = 1
        break
  ans += 1
  if stop == 1:
    break

print(ans)

def knapsack(N,W,weight,value):
  
  dp=[[10**7 for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1):
    dp[0][i]=i
  #DP
  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w: 
        dp[i+1][w]=min(dp[i+1][w-weight[i]]+value[i], dp[i][w])
      else:
        dp[i+1][w]=dp[i][w]
        
  
  return dp[N][W]

N = 12
W = int(input())
weight = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
value = [1,1,1,1,1,1,1,1,1,1,1,1,1]

a = knapsack(N,W,weight,value)

print(a)

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())
sixs = [6,36,216,1296,7776,46656]
nines = [9,81,729,6561,59049]
lis = [0] + [100000 for i in range(170000)]
for i in range(0,100001):
 for j in sixs:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
 for j in nines:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
print(lis[n])

n = int(input())
sixs = [6,36,216,1296,7776,46656]
nines = [9,81,729,6561,59049]
lis = [i for i in range(170000)]
for i in range(0,100001):
 for j in sixs:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
 for j in nines:
  if lis[i+j] > lis[i]+1:
    lis[i+j] = lis[i] + 1
print(lis[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())

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

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

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

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


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


N = int(input())

result = N
for i in range(0,N+1):
    count = 0
    tmp = i 
    while tmp > 0:
        count += tmp%6
        tmp //= 6
    tmp = N - i 
    while tmp > 0:
        count += tmp%9
        tmp //=9
    
    if result > count:
        result = count

print(result)

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):
dp=[0 for i in range(100010)]
dp[0]=0
for n in range(1,100001):
  dp[n]=200000
  power=1
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=6
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=9

n=int(input())
print(dp[n])

dp=[1000000 for i in range(100010)]
dp[0]=0
for n in range(1,11):
  power=1
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=6
  power=1
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=9

i=int(input())
print(dp[i])

n=int(input())
dp=[0 for i in range(100010)]
dp[0]=0
for i in range(100000):
  dp[i]=200000
  power=1
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=6
  while(power<=n):
    dp[n]=min(dp[n],dp[n-power]+1)
    power*=9

print(dp[n])

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

i=int(input())
print(dp[i])

Verdicts: Wrong Answer

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):
nine, six = [9 ** i for i in range(1, 6)], [6 ** i for i in range(1, 7)]


def minimize(n, a_idx, b_idx, t):
    if n == 0:
        return t
    elif a_idx == -1 and b_idx == -1:
        return t + n

    t1, t2 = 100000, 100000
    if a_idx != -1:
        p = n // nine[a_idx]
        t1 = minimize(n-p*nine[a_idx], a_idx-1, b_idx, t+p)

    if b_idx != -1:
        q = n // six[b_idx]
        t2 = minimize(n-q*six[b_idx], a_idx, b_idx-1, t+q)

    return min(t1, t2, t+n-1)


def main():
    n = int(input())

    cnt9, cnt6 = 0, 0
    while 9 ** (cnt9+1) <= n:
        cnt9 += 1

    while 6 ** (cnt6+1) <= n:
        cnt6 += 1

    t = minimize(n, cnt9-1, cnt6-1, 0)

    print(t)


if __name__ == '__main__':
    main()


def main():
    n = int(input())

    min_t = 100000
    for i in range(n+1):
        x, six = i, 0
        while x > 0:
            six += x % 6
            x //= 6

        y, nine = n - i, 0
        while y > 0:
            nine += y % 9
            y //= 9

        if six + nine < min_t:
            min_t = six + nine

    print(min_t)


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):
import itertools as i
n=int(input())
count=[]
def f(x):
    if x==0:
        return count
    b=list(i.takewhile(lambda i:9**i<=x,(i for i in range(100))))[-1]
    c=list(i.takewhile(lambda i:6**i<=x,(i for i in range(100))))[-1]
    if 9**b>6**c:
        count.append(b)
        return f(x-9**b)
    else:
        count.append(c)
        return f(x-6**c)

print(f(n))

n=int(input())
from copy import*
ans=[]
for i in range(n+1): 
    count=0
    money6=i
    money9=n-i
    while money6:
        count+=money6%6
        money6//=6
    while money9:
        count+=money9%9
        money9//=9
    ans.append(count)
print(min(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())

M = 100000

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


#     val = 9 ** i
#     if val <= M:
#         print(val)
#         c.append(val)
#

#     val = 6 ** i
#     if val <= M:
#         print(val)
#         c.append(val)

count = 0
rest = N

for i in c:
    if rest // i > 0:
        count += rest // i
        print(str(i) + ', ' + str(rest // i) + ' times, rest = ' + str(rest % i))
        rest = rest % i

    if rest == 0:
        break

print(count)



def main():
    max_val = 10**5 + 1
    dp = [i for i in range(max_val)]

    for i in range(max_val):
        p = 1
        while p < max_val:
            dp[i] = min(dp[i], dp[i - p] + 1)
            p *= 6
        p = 1
        while p < max_val:
            dp[i] = min(dp[i], dp[i - p] + 1)
            p *= 9

    N = int(input())
    print(dp[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):
import math
n = (int)(input())

ans = n
l = (int)(math.log(n, 9)+1)

for i in range(n+1):
  tmp_ans = 0
  a_six = i
  a_nine = n-i
  for i in reversed(range(-1, 6)):
    tmp = a_six//6**i
    tmp_ans += tmp
    a_six -= tmp*6**i
  a_nine += a_six
  for i in reversed(range(-1, 5)):
    tmp = a_nine//9**i
    tmp_ans += tmp
    a_nine -= tmp*9**i
  if ans > tmp_ans:
    ans = tmp_ans

print(ans)


import math
n = (int)(input())

ans = n
l = (int)(math.log(n, 9)+1)

for i in range(n+1):
  tmp_ans = 0
  a_six = i
  a_nine = n-i
  for i in reversed(range(7)):
    tmp = a_six//6**i
    tmp_ans += tmp
    a_six -= tmp*6**i
  a_nine += a_six
  for i in reversed(range(7)):
    tmp = a_nine//9**i
    tmp_ans += tmp
    a_nine -= tmp*9**i
  if ans > tmp_ans:
    ans = tmp_ans

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 zlib
sol=b"x\x9c\xed\x9dm\x8f\xe36\x0c\x84\x7fk\xaf\xed%\x96\xb7\xbd\xeb\xff\xffR\xc1\xc1\x12\x01\xb8\x1e\xd8c.3\x8a\x08\x18\x0b\xc3\xd4\x0bE=\x19\xcbT6\xfe\xe3\xc7\x9f\x7f\xfd\xfd\xb3\xff\xe9G?{\x1c\xfd\xca\xe3\xf8\xfb\xe7\xad\x1f[\x91\xdb\x97\xa6~\xfc\xbc\xdd\xfb\xb1\x15\xb9?\x9a\xda+\xdcOz\x99\x87\xf5Q\xd8\xb7\xd3On\xf7\xe5a\xed\'g\x0b\x9bI\xc4\x8d~\xf4+\x0f\xeb}i\x0fk?9[\xd8L"n\xf4\xa3_yX\x97\xb6>\xac\xfd\xe4la3\x85\xbbq\nZo\xb2..\x02`&k\xf0=\x000\x93M\x81\x1a\x00\x9c\x1b"\xd8\x80\xb1\x9f\xea\xfd\x88\xcfV\xd8\x84\xd17h\xbd\x1f\xf1\xd9\x17\xf6S`\x91\xb7\x01r\x00\x84\xbb\x01\xb0\xf1\x85\xcd\xd4\x8fnzX\xdb\xfa\xf1\xcc\x18\xc7a\xb8\x1b\x1c6\xbe\xf7\xef\xd3\x8dS\xbd\xab\x01`q\xf6\'"\x00\xf8.@a3\x89`\x03"\xa6\x8f\r0Y\x9c\xa3\x00\x08\xa7\x17`\x03L\xfd\xa4\x13\xf5\x8c\xd6\x91Z\x80C\xae\x96\xb9\xe1O8l@\x10\xb8\x8f\xb9\xf7\xd9\x86\x93\x89\r\xa7\x1bC\x03\xe0\x1d\xebG\xbf\xd2\x0f`\x12\xc1\x06\xc4yhl\xc0\x14db\xe3{\xbf\x88\xcdf\xf9\xe7\xb9\x9d\x97\xd42\x93]\xe9\'\xfdJ?\xe1\xb0\x01A\xe0\xc4\x01\xf8\x9c\x89\r\x08&\x07\x80\xc5\xd9O\x81\x08\x00\xde\xd4\x8f~\xa5\x1f\xc0$\x82\r\x18\xce\xd0\xd8\x80)\x18\x1a\x9b\xcd\xf2\xefs;/\xa9e&\xbb\xd2O\xfa\x95~\xc2a\x03\x82\xc0\x89\x03\xf09\x13\x1b\x10L\x0e\x00\x8b\xb3\x9f\x02\x11\x00\xbc\xa9\x1f\xfdJ?\x80)\x1c\x1b\xfd\x84\xe4\xd0y\xec\xdb\xfeb\x9b[\x99\x8b\xb8\x01n\x9a\xdc\x1d6\xdc\r\x91\xcc\x92\x7f\xa8y\x0f\x00n\xfb\x0f5\x99\x00L(_"\xfb)\xdc\x13\xbd\x88\x1b\x1e\xda
print(zlib.decompress(sol)[int(input())]-97)

l=[100000 for i in range(100001)]
l[0]=0
dif=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
for i in range(1,100001):
	for j in dif:
		if j>i:
			break
		l[i]=min(l[i],l[i-j]+1)
n=int(input())
print(l[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):
a = int(input())
l1 = [6**i for i in range(7)]
l2 = [9**i for i in range(7)]
l = sorted(l1 + l2)
l.pop(0)
l.pop(-1)
cnt = 0
print(l)
while a != 0:
  print(a)
  for i in range(len(l)):
    if a - l[i] < 0:
      a -= l[i-1]
      cnt += 1
      break
    
print(cnt)

a = int(input())
l = [6**i for i in range(10) if 6**i < 10**5]
l += [9**i for i in range(10) if 9**i < 10**5]
l = sorted(list(set(l)))

ans = [10 ** 9 for i in range(a+1)]
ans[0] = 0

for i in range(a):
  for j in l:
#    print(j)
    if i + j <= a:
      ans[i+j] = min(ans[i] + 1, ans[i+j])

print(ans[a])

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):
# -*- coding: utf-8 -*-

N = int(input())

ans = N
for i in range(N // 9 + 1):
    nine = i * 9
    six = N - nine
    tmp_ans = 0
    print(nine, six)
    while nine > 0:
        tmp_ans += nine % 9
        nine = nine // 9
    while six > 0:
        tmp_ans += six % 6
        six = six // 6
    ans = min(tmp_ans, ans)

print(ans)


# -*- coding: utf-8 -*-

N = int(input())

ans = N
for i in range(N // 9 + 1):
    nine = i * 9
    six = N - nine
    tmp_ans = 0
    while nine > 0:
        tmp_ans += nine % 9
        nine = nine // 9
    while six > 0:
        tmp_ans += six % 6
        six = six // 6
    ans = min(tmp_ans, ans)

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):
A=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
N=int(input())
ans=0
while N!=0:
  N-=max([a for _ in A if A<=N])
  ans+=1
print(ans)

N=int(input())
dp=[float("INF")]*(N+2)
dp[0]=0
a,b,c=1,1,0
for i in range(1,N+1):
  if i==6*a:
    a*=6
  if i==9*b:
    b*=9
  dp[i]=min(dp[i],dp[i-1],dp[i-a],dp[i-b])+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())

def search(n,num):
    i = 1
    while True:
        if n < num**i:
            return i-1
        i += 1
        
ans = n
for i1 in range(0,6):
    for i2 in range(0,6):
        for i3 in range(0,6):
            for i4 in range(0,6):
                for i5 in range(0,6):
                    for i6 in range(0,6):
                            res = n
                            res -= (6**1)*i1+(6**2)*i2+(6**3)*i3+(6**4)*i4+(6**5)*i5+(6**6)*i6
                            if res > 0:
                                count = i1+i2+i3+i4+i5+i6
                                for i in reversed(range(1,6)):
                                    cnt = int(res / (9**i))
                                    res -= (9**i) * cnt
                                    count += cnt
                                if ans > count:
                                    ans = count
print(ans)

n = int(input())

def search(n,num):
    i = 1
    while True:
        if n < num**i:
            return i-1
        i += 1
        
ans = n
for i1 in range(0,6):
    for i2 in range(0,6):
        for i3 in range(0,6):
            for i4 in range(0,6):
                for i5 in range(0,6):
                    for i6 in range(0,6):
                        res = n
                        res -= (6**1)*i1+(6**2)*i2+(6**3)*i3+(6**4)*i4+(6**5)*i5+(6**6)*i6
                        if res >= 0:
                            count = i1+i2+i3+i4+i5+i6
                            while res > 6:
                                i = search(res,9)
                                cnt = int(res / (9**i))
                                res -= (9**i) * cnt
                                count += cnt
                            count += res
                            if ans > count:
                                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):
def tans(N, sei):
  import math
  sin = int(math.log(N,9))
  cos = int(math.log(N,6))
  count = sei
  if ((sin != 0) and (cos != 0)):
    if N < 15:
      if N >= 12:
        count += 2
        b2 = N - 12
        return tans(b2, count)
    elif (math.pow(9, sin) > math.pow(6,cos)):
      c = int(N - math.pow(9,sin))
      count += 1
      return tans (c, count)
    else:
      c2 = int(N - math.pow(6,cos))
      count += 1
      return tans (c2, count)
  else:
    count += N
    return count

n1 = int(input())
print(tans(n1, 0))

from itertools import count, takewhile, dropwhile
 
def dfs(n, max9, max6, d={0:0}):
    if n in d: 
      return d[n]
  
    max9 = next(dropwhile(lambda x: x>n, (max9 / 9**i for i in count())))
    max6 = next(dropwhile(lambda x: x>n, (max6 / 6**i for i in count())))
    d[n] = min(dfs(n-max9, max9, max6), dfs(n-max6, max9, max6)) + 1
    return d[n]
 
n = int(input())
 
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())))
 
print(dfs(n, max9, max6))


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())
count = 0
ans = []
for i in range(N+1):
    count1 = 0
    count2 = 0
    N1 = N - i
    x = i
    while x:
        count1 += x % 6
        x //= 6
    while N1
        count2 += x % 9
        N1 //= 9
    count = count1 + count2
    ans.append(count)
print(min(ans))


N = int(input())
count = 0
ans = []
for i in range(N+1):
    count1 = 0
    count2 = 0
    N1 = N - i
    x = i
    while x:
        count1 += x % 6
        x //= 6
    while N1
        count2 += N1 % 9
        N1 //= 9
    count = count1 + count2
    ans.append(count)
print(min(ans))


N = int(input())
count = 0
ans = []
for i in range(N+1):
    count1 = 0
    count2 = 0
    N1 = N - i
    x = i
    while x:
        count1 += x % 6
        x //= 6
    while N1:
        count2 += N1 % 9
        N1 //= 9
    count = count1 + count2
    ans.append(count)
print(min(ans))


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())
nums = [1]
def under_nums(N,m):
    nums = []
    i = 1
    while m**i <= N:
        nums.append(m**i)
        i += 1
    return nums
all_nums = nums+under_nums(N,6)+under_nums(N,9)
all_nums.sort(reverse=True)
print(all_nums)
cnt = 0
idx = 0
money = N
a = []
while money > 0:
    while money >= all_nums[idx]:
        #print(all_nums[idx])

        money -= all_nums[idx]
        a.append(all_nums[idx])
        #print("money="+str(money))
        cnt += 1
    idx += 1
print(cnt)
# print(a)
# print(sum(a))

N = int(input())
memo = [-1]*(N+1)
import sys
sys.setrecursionlimit(10**8)
def rec(n):
    if n == 0:return 0
    if memo[n] != -1:return memo[n]

    res = float('inf')

    pow6 = 1
    while pow6 <= n:
        res = min(res,rec(n-pow6)+1)
        pow6 *= 6

    pow9 = 1
    while pow9 <= n:
        res = min(res,rec(n-pow9)+1)
        pow9 *= 9

    memo[n] = res
    return memo[n]

print(rec(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())
ans = 0
a = [9**i for i in range(1, 6)]
b = [6**i for i in range(1, 7)]
ab = a+b
ab.sort(reverse=True)
while N >= 6:
    for i in ab:
        if N >= i:
            N = N - i
            ans += 1
            break
print(ans+N)
print(ans)
print(N)

N = int(input())

dp = [int(i) for i in range(N+1)]
B6 = [6**i for i in range(1,7)]
B9 = [9**i for i in range(1,6)]
L = B6 + B9
L = sorted(list(set(L)))

for i in L:
    for j in range(1, N+1):
        if j - i >= 0:
            dp[j] = min(dp[j], dp[j-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 = int(input())
ws = [1]
ws += [6**i for i in range(1, 8)]
ws += [9**i for i in range(1, 6)]
ws = sorted(set(ws))

print(ws)
INF = 10**5
dp = [INF] * (n+1)
dp[0] = 0
for i in range(n+1):
    for w in ws:
        if i + w <= n:
            dp[i+w] = min(dp[i]+1, dp[i+w])
print(dp[-1])

n = int(input())
ws = [1]
ws += [6**i for i in range(1, 8)]
ws += [9**i for i in range(1, 6)]
ws = sorted(set(ws))

INF = 10**5
dp = [INF] * (n+1)
dp[0] = 0
for i in range(n+1):
    for w in ws:
        if i + w <= n:
            dp[i+w] = min(dp[i]+1, dp[i+w])
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=int(input())
num6=6
num9=9
while num6<=n:
  l.append(num6)
  num6*=6
while num9<=n:
  l.append(num9)
  num9*=9
count=[0,1,2,3,4,5,1,2,3,1,2,3]
for i in range(12,n+1):
  min=100000
  for j in l:
    if i-j<0:
      pass
    else:
      if min>count[i-j]+1:
        min=count[i-j]+1
  count.append(min)
print(count[n])

l=[1]
for i in range(1,6):
  l.append(9**i)
for i in range(1,7):
  l.append(6**i)
l=sorted(l)
i=int(input())
c=0
for j in range(1,len(l)+1):
  if i>=l[-j]:
    i=i%l[-j]
    c+=i//l[-j]
  elif i==0:
    break
print(c)
    
  

  

n=int(input())
num6=6
num9=9
l=[]
while num6<=n:
  l.append(num6)
  num6*=6
while num9<=n:
  l.append(num9)
  num9*=9
count=[0,1,2,3,4,5,1,2,3,1,2,3]
for i in range(12,n+1):
  min=100000
  for j in l:
    if i-j<0:
      pass
    else:
      if min>count[i-j]+1:
        min=count[i-j]+1
  count.append(min)
print(count[n])


Verdicts: 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):
# coding: utf-8
# Your code here!
import math
from collections import defaultdict
 
N = int(input())
 
memo = defaultdict(lambda: -1)
memo[0] = 0
def recursive(n):
    if memo[n] != -1:
        return memo[n]
    
    min_num_operation = n
    
    index = 0
    temp_n = n
    while temp_n > 0:
        if temp_n % 9 == 0:
            index += 1
            temp_n /= 9
        else:
            break
    if index > 0:
        min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(9, index))))
        
    index = 0
    temp_n = n
    while temp_n > 0:
        if temp_n % 6 == 0:
            index += 1
            temp_n /= 6
        else:
            break
    if index > 0:
        min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(6, index))))
        
    memo[n] = min_num_operation
    
    return min_num_operation
 
print(recursive(N))

# coding: utf-8
# Your code here!
import math
from collections import defaultdict
 
N = int(input())
 
memo = defaultdict(lambda: -1)
memo[0] = 0
def recursive(n):
    if memo[n] != -1:
        return memo[n]
    
    min_num_operation = n
    
    index = 0
    temp_n = n
    while temp_n > 0:
        if temp_n % 9 == 0:
            index += 1
            temp_n //= 9
        else:
            index += int(math.log(temp_n, 9))
            break
    if index > 0:
        min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(9, index))))
        
    index = 0
    temp_n = n
    while temp_n > 0:
        if temp_n % 6 == 0:
            index += 1
            temp_n //= 6
        else:
            index += int(math.log(temp_n, 6))
            break
    if index > 0:
        min_num_operation = min(min_num_operation, 1 + recursive(int(n - math.pow(6, index))))
        
    memo[n] = min_num_operation
    
    return min_num_operation
 
print(recursive(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())
k=[59049,46646,7776,6561,1296,729,216,81,36,9,6]
c=0
while n>6:
  for i in k:
    if n-i>0:
      n=n-i
      c+1
c+=n
print(n)

n=int(input())
b=[1,6,36,216,1296,7776,46656]
q=[9,81,729,6561,59049]
d=[100000]*(n+1)
d[0]=0
for i in range(n):
  for j in b:
    if i+j<=n:
      d[i+j]=min(d[i+j],d[i]+1)
  for k in q:
    if i+k<=n:
      d[i+k]=min(d[i+k],d[i]+1)
print(d[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') for i in range(N+1)] for j in range(3)]
dp[0][0] = 0
dp[2][0]= 0
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(nine,0,-1):
    dp[1][9**i] = 1
    x= (9**i)
    for j in range(x,N+1):
        dp[1][j] = min(dp[1][j],dp[1][j-x]+1)
for i in range(1,six+1):
    dp[2][6**i] = 1
    x= (6**i)
    for j in range(N+1):
        if j >= 9:
            dp[2][j] = min(dp[2][j],dp[2][j-x]+1)
        if j >= x:
            dp[2][j] = min(dp[2][j],dp[1][j-x]+1)
print(dp)
ans = dp[2][N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[2][N-i]+i)
print(ans)


N = int(input())
dp = [float('inf') for i in range(N+1)]
dp[0] = 0
if N >= 6:
    dp[6] = 1
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(six,0,-1):
    for j in range(N+1):
        if j - 6**i >= 0:
            dp[j] = min(dp[j],dp[j-6**i]+1)
        if j - 9**i >= 0:
            dp[j] = min(dp[j],dp[j-9**i]+1)       
ans = dp[N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[N-i]+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())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in x61:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)    

n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in l6:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
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())
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)


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

N = int(input())
n6 = 1
n9 = 1
li = []
while 9**n9 <= N:
    li.append(9**n9)
    n9 += 1
while 6**n6 <= N:
    li.append(6**n6)
    n6 += 1

li.sort()
INF = 10**10

dp = [[i for i in range(N+1)] for i in range(len(li) + 1)]
dp = [i for i in range(N+1)]


for i,l in enumerate(li):
    for j in range(N+1):
        if j+l > N : continue
        dp[j+l] = min(dp[j+l], dp[j]+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 sys
sys.setrecursionlimit(10**9)

n=int(input())
maxn=110000
memo=[-1 for i in range(maxn)]
def rec(n):
    if n==0:
        return 0
    if memo[n]!=-1:
        return memo[n]
    res=n
    i=1
    while i<=n:
        res=min(res,rec(n-i)+1)
        i*=6
    j=1
    while i<=n:
        res=min(res,rec(j-i)+1)
        j*=9
    memo[n]=res
    return memo[n]
print(rec(n))

n=int(input())
maxn=110000
dp=[n for i in range(maxn)] 
dp[0]=0
for i in range(n): 
    pow6=1
    while i+pow6<=n:
        dp[i+pow6]=min(dp[i+pow6],dp[i]+1)
        pow6*=6
    pow9=1
    while i+pow9<=n:
        dp[i+pow9]=min(dp[i+pow9],dp[i]+1)
        pow9*=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())
ans=0
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
    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

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

n9=9**5
n6=6**6

k9=5+1
k6=6+1
n9=9**k9
smin=n
for i9 in range(n9):
    ii9=i9
    s=0
    m=0
    astr=""
    for ii in range(1,k9+1):
        r9=ii9%9
        ii9=(ii9-r9)//9    
        s=s*9+r9
        m=m+r9
        astr=astr+str(r9)
#    print("i9",i9,"astr",astr,"s",s,"m",m)
    
    nr=n-s
    nr1=nr
#    print("nr",nr,"m",m)
    
    if nr==0:
        snra=m
#        print(nr,m)
    elif nr>0:
        snra=m
        for jj in range(k6,-1,-1):
            nra=nr1//(6**jj)
            nr1=nr1%(6**jj)
            snra=snra+nra

    if smin>snra:
        smin=snra
print(smin)

n=int(input())

#n=44852
n9=9**5
n6=6**6

#n9=9**3
#n6=6**4

k9=5
k6=6
n9=9**k9
smin=n
for i9 in range(n9):
    ii9=i9
    s=0
    m=0
    astr=""
    for ii in range(1,k9+1):
        r9=ii9%9
        ii9=(ii9-r9)//9    
        s=s*9+r9
        m=m+r9
        astr=astr+str(r9)
#    print("i9",i9,"astr",astr,"s",s,"m",m)
    
    nr=n-s
    nr1=nr
#    print("nr",nr,"m",m)
    
    if nr<=0:
        print(m)
    else:
        snra=m
        for jj in range(k6,-1,-1):
            nra=nr1//(6**jj)
            nr1=nr1%(6**jj)
            snra=snra+nra

        if smin>snra:
            smin=snra
        print(smin)

n=int(input())

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

print(res)


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted