ZhenlongDai/ACPR huggingface dataset:
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
res = n
for i in range(n):
    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)


Failing test case input:
24408

Expected output:
8


Actual output:
9


Fixed submission (verdict: Accepted):
n = int(input())
res = n
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)

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
dp = [10**15] * 1000000
dp[1] = 1
for i in range(1,N + 1):
    dp[i + 1] = min (dp[i] + 1 , dp[i + 1])
    for k in range(1,7):
        dp[i + 6 ** k ] = min (dp[i] + 1 ,dp[i + 6 ** k ])
    for k in range(1, 7):
        dp[i + 9 ** k] = min(dp[i] + 1, dp[i + 9 ** k])
print(dp[N])

Failing test case input:
879

Expected output:
6


Actual output:
9


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

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

tannis = [1]

i = 1
while 6**i < N:
    tannis.append(6**i)
    i += 1

i = 1
while 9**i < N:
    tannis.append(9**i)
    i += 1

tannis.sort(reverse=True)


count = 0
i = 0
while N > 0:
    if N >= tannis[i]:
        count += N 
        N = N % tannis[i]
    else:
        i += 1

print(count)


Failing test case input:
34020

Expected output:
5


Actual output:
37395


Fixed submission (verdict: Accepted):
N = int(input())
tannis = [1]

i = 1
while 6**i <= N:
    tannis.append(6**i)
    i += 1

i = 1
while 9**i <= N:
    tannis.append(9**i)
    i += 1

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

for i in range(1, N+1):
    for t in tannis:
        if i-t >= 0:
            dp[i] = min(dp[i], dp[i-t]+1)


print(dp[N])

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
dp=[float("inf")]*(n+1)
dp[0]=0
for i in range(n):
    for j in range(1,7):
        j=6**j
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    for j in range(1,6):
        j=9**j
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    dp[i+1]=min(dp[i+1],dp[i]+1)

Failing test case input:
1214

Expected output:
8


Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
dp=[float("inf")]*(n+1)
dp[0]=0
for i in range(n):
    for j in range(1,7):
        j=6**j
        if i+j<n+1:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    for j in range(1,6):
        j=9**j
        if i+j<n+1:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    dp[i+1]=min(dp[i+1],dp[i]+1)
print(dp[-1])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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


Failing test case input:
4632

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):


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

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)
        
INF = float("inf")
dp=[INF]*(N)
dp[0]=1

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

print(dp[-1])

Failing test case input:
27198

Expected output:
7


Actual output:
10


Fixed submission (verdict: Accepted):
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)

        
INF = float("inf")
dp=[INF]*(N+1)
dp[0]=0

for i in range(N+1):
    for j in AA:
        if i>=j:
            dp[i]=min(dp[i-j]+1,dp[i])
        else:
            dp[i]=dp[i]
    

print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
ans = N

for N1 in range(N):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = int(N1/6)
    
    while N2 > 0:
        count += N2%9
        N2 = int(N2/9)
    
    if ans > count:
        ans = count

print(ans)

Failing test case input:
4152

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
ans = N

for N1 in range(N+1):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = int(N1/6)
    
    while N2 > 0:
        count += N2%9
        N2 = int(N2/9)
    
    if ans > count:
        ans = count

print(ans)
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
can=set()

can.add(1)
i=1
ans=0
while True:
  ans=6**i
  if ans<=100000:
    can.add(ans)
    i+=1
  else:
    break
    
j=1
ans=0
while True:
  ans=9**j
  if ans<=100000:
    can.add(ans)
    j+=1
  else:
    break

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

for k in range(2,N+1):
  mini=1000000
  for item in can:
    if k-item>=1:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])

Failing test case input:
34020

Expected output:
5


Actual output:
14


Fixed submission (verdict: Accepted):
N=int(input())
can=set()

can.add(1)
i=1
ans=0
while True:
  ans=6**i
  if ans<=100000:
    can.add(ans)
    i+=1
  else:
    break
    
j=1
ans=0
while True:
  ans=9**j
  if ans<=100000:
    can.add(ans)
    j+=1
  else:
    break

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

for k in range(2,N+1):
  mini=10000000
  for item in can:
    if k-item>=0:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
dp=[float("inf")]*(n+1)
dp[0]=0
for i in range(n):
    for j in range(1,7):
        j=6**j
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    for j in range(1,6):
        j=9**j
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    dp[i+1]=min(dp[i+1],dp[i]+1)
print(dp[-1])

Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
n=int(input())
dp=[float("inf")]*(n+1)
dp[0]=0
for i in range(n):
    for j in range(1,7):
        j=6**j
        if i+j<n+1:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    for j in range(1,6):
        j=9**j
        if i+j<n+1:
            dp[i+j]=min(dp[i+j],dp[i]+1)
    dp[i+1]=min(dp[i+1],dp[i]+1)
