Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

mod = 10**9+7
dp = [-1]*(n+1)
dp[0] = 1
dp[1] = 1

for i in a:
    dp[i] = 0

for i in range(2, n+1):
    if dp[i] < 0:
        dp[i] = (dp[i-1] + dp[i-2])%mod

print(dp[n])

Buggy submission (verdict: Runtime Error):
memo = {}

def starsFib(n,a):
    if n == 1:
        return 1
    elif n == 2:
        return 2

    elif n in a:
        return 0
    else:
        memo[n] = starsFib(n-1,a) + starsFib(n-2,a)
        return memo[n]

def run():
    n,m = map(int, input().split())
    a = [int(input()) for i in range(m)]

    all = starsFib(n,a)

    ans = all % 1000000007

    print(ans)

if __name__ == '__main__':
    run()
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list( map(int, input().split()) )

A.insert(0, 0)
B.insert(0,0)

# convert to the cumulative/prefix sum
for i in range(1, len(A)):
    A[i] += A[i-1]

for i in range(1, len(B)):
    B[i] += B[i-1]

# print(A)
# print(B)

books_stack_a = 0

books_stack_b = M

cur_max = 0

for books_stack_a in range(0, N + 1):
    if A[books_stack_a] > K:
        break
    diff = K - A[books_stack_a]
    while diff < B[books_stack_b]:
        books_stack_b -= 1

    cur_max = max(cur_max, books_stack_b + books_stack_a)

print(cur_max)

Buggy submission (verdict: Runtime Error):

N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list( map(int, input().split()) )

books = 0

p1 = 0
p2 = 0

while K > 0 and ( p1 < N or p2 < M ):
    books += 1

    if p1 < N and A[p1] < B[p2]:
        # print("chosen", "p1", p1)
        K -= A[p1]
        p1 += 1

    elif p2 < M:
        # print("chosen", "p2", p2)
        K -= B[p2]
        p2 += 1

    # print(K, p1, p2)

# print(K)

if K < 0:
    books -= 1
    print(books)

elif K == 0:
    print(books)

else:
    if p1 < N:
        while K > 0 and p1 < N:
            books += 1
            K -= A[p1]
            p1 += 1

    if p2 < M:
        while K > 0 and p2 < M:
            books += 1
            K -= B[p2]
            p2 += 1

    print(books)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list( map(int, input().split()) )

books = 0

p1 = 0
p2 = 0

while K > 0 and ( p1 < N or p2 < M ):
    books += 1

    if p1 < N and A[p1] < B[p2]:
        # print("chosen", "p1", p1)
        K -= A[p1]
        p1 += 1

    elif p2 < M:
        # print("chosen", "p2", p2)
        K -= B[p2]
        p2 += 1

    # print(K, p1, p2)

if K < 0:
    books -= 1
print(books)
Problem p02629 (python)

Fixed submission:
n = 1
N = int(input())

while True:
  if  26*(26**n-1)/25 >= N:
    break
  else:
    n +=1

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
num = []

num = [0 for _ in range(n)]

for i in reversed(range(n)):
  for j in range(1,27):
    pre = 26*(26**i-1)/25
    if 26**i * j + pre >= N:
      num[i] = alpha[j-1]

      N -= 26**i * j
      break


print(''.join(num[::-1]))

Buggy submission (verdict: Runtime Error):
n = 1
N = int(input())

while True:
  if  26*(26**n-1)/25 >= N:
    break
  else:
    n +=1

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
num = [0 for _ in range(n)]

for i in range(n):
  ii = n-i
  for j in range(1,27):
    if 26**(ii-1) * j >= N:
      if i != n-1:
        num[i] = alpha[j-2]
      else:
        num[i] = alpha[j-1]
      N -= 26**(ii-1) * (j-1)
      break

print(''.join(num))

Buggy submission (verdict: Runtime Error):
n = 1
N = int(input())

while True:
  if  26*(26**n-1)/25 > N:
    break
  else:
    n +=1

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


num = [0 for _ in range(n)]
for i in range(n):
  ii = n-i
  for j in range(1,27):
    if 26**(ii-1) * j > N:
      num[i] = alpha[j-2]
      N -= 26**(ii-1) * (j-1)
      break

print(''.join(num))

Buggy submission (verdict: Runtime Error):
n = 1
N = int(input())

while True:
  if  26*(26**n-1)/25 > N:
    break
  else:
    n +=1

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


num = [0 for _ in range(n)]
for i in range(n):
  ii = n-i
  for j in range(1,27):
    if 26**(ii-1) * j > N:
      num[i] = alpha[j-2]
      N -= 26**(ii-1) * (j-1)
      break

