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

Fixed submission:
from scipy.misc import comb
n, k = map(int, input().split())
for i in range(1, k+1):
	print( comb(k-1, i-1, exact=True)*comb(n-k+1, n-k-i+1, exact=True)%(10**9+7) )

Buggy submission (verdict: Runtime Error):
from scipy.special import perm, comb
n, k = map(int, input().split())
for i in range(1, k+1):
	print( comb(k-1, i-1, exact=True)*comb(n-k+1, n-k-i+1, exact=True)%(10**9+7) )
Problem p03041 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n, k = map(int, raw_input().split())

# 文字列の入力
str = list(raw_input())

str[k-1] = str[k-1].lower()
# 出力
newstr = "".join(str)
print(newstr)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
str = list(raw_input())
f = int(str[0]+str[1])
l = int(str[2]+str[3])
# 文字列の入力
ans = ""
if(f > 0 and 13 > f):
    if(l == 0):
        ans = "MMYY"
    if(l > 0 and 13 > l):
        ans = "AMBIGUOUS"
    if(l >= 13):
        ans= "MMYY"
elif(f == 0):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
elif(f>=13):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
 
print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
str = list(raw_input())
f = int(str[0]+str[1])
l = int(str[2]+str[3])
# 文字列の入力
if(f == 0):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
elif(f > 0 and 13 > f):
    if(l == 0):
        ans = "MMYY"
    if(l > 0 and 13 > l):
        ans = "AMBIGUOUS"
    if(l >= 13):
        ans= "MMYY"
elif(f >= 13):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"

print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
str = list(raw_input())
f = int(str[0]+str[1])
l = int(str[2]+str[3])
# 文字列の入力
if(f == 0):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
elif(f > 0 and 13 > f):
    if(l == 0):
        ans = "MMYY"
    if(l > 0 and 13 > l):
        ans = "AMBIGUOUS"
    if(l >= 13):
        ans= "MMYY"
elif(f >= 13):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"

print ans
# 出力
Problem p03011 (python)

Fixed submission:
ini=input().split()
ini=[int(i) for i in ini]

P=ini[0]
Q=ini[1]
R=ini[2]

ans=P+Q+R-max(ini)

print(ans)

Buggy submission (verdict: Runtime Error):
ini=input().split()
ini=[int(i) for i in ini]
N=ini[0]
M=ini[1]

a=[0]
for i in range(M):
    a.append(int(input()))
a.append(N)

#print(a)
ans=1
def fib(n):
    
    atai = 1
    atai2 = 2
   # global atai,atai2
    if n==1:
        atai2=1
        return atai2
    if n==2:
        atai2=2
        return atai2
    else:
        for i in range(1,n):
            temp=atai2
            atai2=atai+temp
            atai=temp
        return atai2
#print(N,M)
for i in range(M+1):
    b=a[i+1]-a[i]-1
    # if i==M:
    #     ans=ans*fib(N-a[i]-1)
    #     print("iff",ans,fib(N-a[i]-1))
    if b==0 and a[1]!=1:
        ans=0
        break
    if b>0:
        ans=ans*fib(b)
#        if ans>1000000007:
        ans=ans % 1000000007
#        print("if",ans,fib(b))
#        print(ans,fib(b),c[i])

ans=ans % 1000000007
print(ans)
Problem p03012 (python)

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

ini=input().split()
W=[int(i) for i in ini]

Wa=0
S=0
for i in range(N):
    Wa+=W[i]

#print(Wa)
for i in range(N):
    S+=W[i]
    if S>Wa/2:
        S1=S
        S2=Wa-S1
        S11=S-W[i]
        S22=Wa-S11
        break

ans1=abs(S1-S2)
ans2=abs(S11-S22)

#print(ans1,ans2,S1,S2,S11,S22)

if ans1>=ans2:
    print(ans2)
else:
    print(ans1)

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

ini=input().split()
W=[int(i) for i in ini]

Wa=0
S=0
for i in range(N):
    Wa+=W[i]


for i in range(N):
    S+=W[i]
    if S>Wa/2:
        S1=S-W[i-1]
        S2=S