print(dp[-1])

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)
        
INF = float("inf")
dp=[INF]*(N)
dp[0]=1

for i in range(N):
    for j in AA:
        if i>=j:
            dp[i]=min(dp[i-j]+1,dp[i])
        else:
            dp[i]=dp[i]
    

print(dp[-1])

Failing test case input:
9627

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())

A = []
for i in range(20):
    if 6**i<=N:
        A.append(6**i)
for i in range(1,20):
    if 9**i<=N:
        A.append(9**i)
AA = sorted(A,reverse=True)

        
INF = float("inf")
dp=[INF]*(N+1)
dp[0]=0

for i in range(N+1):
    for j in AA:
        if i>=j:
            dp[i]=min(dp[i-j]+1,dp[i])
        else:
            dp[i]=dp[i]
    

print(dp[-1])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import log
n = int(input())


def make_list(n, x):
    return [x ** i for i in range(1, int(log(n, x))+1)]


sixes = make_list(n, 6)
nines = make_list(n, 9)
nums = [1] + sixes + nines

dp = [float('inf')] * (n+1)
for num in nums:
    for i in range(1, n+1):
        if i <= num:
            dp[i] = min(dp[i], num)
        else:
            dp[i] = min(dp[i], dp[i-num]+1)
print(dp[n])


Failing test case input:
4632

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
from math import log
n = int(input())










nums = [1]
i = 1
num = 1
while num <= n:
    num = 6 ** i
    nums.append(num)
    i += 1
i = 1
num = 1
while num <= n:
    num = 9 ** i
    nums.append(num)
    i += 1


dp = [float('inf')] * (n+1)
dp[0] = 0
for num in nums:
    for i in range(1, n+1):
        if i >= num:
            dp[i] = min(dp[i], dp[i-num]+1)
print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left

n = int(input())

six = [0] + [6**i for i in range(7)]
nine = [0] + [9**i for i in range(6)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_left(six, i)
    if j: dp[i] = min(dp[i], dp[i-six[j-1]] + 1)
    k = bisect_left(nine, i)
    if k: dp[i] = min(dp[i], dp[i-nine[k-1]] + 1)

print(dp[-1])


Failing test case input:
5907

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())

