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

Fixed submission:
N = int(input())

m = int(N **0.5)+1
for i in range(1,m):
    j = N // i
    if i*j < N:
        continue
    k = i
a = N // k
ans=0
b = str(a)
ans = len(b)

print(ans)

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

m = int(N **0.5)
for i in range(1,m):
    j = N // i
    if i*j < N:
        continue
    k = i
a = N // k
ans=0
b = str(a)
ans = len(b)

print(ans)

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

m = int(N **0.5)
for i in range(1,m):
    j = N / i
    if int(j) < j:
        continue
    k = i
a = N // k
ans=0
while a >= 1:
    a //=10
    ans+=1

print(ans)
Problem p03834 (python)

Fixed submission:
x, y, z = input().split(",")
print(x, y, z)

Buggy submission (verdict: Runtime Error):
x, y, z = input.split(",")

print(x, y, z)
Problem p02682 (python)

Fixed submission:
A, B, C, K = [int(i) for i in input().split()]
if A + B >= K:
    if K < A:
        print(K)
    else:
        print(A)
else:
    tmp = K - A - B
    print(A - tmp)

Buggy submission (verdict: Runtime Error):
A, B, C, K = [int(i) for i in input().split()]
D = [1] * A + [0] * B + [-1] * C
print(sum(D[:K]))
Problem p02707 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
B = [0]*N
for i in A:
    B[i-1] += 1
for i in B:
    print(i)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10000)

@lru_cache(maxsize = None)
def rec(i, j):
    flag = False
    flag_ = False
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        dp[i+1][j] = tmp
        flag = True
    tmp_ = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp_ > dp[i][j+1]:
        dp[i][j+1] = tmp_ if tmp_ > dp[i][j+1] else dp[i][j+1]
        flag_ = True
    if i + j == N - 1:
        return
    if flag:
        rec(i + 1, j)
    if flag_:
        rec(i, j + 1)
    
N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]

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

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

def rec(i, j):
    flag = False
    flag_ = False
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        dp[i+1][j] = tmp
        flag = True
    tmp_ = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp_ > dp[i][j+1]:
        dp[i][j+1] = tmp_ if tmp_ > dp[i][j+1] else dp[i][j+1]
        flag_ = True
    if i + j == N - 1:
        return
    if flag:
        rec(i + 1, j)
    if flag_:
        rec(i, j + 1)
    
N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]

dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
rec(0, 0)
ans = -1
for i in range(N):
    for j in range(N):
        if dp[i][j] > ans:
            ans = dp[i][j]
print(ans)
Problem p02793 (python)

Fixed submission:
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
lcd = A[0]
for i in A:
    lcd = lcd * i // gcd(lcd,i)
ans = 0
for i in A:
    ans += lcd // i
print( ans% (10**9+7))

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = [int(i) for i in input().split()]
lcd = A[0]
for i in A:
    lcd = lcd * i // gcd(lcd,i)
ans = 0
for i in A:
    ans += lcd // i
print(ans% (10**9+7))
Problem p02757 (python)

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

res = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
else:
    mp = [0]*P
    mp[0] = 1
    cur = 0
    p10 = 1
    for c in S[::-1]:
        cur = (cur + int(c)*p10) % P
        res += mp[cur]
        mp[cur] += 1
        p10 *= 10
        p10 %= P

print(res)

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

res = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
else:
    mp = [0]*len(S)
    mp[0] = 1
    cur = 0
    p10 = 1
    for c in S[::-1]:
        cur = (cur + int(c)*p10) % P
        res += mp[cur]
        mp[cur] += 1
        p10 *= 10
        p10 %= P

print(res)
Problem p02781 (python)

Fixed submission:
N = input()
K = int(input())

digit = len(N)
dp = [[[0]*(K+1) for _ in range(2)] for _ in range(digit)]

cd = int(N[0])
dp[0][0][0] = 0
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = cd-1

for i in range(1, digit):
    for k in range(K+1):
        cd = int(N[i])
        if k == 0:
            dp[i][1][0] = 1
        else:
            if cd == 0:
                dp[i][0][k] = dp[i-1][0][k]
                dp[i][1][k] = dp[i-1][1][k] + dp[i-1][1][k-1]*9
            else:
                dp[i][0][k] = dp[i - 1][0][k - 1]
                dp[i][1][k] = dp[i-1][0][k-1]*(cd-1)+dp[i-1][0][k]\
                          +dp[i-1][1][k]+dp[i-1][1][k-1]*9


print(dp[-1][0][K]+dp[-1][1][K])

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

digit = len(N)
dp = [[[0]*(digit+1) for _ in range(2)] for _ in range(digit)]

cd = int(N[0])
dp[0][0][0] = 0
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = cd-1