ans=abs(S1-S2)

print(ans)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
A = []
for i in range(M):
	curr = int(input())
	A.append(curr)

mod = 1000000007

ans = [0] * (N + 1)

ans[0] = 1

for a in A:
	ans[a] = -1

for i in range(len(ans)):
	if ans[i] == -1:
		continue
	if(i+1 < len(ans) and ans[i+1] != -1):
		ans[i+1] += ans[i]
		ans[i+1] %= mod
	if(i+2 < len(ans) and ans[i+2] != -1):
		ans[i+2] += ans[i]
		ans[i+2] %=mod

print(ans[N])

Buggy submission (verdict: Runtime Error):
class Solution(object):
	def __init__(self):
		self.ans = 0
	def search(self, pos, dest):
		if(pos > dest):
			return
		if(pos == dest):
			self.ans += 1
			return
		if(pos - dest % 3 == 0):
			self.ans += (pos // 3) * 2
			return
		self.search(pos+1, dest)
		self.search(pos+2, dest)

N, M = map(int, input().split())
A = []

prev = 0

for i in range(M):
	curr = int(input())
	A.append(curr)
	#prev = curr

A.append(N+1)

#print(A)

ans = 1

prev = 0
for i in range(len(A)):
	s = Solution()
	if(i == 0):
		prev = 0
	else:
		prev = A[i-1] + 1
	#print(prev)
	s.search(prev,A[i]-1)
	con = s.ans
	#print(con)
	ans *= con % 1000000007

print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
class Solution(object):
	def __init__(self):
		self.ans = 0
	def search(self, pos, dest):
		if(pos > dest):
			return
		if(pos == dest):
			self.ans += 1
			return
		self.search(pos+1, dest)
		self.search(pos+2, dest)

N, M = map(int, input().split())
A = []

prev = 0

for i in range(M):
	curr = int(input())
	A.append(curr)
	#prev = curr

A.append(N+1)

#print(A)

ans = 1

prev = 0
for i in range(len(A)):
	s = Solution()
	if(i == 0):
		prev = 0
	else:
		prev = A[i-1] + 1
	#print(prev)
	s.search(prev,A[i]-1)
	con = s.ans
	#print(con)
	ans *= con

print(ans % 1000000007)
Problem p03012 (python)

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

print(min(*[abs(sum(wl[:a]) - sum(wl[a:])) for a in range(N)]))

Buggy submission (verdict: Runtime Error):
def combination(n, r):
    r = min(r, n-r)
    nume = 1
    denomi = 1
    for i in range(1, r+1):
        denomi *= i
    for i in range(n-r+1, n+1):
        nume *= i
    return nume // denomi

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

sl = []
cnt = -1
ng = 0
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        ng = 1
    sl.append(max(b, 1))
    cnt = a

if ng:
    print(0)
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combination(j, i)
            else:
                break
        ans *= p
    print(ans % 1000000007)
Problem p03108 (python)

Fixed submission:
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, size):
        self.rank = [-1]*(size+1)
        self.number = [1]*(size+1)
        
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    
    def union(self, a, b):
        if a == b:
            return
        if self.rank[a] == self.rank[b]:
            self.rank[b] = a
            self.rank[a] -= 1
            self.number[a] += self.number[b]
        elif self.rank[a] < self.rank[b]:
            self.rank[b] = a
            self.number[a] += self.number[b]
        else:
            self.rank[a] = b
            self.number[b] += self.number[a]
            
p = N * (N - 1) // 2
ans = [p]
uf = UnionFind(N)

for a, b in ab[::-1]:
    ar = uf.find(a)
    br = uf.find(b)
    
    if ar != br:
        p -= uf.number[ar] * uf.number[br]
        uf.union(ar, br)
    ans.append(p)

print(*ans[::-1][1:], sep='\n')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, size):
        self.rank = [-1]*(size+1)
        self.number = [1]*(size+1)
        
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    
    def union(self, a, b):
        if a == b:
            return
        if self.rank[a] == self.rank[b]:
            self.rank[b] = a
            self.rank[a] -= 1
            self.number[a] += self.number[b]
        elif self.rank[a] < self.rank[b]:
            self.rank[b] = a
            self.number[a] += self.number[b]
        else:
            self.rank[a] = b
            self.number[b] += sekf.number[a]
            