six = [0] + [6**i for i in range(1,8)]
nine = [0] + [9**i for i in range(1,7)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_right(six, i) - 1
    if j: dp[i] = min(dp[i], dp[i-six[j]] + 1)
    k = bisect_right(nine, i) - 1
    if k: dp[i] = min(dp[i], dp[i-nine[k]] + 1)

print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
tannis = [1]

i = 1
while 6**i < N:
    tannis.append(6**i)
    i += 1

i = 1
while 9**i < N:
    tannis.append(9**i)
    i += 1

dp = [float('inf') for _ in range(2*(N+1))]
dp[1] = 1

for i in range(2, N+1):
    for t in tannis:
        dp[i] = min(dp[i], dp[i-t]+1)

print(dp[N])



Failing test case input:
3840

Expected output:
7


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
tannis = [1]

i = 1
while 6**i <= N:
    tannis.append(6**i)
    i += 1

i = 1
while 9**i <= N:
    tannis.append(9**i)
    i += 1

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

for i in range(1, N+1):
    for t in tannis:
        if i-t >= 0:
            dp[i] = min(dp[i], dp[i-t]+1)


print(dp[N])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
dp=[10]*(n+1)
dp[0]=0
for i in range(n):
    power=1
    while i+power <= n:
        dp[i+power] = min(dp[i+power],dp[i]+1)
        power*=6
    power=1
    while i+power <= n:
        dp[i+power] = min(dp[i+power],dp[i]+1)
        power*=9
print(dp[n])

Failing test case input:
40994

Expected output:
11


Actual output:
10


Fixed submission (verdict: Accepted):
n=int(input())
dp=[float("inf") for _ in range(n+1)]
dp[0]=0
for i in range(n):
    power=1
    while i+power <= n:
        dp[i+power] = min(dp[i+power],dp[i]+1)
        power*=6
    power=1
    while i+power <= n:
        dp[i+power] = min(dp[i+power],dp[i]+1)
        power*=9
print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import os
import sys

def main():
    n = int(input())
    l1 = lis(n, 9)
    l2 = lis(n, 6)
    l1.extend(l2)
    l1 = list(set(l1))
    l1.sort(key=int, reverse=True)
    print(minus(n, l1))

def lis(n, i):
    count = 0
    res = []
    oi = i
    while i < n:
        res.append(i)
        i = i * oi
        count = count + 1
    return res

def minus(n, l):
    minus_count = 0
    for i in l:
        while n > i:
            if n - i > 0:
                n = n - i
                minus_count = minus_count + 1
            else:
                break
    return minus_count, n

if __name__ == '__main__':
    main()

Failing test case input:
58523

Expected output:
12


Actual output:
(8, 5)


Fixed submission (verdict: Accepted):


def main():
    n = int(input())
    li = dp(n)
    print(li[n])

def dp(n):
    inf=float('inf')
    dp = [inf for i in range(n+1)]
    dp[0] = 0
    money_list = get_money_list()
    for i in range(1, n + 1):
        for pay in money_list:
            if pay > i:
                continue
            else:
                dp[i] = min(dp[i - pay] + 1, dp[i])
    return dp

def create_list(n):
    i = 1
    money_list = []
    while i < 100000:
        money_list.append(i)
        i = i * n
    return money_list

def get_money_list():
    li = create_list(9)
    li.extend(create_list(6))
    li = list(set(li))
    li.sort(key=int, reverse=True)
    return li

if __name__ == '__main__':
    main()
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

yen9=[9**i for i in range(5)]
yen6=[6**i for i in range(6)]
yen1=[1]

def withdraw(n,count):
  if n ==0:
    return count

  maxmoney = 0
  for i in range(5):
    if yen9[i] <= n:
      maxmoney = max(yen9[i],maxmoney)
      
  for i in range(6):
    if yen6[i] <= n:
      maxmoney = max(yen6[i],maxmoney)
      
  if maxmoney ==0:
    maxmoney = 1
  print(maxmoney)
  return withdraw(n-maxmoney,count+1)

print(withdraw(n,0))

Failing test case input:
1477

Expected output:
5


Actual output:
1296
81
81
9
9
1
6


Fixed submission (verdict: Accepted):
n = int(input())

yen9=[9**i for i in range(6)]
yen6=[6**i for i in range(7)]
memo = {}

def withdraw_times(n):
  if n in memo:
    return memo[n]
  if n ==0:
    return 0

  maxmoney9 = 0
  maxmoney6 =0
  for i in range(6):
    if yen9[i] <= n:
      maxmoney9 = max(yen9[i],maxmoney9)
      
  for i in range(7):
    if yen6[i] <= n:
      maxmoney6 = max(yen6[i],maxmoney6)
      
  memo[n] =  min(withdraw_times(n-maxmoney6),withdraw_times(n-maxmoney9))+1
  return memo[n]

print(withdraw_times(n))

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N = int(input())

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

print(dp[-1] + 1)

Failing test case input:
27198

Expected output:
7


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
N = int(input())

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

print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
dp = [200000] * (n+10)
dp[0] = 0
dp[1] = 1
for i in range(1,n):
    dp[i+1] = min(dp[i+1], dp[i]+1)
    six = 6
    while i + six <= n:
        dp[i+six] = min(dp[i+six], dp[i]+1)
        six *= 6 

    nine = 9
    while i + nine <= n:
        dp[i+nine] = min(dp[i+nine], dp[i]+1)
        nine *= 9

print(dp[n])

Failing test case input:
345

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
dp = [200000] * (n+10)
dp[0] = 0

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

    nine = 9
    while i + nine <= n:
        dp[i+nine] = min(dp[i+nine], dp[i]+1)
        nine *= 9

print(dp[n])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
dp=list(range(N+1))

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

print(dp[N])

Failing test case input:
58523

Expected output:
12


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())
dp=list(range(N+1))

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