for i in range(1, digit):
    for k in range(i+2):
        cd = int(N[i])
        if k == 0:
            dp[i][1][0] = 1
        else:
            dp[i][0][k] = dp[i-1][0][k-1]
            dp[i][1][k] = dp[i-1][0][k-1]*(cd-1)+dp[i-1][0][k]\
                          +dp[i-1][1][k]+dp[i-1][1][k-1]*9


print(dp[-1][0][K]+dp[-1][1][K])
Problem p02793 (python)

Fixed submission:
from fractions import gcd

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

l = A[0]
for i in range(1, N):
    l = l * A[i] // gcd(l, A[i])

for a in A:
    res += l//a

print(res % 1000000007)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

l = lcm(A[0], A[1])
for i in range(2, N):
    l = lcm(l, A[i])

for i in range(N):
    res += l//A[i]

print(res % 1000000007)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    for _ in range(b):
        if i == N:
            break
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    if i == N:
        break
    for _ in range(b):
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    for _ in range(b):
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1], reverse=True)
A.sort()
i = 0
for bc in BC:
    for _ in range(bc[0]):
        if bc[1] > A[i]:
            A[i] = bc[1]
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
C = []
A.sort()
i = 0
for bc in BC:
    for _ in range(bc[0]):
        if bc[1] > A[i]:
            A[i] = bc[1]
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1], reverse=True)
A.sort()
i = 0
for bc in BC:
    for _ in range(bc[0]):
        if bc[1] > A[i]:
            A[i] = bc[1]
            i += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1], reverse=True)
A.sort()
i = 0
for bc in BC:
    for _ in range(bc[0]):
        if bc[1] > A[i]:
            A[i] = bc[1]
            i += 1
        else:
            break

print(sum(A))
Problem p03108 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000) 

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
AB = AB[::-1]
res = (N*(N-1))//2
ans = []
for l in AB:
    l[0] -= 1
    l[1] -= 1
parent = [-1]*N


def root(node):
    if parent[node] < 0:
        return node
    else:
        parent[node] = root(parent[node])
        return parent[node]


def size(node):
    return -parent[root(node)]


def connect(a, b):
    a = root(a)
    b = root(b)
    if a == b:
        return False
    parent[a] += parent[b]
    parent[b] = a
    return True


for A, B in AB:
    ans.append(res)
    a = size(A)
    b = size(B)
    if connect(A, B):
        res -= a*b

for i in ans[::-1]:
    print(i)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
AB = AB[::-1]
res = (N*(N-1))//2
ans = []
for l in AB:
    l[0] -= 1
    l[1] -= 1
parent = [-1]*N  # 親の番号を格納 -(size)の場合は親


def root(node):
    if parent[node] < 0:
        return node
    else:
        parent[node] = root(parent[node])
        return parent[node]


def size(node):
    return -parent[root(node)]


def connect(a, b):
    a = root(a)
    b = root(b)
    if a == b:
        return False
    parent[a] += parent[b]
    parent[b] = a
    return True


for A, B in AB:
    ans.append(res)
    a = size(A)
    b = size(B)
    if connect(A, B):
        res -= a*b

for i in ans[::-1]:
    print(i)
Problem p02723 (python)

Fixed submission:
S = input()

if S[2]==S[3]:
    if S[4]==S[5]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

if S[3]==S[4]:
    if S[5]==S[6]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p02785 (python)

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
if K == 0:
    pass
elif K > N:
    H.clear()
else:
    H = H[:-K]
print(sum(H))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
if K <= N and K != 0:
    H.remove(H[:K])
elif K > N and K != 0:
    H.clear()
print(sum(H))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
if K <= N:
    for k in range(K):
        H.remove(H[k])
else:
    H.clear()
print(sum(H))
Problem p02835 (python)

Fixed submission:
A,B,C = map(int,input().split())
ans = A + B + C

if ans >= 22:
	print("bust")
else:
	print("win")

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

ans = A+B+C
if ans>=22:
	print(bust)
elif ans <= 21:
	print(win)
Problem p02847 (python)

Fixed submission:
S = input()

mp = {
    'SUN':7,
    'MON':6,
    'TUE':5,
    'WED':4,
    'THU':3,
    'FRI':2,
    'SAT':1
}

print(mp[S])

Buggy submission (verdict: Runtime Error):
def nibutan(A,B,X,L,H):
	M=(H+L)//2
	tmp=A*M+B*len(str(M))
	if M == 0:
		return 0
	elif tmp==X:
		return M
	elif tmp<X:
		if M==999999999:
			return M
		else:
			return nibutan(A,B,X,M,H)
	elif tmp>X:
		tmp_2=A*(M-1)+B*len(str(M-1))
		if tmp_2<X:
			return M-1
		else:
			return nibutan(A,B,X,L,M)

A,B,X=map(int,input().split())
if X>=A*1000000000+B*10:
	print(1000000000)
