ZhenlongDai/ACPR huggingface dataset:
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

x,y = map(int,input().split())
input()

low = math.floor(x / (y - 1))
if ((y - 1) * low) + 1 >= x:
    print(low)
else:
    print(low + 1)

Failing test case input:
31 2
-4 3 -2 2

Expected output:
30


Actual output:
31


Fixed submission (verdict: Accepted):
import math

x,y = map(int,input().split())
input()

low = math.floor(x / (y - 1))
high = math.ceil(x / (y - 1))

if low == high:
    low = low - 1

if ((y - 1) * low) + 1 >= x:
    print(low)
else:
    print(low + 1)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int,input().split())
a = list(map(int,input().split()))
g=1
while k+(k-1)*(g-1)<= n:
  g+=1
print(g)

Failing test case input:
3 3
1 2 3

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
g=1
while k+(k-1)*(g-1)< n:
  g+=1
print(g)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split(" "))
a = map(int, input().split(" "))

print(int(N/2))

Failing test case input:
152 5
0 0 2 7

Expected output:
38


Actual output:
76


Fixed submission (verdict: Accepted):
import math

N, K = map(int, input().split(" "))
a = map(int, input().split(" "))



print(math.ceil((N - 1) / (K - 1)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
print(math.ceil(n/k))

Failing test case input:
37 3
0 11 -1 4

Expected output:
18


Actual output:
13


Fixed submission (verdict: Accepted):
import math
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
print(1+math.ceil((n-k)/(k-1)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(0,n,k-1):
    ans += 1
print(ans)

Failing test case input:
7 3
0 4 0 4

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(0,n,k-1):
    if i+1==n:
        break
    ans += 1
print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from math import floor
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

print(floor(n / (k-1)))

Failing test case input:
26 4
-8 3 1 6

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
import sys
from math import ceil
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

print(ceil((n-k)/(k-1))+1)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,k=map(int, input().split(" "))
A=input().split(" ")
print(math.ceil(n/(k-1)))


Failing test case input:
7 3
-1 3 0 4

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import math
n,k=map(int, input().split(" "))
A=input().split(" ")
print(math.ceil((n-1)/(k-1)))
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int,input().split())
a = list(map(int,input().split()))
ans =  n 
print(ans)

Failing test case input:
21 3
-1 4 0 6

Expected output:
10


Actual output:
21


Fixed submission (verdict: Accepted):
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))

print(math.ceil((n-1)/(k-1)))

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


import math
import sys

a,b = input().split(" ")

ans = int(a) / int(b)

print(math.ceil(ans))


Failing test case input:
167 4
1 0 4 7

Expected output:
56


Actual output:
42


Fixed submission (verdict: Accepted):


import math
import sys

a,b = input().split(" ")

ans = math.ceil((int(a)-1) / (int(b)-1))
print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

b, c  = [int(a) for a in input().split()]
print (math.ceil(b / ((c - 1) * 1.0)))

Failing test case input:
31 3
-2 6 0 6

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
import math

b, c  = [int(a) for a in input().split()]
print (math.ceil((b - 1) / ((c - 1) * 1.0)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))

if N<=K : num=1
else: num = (N-K)

print(num)

Failing test case input:
31 5
-8 3 1 6

Expected output:
8


Actual output:
26


Fixed submission (verdict: Accepted):
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))

num = ceil((N-1)/(K-1))

print(num)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


answer = N / (K - 1)

print(answer)


Failing test case input:
204 3
-1 2 1 6

Expected output:
102


Actual output:
102.0


Fixed submission (verdict: Accepted):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


answer = math.ceil((N - 1)/ (K - 1))

print(answer)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = int((n-k)/(k-1)+2)
print(ans)

Failing test case input:
57 3
-2 4 0 6

Expected output:
28


Actual output:
29


Fixed submission (verdict: Accepted):
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = math.ceil((n-1)/(k-1))
print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))

print(math.ceil((n-3)/(k-1))+1)

Failing test case input:
31 2
-4 3 -2 2

Expected output:
30


Actual output:
29


Fixed submission (verdict: Accepted):
import math
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
for i in range(len(a)):
    if a[i]==1:
        p1=i

print(math.ceil((n-k)/(k-1))+1)
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

print(round((N - 1) / (K - 1)))

Failing test case input:
90 3
-2 2 2 1

