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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
m = max(A)+10
dp = [0] * m

for x in A:
    dp[x] += 1

ans = 0
for i in range(1, m):
    if dp[i]:
        if dp[i] == 1:
            ans += 1
        for j in range(i, m, i):
            dp[j] = 0
print(ans)

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

A = sorted(A)
ans = 0
for i in range(N):
    for j in range(i-1, -1, -1):
        if A[i] % A[j] == 0:
            break
    else:
        if i == 0 and A[i] == A[i+1]:
            continue
        ans += 1
print(ans)
Problem p02660 (python)

Fixed submission:
N = int(input())

def factorize(n):
     a = []
     # 2で割り切れるまでnを割り続ける
     while n % 2 == 0:
         a.append(2)
         n //= 2
     f = 3
     # 3からはじめて各奇数で割り切れるまでnを割り続ける
     # nの最大約数は√nなので、f*fで計算
     while f * f <= n:
         if n % f == 0:
             a.append(f)
             n //= f
         else:
             f += 2
     if n != 1:
         a.append(n)
     return a
    
fs = factorize(N)

from collections import Counter
fc = Counter(fs)

ans = 0
i = 1
for k, v in fc.items():
    # print(k, v)
    k2, v2 = k,v
    while v2 >= i:
        # print(k, v, i)
        ans += 1
        v2 -= i  
        i += 1
    i = 1

print(ans)

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

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors



facts = factorize(N)
fs = set(facts)

from collections import Counter
fc = Counter(facts)
divisiors = sorted(make_divisors(N))
fms = max([v for k,v in fc.items()])
fm = max(max(facts), fms) 
ans = 0

# print(facts)
# print(divisiors)
done = set()

for d in divisiors:
    if d == 1:
        continue
    if N % d == 0:
        N //= d
        ans += 1

print(ans)

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

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors



facts = factorize(N)
fs = set(facts)

from collections import Counter
fc = Counter(facts)
# divisiors = make_divisors(N)
fms = max([v for k,v in fc.items()])
fm = max(max(facts), fms) 
ans = 0

# print(facts)
# print(divisiors)

# for d in divisiors:
#     if d

for f in fs:
    i = 1
    for j in range(fm):
        if N % f == 0:
            x = f * i
            if N % x == 0:
                ans += 1
                N //= x
            i += 1
        else:
            break

print(ans)
Problem p02917 (python)

Fixed submission:
n = int(input())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i-1]
print(sum(arr))

Buggy submission (verdict: Runtime Error):
n = int(input())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i]
print(sum(arr))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

n, q = map(int, input().split())
g = [list() for i in range(n)]
node = [0] * n

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

for i in range(q):
    p, x = map(int, input().split())
    node[p-1] += x

def dfs(v, p=-1):
    for u in g[v]:
        if u == p: continue
        node[u] += node[v]
        dfs(u, v)

dfs(0)
print(*node)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
N, Q = map(int, input().split())
parents = {}
for _ in range(N-1):
    a, b = map(int, input().split())
    parents[b] = a
process = dd(int)
for _ in range(Q):
    p, x = map(int, input().split())
    process[p] += x
points = [0]*(N+1)
for i in range(1, N+1):
    points[i] += process[i]
    if i != 1:
        points[i] += points[parents[i]]
print(' '.join(map(str, points[1:])))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
rs = [map(int, input().split()) for _ in range(N-1)]
ps = [map(int, input().split()) for _ in range(Q)]

cs = [0] * N
nodes = [set() for _ in range(N)]
for n1, n2 in rs:
    nodes[n1-1].add(n2-1)

def f(n, p):
    cs[n] += p
    if not nodes[n]:
        return
    for _n in nodes[n]:
        f(_n, p)

_ps = [0] * N
for n, p in ps:
    _ps[n-1] += p

for i, p in enumerate(_ps):
    f(i, p)

print(' '.join(map(str, cs)))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
rs = [map(int, input().split()) for _ in range(N-1)]
ps = [map(int, input().split()) for _ in range(Q)]