else:
	ans=nibutan(A,B,X,0,1000000000)
	print(ans)

Buggy submission (verdict: Runtime Error):
def nibutan(A,B,X,L,H):
	M=(H+L)//2
	tmp=A*M+B*len(str(M))
	if M == 0:
		return 0
	elif tmp==X:
		return M
	elif tmp<X:
		if M=999999999:
			return 999999999
		else:
			return nibutan(A,B,X,M,H)
	elif tmp>X:
		tmp_2=A*(M-1)+B*len(str(M-1))
		if tmp_2<X:
			return M-1
		else:
			return nibutan(A,B,X,L,M)

A,B,X=map(int,input().split())
if X>=A*1000000000+B*10:
	print(1000000000)
else:
	ans=nibutan(A,B,X,0,1000000000)
	print(ans)
Problem p02879 (python)

Fixed submission:
A,B = map(int,input().split())
if A>0 and A<10 and B>0 and B<10:
	print(A*B)
else:
	print(-1)

Buggy submission (verdict: Runtime Error):
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B+1)):
	if count == 0:
		if A % i == 0:
			print(int(i+A/i-2))
			count += 1

Buggy submission (verdict: Runtime Error):
A,B = map(int(input().split()))
if A>0 and A<10 and B>0 and B<10:
	print(A*B)
else:
	print(-1)
Problem p02881 (python)

Fixed submission:
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B+1)):
	if count == 0:
		if A % i == 0:
			print(int(i+A/i-2))
			count += 1

Buggy submission (verdict: Runtime Error):
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B)):
	if count == 0:
    	if A % i == 0:
			print(i+A/i-2)
        	count += 1
Problem p03011 (python)

Fixed submission:
P,Q,R = map(int,input().split())
A = [P+Q,Q+R,P+R]
A.sort()
print(A[0])

Buggy submission (verdict: Runtime Error):
A = int(input())
W = list(map(int,input().split()))
tmp = 0
ans = 0
wa = 0

for i in range (A):
    wa += W[i]
for i in range (A):
    tmp += W[i]
    tmp_r = wa-tmp
    if i == 0:
        ans = tmp
    if ans > abs(tmp-tmp_r):
        ans = abs(tmp-tmp_r)
print(ans)
Problem p02682 (python)

Fixed submission:
# S = input()
# N = int(input())
# A, B = map(int, input().split(' '))
# A = list(map(int, input().split(' ')))

A, B, C, K = map(int, input().split(' '))
result = 0

if A < K:
  result += A
  K -= A
else:
  result = K
  K -= A

if K > 0:
  if B < K:
    K -= B
  else:
    K -= B

if K > 0:
  if C < K:
    result -= C
    K -= C
  else:
    result -= K

print(result)

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

A, B, C, K = map(int, input().split(' '))

card = []
a = [1]*A
b = [0]*B
c = [-1]*C

card.extend(a)
card.extend(b)
card.extend(c)


card = sorted(card, reverse=True)

print(sum(card[:K]))
Problem p02779 (python)

Fixed submission:
n = int(input())
a = input().split(' ')
 
if len(set(a)) == n:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split(' ')

if len(set(a)) == n:
  print('YES')
else
  print('NO')
Problem p02831 (python)

Fixed submission:
#!python3.4.3
from fractions import gcd

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

if __name__ == "__main__":
    a, b = map(int, input().split(' '))
    
    print(lcm(a, b))

Buggy submission (verdict: Runtime Error):
#!python3.4.3
import math

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

if __name__ == "__main__":
    a, b = map(int, input().split(' '))
    
    print(lcm(a, b))
Problem p02881 (python)

Fixed submission:
import math


def main():
    n = int(input())
    a = 1
    b = n
    
    ans = n - 1 
    
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            a = int(i)
            b = int(n / i)
            ans = min(ans, a+b-2)
    print(ans)
        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