Expected output:
45


Actual output:
44


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

print(-(-(N - 1)

Problem: p03317
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
n, k = map(int,input().split())
input()
print((n-1)/(k-1), math.ceil((n - 1)/(k - 1)))


Failing test case input:
34 2
-1 4 0 1

Expected output:
33


Actual output:
33.0 33


Fixed submission (verdict: Accepted):
import math
n, k = map(int,input().split())
input()
print(math.ceil((n-1)/(k-1)))

Problem: p03317
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
N, K = map(int,input().split())
A = list(map(int,input().split()))
print(math.ceil(N/(K-1)))

Failing test case input:
8 2
14 5 1 4 2 6 2 5

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
import math
N, K = map(int,input().split())
A = list(map(int,input().split()))
print(math.ceil((N-1)/(K-1)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
A=list(map(int,input().split()))

Failing test case input:
130 4
1 1 0 2

Expected output:
43


Actual output:

Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
A=list(map(int,input().split()))
print((N-2)

Problem: p03317
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

n, k = map(int, input().split())
lis = list(map(int, input().split()))

if n == k:
    print(1)
else:
    print(math.ceil(n/(k-1)))

Failing test case input:
130 4
1 1 0 2

Expected output:
43


Actual output:
44


Fixed submission (verdict: Accepted):
import math

n, k = map(int, input().split())
lis = list(map(int, input().split()))

print(math.ceil((n-1)/(k-1)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print('1')
else:
    a=N
    print(a)


Failing test case input:
6 3
0 2 2

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print(1)
else:
    a=-(-(N-1)
    print(a)
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_min = min(A)
index = A.index(A_min)
ans = 0
left = index
right = N - 1 - index
if left % (K - 1) == 1:
    right -= 1
elif right % (K - 1) == 1:
    left -= 1
ans += math.ceil(left / (K - 1))
ans += math.ceil(right / (K - 1))   
print(ans)

Failing test case input:
130 4
1 1 0 2

Expected output:
43


Actual output:
44


Fixed submission (verdict: Accepted):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_min = min(A)
index = A.index(A_min)
ans = 0
left = index
right = N - 1 - index
if left % (K - 1) != 0:
    right -= K - 1 - left % (K - 1)
elif right % (K - 1) != 0:
    left -= K - 1 - right % (K - 1)
ans += math.ceil(left / (K - 1))
ans += math.ceil(right / (K - 1))   
print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N, K = map(int,input().split())
A = list(map(int,input().split()))
if N <= K:
  print(1)
else:
  print(math.floor(N / (K - 1) ))
  

Failing test case input:
13 2
-6 1 -4 1

Expected output:
12


Actual output:
13


Fixed submission (verdict: Accepted):
import math
N, K = map(int,input().split())
A = list(map(int,input().split()))
if N <= K:
  print(1)
else:
  print(math.ceil((N - K) / (K - 1)) + 1)

Problem: p03317
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=map(int,input().split())
List = list(map(int, input().split()))
k=K-1
n = (N-1)/k
nn = int(n)
if n-nn > 0:
  n = nn+1
print(n)

Failing test case input:
3 3
2 2 3

Expected output:
1


Actual output:
1.0


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
List = list(map(int, input().split()))
k=K-1
n = (N-1)/k
nn = int(n)
if n-nn > 0:
  nn = nn+1
print(nn)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print(1)
else:
    b=(N-K)
    print(b)

Failing test case input:
152 5
0 0 2 7

Expected output:
38


Actual output:
147


Fixed submission (verdict: Accepted):
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print(1)
else:
    a=-(-(N-1)
    print(a)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))
import math as m
if n==k:
    print(1)
else:
    print(1+m.ceil((n+1-k)/2))

Failing test case input:
31 3
-8 3 1 6

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
a = list(map(int,input().split()))
import math as m
if n==k:
    print(1)
else:
    print(1+m.ceil((n-k)/(k-1)))
Problem: p03317
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = (N-1)
print(ans)

Failing test case input:
31 4
-2 2 1 6

Expected output:
10


Actual output:
30


Fixed submission (verdict: Accepted):
import math

N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = math.ceil((N-1)/(K-1))  
print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
ans = math.ceil(n/(k-1))
print(ans)

Failing test case input:
7 3
-1 3 1 4

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
print(math.ceil((n-1)/(k-1)))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil


class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.a_s = list(map(int, input().split(" ")))

    def solve(self):
        if self.n == self.k:
            print(1)
        else:
            print(ceil(self.n / (self.k-1)))


if __name__ == "__main__":
    s = Solver()
    s.solve()

Failing test case input:
7 3
0 4 1 3

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from math import ceil


class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.a_s = list(map(int, input().split(" ")))

    def solve(self):
        print(ceil((self.n-self.k) / (self.k-1)) + 1)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))
print(int((N - 1) / (K - 1)) + (N - 1) % (K - 1))


Failing test case input:
128 6
35 6 2 5 0 5 2 5

Expected output:
26


Actual output:
27


Fixed submission (verdict: Accepted):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
print(math.ceil((N - 1) / (K - 1)))

Problem: p03317
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))

if N == K:
    print(1)
    exit()

print(ceil((N - K + 1) / (K - 1)) + 1)


Failing test case input:
63 2
-2 7 0 6

Expected output:
62


Actual output:
63


Fixed submission (verdict: Accepted):
from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))

if N == K:
    print(1)
    exit()


print(ceil((N - K) / (K - 1)) + 1)
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

min_idx = A.index(min(A))

count = N
for i in range(min_idx-K+1, min_idx+1):
    tmp = math.ceil(i/(K-1)) + math.ceil((N-(i+K))/(K-1))
    if count > tmp:
        count = tmp

print(tmp+1)

Failing test case input:
340 5
-1 2 -2 -1

Expected output:
85


Actual output:
86


Fixed submission (verdict: Accepted):
import math

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

min_idx = A.index(min(A))

count = N
start = max(0,min_idx-K+1)
end = min(start+K, N)
for i in range(start, end):
    tmp = math.ceil(i/(K-1)) + max(0, math.ceil((N-(i+K))/(K-1)))
    if count > tmp+1:
        count = tmp+1

print(count)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Len, Split = map(int, input().split())
_res = Len % Split
if _res:
    res = int((Len / Split) + 1)
    print(res)
else:
    res = int(Len / Split)
    print(res)

Failing test case input:
32 3
-1 4 0 1

Expected output:
16


Actual output:
11


Fixed submission (verdict: Accepted):
Len, Split = map(int, input().split())
_res = (Len - 1) % (Split - 1)
if _res:
    res = int(((Len - 1) 
    print(res)
else:
    res = int((Len - 1) 
    print(res)

Problem: p03317
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
if N == K:
    print(1)
elif K == 2:
    print(N-1)
else:
    ans = ceil(N/(K-1))
    print(ans)


Failing test case input:
41 3
-2 6 0 6

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
if N == K:
    print(1)
elif (N-1)%(K-1) == 0:
    print((N-1)
elif K == 2:
    print(N-1)
else:
    ans = ceil(N/(K-1))
    print(ans)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
l=list(map(int,input().split()))
print(-(-int(len(l)-m/m-1)))

Failing test case input:
200 4
0 0 -1 0

Expected output:
67


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split()) 
l=list(map(int,input().split())) 
print(-(-(len(l)-m)

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
A=list(map(int,input().split()))
print((N-K)%2+2)

Failing test case input:
63 2
-2 7 0 6

Expected output:
62


Actual output:
3


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
A=list(map(int,input().split())) 
if (N-K)%(K-1)==0:
  print((N-K)
else:
  print((N-K)
Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N ,K = map(int,input().split())
L = list(map(int,input().split()))
def ceil(x):
    if x == int(x):
        return x
    else:
        return int(x) + 1


cnt = 0

N = N - K 
cnt += 1
if N > 0:
    cnt += ceil(N / (K-1))
print(cnt)

Failing test case input:
37 3
0 11 -1 4

Expected output:
18


Actual output:
18.0


Fixed submission (verdict: Accepted):
N ,K = map(int,input().split())
L = list(map(int,input().split()))
def ceil(x):
    if x == int(x):
        return x
    else:
        return int(x) + 1


cnt = 0

N = N - K 
cnt += 1
if N > 0:
    cnt += ceil(N / (K-1))
print(int(cnt))

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, K = [int(x) for x in input().strip().split()]
    line = [int(x) for x in input().strip().split()]
    counter = 0
    result = 0
    while counter < N:
        counter += K - 1
        result += 1
    print(result)


if __name__ == '__main__':
    main()


Failing test case input:
130 4
1 1 0 2

Expected output:
43


Actual output:
44


Fixed submission (verdict: Accepted):
def main():
    N, K = [int(x) for x in input().strip().split()]
    line = [int(x) for x in input().strip().split()]
    counter = K - 1
    result = 0
    while counter < N:
        counter += K - 1
        result += 1
    if counter - (K - 1) < N - 1:
        result += 1
    print(result)


if __name__ == '__main__':
    main()

Problem: p03317
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
A = [int(i) for i in input().split()]

print(int(N/(K-1)))



Failing test case input:
31 8
-2 2 0 6

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import math

N,K = map(int,input().split())
A = [int(i) for i in input().split()]

res = math.ceil((N-1)/(K-1))

print(int(res))
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

print(dp[N])

Failing test case input:
44852

Expected output:
16

Actual output:
19


Fixed submission (verdict: Accepted):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

print(dp[N])

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/=6
        t = int(t)
    t = n-i
    while(t>0):
        cc+=t%9
        t/=9
        t=int(t)
    if res > cc:
        res =cc
print(res)


Failing test case input:
4152

Expected output:
7


Actual output:
8


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 = 127
inf = float('inf')

dp = [inf]*(n+1000000)
dp[0]=0



def motome(target):
    tmp = []
    a = int(math.log(target,9))
    b = int(math.log(target,6))
    for i in range(a+1):
        tmp.append(9**i)
    for j in range(b+1):
        tmp.append(6**j)
    
    
    
    for k in range(target+1):
        for t in sorted(list(set(tmp))):
            if k-t>=0:
                dp[k] = min(dp[k],1 + dp[k-t])
                
                
        
        
        

motome(n)

print(dp[n])

Failing test case input:
16463

Expected output:
9


Actual output:
4


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

inf = float('inf')

dp = [inf]*(n+100000)
dp[0]=0



def motome(target):
    tmp = []
    for i in range(10):
        if 9**i <= n:
            tmp.append(9**i)
        if 6**i <= n:
            tmp.append(6**i)
    
    
    
    for k in range(target+1):
        for t in sorted(list(set(tmp))):
            if k-t>=0:
                dp[k] = min(dp[k],1 + dp[k-t])
                
                
        
        
        

motome(n)

print(dp[n])

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

Failing test case input:
24408

Expected output:
8


Actual output:
2219


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

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

Failing test case input:
135433

Expected output:
10


Actual output:
[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
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.8.2), verdict: Wrong Answer):
N = int(input())

dp=[0]*N
for i in range(10):
  if 6**i-1 <= N:
    dp[6**i-1] = 1
for i in range(10):
  if 9**i-1 <= N:
    dp[9**i-1] = 1


for k in range(1,N):
  dp_list = []
  for j in range(10):
    if k >= 6**j:
      dp_list.append(dp[k-6**j])
    if k >= 9**j:
      dp_list.append(dp[k-9**j])
  
  dp[k] = 1+min(dp_list)

print(dp[N-1]%1000000007)

Failing test case input:
18666

Expected output:
8


Actual output:
11


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

dp=[0]*N
for i in range(10):
  if 6**i-1 < N:
    dp[6**i-1] = 1
for i in range(10):
  if 9**i-1 < N:
    dp[9**i-1] = 1


for k in range(1,N):
  if dp[k] != 1:
    dp_list = []
    for j in range(10):
      if k >= 6**j:
        dp_list.append(dp[k-6**j])
      if k >= 9**j:
        dp_list.append(dp[k-9**j])
  
    dp[k] = 1+min(dp_list)

print(dp[N-1]%1000000007)

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-1):
    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:
1214

Expected output:
8


Actual output:
inf


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 = [i for i in range(n+1)]

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

Failing test case input:
34020

Expected output:
5


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
dp = [i for i in range(n+1)]

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

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

for i in range(n):
    c = 0
    t = i
    while t>0:
        c += t%6
        t = int(t/6)

    t = n-i

    while t>0:
        c += t%9
        t = int(t/9)

    if res>c:
        res = c


print(res)


Failing test case input:
4152

Expected output:
7


Actual output:
8


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

for i in range(n+1):
    c = 0
    t = i
    while t>0:
        c += t%6
        t = int(t/6)

    t = n-i

    while t>0:
        c += t%9
        t = int(t/9)

    if res>c:
        res = c


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

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

print(result)
        

Failing test case input:
24408

Expected output:
8


Actual output:
9


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

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

print(result)

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

lst = []
for i in range(7):
    lst.append(6 ** i)
for j in range(1, 5):
    lst.append(9 ** j)
lst.sort()

DP = [_ for _ in range(N + 1)]
DP[0] = 0

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

print(DP[N])


Failing test case input:
135433

Expected output:
10


Actual output:
12


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

lst = []
for i in range(10):
    if 6 ** i > 100000:
        break
    lst.append(6 ** i)
for j in range(1, 9):
    if 9 ** j > 100000:
        break
    lst.append(9 ** j)

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

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

print(DP[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)

def rec(n, dp):
	if n == 1:
		return 1
	if dp[n] < float('inf'):
		return dp[n]
	pow6 = 6
	pow9 = 9
	dp[n] = min(n, dp[n])
	while n > pow6:
		dp[n] = min(dp[n], rec(n-pow6, dp) + 1)
		pow6 *= 6
	while n > pow9:
		dp[n] = min(dp[n], rec(n-pow9, dp) + 1)
		pow9 *= 9
	return dp[n]

def resolve():
	n = int(input())
	dp = [float('inf')]*(n+1)
	print(rec(n, dp))
resolve()

Failing test case input:
9627

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)

def rec(n, dp):
	if n <= 1:
		return n
	if dp[n] < float('inf'):
		return dp[n]
	pow6 = 6
	pow9 = 9
	dp[n] = min(n, dp[n])
	while n >= pow6:
		dp[n] = min(dp[n], rec(n-pow6, dp) + 1)
		pow6 *= 6
	while n >= pow9:
		dp[n] = min(dp[n], rec(n-pow9, dp) + 1)
		pow9 *= 9
	return dp[n]

def resolve():
	n = int(input())
	dp = [float('inf')]*(n+1)
	print(rec(n, dp))
resolve()
Problem: p03329
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
dp=[float("inf")]*n
dp[0]=1
for i in range(n-1):
    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:
3840

Expected output:
7


Actual output:
12


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())
count = 0

values = [1]

for i in range(1, 7):
    values.append(6**i)
    values.append(9**i)

values.sort()


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

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

print(dp[N])


Failing test case input:
345

Expected output:
5


Actual output:
7


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

values = [1]

for i in range(1, 7):
    values.append(6**i)
    values.append(9**i)

values.sort()


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

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

print(dp[N])

Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    return n

def main(n):
    dp=[INFTY]*(n+1)
    dp[0]=0
    dp[1]=1
    for i in range(2,n+1):
        dp[i]=min(dp[i],dp[i-1]+1)  
        k=1
        while(i-6**k>0):
            dp[i]=min(dp[i],dp[i-6**k]+1)
            k+=1
        k=1
        while(i-9**k>0):
            dp[i]=min(dp[i],dp[i-9**k]+1)
            k+=1
    return dp[n]

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Failing test case input:
5907

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    return n

def main(n):
    dp=[INFTY]*(n+1)
    dp[0]=0
    dp[1]=1
    for i in range(2,n+1):
        dp[i]=min(dp[i],dp[i-1]+1)  
        k=1
        while(i-6**k>=0):
            dp[i]=min(dp[i],dp[i-6**k]+1)
            k+=1
        k=1
        while(i-9**k>=0):
            dp[i]=min(dp[i],dp[i-9**k]+1)
            k+=1
    return dp[n]

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)
Problem: p03329
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

patterns = []
patterns.append(1)

f = 6
a = 6
while a <= N:
    patterns.append(a)
    a *= f

f = 9
a = 9
while a <= N:
    patterns.append(a)
    a *= f

dp = [float('inf')] * (N + 1)
dp[0] = 0
for n in range(1, N + 1):
    for p in patterns:
        if n - p < 0:
            break

        dp[n] = min(dp[n - p] + 1, dp[n])


print(dp[-1])


Failing test case input:
32841

Expected output:
6


Actual output:
8


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

patterns = []
patterns.append(1)

f = 6
a = 6
while a <= N:
    patterns.append(a)
    a *= f

f = 9
a = 9
while a <= N:
    patterns.append(a)
    a *= f

dp = [float('inf')] * (N + 1)
dp[0] = 0
for n in range(1, N + 1):
    for p in patterns:
        if n - p < 0:
            continue

        dp[n] = min(dp[n - p] + 1, dp[n])


print(dp[-1])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[1, 6, 36, 216, 1296, 7776, 46656]
b=[1, 9, 81, 729, 6561, 59049]
def ab_cal(num,arr):
  i=len(arr)-1
  cnt1=0
  while num>0:
    if arr[i]<=num:
      num-=arr[i]
      cnt1+=1
    else:
      i-=1
  return cnt1

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

Failing test case input:
4152

Expected output:
7


Actual output:
8


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

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

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
for i in [6,9]:
    j = 1
    while i**j<100000:
        a.append(i**j)
        j += 1
a.sort()
dp = [i for i in range(n+1)]
dp[0]= 0
for c in a:
    for i in range(c+1,n+1):
        dp[i] = min(dp[i-c]+1, dp[i])
print(dp[n])


Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
n = int(input())
a = []
for i in [6,9]:
    j = 1
    while i**j<1000000:
        a.append(i**j)
        j += 1
a.sort()
dp = [i for i in range(n+1)]
dp[0]= 0
for c in a:
    for i in range(c,n+1):
        dp[i] = min(dp[i-c]+1, dp[i])
print(dp[n])
Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

ms = set([1])
i = 1
while True:
    m = 6**i
    if m > N:
        break
    ms.add(m)
    i += 1
i = 1
while True:
    m = 9**i
    if m > N:
        break
    ms.add(m)
    i += 1

dp = [10**9] * N 
dp[0] = 1
for i in range(1, N):
    dp[i] = min(dp[i], min(dp[i-m] for m in ms if i-m >= 0) + 1)
print(dp[-1])


Failing test case input:
4632

Expected output:
6


Actual output:
9


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

ms = set([1])
i = 1
while True:
    m = 6**i
    if m > N:
        break
    ms.add(m)
    i += 1
i = 1
while True:
    m = 9**i
    if m > N:
        break
    ms.add(m)
    i += 1

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

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

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

Failing test case input:
879

Expected output:
6


Actual output:
7


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

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

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

def chmin(a, b):
    if a > b:
        a = b
        return a
    else:
        return a

n = int(input())

dp = [10**5] * n
dp[0] = 1

p = int(math.log(n, 6))
q = int(math.log(n, 9))

for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + 1)
    for j in range(1, p + 1):
        if i - 6 ** j < 0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i - 6 ** j] + 1)
    for k in range(1, q + 1):
        if i - 9 ** k < 0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i - 9 ** k] + 1)