cs = [0] * N
nodes = [set() for _ in range(N)]
for n1, n2 in rs:
    nodes[n1-1].add(n2-1)

def f(n, p):
    cs[n] += p
    if not nodes[n]:
        return
    for _n in nodes[n]:
        f(_n, p)

while ps:
    n, p = ps.pop()
    f(n-1, p)

print(' '.join(map(str, cs)))
Problem p02947 (python)

Fixed submission:
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += c * (c-1) // 2
print(t)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += factorial(c) / 2
print(int(t))
Problem p02995 (python)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) // gcd(x, y)

lcmv = lcm(C, D)
bc = B // C
bd = B // D
bl = B // lcmv
ac = (A-1) // C
ad = (A-1) // D
al = (A-1) // lcmv
print(B - A + 1 - ((bc + bd - bl) - (ac + ad - al)))

Buggy submission (verdict: Runtime Error):
from math import gcd
A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) // gcd(x, y)

lcmv = lcm(C, D)
bc = B // C
bd = B // D
bl = B // lcmv
ac = (A-1) // C
ad = (A-1) // D
al = (A-1) // lcmv
print(B - A + 1 - ((bc + bd - bl) - (ac + ad - al)))
Problem p03061 (python)

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

for i in range(1, N-1):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[-1-i]))

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[-1]
    elif i == N-1:
        tmp = left[-1]
    else:
        tmp = gcd(left[i-1], right[N-2-i])
    ans = max(ans, tmp)

print(ans)

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

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

m = [0] * (N+1)
for i in range(N):
    divisors = make_divisors(A[i])
    for d in divisors:
        m[d] += 1

ans = 1
for i in range(N+1):
    if (N-1) <= m[i] and ans < m[i]:
        ans = m[i]

print(ans)
Problem p03436 (python)

Fixed submission:
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque([(0, 0)])
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
l[0][0] = 0

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

try:
    g = l[H-1][W-1]
    total = 0
    for _l in l:
        for i in _l:
            if i != '#':
                total += 1
    print(total - g - 1)
except:
    print(-1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque([(0, 0)])
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
l[0][0] = 0

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

g = l[H-1][W-1]
total = 0
for _l in l:
    for i in _l:
        if i != '#':
            total += 1
print(total - g - 1)
Problem p03493 (python)

Fixed submission:
print(input().count('1'))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = tuple(map(int, input().split()))
count = 0
while all(i % 2 == 0 for i in l):
    count += 1
    l = tuple(map(lambda x: x / 2, l))
print(count)
Problem p03636 (python)

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))

Buggy submission (verdict: Runtime Error):
s = input()
print(f'{s[0]}{len(s)-2}{s[-1]}')

Buggy submission (verdict: Runtime Error):
s = input()
print(f'{s[0]}{len(s)-2}{s[-1]}')
Problem p03673 (python)

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

from collections import deque
b1 = deque([])
b2 = deque([])

for i in range(N):
    if i % 2 == 0:
        b1.append(A[i])
    else:
        b2.appendleft(A[i])
print(*(list(b1)+list(b2)))

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

from collections import deque
b1 = deque([])
b2 = deque([])

for i in range(N):
    if i % 2 == 0:
        b1.append(A[i])
    else:
        b2.appendleft(A[i])
print(*(b1+b2))
Problem p03854 (python)