def make_divisors(n):
    divisors = []
    for i in range(int(math.sqrt(n))+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    return divisors

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

    a, b = make_divisors(target)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    return divisors

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

    a, b = make_divisors(target)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

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

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

    a, b = make_divisors(n)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

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

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

    a, b = make_divisors(n)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()
Problem p02951 (python)

Fixed submission:
from sys import stdin

param = input().split()
A=int(param[0])
B=int(param[1])
C=int(param[2])

hituyou=A-B
if hituyou<=C :
  nokori = C-hituyou
elif hituyou>C:
  nokori = 0
  
print(nokori)

Buggy submission (verdict: Runtime Error):
from sys import stdin

param = input().split()
A=param[0]
B=param[1]
C=param[2]

hituyou=A-B
if hituyou<=C :
  nokori = C-hituyou
elif hituyou>C:
  nokori = 0
  
print(nokori)
Problem p03208 (python)

Fixed submission:
import sys, math, itertools, collections, bisect
n,k=map(int,input().split())
h=[]
for i in range(n):
    tmp=int(input())
    h.append(tmp)
h.sort()
min=10000000000
for i in range(len(h)-k+1):
    tmp2=h[i+k-1]-h[i]
    if min>tmp2:
        min=tmp2
print(min)

Buggy submission (verdict: Runtime Error):
import sys, math, itertools, collections, bisect
n,k=map(int,input().split())
h=[]
for i in range(n):
    tmp=int(input())
    h.append(tmp)
h.sort()
min=10000000000
for i in range(len(h)-2):
    tmp2=h[i+k-1]-h[i]
    if min>tmp2:
        min=tmp2
print(min)
Problem p03265 (python)

Fixed submission:
x=list(input().split())
x1=int(x[0])
y1=int(x[1])
x2=int(x[2])
y2=int(x[3])
xlength=x2-x1
ylength=y2-y1
x3=x2-ylength
y3=y2+xlength
x4=x1-ylength
y4=y1+xlength

  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))

Buggy submission (verdict: Runtime Error):
x=list(input().split())
x1=int(x[0])
y1=int(x[1])
x2=int(x[2])
y2=int(x[3])
xlength=abs(x1-x2)
ylength=abs(y1-y2)
if x1>x2 and y2>y1:
  x3=x2-ylength
  y3=y2-xlength
  x4=x3+xlength
  y4=y3-ylength
elif x1>x2 and y1>y2:
  x3=x2+xlength
  y3=y2-ylength
  x4=x3+ylength
  y4=y3+xlength
elif x1<x2 and y1>y2:
  x3=x2+ylength
  y3=y2+xlength
  x4=x3-xlength
  y4=y3+ylength
elif x1<x2 and y1<y2:
  x3=x2-xlength
  y3=y2+ylength
  x4=x3-ylength
  y4=y3-xlength
  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))
Problem p03013 (python)

Fixed submission:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(nsm())

mod = 1000000007

n, m = nm()
dp = [0] * (n + 1)
for i in range(m):
    tmp = ni()
    dp[tmp] = -1
dp[0] = 1
for i in range(n):
    if i + 1 < n + 1 and dp[i + 1] != -1 and dp[i] != -1:
        dp[i + 1] += dp[i] % mod
        dp[i + 1] %= mod
    if i + 2 < n + 1 and dp[i + 2] != -1 and dp[i] != -1:
        dp[i + 2] += dp[i] % mod
        dp[i + 2] %= mod
print(dp[n] % mod)

Buggy submission (verdict: Runtime Error):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(nsm())

mod = 1000000007

n, m = nm()
dp = [0] * (n + 2)
for i in range(m):
    tmp = ni()
    dp[tmp] = -1
dp[0] = 1
for i in range(n):
    if i + 1 <= n:
        if dp[i + 1] != -1 and dp[i] != -1:
            dp[i + 1] += dp[i] % mod
            dp[i + 1] %= mod
    if i + 2 <= n:
        if dp[i + 2] != -1 and dp[i] != -1:
            dp[i + 2] += dp[i] % mod
            dp[i + 2] %= mod
if dp[n] = -1:
    print(0)
else:
    print(dp[n] % mod)
Problem p03108 (python)

Fixed submission:
n, m = map(int, input().split())
pair = []
for i in range(m):
	pair.append(list(map(int, input().split())))
pair = pair[::-1]
ans = []
ans.append(int(n*(n-1)/2))

class UnionFind:
    def __init__(self, n):
        self.par = [-1] * (n+1)
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def size(self, x):
        return -self.par[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.size(x) < self.size(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        return

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u = UnionFind(n)
for i in range(len(pair) - 1):
    if u.find(pair[i][0]) != u.find(pair[i][1]):
        ans.append(max(0, int(ans[i] - u.size(pair[i][0]) * u.size(pair[i][1]))))
    else:
        ans.append(ans[i])
    u.union(pair[i][0], pair[i][1])
ans = ans[::-1]
for i in range(len(ans)):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
pair = []
for i in range(m):
	pair.append(list(map(int, input().split())))
pair = pair[::-1]
ans = []
ans.append(int(n*(n-1)/2))

class UnionFind:
    def __init__(self, n):
        self.par = [-1] * (n+1)
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def size(self, x):
        return -self.par[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        elif self.size(x) < self.size(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        return True

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u = UnionFind(n)
for i in range(len(pair) - 1):
    if u.union(pair[i][0], pair[i][1]) == True:
        ans.append(int(ans[i] - u.size(pair[i][0]) * u.size(pair[i][1])))
    u.union(pair[i][0], pair[i][1])
ans = ans[::-1]
for i in range(len(ans)):
    print(ans[i])