print(dp[n - 1])

Failing test case input:
24408

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
import math

def chmin(a, b):
    if a > b:
        a = b
        return a
    else:
        return a

n = int(input())

dp = [10**5] * (n + 1)
dp[0] = 0

p = int(math.log(n, 6))
q = int(math.log(n, 9))

for i in range(1, n + 1):
    dp[i] = chmin(dp[i], dp[i - 1] + 1)
    for j in range(1, p + 2):
        if i - 6 ** j >= 0:
            dp[i] = chmin(dp[i], dp[i - 6 ** j] + 1)
        else:
            break
    for k in range(1, q + 2):
        if i - 9 ** k >= 0:
            dp[i] = chmin(dp[i], dp[i - 9 ** k] + 1)
        else:
            break

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

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

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

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

Failing test case input:
58523

Expected output:
12


Actual output:
15


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

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

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

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

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 = [0]*N
for i in range(N):
    X[i] = i+1

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


Failing test case input:
345

Expected output:
5


Actual output:
7


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 (7.3.0), verdict: Wrong Answer):
n=int(input())
dp=list(range(n+1))
dp[0]=0
a=[]
b=[]
i=1
while True:
  if 6**i>n:break
  a.append(6**i)
  i+=1
i=1
while True:
  if 9**i>n:break
  b.append(9**i)
  i+=1