Fixed submission:
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
import re
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while s != '':
    tmp = s
    for word in words:
        s = re.sub(f'{word}$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break
Problem p02658 (python)

Fixed submission:
import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = list(input().split())

for num in nums:
    num = int(num)
    if num == 0:
        print(0)
        sys.exit(0)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except Exception:
        accum = -1
        break

    if accum > limit:
        accum = -1
        break

print(accum)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = []

nums = input().rsplit()

# for i in range(0, N - 1):
#     a = input()
#     if a == 0:
#         print(0)
#         sys.exit(1)
#     nums.append(a)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except OverflowError:
        print(-1)
        sys.exit(1)

    if accum > limit:
        print(-1)
        sys.exit(1)

print(accum)
Problem p02683 (python)

Fixed submission:
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
cost=100000001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	#print(list_C)
	for h in range(len(list_C)):
		if all(np.sum(list_C[h], axis=0)[1:]>=X):
			if np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
			#print(np.sum(list_C[h], axis=0),cost)
			count+=1
	if count==0:
		break

print(cost if cost<100000001 else "-1")

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
gokei=X
cost=100001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	for h in range(len(list_C)):

		if all(np.sum(list_C[h], axis=0)[1:]>=X) and np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
				count+=1

		if count==0:
		break

print(cost if cost<100001 else -1)
Problem p02719 (python)

Fixed submission:
N,K = map(int, input().split())
if N > K and N//K>2:
	a = N//K
	N= N-K*(a-2)

while N>0:
	T = N
	N = abs(N-K)
	if N >T:
		break

print(N if N==0 else min(N,T) )

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
if N > K and N//K>2:
	a = N//K
	N= N-K*(a-2)

while N>0:
	T = N
	N = abs(N-K)
	if N >T:
		break

print(min(N,T))
Problem p02947 (python)

Fixed submission:
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))

Buggy submission (verdict: Runtime Error):
from math import factorial
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  if i>1:
    count+=factorial(i)/factorial(2)/factorial(i-2)
print(int(count))
Problem p02600 (python)

Fixed submission:
MI = lambda :(map(int,input().split()))
x = int(input())
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)

Buggy submission (verdict: Runtime Error):
MI = lambda :(map(int,input().split()))
x = II()
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)
Problem p02755 (python)

Fixed submission:
import math
a,b = map(int,input().split())
a1 = round(a/0.08)
b1 = round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) > a and math.floor(c*0.1) > b:
		print(-1)
		break
	else:
		c+=1

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
a1 = math.round(a/0.08)
b1 = math.round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) != a and math.floor(c*0.1) != b:
		print(-1)
		break
	else:
		c+=1
Problem p02684 (python)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
    
al = [1]
num2ind = {1:0}
for i in range(K):
    ne = A[al[-1]-1]
    al.append(ne)
    if ne in num2ind:
        tar = num2ind[ne]
        break
    num2ind[ne] = i+1
    
ne = i+1
if K<=len(al):
    print(al[K])
else:
    K-=tar
    K%=(ne-tar)
    print(al[tar+K])

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
    
al = [1]
num2ind = {1:0}
for i in range(N):
    ne = A[al[-1]-1]
    if ne in al:
        tar = num2ind[ne]
        break
    al.append(ne)
    num2ind[ne] = i+1
    
ne = i+1
if K<=len(al):
    print(al[K])
else:
    K-=tar
    K%=(ne-tar)
    print(al[tar+K])
Problem p02761 (python)

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

p = {}
flag=True
for _ in range(M):
    s,c = list(map(int, input().split()))
    if s in p and p[s]!=c:
        flag=False
    p[s] = c

if 1 in p:
    if N!=1 and p[1]==0:
        flag=False
        
if flag:
    ans = ''
    for i in range(1, N+1):
        if i in p:
            ans+=str(p[i])
        elif N!=1 and i==1:
            ans+='1'
        else:
            ans+='0'
    print(int(ans))
else:
    print(-1)

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

p = {}
flag=True
for _ in range(M):
    s,c = list(map(int, input().split()))
    if s in p and p[s]!=c:
        flag=False
    p[s] = c

if flag and p[1]!=0:
    ans = ''
    for i in range(1, N+1):
        if i in p:
            ans+=str(p[i])
        else:
            ans+='0'
    print(int(ans))
else:
    print(-1)
Problem p02843 (python)

Fixed submission:
N = int(input())
dp = [0]*(100000+1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(200, N+1):
    if dp[i-100]==1 or dp[i-101]==1 or dp[i-102]==1 or dp[i-103]==1 or dp[i-104]==1  or dp[i-105]==1:
        dp[i]=1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
dp = [0]*100000
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(200, N+1):
    if dp[i-100]==1 or dp[i-101]==1 or dp[i-102]==1 or dp[i-103]==1 or dp[i-104]==1  or dp[i-105]==1:
        dp[i]=1
print(dp[N])
Problem p02882 (python)

Fixed submission:
import math

a, b, x = list(map(int, input().split()))
if x==a**2*b:
    print(0)
elif x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)