print(''.join(num))

Buggy submission (verdict: Runtime Error):
n = 1
N = int(input())

while True:
  if  26*(26**n-1)/25 > N:
    break
  else:
    n +=1

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


num = [0 for _ in range(n)]
for i in range(n):
  ii = n-i
  for j in range(1,27):
    if 26**(ii-1) * j > N:
      num[i] = alpha[j-2]
      N -= 26**(ii-1) * (j-1)
      break

print(''.join(num))
Problem p02693 (python)

Fixed submission:
K=int(input())
A,B=map(int,input().split())
for i in range(A,B+1):
    if i%K==0:
        print("OK")
        break
    elif i%K!=0 and i==B:
        print("NG")

Buggy submission (verdict: Runtime Error):
A,B,N = map(int,input().split())
tmp=0
for i in range(N//2,N+1):
    floor = (A*i)//B-A*(i//B)
    if floor>tmp:
        tmp = floor
print(tmp)
Problem p02829 (python)

Fixed submission:
from math import sqrt
from decimal import Decimal
ans = [1,2,3]
A,B=int(input()),int(input())
ans.remove(A)
ans.remove(B)
print(ans[0])

Buggy submission (verdict: Runtime Error):
import fractions
A,B=map(int,input().split())
print(int(A*B/fractions.gcd(A,B)))

Buggy submission (verdict: Runtime Error):
from math import sqrt
from decimal import Decimal
ans = [1,2,3]
A,B=map(int,input().split())
ans.remove(A)
ans.remove(B)
print(ans[0])
Problem p02831 (python)

Fixed submission:
import fractions
A,B=map(int,input().split())
print(int(A*B/fractions.gcd(A,B)))

Buggy submission (verdict: Runtime Error):
import math as mt 
A,B=map(int,input().split())
print(int(A*B/mt.gcd(A,B)))
Problem p02832 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
b = 1
ans = 0
for i in range(0,N):
    if a[i] == b:
        b += 1
        ans += 1
if ans == 0:
    print(-1)
else:
    print(N-ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
count = 0
tmp = 0
while(1):
    if a[0] == 1:
        tmp = a[0]
        break
    else:
        count += 1
        a.pop(0)
if tmp == 1:
    for i in range(1,N-count):
        if a[i] == tmp + 1:
            tmp = a[i]
        else:
            count += 1
    print(count)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
count=0
while(1):
    if a[0]==1:
        tmp = a[0]
        break
    else:
        count += 1
        a.pop(0)
for i in range(1,N-count):
    if a[i] == tmp + 1:
        tmp=a[i]
    else:
        count+=1
print(count)
Problem p02682 (python)

Fixed submission:
a, b, c, k = map(int, input().split())

if k <= a:
    sum = k
elif k <= a + b:
    sum = a
else:
    sum = a - (k - a - b)

print(sum)

Buggy submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
l = [1] * a + [0] * b + [-1] * c
print(sum(l[:k]))

Buggy submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
l = [1] * a + [0] * b + [-1] * c
print(sum(l[:k]))
Problem p02835 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 22:
    print("bust")
else:
    print("win")

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = np.zeros((l,2))
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i,0] += 1
        else:
            bits[i,1] += 1

sumation = 0
div = (10**9+7)
for i in range(l):
    sumation += (bits[i,0]) * (bits[i, 1]) * (2**(l-i-1) % div)
print(int(sumation % (10**9+7)))
Problem p02897 (python)

Fixed submission:
n = int(input())
print((int(n/2) + n%2) / n)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split(" "))))
b = list(np.argsort(a) + 1)
b = [str(s) for s in b]
print(" ".join(b))
Problem p02629 (python)

Fixed submission:
LIMIT = 1000000000000001
alphabet = {-1: "!", 0: "a", 1:"b", 2:"c", 3:"d", 4:"e", 5:"f", 6: "g", 7:"h", 8:"i", 9:"j", 10:"k", 11:"l",
                12:"m", 13:"n", 14: "o", 15:"p", 16:"q", 17:"r", 18:"s", 19:"t", 20:"u", 21: "v",
                22: "w", 23: "x",  24: "y",  25: "z"}



N = int(input())
answer = ""
# times = 1

while True:
    N = N - 1
    a = int(N / 26)
    b = N % 26
    answer += alphabet[b]
    if a == 0: break
    N = a


print(answer[::-1])