p = N * (N - 1) // 2
ans = [p]
uf = UnionFind(N)

for a, b in ab[::-1]:
    ar = uf.find(a)
    br = uf.find(b)
    
    if ar != br:
        p -= uf.number[ar] * uf.number[br]
        uf.union(ar, br)
    ans.append(p)

print(*ans[::-1], sep='\n')
Problem p03011 (python)

Fixed submission:
A, B, C = map(int,input().split())
print(sum([A,B,C])-max(A,B,C))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int,input().split())
print(sum(A,B,C)-max(A,B,C))
Problem p03075 (python)

Fixed submission:
[a, b, c, d, e] = [int(input()) for i in range(5)]
k = int(input())

if e-a <= k:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
[a, b, c, d, e] = [int(input()) for i in range(5)]
k = int(input())

difs = [b-a, c-b, d-c, e-d]
Mdif = Max(difs)
if Mdif <= k:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
[a, b, c, d, e] = [int(input()) for i in range(5)]
k = int(input())

difs = [b-a, c-b, d-c, e-d]
Mdif = Max(difs)
if Mdif <= k:
  print("Yay!)
else:
  print(":(")
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengths)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengthes)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)
Problem p03242 (python)

Fixed submission:
inp = input()

corrected = ""
for l in inp:
  if l == "1":
    corrected += "9"
  elif l == "9":
    corrected += "1"
  else:
    print("error")

print(int(corrected))

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

corrected = ""
for l in inp:
  if l == "1":
    corrected += "9"
  elif l == 9:
    corrected += "1"
  else:
    print("error")

print(int(corrected))
Problem p03250 (python)

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

print(sum(numbers) + max(numbers)*9)

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

print(sum(numbers) + max(numbers)*9)

Buggy submission (verdict: Runtime Error):
numbers = [int(input()) for i in range(3)]

print(sum(numbers) + max(numbers)*9)

Buggy submission (verdict: Runtime Error):
numbers = [int(input()) for i in range(3)]

numbers.sort()
numbers.reverse()

print(numbers[0]*10 + numbers[1] + numbers[2])

Buggy submission (verdict: Runtime Error):
numbers = [int(input()) for i in range(3)]

numbers.sort()
numbers.reverse()

print(numbers[0]*10 + numbers[1] + numbers[2])
Problem p03307 (python)

Fixed submission:
N = int(input())

if N%2 == 0:
    print(N)
else:
    print(2*N)

Buggy submission (verdict: Runtime Error):
print(2*N if N%2==1 else N)

Buggy submission (verdict: Runtime Error):
print(2*N if N%2==0 else N)
Problem p03315 (python)

Fixed submission:
print((input().count('+')-2)*2)