Buggy submission (verdict: Runtime Error):
import math

a, b, x = list(map(int, input().split()))
if x==a*b:
    print(0)
elif x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)

Buggy submission (verdict: Runtime Error):
import math

a, b, x = list(map(int, input().split()))
if x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)
Problem p03061 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = gcd(L[i], A[i])
    R[N-i-1] = gcd(R[N-i], A[N-i-1])
    
M = []
for i in range(N):
    M.append(gcd(L[i],R[i+1]))

print(max(M))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))

L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = math.gcd(L[i], A[i])
    R[N-i-1] = math.gcd(R[N-i], A[N-i-1])

M = []
for i in range(N-1):
    M.append(math.gcd(L[i],R[i+1]))
    
print(max(M))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+100)

N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N
 
# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res
 
ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N

# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res

ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N

# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    return res

ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)
Problem p03167 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+100)
MOD = 10**9+7

H, W = list(map(int, input().split()))
a = [input() for _ in range(H)]

dp = [[-1]*W for _ in range(H)]
def rec(h, w):
    if dp[h][w]!=-1:
        return dp[h][w]
    else:
        dp[h][w] = 0
        if h<H-1:
            if a[h+1][w]!='#':
                dp[h][w] = rec(h+1, w)%MOD
        if w<W-1:
            if a[h][w+1]!='#':
                dp[h][w] += rec(h, w+1)%MOD
        if h==H-1 and w==W-1:
            dp[h][w] = 1
        return dp[h][w]%MOD

print(rec(0,0))

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7

H, W = list(map(int, input().split()))
a = [input() for _ in range(H)]

dp = [[-1]*W for _ in range(H)]
def rec(h, w):
    if dp[h][w]!=-1:
        return dp[h][w]
    else:
        dp[h][w] = 0
        if h<H-1:
            if a[h+1][w]!='#':
                dp[h][w] = rec(h+1, w)%MOD
        if w<W-1:
            if a[h][w+1]!='#':
                dp[h][w] += rec(h, w+1)%MOD
        if h==H-1 and w==W-1:
            dp[h][w] = 1
        return dp[h][w]%MOD

print(rec(0,0))
Problem p03294 (python)

Fixed submission:
n = int(input())
a = input().split()
s = 0
for i in range(n):
    s += int(a[i])
print(s - n)

Buggy submission (verdict: Runtime Error):
from math import *

def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
a = input().split()

for i in range(n):
    a[i] = int(a[i])

l = 1
for i in range(n):
    l = lcm(l, a[i])

l -= 1
s = 0

for i in range(n):
    s += l % a[i]

print(s)
Problem p02573 (python)

Fixed submission:
def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m, *ab, = map(int, open(0).read().split())

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

    def f(x):
        if p[x] < 0:
            return x
        else:
            return f(p[x])

    ans = -1
    for i, j in zip(ab[::2], ab[1::2]):
        if i > j:
            i, j = j, i

        pi, pj = f(i), f(j)
        if pi == pj:
            continue
        p[pi] += p[pj]
        ans = min(ans, p[pi])
        p[j] = pi
        p[pj] = pi

    print(-ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m, *ab, = map(int, open(0).read().split())
    f = [set() for _ in range(n)]
    for i, j in zip(ab[::2], ab[1::2]):
        f[i].add(j)
        f[j].add(i)

    group = []
    i = 1
    g = {i}
    nx = {i}
    checked = set()
    m = 0
    ans = 0
    while i <= n:
        if i in checked:
            i += 1
            continue

        tmp = set()
        for j in list(nx):
            tmp |= f[j]
        tmp -= nx

        if len(tmp) == 0:
            checked |= g
            group.append(g)
            l = len(g)
            m += l
            r = n - m
            ans = max(ans, l)
            if l >= r:
                break
            i += 1
            g = {i}
        else:
            g |= tmp
            nx = tmp

    print(ans)


if __name__ == '__main__':
    main()