for i in a:
  for j in range(i+1,n+1):
    dp[j]=min(dp[j],dp[j-i]+1)
for i in b:
  for j in range(i+1,n+1):
    dp[j]=min(dp[j],dp[j-i]+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))
dp[0]=0
a=[]
b=[]
i=1
while True:
  if 6**i>n:break
  a.append(6**i)
  i+=1
i=1
while True:
  if 9**i>n:break
  b.append(9**i)
  i+=1
for i in a:
  for j in range(i,n+1):
    dp[j]=min(dp[j],dp[j-i]+1)
for i in b:
  for j in range(i,n+1):
    dp[j]=min(dp[j],dp[j-i]+1)
print(dp[n])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(open(0).read())
A = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [0] * (10**6 + 1)
dp[1] = 1
for i in range(2, n+1):
    dp[i] = min(dp[i-a]+1 for a in A if i>a)
for a in A:
    dp[a] = 1
print(dp[n])

Failing test case input:
4632

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
n = int(input())
A = [0, 1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [10**6] * (10**6 + 1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = min(dp[i-a]+1 for a in A if i>=a)
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-1):
                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())
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])

Failing test case input:
182896

Expected output:
14


Actual output:
[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 279936]
14


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

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

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


Failing test case input:
24408

Expected output:
8