Buggy submission (verdict: Runtime Error):
print((S = input().count('+')-2)*2)
Problem p03767 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
print(sum(A[1::2][:N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
print(sum(A[1::2][N]))
Problem p03835 (python)

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

cnt = 0
for x in range(K+1):
  for y in range(K+1):
      if 0 <= S-(x+y) <= K:
        cnt += 1
print(cnt)

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

cnt = 0
for x in range(K+1):
  for y in range(K+1):
      if 0 <= S-(x+y) <= K 
        cnt += 1
print(cnt)
Problem p02990 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
max_i = min(K, N - K + 1)

MAX = N * 2
PRIME = 10 ** 9 + 7

fac = [0] * MAX
finv = [0] * MAX


def invMod(a, m):
    a %= m
    b, x, y = m, 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        x -= t * y
        x, y = y, x
    return x % m


def binomInit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fac[i] = (fac[i - 1] * i) % PRIME
        finv[i] = (finv[i - 1] * invMod(i, PRIME)) % PRIME
        

def binom(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % PRIME


binomInit()
    

for i in range(1, K + 1):
    blue_part = binom(K - 1, i - 1)
    red_part = binom(N - K + 1, i)
    print((blue_part * red_part) % PRIME)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
max_i = min(K, N - K + 1)

MAX = max_i + 2
PRIME = 10 ** 9 + 7

fac = [0] * MAX
finv = [0] * MAX


def invMod(a, m):
    a %= m
    b, x, y = m, 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        x -= t * y
        x, y = y, x
    return x % m


def binomInit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fac[i] = (fac[i - 1] * i) % PRIME
        finv[i] = (finv[i - 1] * invMod(i, PRIME)) % PRIME
        

def binom(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % PRIME


binomInit()
    

for i in range(1, K + 1):
    blue_part = binom(K - 1, i - 1)
    red_part = binom(N - K + 1, i)
    print((blue_part * red_part) % PRIME)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))

MAX = N
PRIME = 10 ** 9 + 7

fac = [0] * MAX
finv = [0] * MAX


def invMod(a, m):
    a %= m
    b, x, y = m, 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        x -= t * y
        x, y = y, x
    return x % m


def binomInit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fac[i] = (fac[i - 1] * i) % PRIME
        finv[i] = (finv[i - 1] * invMod(i, PRIME)) % PRIME
        

def binom(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % PRIME


binomInit()
    
    
max_i = min(K, N - K + 1)

for i in range(1, max_i + 1):
    blue_part = 1 if K - i == 0 else binom(K - 1, i - 1)
    red_part = 1 if (N - K) - (i - 1) == 0 else binom(N - K + 1, i)
    print((blue_part * red_part) % PRIME)
Problem p03013 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def fib_memo(n):
    if n <= 1:
        return 1
    memo = [0] * n
    memo[0] = 1
    memo[1] = 2
    for i in range(2, n):
        memo[i] = (memo[i - 1] + memo[i - 2]) % PRIME
    return memo[n-1]

PRIME = 10 ** 9 + 7
N, M = list(map(int, input().split()))
broken_stairs = []
for _ in range(M):
    broken_stairs.append(int(input()))

prev_broken = -1
cannot = False
ans = 1
for a in broken_stairs:
    if a - prev_broken == 1:
        cannot = True
        break
    ans *= fib_memo(a - prev_broken - 2)
    ans %= PRIME
    prev_broken = a

ans *= fib_memo(N - prev_broken - 1)
ans %= PRIME

if cannot:
    print(0)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import lru_cache

@lru_cache(maxsize=None)
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)

PRIME = 10 ** 9 + 7
N, M = list(map(int, input().split()))
broken_stairs = []
for _ in range(M):
    broken_stairs.append(int(input()))

prev_broken = -1
cannot = False
ans = 1
for a in broken_stairs:
    if a - prev_broken == 1:
        cannot = True
        break
    ans *= fib(a - prev_broken - 2)
    ans %= PRIME
    prev_broken = a

ans *= fib(N - prev_broken - 1)
ans %= PRIME

if cannot:
    print(0)
else:
    print(ans)
Problem p03272 (python)

Fixed submission:
N,M = map(int, input().split())
print(N-M+1)

Buggy submission (verdict: Runtime Error):
N , M = map(int, input())
print(N-M+1)
Problem p03345 (python)

Fixed submission:
A,B,C,K= map(int, input().split())
 
if (A-B) > 10e18 or (B-A) > 10e18:
 print("Unfair")
elif K % 2 == 1:
 print(B-A)
else:
 print(A-B)

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

start = int(input())
flag = 0
if start != 0:
 flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

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

if (A-B) ** 2 **0.5 > 10e18:
 print("Unfair")
elif K % 2 == 1:
 print(A-B)
else:
 print(B-A)
Problem p03013 (python)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
 
a = []
aindex = 0
for _ in range(M):
    a.append(int(input()))
 
before1 = 1
before2 = 0
ai=0
if len(a)>0:
    ai = a[aindex]
 
for i in range(1, N+1):
    if i == ai:
        before2 = before1
        before1 = 0
        if aindex < len(a)-1:
            aindex += 1
            ai = a[aindex]
    else:
        current = divmod(before1 + before2, 10**9+7)[1]
        before2 = before1
        before1 = current
 
 
print(before1)

Buggy submission (verdict: Runtime Error):
from collections import deque

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

a = []
aindex = 0
for _ in range(M):
    a.append(int(input()))

before1 = 1
before2 = 0
if len(a)>0:
    ai = a[aindex]

for i in range(1, N+1):
    if i == ai:
        before2 = before1
        before1 = 0
        if aindex < len(a)-1:
            aindex += 1
            ai = a[aindex]
    else:
        current = divmod(before1 + before2, 10**9+7)[1]
        before2 = before1
        before1 = current


print(before1)

Buggy submission (verdict: Runtime Error):
from collections import deque

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

a = deque()
for _ in range(M):
    a.append(int(input()))

before1 = 1
before2 = 0
if len(a)>0:
    ai = a.popleft()

for i in range(N):
    if i == (ai-1):
        before2 = before1
        before1 = 0
        if len(a)>0:
            ai = a.popleft()
    else:
        current = divmod(before1 + before2, 10**9+7)[1]
        before2 = before1
        before1 = current


print(before1)

Buggy submission (verdict: Runtime Error):
from collections import deque

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

a = deque()
for _ in range(M):
    a.append(int(input()))

before1 = 1
before2 = 0
ai = a.popleft()
for i in range(N):
    if i == (ai-1):
        before2 = before1
        before1 = 0
        if len(a)>0:
            ai = a.popleft()
    else:
        current = divmod(before1 + before2, 10**9+7)[1]
        before2 = before1
        before1 = current
    
print(before1)
Problem p02970 (python)

Fixed submission:
inputing=input()
N=int(inputing.split()[0])
D=int(inputing.split()[1])

maximum=2*D+1
if N%maximum==0:
    print(int(N/maximum))
else:
    print(int(N/maximum+1))

Buggy submission (verdict: Runtime Error):
N=int(input())
D=int(input())
maximum=2*D+1
if N%maximum==0:
    print(int(N/maximum))
else:
    print(int(N/maximum+1))
Problem p03135 (python)

Fixed submission:
s = input().split()
T = int(s[0])
X = int(s[1])
print(T / X)

Buggy submission (verdict: Runtime Error):
T / X

Buggy submission (verdict: Runtime Error):
X / T
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
As = [int(input()) for _ in range(M)]+[0]
mod = 10**9 +7
dp = [0]*(N+1)
dp[0] = 1
j = 0
if As[j] != 1:
    dp[1] = 1
else:
    j += 1
for i in range(2, N+1):
    if i == As[j]:
        j += 1
        continue
    dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[N]%mod)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
As = [int(input()) for _ in range(M)]
mod = 10**9 +7
dp = [0]*(N+1)
dp[0] = 1
if As[0] != 1:
    dp[1] = 1
for i in range(2, N+1):
    if i in As:
        continue
    dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[N]%mod)
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
 
    def root(self, i):
        if self.parent[i] == i:
            return i
        else:
            self.parent[i] = self.root(self.parent[i])
            return self.parent[i]
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        self.parent[j] = i
N, M = map(int, input().split())
tree = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    tree.union(x-1, y-1)
for i in range(N):
    tree.root(i)
print(len(set(tree.parent)))

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
 
    def root(self, i):
        if self.parent[i] == i:
            return i
        else:
            self.parent[i] = self.root(self.parent[i])
            return self.parent[i]
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        self.parent[j] = i
N, M = map(int, input().split())
tree = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    tree.union(x-1, y-1)
for i in range(N):
    tree.root(i)
print(len(set(tree.parent)))
Problem p03104 (python)

Fixed submission:
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Buggy submission (verdict: Runtime Error):
def f(n):
    if n+1 % 4 == 0:
        return 0
    if n+1 % 4 == 1:
        return n
    if n+1 % 4 == 2:
        return 1
    if n+1 % 4 == 3:
        return 1^n
a, b = map(int, input().split())
ans = f(a-1) ^ f(b)
print(ans)