Buggy submission (verdict: Runtime Error):
LIMIT = 1000000000000001
alphabet = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6: "f", 7:"g", 8:"h", 9:"i", 10:"j", 11:"k",
                12:"l", 13:"m", 14: "n", 15:"o", 16:"p", 17:"q", 18:"r", 19:"s", 20:"t", 21: "u",
                22: "v", 23: "w",  24: "x",  25: "y",  26: "z"}



N = int(input())
answer = ""

while True:
    if N >= 27:
        a = int(N / 26)
        b = int(N % 26)
        answer += alphabet[b]
        N = a
    else:
        answer += alphabet[N]
        break

print(answer[::-1])
Problem p02762 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n  # 要素の総数．
        self.parents = [-1] * n  # 各要素の親要素の番号を格納するリスト．要素がrootの場合は-(そのグループの要素数)を返す

    def find(self, x):
        """要素xが属するグループの根を返す"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素xが属するグループと要素yが属するグループとを併合する"""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """要素xが属するグループの要素数を返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x, yが同じグループに属するかどうかを返す"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属するグループに属する要素をリストで返す"""
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """全ての根の要素をリストで返す"""
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """グループの数を返す"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループの要素のリスト]} の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M, K = map(int, input().split())
    cnt = [0] * N
    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(lambda x: int(x)-1, input().split())
        cnt[A] += 1
        cnt[B] += 1
        uf.union(A, B)

    for _ in range(K):
        C, D = map(lambda x: int(x)-1, input().split())
        if uf.same(C, D):
            cnt[C] += 1
            cnt[D] += 1

    for i in range(N):
        print(uf.size(i) - cnt[i] - 1, end=" ")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from DataStructures.UnionFind import UnionFind


def main():
    N, M, K = map(int, input().split())
    cnt = [0] * N
    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(lambda x: int(x)-1, input().split())
        cnt[A] += 1
        cnt[B] += 1
        uf.union(A, B)

    for _ in range(K):
        C, D = map(lambda x: int(x)-1, input().split())
        if uf.same(C, D):
            cnt[C] += 1
            cnt[D] += 1

    for i in range(N):
        print(uf.size(i) - cnt[i] - 1, end=" ")


if __name__ == '__main__':
    main()
Problem p02695 (python)

Fixed submission:
N, M, Q = map(int, input().split())
tmp = [list(map(int, input().split())) for i in range(Q)]


#最初に全てのAペアを作ればいいだけだった
#1stepで何するか
#終了条件
ans = [0]
def dfs(A):
    # print(A)
    if len(A) == N:
        tmp_ans = 0
        for ele in tmp:
            if A[ele[1]-1] - A[ele[0]-1] == ele[2]:
                tmp_ans += ele[-1]
        ans[0] = max(tmp_ans,ans[0])

        return
    
    A_min = A[-1]
    while(1):
        if A_min > M:
            break
        A.append(A_min)
        dfs(A)
        A.pop()
        A_min += 1

for i in range(M):
    dfs([i+1])

print(ans[0])

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
tmp = [list(map(int, input().split())) for i in range(Q)]


#最初に全てのAペアを作ればいいだけだった
#1stepで何するか
#終了条件
ans = [0]
def dfs(A):
    if len(A) == N:
        tmp_ans = 0
        for ele in tmp
            if ele[1] - ele[0] == ele[2]:
                tmp_ans += ele[-1]
        ans[0] = max(tmp_ans,ans[0])

        return
    
    A_min = A[-1]
    while(1):
        if A_min > M:
            break
        A.append(A_min)
        dfs(A)
        A.pop()
        A_min += 1

for i in range(M):
    dfs([i+1])

print(ans[0])

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
tmp = [list(map(int, input().split())) for i in range(Q)]


#最初に全てのAペアを作ればいいだけだった
#1stepで何するか
#終了条件
ans = [0]
def dfs(A):
    if len(A) == N:
        tmp_ans = 0
        for ele in tmp
            if ele[1] - ele[0] == ele[2]:
                tmp_ans += ele[-1]
        ans[0] = max(tmp_ans,ans[0])

        return
    
    A_min = A[-1]
    while(1):
        if A_min > M:
            break
        A.append(A_min)
        dfs(A)
        A.pop()
        A_min += 1

for i in range(M):
    dfs([i+1])

print(ans[0])
Problem p03038 (python)

Fixed submission:
N,M= map(int,input().split())

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

bc = [0]*M

for i in range(M):
    bc[i]=list(map(int, input().split()))


a.sort()
bc.sort(key=lambda x:-x[1])

# print(a)
# print(bc)
ans = sum(a)
pre_ind = 0
now_ind = 0
for i in range(M):
    key = bc[i][0]
    value = bc[i][1]
    now_ind += key
    if now_ind > N:
        now_ind = N

    if value > a[now_ind-1]:
        ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
        # a=a[:pre_ind]+[value]*(now_ind-pre_ind)+ a[now_ind:]
        pre_ind = now_ind
        if now_ind == N:
            # print("ok")
            break
    else:
        max_count = key
        # print(key)
        key2 = key
        for j in range(key-1):
            now_ind -= 1
            key2 -= 1
            if value > a[now_ind-1]:
                # a=a[:pre_ind]+[value]*(now_ind-pre_ind) + a[now_ind:]
                ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
                # print(key2)
                break
        break

# print(a)

# print(sum(a))
print(ans)

Buggy submission (verdict: Runtime Error):
N,M= map(int,input().split())

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

bc = [0]*M

for i in range(M):
    bc[i]=list(map(int, input().split()))


a.sort()
bc.sort(key=lambda x:-x[1])

# print(a)
# print(bc)
# ans = sum(a)
pre_ind = 0
now_ind = 0
for i in range(M):
    key = bc[i][0]
    value = bc[i][1]
    now_ind += key

    if value > a[now_ind-1]:
        a=a[:pre_ind]+[value]*key + a[now_ind:]
        pre_ind = now_ind


    else:
        max_count = key
        # print(key)
        key2 = key
        for j in range(key):
            now_ind -= 1
            key2 -= 1
            if value > a[now_ind-1]:
                a=a[:pre_ind]+[value]*key2 + a[now_ind:]
                # print(key2)
                break
        break

# print(a)

print(sum(a))
Problem p03127 (python)

Fixed submission:
N = int(input())

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

#0の数がN-1になった時点で終了
#Aの中のminを割り出しそれのmodをA内でとるを繰り返す

mina = 0
while(1):
    if(len(A)==1):break
    mina = min(A)
    minaind = A.index(mina)
    delind =[]
    for i in range(0,len(A)):
        # print(A,minaind)
        if i == minaind:continue
        # print(i)
        A[i]%=mina
        # if A[i] <= 0: delind.append(i)
    B=[]
    for i in range(0,len(A)):
        if(A[i]>0):
            B.append(A[i])
            
    A = B

print(A[0])

Buggy submission (verdict: Runtime Error):
N = int(input())

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

#0の数がN-1になった時点で終了
#Aの中のminを割り出しそれのmodをA内でとるを繰り返す

mina = 0
while(1):
    if(len(A)==1):break
    mina = min(A)
    minaind = A.index(mina)
    delind =[]
    for i in range(0,len(A)):
        # print(A,minaind)
        if i == minaind:continue
        # print(i)
        A[i]%=mina
        if A[i] <= 0: delind.append(A.index(A[i]))
    for i in delind:
        del(A[i])

print(A[0])
Problem p03295 (python)

Fixed submission:
N,M = map(int,input().split())
a = list(list(map(int, input().split())) for x in range(M))

#aをbについて昇順にする。
a=sorted(a, key=lambda x: x[1])
hasi = -1#どこの橋を壊したか
sum = 0

for i in range(0,M):
    # print(c1,c2,hasi)
    if (hasi >= a[i][0])and (hasi < a[i][1]):
        continue
    else:
        hasi = a[i][1]-1
        sum = sum+1

print(sum)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
for i in range(M):
    a[i]=input().rstrip().split()
# 左側の島の一番大きい島の１個→に橋をたてていく
#　全て分割されたら終了
#　左側は昇順になっている？なっていなかったらそこ修正
a = [[]*2]*M
sum = 0#分割の数
hasi = [0]*(N-1)#どこの橋を壊したか
for i in range(0,M):
    c1 = int(a[M-1-i][0])
    c2 = int(a[M-1-i][1])
    f = [False]
    for m in range(c1-1,c2-1):
        if hasi[m]==1:
            f[0]=True
    if f[0]==True:
        continue
    else:
        hasi[c1-1]=1
        sum = sum+1



print(sum)
Problem p03317 (python)

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

min_ind = A.index(1)

print(int((N-1)/(K-1)) if (N-1)%(K-1)==0 else (N-1)//(K-1)+1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
li = list(map(int, input().split()))
#左から最小値を探していく
#最小値を見つけたら、左側を最小値にしていく
#ないなら(１は１個しかない！！)最小値エリアの右端の値から最小値にしていく

mn = 1#min値を取得
mnix = li.index(1)
mnix0 =mnix #min値の最初のindex
sum = 0 #操作の回数
# li
f=[False]
#左側をまず1へ
while(1):
    if f[0]==True:
        break
    if (mnix+1-k) >0:
        for i in range(mnix+1-k,mnix+1):
            li[i] = mn
        sum +=1
        mnix=li.index(1)
    else:
        for i in range(0,k):
            li[i] = mn
        f[0]=True
        sum +=1

# li
#次に右側を1へ
if (mnix0+1-k) >0:
    #mnix0が右端
    migi = mnix0
if (mnix0+1-k) <=0:
    #k-1が右端
    migi = k-1
# migi

    
f[0]=False
if li[n-1]==1:
    f[0]=True
while(1):
    if f[0]==True:
        break
    if (migi+2)>(n-1):
        for i in range(migi,n):
            li[i] = mn
        sum +=1
        f[0]=True
    else:
        for i in range(migi,migi+k):
            li[i] = mn
        sum +=1
        migi = migi+k-1

 
print(sum)
Problem p02659 (python)

Fixed submission:
a, b = input().split()

x = int(a)
y = round(100*float(b))

print(x * y // 100)

Buggy submission (verdict: Runtime Error):
import math
a, b = [int(i) for i in input().split()]

print(math.floor(a*b))
Problem p02699 (python)

Fixed submission:
s, w = [int(i) for i in input().split()]
if s <= w:
  print("unsafe")
else:
  print("safe")

Buggy submission (verdict: Runtime Error):
s, w = [int(i) for i in input().spli()]
if s <= w:
  print("unsafe")
else:
  print("safe")
Problem p02790 (python)

Fixed submission:
def make_num(a, b):
    num = ""
    for i in range(b):
        num += str(a)
    return num

def slove(a, b):

    num1 = make_num(a, b)
    num2 = make_num(b, a)
    
    return min(num1, num2)

if __name__ == "__main__":

    a, b = [int(i) for i in input().split()]
    ans = slove(a, b)
    print(ans)

Buggy submission (verdict: Runtime Error):
def slove(a, b):

    return min(a,b)

if __name__ == "__main__":

    a, b = inpu().split()

    ans = slove(a, b)
    print(ans)
Problem p03329 (python)

Fixed submission:
n = int(input())

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

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

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

print(dp[n])

Buggy submission (verdict: Runtime Error):
n = int(input())

memo = [-1]*(n+1)

def func(n):
    if n == 0:
        return 0

    if memo[n] != -1:
        return memo[n]

    res = n
    i = 1
    while i <= n:
        res = min(res, func(n-i)+1)
        i *= 6

    j = 1
    while j <= n:
        res = min(res, func(n-j)+1)
        j *= 9

    memo[n] = res
    return memo[n]

ans = func(n)
print(ans)
Problem p03804 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]

def init_img(n):
    return [[0 if j == "#" else 1 for j in input()] for i in range(n)]

img = init_img(n)

tmp_img = init_img(m)

flg = False

for i in range(n):
    if flg:
        break

    if i+m > n:
        break

    for j in range(n):
        count = 0
        if j+m > n:
            break
        
        for k in range(m):
            if img[i+k][j:j+m] == tmp_img[k]:
                count += 1

        if count == m:
            flg = True

if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]

def init_img(n):
    return [[0 if j == "#" else 1 for j in input()] for i in range(n)]

img = init_img(n)

tmp_img = init_img(m)

flg = False

for i in range(n):
    if flg:
        break

    for j in range(n):
        count = 0
        for k in range(m):
            if img[i+k][j:j+m] == tmp_img[k]:
                count += 1

        if count == 3:
            flg = True

if flg:
    print("Yes")
else:
    print("No")
Problem p02676 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    k = int(input())
    s = input().rstrip()

    if len(s) <= k:
        print(s)
    else:
        print(s[:k] + '...')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

if len(S) > K:
    S = S[:k] + "..."

print(s)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

if len(S) > K:
    S = s[:k] + "..."

print(s)
Problem p02707 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_li = list(map(int, input().strip().split()))

    a_dict = {}

    for a in a_li:
        if str(a) in a_dict:
            a_dict[str(a)] += 1
        else:
            a_dict[str(a)] = 1

    for i in range(1, n+1):
        if str(i) in a_dict:
            print(a_dict[str(i)])
        else:
            print(0)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
a_li = list(map(int, input().strip().split()))

a_set = set(a_li)

for i in range(1, n+1):
  if i in a_set:
    print(a_li.count(i))
    else:
      print(0)