Actual output:
9


Fixed submission (verdict: Accepted):
import math

n = int(input())
ans = n
for i in range(n+1):
    cc = 0
    t = i
    while (t > 0):
        cc += t % 6
        t = math.floor(t/6)
    t = n - i
    while (t > 0):
        cc += t % 9
        t = math.floor(t/9)
    ans = min(ans, cc)
print(ans)
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 = min(base_10_n(N,6), base_10_n(N,9))
    for j in range(1, N):
        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:
24408

Expected output:
8


Actual output:
24786


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):
import sys
input = sys.stdin.readline

n = int(input())

dp = [0] * (n+1)

for i in range(0, n+1):
  dp[i] = i
  six = 6
  nine = 9
  while True:
    six *= 6
    if six > i:
      six /= 6
      break
  if i - six >= 0:
    dp[i] = min(dp[i], dp[i-int(six)]+1)
  while True:
    nine *= 9
    if nine > i:
      nine /= 9
      break
  if i - six >= 0:
    dp[i] = min(dp[i], dp[i-int(nine)]+1)

print(dp[-1])  


Failing test case input:
8459

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

n = int(input())

dp = [0] * (n+1)

for i in range(0, n+1):
  dp[i] = i
  six = 6
  nine = 9
  while True:
    if i - six >= 0:
      dp[i] = min(dp[i], dp[i-int(six)]+1)
      six *= 6
    else:
      break
  while True:
    if i - nine >= 0:
      dp[i] = min(dp[i], dp[i-int(nine)]+1)
      nine*= 9
    else:
      break

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] = 1
        else:
            dp[i] = min(dp[i], dp[i-num]+1)