print(dp[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
dp=[i for i in range(n+1)]
k=0
lw=[6,9]
for w in lw:
    while w**k<=n:
        k+=1
        q=w**k
        for j in range(n+1-q):
            dp[j+q]=min(dp[j]+1,dp[j+q])
            if j==q*w:
                break
print(dp[n])

Failing test case input:
34020

Expected output:
5


Actual output:
10


Fixed submission (verdict: Accepted):
n=int(input())
dp=[i for i in range(n+1)]
lw=[6,9]
for w in lw:
    k=1
    while w**k<=n:
        q=w**k
        for j in range(n+1-q):
            dp[j+q]=min(dp[j]+1,dp[j+q])
        k+=1
print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
dp = [10**6 for i in range(n)]
dp[0] = 1

for i in range(1,n):
    dps = [dp[i-1]+1]
    for c in [6,9]:
        j = 0
        while True:
            j += 1
            if c**j > i:
                break
            else:
                dps += [dp[i-c**j]+1]
    
    dp[i] = min(dps)
    
print(dp[n-1])

Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
n = int(input())
dp = [-1 for i in range(n+1)]
c = [1]
for i in [6,9]:
    c += [i**j for j in range(1,10) if i**j <=10**5]

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

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

N = int(input())



table = [i for i in range(0, N  + 1)]  

for base in (6, 9):  
  unit = base  
  while unit <= N:
    for i in range(N + 1):
      table[i] = min(
        table[i],
        table[i - unit] + 1
      )
    
    unit *= base

print(table[N])    

Failing test case input:
9670

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
import sys

N = int(input())



table = [i for i in range(0, N  + 1)]  

for base in (6, 9):  
  unit = base  
  while unit <= N:
    for i in range(unit, N + 1):
      table[i] = min(
        table[i],
        table[i - unit] + 1
      )
    
    unit *= base

print(table[N])
Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

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

pow6 = [6**i for i in range(1,8)]
pow9 = [9**i for i in range(1,7)]

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

print(dp[-1])


Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())

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

pow6 = [6**i for i in range(1,8)]
pow9 = [9**i for i in range(1,7)]



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


print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

yen9=[9**i for i in range(5)]
yen6=[6**i for i in range(6)]
yen1=[1]

def withdraw(n,count):
  if n ==0:
    return count

  maxmoney = 0
  for i in range(5):
    if yen9[i] <= n:
      maxmoney = max(yen9[i],maxmoney)
      
  for i in range(6):
    if yen6[i] <= n:
      maxmoney = max(yen6[i],maxmoney)
      
  if maxmoney ==0:
    maxmoney = 1
  return withdraw(n-maxmoney,count+1)

print(withdraw(n,0))

Failing test case input:
3008

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())

yen9=[9**i for i in range(6)]
yen6=[6**i for i in range(7)]
memo = {}

def withdraw_times(n):
  if n in memo:
    return memo[n]
  if n ==0:
    return 0

  maxmoney9 = 0
  maxmoney6 =0
  for i in range(6):
    if yen9[i] <= n:
      maxmoney9 = max(yen9[i],maxmoney9)
      
  for i in range(7):
    if yen6[i] <= n:
      maxmoney6 = max(yen6[i],maxmoney6)
      
  memo[n] =  min(withdraw_times(n-maxmoney6),withdraw_times(n-maxmoney9))+1
  return memo[n]

print(withdraw_times(n))

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
INF = 50000000000000000
dp = [INF for i in range(n+1)]
dp[1] = 1
if n >= 6:
    dp[6] = 1
if n >= 9:
    dp[9] = 1
for i in range(1, n+1):
    for j in range(7):
        if i - 6**j >= 0:
            dp[i] = min(dp[i], dp[i - 6**j] + 1)
    for j in range(6):
        if i - 9**j >= 0:
            dp[i] = min(dp[i], dp[i - 9**j] + 1)
print(dp[n])




Failing test case input:
32841

Expected output:
6


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())

dp = [i for i in range(n+1)]
dp[1] = 1
if n >= 6:
    dp[6] = 1
if n >= 9:
    dp[9] = 1
for i in range(1, n+1):
    for j in range(7):
        if i - 6**j >= 0:
            dp[i] = min(dp[i], dp[i - 6**j] + 1)
    for j in range(6):
        if i - 9**j >= 0:
            dp[i] = min(dp[i], dp[i - 9**j] + 1)
print(dp[n])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
dp = [100000000000 for _ in range(n+1)]
dp[0] = 0
for i in range(n):
    dp[i+1] = min(dp[i]+1,dp[i+1])
    six = 0
    nine = 0
    while (6**six <= i):
        dp[i+1] = min(dp[(i+1) - 6**six] + 1,dp[i+1])
        six += 1
    while (9**nine <= i):
        dp[i+1] = min(dp[(i+1) - 9**nine] + 1,dp[i+1])
        nine += 1
print(dp[-1])