print(dp[n])


Failing test case input:
66223

Expected output:
9


Actual output:
6


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
ans = float('inf')
ls = []
l = [1]
tmp = 6
while tmp <= 100000:
    l += [tmp]
    tmp *= 6

tmp = 9
while tmp <= 100000:
    l += [tmp]
    tmp *= 9

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

Failing test case input:
879

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
ans = float('inf')
ls = []
l = [1]
tmp = 6
while tmp <= 100000:
    l += [tmp]
    tmp *= 6

tmp = 9
while tmp <= 100000:
    l += [tmp]
    tmp *= 9

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

print(dp[N])

Problem: p03329
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()

l = []
for i in range(1,6):
  l.append(9**i)
for i in range(7):
  l.append(6**i)
l.sort(reverse=True)

cache = {n:n for n in l}
def f(n):
  if n in cache:
    return cache[n]
  ret = 100000
  for i in l:
    if i <= n:
      ret = min(ret, f(n-i)+1)
  cache[n] = ret
  return ret
print(f(N))

Failing test case input:
34020

Expected output:
5


Actual output:
14


Fixed submission (verdict: Accepted):
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()

l = []
for i in range(1,6):
  l.append(9**i)
for i in range(7):
  l.append(6**i)
l.sort(reverse=True)

cache = {n:1 for n in l}
def f(n):
  if n in cache:
    return cache[n]
  ret = 100000
  for i in l:
    if i <= n:
      ret = min(ret, f(n-i)+1)
  cache[n] = ret
  return ret
print(f(N))

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

print(dp[n-1])

Failing test case input:
24408

Expected output:
8


Actual output:
12


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

print(dp[n])