Failing test case input:
5907

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
dp = [100000000000 for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
    dp[i] = min(dp[i-1]+1,dp[i])
    six = 0
    nine = 0
    while (6**six <= i):
        dp[i] = min(dp[i - 6**six] + 1,dp[i])
        six += 1
    while (9**nine <= i):
        dp[i] = min(dp[i - 9**nine] + 1,dp[i])
        nine += 1
print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left

n = int(input())

six = [0] + [6**i for i in range(1,8)]
nine = [0] + [9**i for i in range(1,7)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_left(six, i) - 1
    if j: dp[i] = min(dp[i], dp[i-six[j]] + 1)
    k = bisect_left(nine, i) - 1
    if k: dp[i] = min(dp[i], dp[i-nine[k]] + 1)

print(dp[-1])


Failing test case input:
9627

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())

six = [0] + [6**i for i in range(1,8)]
nine = [0] + [9**i for i in range(1,7)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_right(six, i) - 1
    if j: dp[i] = min(dp[i], dp[i-six[j]] + 1)
    k = bisect_right(nine, i) - 1
    if k: dp[i] = min(dp[i], dp[i-nine[k]] + 1)

print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

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

Failing test case input:
24408

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())

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

for i in range(N+1):
    for l in L:
        if i+l <= N:
            X[i+l] = min(X[i] + 1, X[i+l])
        
print(X[-1])
Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())

INF = 100010
dp = [INF] * n
dp[0] = 1
for i in range(n):
    if i + 1 < n: dp[i + 1] = min(dp[i + 1], dp[i] + 1)
    
    j = 6
    while i + j < n:
        dp[i + j] = min(dp[i + j], dp[i] + 1)
        j *= 6
    
    j = 9
    while i + j < n:
        dp[i + j] = min(dp[i + j], dp[i] + 1)
        j *= 9

print(dp[n - 1])

Failing test case input:
32841

Expected output:
6


Actual output:
11


Fixed submission (verdict: Accepted):
n = int(input())

INF = 100010
dp = [INF] * (n + 1)
dp[0] = 0
for i in range(n + 1):
    if i + 1 <= n: dp[i + 1] = min(dp[i + 1], dp[i] + 1)
    
    j = 6
    while i + j <= n:
        dp[i + j] = min(dp[i + j], dp[i] + 1)
        j *= 6
    
    j = 9
    while i + j <= n:
        dp[i + j] = min(dp[i + j], dp[i] + 1)
        j *= 9

print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
dp = list(range(N+1))

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

Failing test case input:
66223

Expected output:
9


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
dp = list(range(N+1))

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

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline

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

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

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

dp[-1]

Failing test case input:
2105

Expected output:
7


Actual output:

Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline

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

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

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

print(dp[-1])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def run(n):
    cost = [6**i for i in range(6)]
    cost.extend([9**i for i in range(1, 5)])
    cost = sorted(cost)
    
    dp = {0: 0}
    for i in range(1, n+1):
        if i in cost:
            dp[i] = 1
        else:
            dp[i] = dp[i-1] + 1
        for c in cost:
            if i >= c:
                dp[i] = min(dp[i-c]+1, dp[i])
            else:
                break
    return dp[n]


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


if __name__ == '__main__':
    main()


Failing test case input:
66223

Expected output:
9


Actual output:
15


Fixed submission (verdict: Accepted):
def run(n):
    cost = [6**i for i in range(7)]
    cost.extend([9**i for i in range(1, 6)])
    cost = sorted(cost)
    
    
    dp = {0: 0}
    for i in range(1, n+1):
        dp[i] = dp[i-1] + 1
        for c in cost:
            if i >= c:
                dp[i] = min(dp[i-c]+1, dp[i])
            else:
                break
        
    return dp[n]


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


if __name__ == '__main__':
    main()

Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n=int(input())
    dp=[float("inf")]*(n+1)
    dp[0]=0
    for i in range(n):
        dp[i+1] = min(dp[i+1], dp[i]+1)
        j,k = 6,9
        while i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+1)
            j *= 6
        while i+k < n:
            dp[i+k] = min(dp[i+k], dp[i]+1)
            k *= 9
    print(dp[-1])

if __name__ == "__main__":
    main()

Failing test case input:
3840

Expected output:
7


Actual output:
12


Fixed submission (verdict: Accepted):
from functools import lru_cache

def main():
    n=int(input())
    dp=[float("inf")]*(n+1)
    dp[0]=0
    for i in range(n):
        dp[i+1] = min(dp[i+1], dp[i]+1)
        j,k = 6,9
        while i+j <= n:
            dp[i+j] = min(dp[i+j], dp[i]+1)
            j *= 6
        while i+k <= n:
            dp[i+k] = min(dp[i+k], dp[i]+1)
            k *= 9
    print(dp[-1])

if __name__ == "__main__":
    main()

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

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

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

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

print(DP[-1])


Failing test case input:
32841

Expected output:
6


Actual output:
11


Fixed submission (verdict: Accepted):
n = int(input())

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

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

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


print(DP[-1])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
dp=[0]*(N+1)
dp[1]=1

sixes=[6**(i) for i in range(1,7)]
nines=[9**(i) for i in range(1,6)]

for i in range(1,N):
  dp[i+1]=dp[i]+1
  
  for s in sixes:
    if i-s>=0:
      dp[i+1]=min(dp[i+1],dp[i+1-s]+1)
    else:
      break
      
  for n in nines:
    if i-n>=0:
      dp[i+1]=min(dp[i+1],dp[i+1-n]+1)
    else:
      break

print(dp[N])

Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
N=int(input())
inf=10**5
dp=[inf]*(N+1)
dp[0]=0

sixes=[6**(i) for i in range(1,7)]
nines=[9**(i) for i in range(1,6)]

for i in range(1,N+1):
  dp[i]=dp[i-1]+1
  
  for s in sixes:
    if i-s>=0:
      dp[i]=min(dp[i],dp[i-s]+1)
    else:
      break
      
  for n in nines:
    if i-n>=0:
      dp[i]=min(dp[i],dp[i-n]+1)
    else:
      break

print(dp[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
dp = list(range(N+1))
price = []
base = 1
while base<=100000:
    base *= 6
    price.append(base)
base = 1
while base<=100000:
    base *= 9
    price.append(base)

for i in range(2,N+1):
    for p in price:
        if p < i:
             temp = dp[i-p]
             if temp < dp[i-1] and temp+1 < dp[i]:
                 dp[i] = temp+1
print(dp[N])


Failing test case input:
32841

Expected output:
6


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())
dp = list(range(N+1))
price = [1]
base = 1
while base<=100000:
    base *= 6
    price.append(base)
base = 1
while base<=100000:
    base *= 9
    price.append(base)

for i in range(1,N+1):
    for p in price:
        if p == i:
            dp[i] = 1
            break
        elif p < i:
            temp = dp[i-p]
            if temp+1 < dp[i]:
                dp[i] = temp+1
print(dp[N])

Problem: p03329
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
Dp = [a for a in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1,7):
        if i > (6 ** j):
            Dp[i] = min(Dp[i], Dp[i-6**j] + 1)
    for h in range(1,6):
        if i > (9 ** h):
            Dp[i] = min(Dp[i], Dp[i-9**h] + 1)
print(Dp[N])    

Failing test case input:
24408

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
Dp = [a for a in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1,7):
        if i >= (6 ** j):
            Dp[i] = min(Dp[i], Dp[i-6**j] + 1)
    for h in range(1,6):
        if i >= (9 ** h):
            Dp[i] = min(Dp[i], Dp[i-9**h] + 1)
print(Dp[N])
Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
L = [1]
for i in range(N):
	if 6**(i+1) <=N:
		L.append(6**(i+1))
	if 9**(i+1) <= N:
		L.append(9**(i+1))
	if 9**(i+1) >N:
		break
L.sort(reverse =True)
dp = []
dp = [float("inf")]*(N+1)

dp[0] = 0

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

print(dp[N])


Failing test case input:
58523

Expected output:
12


Actual output:
15


Fixed submission (verdict: Accepted):
N = int(input())
L = [1]
for i in range(N):
	if 6**(i+1) <=N:
		L.append(6**(i+1))
	if 9**(i+1) <= N:
		L.append(9**(i+1))
	if 6**(i+1) >N:
		break
L.sort(reverse =True)
dp = []
dp = [float("inf")]*(N+1)

dp[0] = 0

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

print(dp[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n=int(input())
    mon6=[6]
    mon9=[1]
    for i in range(5):
        mon6.append(6*mon6[i])
        mon9.append(9*mon9[i])
    mon=mon6+mon9
    mon.sort()

    inf=10**9
    dp=[[inf]*n for i in range(13)]
    
    dp[0][0]=1
    for i in range(12):
        for j in range(n):
            if j-mon[i]>=0:
                dp[i+1][j]=min(dp[i+1][j-mon[i]]+1,dp[i][j])
            else:
                dp[i+1][j]=dp[i][j]
    print(dp[-1][-1]) 
if __name__=='__main__':
    main()

Failing test case input:
5907

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
def main():
    n=int(input())
    mon6=[6]
    mon9=[1]
    for i in range(5):
        mon6.append(6*mon6[i])
        mon9.append(9*mon9[i])
    mon=mon6+mon9
    mon.sort()
    
    
    inf=10**9
    dp=[[inf]*(n+1) for i in range(13)]
    
    for i in range(13):
      dp[i][0]=0
    for i in range(12):
        for j in range(1,n+1):
            if j-mon[i]>=0:
                dp[i+1][j]=min(dp[i+1][j-mon[i]]+1,dp[i][j])
            else:
                dp[i+1][j]=dp[i][j]
    print(dp[-1][-1]) 
if __name__=='__main__':
    main()

Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
INF=10**10
dp=[INF]*(N+1)
dp[0]=0
for i in range(N+1):
    if i<N: dp[i+1]=min(dp[i+1],dp[i]+1)
    j=1
    while i+6**j<N:
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
        j+=1
    j=1
    while i+9**j<N:
        dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
        j+=1
print(dp[N])

Failing test case input:
24408

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
N=int(input())
INF=10**10
dp=[INF]*(N+1)
dp[0]=0
for i in range(N+1):
    if i+1<=N: dp[i+1]=min(dp[i+1],dp[i]+1)
    j=1
    while i+6**j<=N:
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
        j+=1
    j=1
    while i+9**j<=N:
        dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
        j+=1
print(dp[N])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import math

def base_10_n(x,n):
    if x == 0:
        return 0
    tmpx = x
    a = int(math.log(x,n))
    ans = 0
    for i in range(a,-1,-1):
        ans += tmpx 
        tmpx %= n**i
    ans += tmpx
    return ans

def main():
    N = int(input())
    ans = N
    for j in range(N+1):
        c = base_10_n(N-j,6)
        d = base_10_n(j,9)
        ans = min(ans, c+d)
    print(ans)

if __name__ == "__main__":
    main()


Failing test case input:
4632

Expected output:
6


Actual output:
4632


Fixed submission (verdict: Accepted):

import math



def base_10_n(x, n):
    if x == 0:
        return 0
    tmpx = x
    a = int(math.log(x, n))
    ans = 0
    for i in range(a, -1, -1):
        ans += tmpx 
        tmpx %= n**i
    ans += tmpx
    return ans


def s(n, r):
    if n == 0:
        return 0
    return n % r + s(n 


def main():
    N = int(input())
    ans = 10**12
    for j in range(N+1):
        
        
        c = s(j,6)
        d = s(N-j,9)
        ans = min(ans, c+d)
    print(ans)


if __name__ == "__main__":
    main()

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left

n = int(input())

six = [0] + [6**i for i in range(1,7)]
nine = [0] + [9**i for i in range(1,6)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_left(six, i)
    if j: dp[i] = min(dp[i], dp[i-six[j-1]] + 1)
    k = bisect_left(nine, i)
    if k: dp[i] = min(dp[i], dp[i-nine[k-1]] + 1)

print(dp[-1])


Failing test case input:
5907

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())

six = [0] + [6**i for i in range(1,8)]
nine = [0] + [9**i for i in range(1,7)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_right(six, i) - 1
    if j: dp[i] = min(dp[i], dp[i-six[j]] + 1)
    k = bisect_right(nine, i) - 1
    if k: dp[i] = min(dp[i], dp[i-nine[k]] + 1)

print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
can=set()

can.add(1)
i=0
ans=0
while ans<=100000:
  ans=6**i
  can.add(ans)
  i+=1
j=0
ans=0
while ans<=100000:
  ans=9**j
  can.add(ans)
  j+=1

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

for k in range(2,N+1):
  mini=1000000
  for item in can:
    if k-item>=1:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])

Failing test case input:
345

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
N=int(input())
can=set()

can.add(1)
i=1
ans=0
while True:
  ans=6**i
  if ans<=100000:
    can.add(ans)
    i+=1
  else:
    break
    
j=1
ans=0
while True:
  ans=9**j
  if ans<=100000:
    can.add(ans)
    j+=1
  else:
    break

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

for k in range(2,N+1):
  mini=10000000
  for item in can:
    if k-item>=0:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])
Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def resolve():
    import sys
    
    readline = sys.stdin.readline

    def func(n: int, a: int):
        res = 0
        while n > 0:
            res += n % a
            n = int(n / a)
        return res

    N = int(readline())

    res = N
    for i in range(N):
        tmp = func(i, 6) + func(N - i, 9)
        res = min(res, tmp)
    print(res)

resolve()


Failing test case input:
4152

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
import sys


def resolve():
    readline = sys.stdin.readline

    def func(n: int, a: int):
        res = 0
        while n > 0:
            res += n % a
            n = int(n / a)
        return res

    N = int(readline())

    res = N
    for i in range(N + 1):
        tmp = func(i, 6) + func(N - i, 9)
        res = min(res, tmp)
    print(res)

resolve()

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[0]*(n+1)
six=0
nine=0
for i in range(1,n+1):
  if i>6**(six+1):
    six+=1
  if i>9**(nine+1):
    nine+=1
  a[i]=min(a[i-1],a[i-6**six],a[i-9**nine])+1
print(a[n])

Failing test case input:
345

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
n=int(input())
a=[0]*(n+1)
six=0
nine=0
for i in range(1,n+1):
  if i>=6**(six+1):
    six+=1
  if i>=9**(nine+1):
    nine+=1
  a[i]=min(a[i-1],a[i-6**six],a[i-9**nine])+1
print(a[n])

Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = [1]+[pow(6,i) for i in range(1,7)]+[pow(9,i) for i in range(1,6)]
D = [1]+[-1]*(n-1)
for i in range(1,n):
    D[i] = D[i-1]+1
    for j in range(1,7):
        if pow(6,j)>i: break
        D[i] = min(D[i], D[i-pow(6,j)]+1)
    for j in range(1,6):
        if pow(9,j)>i: break
        D[i] = min(D[i], D[i-pow(9,j)]+1)
print(D[-1])

Failing test case input:
34020

Expected output:
5


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
A = [1]+[pow(6,i) for i in range(1,7)]+[pow(9,i) for i in range(1,6)]
D = [0]+[-1]*n
for i in range(1,n+1):
    D[i] = D[i-1]+1
    for j in range(1,7):
        if pow(6,j)>i: break
        D[i] = min(D[i], D[i-pow(6,j)]+1)
    for j in range(1,6):
        if pow(9,j)>i: break
        D[i] = min(D[i], D[i-pow(9,j)]+1)
print(D[-1])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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


Failing test case input:
2028

Expected output:
5


Actual output:
100000


Fixed submission (verdict: Accepted):


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

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
INF = int(1e10)
dp = [INF] * N
dp[0] = 1

bt = set()
for i in range(1, 100):
    if 6**i > N:
        break
    bt.add(6**i)

for i in range(1, 100):
    if 9**i > N:
        break
    bt.add(9**i)

bt = sorted(bt)

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

Failing test case input:
24408

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
INF = int(1e10)
dp = [INF] * N
dp[0] = 1
dp = [0] + dp

bt = set()
for i in range(1, 100):
    if 6**i > N:
        break
    bt.add(6**i)

for i in range(1, 100):
    if 9**i > N:
        break
    bt.add(9**i)

bt = sorted(bt)

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

print(dp[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
c=0


dp=[100000000000000]*(n+1)
for i in range(1,min(6,n+1)):
    dp[i]=i

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

print(dp[n])

Failing test case input:
32841

Expected output:
6


Actual output:
11


Fixed submission (verdict: Accepted):
import math
n=int(input())



dp=[100000000000000]*(n+1)
dp[0]=0
for i in range(1,min(6,n+1)):
    dp[i]=i

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

print(dp[n])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


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

Failing test case input:
21570

Expected output:
9


Actual output:
12


Fixed submission (verdict: Accepted):
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)



dp = [10000000000] * 1008000
dp[0] = 0
for i in range(N):
    for x in X:
        dp[i+x] = min(dp[i]+1, dp[i+x])
print(dp[N])

Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())

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

print(min(nums))

Failing test case input:
4152

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())

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

print(min(nums))

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

dp = [0] * (n + 1)
for i in range(n):
     if i in range(6):
          dp[i+1] = i + 1
     else:
          j = 1
          k = 1
          a = [100000]
          b = [100000]
          while i + 1 - 6**j > 0:
              a += [dp[i + 1 - 6**j]]
              j += 1
          while i + 1 - 9**k > 0:
              b += [dp[i + 1 - 9**k]]
              k += 1
          dp[i + 1] = min(dp[i],min(a),min(b)) + 1
print(dp[n])


Failing test case input:
18666

Expected output:
8


Actual output:
11


Fixed submission (verdict: Accepted):
n = int(input())

dp = [0] * (n + 1)
for i in range(n):
     if i in range(5):
          dp[i+1] = i + 1
     else:
          j = 1
          k = 1
          a = [100001]
          b = [100001]
          while i + 1 - 6**j >= 0:
              a += [dp[i + 1 - 6**j]]
              j += 1
          while i + 1 - 9**k >= 0:
              b += [dp[i + 1 - 9**k]]
              k += 1
          dp[i + 1] = min(dp[i],min(a),min(b)) + 1
print(dp[n])