Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
#グラフの連結成分を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
    return G
from collections import deque
def dfs(G,v,p):
    q=deque()
    q.append((v,p))
    log=[False]*n
    log[v-1]=True
    while q:
        V,P=q[-1]
        for new_v in G[V-1]:
            if new_v==P:continue
            if log[new_v-1]:continue
            log[new_v-1]=True
            score[new_v-1]+=score[V-1]
            q.append((new_v,V))
            break
        else:
            q.pop()


n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]

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

G=Graph(ab)
#print(G,score,sep='\n')
dfs(G,1,-1)
print(*score)

Fixed submission:
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

#グラフの状態を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    #up_G=[0]*n#up_G[i]=頂点iの親
    for a,b in ab:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    return G

from collections import deque
def bfs(G,v,p):
    #(G,v,p)=(グラフ(木の情報),探索中の頂点,vの親)
    #vの子の頂点を決めて、vをpに移す
    q=deque()
    q.append((v,p))
    while q:
        V,P=q.popleft()
        for new_v in G[V]:
            #new_vが頂点の時はアウト
            if new_v==P:continue
            ans[new_v]+=ans[V]
            q.append((new_v,V))

G=Graph(ab)
ans=[0]*n
#print(G)

for p,x in px:
    ans[p-1]+=x
bfs(G,0,-1)
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

#グラフの状態を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    #up_G=[0]*n#up_G[i]=頂点iの親
    for a,b in ab:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    return G

from collections import deque
def bfs(G,v,p):
    #(G,v,p)=(グラフ(木の情報),探索中の頂点,vの親)
    #vの子の頂点を決めて、vをpに移す
    q=deque()
    q.append((v,p))
    while q:
        V,P=q.popleft()
        for new_v in G[V]:
            #new_vが頂点の時はアウト
            if new_v==P:continue
            ans[new_v]+=ans[V]
            q.append((new_v,V))

G=Graph(ab)
ans=[0]*n
#print(G)

for p,x in px:
    ans[p-1]+=x
bfs(G,0,-1)
print(*ans)


Fixed submission:
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

#グラフの状態を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    #up_G=[0]*n#up_G[i]=頂点iの親
    for a,b in ab:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    return G

from collections import deque
def bfs(G,v,p):
    #(G,v,p)=(グラフ(木の情報),探索中の頂点,vの親)
    #vの子の頂点を決めて、vをpに移す
    q=deque()
    q.append((v,p))
    while q:
        V,P=q.popleft()
        for new_v in G[V]:
            #new_vが頂点の時はアウト
            if new_v==P:continue
            ans[new_v]+=ans[V]
            q.append((new_v,V))

G=Graph(ab)
ans=[0]*n
#print(G)

for p,x in px:
    ans[p-1]+=x
bfs(G,0,-1)
print(*ans)
Buggy python submission (verdict: Runtime Error):
K,X=map(int,input().split())

for i in range(X-K+1,X+K):
  string+=i+' '
print(string)

Fixed submission:
A,B=map(int,input().split())
print(max(A+B,A-B,A*B))

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print(max(A+B,A-B,A*B)

Fixed submission:
A,B=map(int,input().split())
print(max(A+B,A-B,A*B))
Buggy python submission (verdict: Runtime Error):
K,X=map(int,input().split())
string=''
for i in range(X-K+1,X+K):
  string+=i+' '
print(string)

Fixed submission:
K,X=map(int,input().split())
string=''
for i in range(X-K+1,X+K):
  string+=str(i)+' '
print(string)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[sorted(list(input())) for i in range(n)]
count=0

for i in range(n-1):
    for j in range(i+1,n):
        if s[i]==s[j]:
            count+=1
        
print(count)

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
an={}
count=0
for i in range(n):
    if s[i] not in an:
        an[s[i]]=1
    else:
        an[s[i]]+=1
        count+=an[s[i]]-1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()

A=[0]*m
heapq.heapify(A)
#日がたつごとに選択肢が少なくなる→後ろから見ていく
ans=0
for day in range(m):
    for a,b in ab:
        if a<day+1:continue
        if a==day+1:
            heapq.heappush(A,-b)
        else:
            temp=heapq.heappop(A)
            ans+=temp
            #print(temp)
            break
    else:
        ans+=heapq.heappop(A)
print(-ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
heapq.heapify(l)
a=[]
heapq.heapify(a)
fd=heapq.heappop(l)
heapq.heappush(a,-fd[1])
ans=0
for day in range(fd[0],m+1):
    while l:
        temp=heapq.heappop(l)
        if temp[0]>day:
            heapq.heappush(l,temp)
            break
        else:
            heapq.heappush(a,-temp[1])
    if a:
        ans+=heapq.heappop(a)
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()

A=[0]*m
heapq.heapify(A)
#日がたつごとに選択肢が少なくなる→後ろから見ていく
ans=0
for day in range(m):
    for a,b in ab:
        if a<day+1:continue
        if a==day+1:
            heapq.heappush(A,-b)
        else:
            temp=heapq.heappop(A)
            ans+=temp
            #print(temp)
            break
    else:
        ans+=heapq.heappop(A)
print(-ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
heapq.heapify(l)
a=[]
heapq.heapify(a)
fd=heapq.heappop(l)
heapq.heappush(a,-fd[1])
ans=0
for day in range(fd[0],m+1):
    while l:
        temp=heapq.heappop(l)
        if temp[0]>day:
            heapq.heappush(l,temp)
            break
        else:
            heapq.heappush(a,-temp[1])
    if a:
        ans+=heapq.heappop(a)
print(-ans)
Buggy python submission (verdict: Runtime Error):
A,B,C=int(input()),int(input()),int(input())
if (A-B)>=C:
    print(0)
else:
    print(C-A+B)

Fixed submission:
A,B,C=map(int,input().split())
if (A-B)>=C:
    print(0)
else:
    ans=C-A+B
    print(ans)

Buggy python submission (verdict: Runtime Error):
A,B,C=int(input()),int(input()),int(input())
if (A-B)>=C:
    print(0)
else:
    print(C-(A-B))

Fixed submission:
A,B,C=map(int,input().split())
if (A-B)>=C:
    print(0)
else:
    ans=C-A+B
    print(ans)

Buggy python submission (verdict: Runtime Error):
A,B,C=int(input()),int(input()),int(input())
if (A-B)>=C:
    print('0')
else:
    print(C-(A-B))

Fixed submission:
A,B,C=map(int,input().split())
if (A-B)>=C:
    print(0)
else:
    ans=C-A+B
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    for i in range(n):
        if a[i]!=a_max:
            print(a_max)
        else:
            a[i]=0
            print(max(a))
            a[i]=a_max

n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
solve()

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
a_sort=sorted(a,reverse=True)
for i in range(n):
    if a[i]!=a_max:
        print(a_max)
    else:
        print(a_sort[1])

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    for i in range(n):
        if a[i]!=a_max:
            print(a_max)
        else:
            a[i]=0
            print(max(a))
            a[i]=a_max

n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
solve()

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
a_sort=sorted(a,reverse=True)
for i in range(n):
    if a[i]!=a_max:
        print(a_max)
    else:
        print(a_sort[1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
for i in range(n):
    if a[i]!=a_max:
        print(a_max)
    else:
        a[i]=0
        print(max(a))
        a[i]=a_max

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
a_sort=sorted(a,reverse=True)
for i in range(n):
    if a[i]!=a_max:
        print(a_max)
    else:
        print(a_sort[1])
Buggy python submission (verdict: Runtime Error):
def check(n):
    num=int(n**0.5)
    l=[1]
    for i in range(2,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return l

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

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[i]:continue
    cnt+=1
    ans[-(i+1)]=1
    box[i]=(box[i]+1)%2
    l=check(n-i)
    for j in l:
        box[j]=(box[j]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end=' ')

Fixed submission:
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return set(l)

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

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[-(i+1)]:continue
    cnt+=1
    ans[-(i+1)]=1
    l=check(n-i)
    for j in l:
        box[j-1]=(box[j-1]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end=' ')

Buggy python submission (verdict: Runtime Error):
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return l

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

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[i]:continue
    cnt+=1
    ans[-(i+1)]=1
    box[i]=(box[i]+1)%2
    l=check(n-i)
    for j in l:
        box[j]=(box[j]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end='')

Fixed submission:
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return set(l)

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

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[-(i+1)]:continue
    cnt+=1
    ans[-(i+1)]=1
    l=check(n-i)
    for j in l:
        box[j-1]=(box[j-1]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end=' ')

Buggy python submission (verdict: Runtime Error):
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return l

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

box=[0]*n
cnt=0
for i in range(n):
    if a[-(i+1)]==box[i]:continue
    cnt+=1
    box[i]=(box[i]+1)%2
    l=check(n-i)
    for j in l:
        box[j]=(box[j]+1)%2

print(cnt)
if cnt==0:exit()
print(*box[::-1])

Fixed submission:
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return set(l)

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

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[-(i+1)]:continue
    cnt+=1
    ans[-(i+1)]=1
    l=check(n-i)
    for j in l:
        box[j-1]=(box[j-1]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = [int(input()) for i in range(n)]

color_num = [a[0]]
cnt = 1
for i in range(1, n):
    if a[i] <= color_num[0]:
        color_num = [a[i]] + color_num
        cnt += 1
    else:
        temp = bisect.bisect_left(color_num, a[i])
        color_num[temp - 1] = a[i]

print(cnt)


Fixed submission:
import bisect
n = int(input())
a = [int(input()) for i in range(n)][::-1]

color_num = [a[0]]
for i in range(1, n):
    if a[i] >= color_num[-1]:
        color_num.append(a[i])
    else:
        temp = bisect.bisect_right(color_num, a[i])
        color_num[temp] = a[i]


print(len(color_num))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = [int(input()) for i in range(n)]

color_num = [a[0]]
cnt = 1
for i in range(1, n):
    temp = bisect.bisect_left(color_num, a[i])
    if cnt == temp:
        color_num[temp - 1] = a[i]
    elif temp == 0:
        color_num = [a[i]] + color_num
        cnt += 1
    else:
        color_num[temp - 1] = a[i]

print(cnt)


Fixed submission:
import bisect
n = int(input())
a = [int(input()) for i in range(n)][::-1]

color_num = [a[0]]
for i in range(1, n):
    if a[i] >= color_num[-1]:
        color_num.append(a[i])
    else:
        temp = bisect.bisect_right(color_num, a[i])
        color_num[temp] = a[i]


print(len(color_num))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = [int(input()) for i in range(n)]

color_num = [a[0]]
cnt = 1
for i in range(1, n):
    temp = bisect.bisect_left(color_num, a[i])
    if cnt == temp:
        color_num[temp - 1] = a[i]
    elif temp == 0:
        color_num = [a[i]] + color_num
        cnt += 1
    else:
        color_num[temp - 1] = a[i]

print(cnt)


Fixed submission:
import bisect
n = int(input())
a = [int(input()) for i in range(n)][::-1]

color_num = [a[0]]
for i in range(1, n):
    if a[i] >= color_num[-1]:
        color_num.append(a[i])
    else:
        temp = bisect.bisect_right(color_num, a[i])
        color_num[temp] = a[i]


print(len(color_num))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == set(0):
    print('Yes')
    exit()
    
if n % 3 != 0 or len(cnt) != 3:
    print('No')
else:
    key = []
    num = []
    for i, j in cnt.items():
        key.append(i)
        num.append(j)
    if len(set(num)) != 1:
        print('No')
    else:
        if key[0]^key[1] == key[2]:print('Yes')
        else:print('No')

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == {0}:
    print('Yes')
    exit()

flag = 0
if n % 3 == 0:
    if len(cnt) == 2:
        if cnt.get(0) == n // 3:flag = 1
    elif len(cnt) == 3:
        if len(set(cnt.values())) == 1:
            new_a = list(cnt.keys())
            if new_a[0]^new_a[1] == new_a[2]:flag = 1

print('Yes' if flag else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            break
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            break
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
l,r=map(int,input().split())
s=list(range(l,r+1))
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            exit()
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
l,r=map(int,input().split())
s=list(range(l,r+1))
ans=2018
for i in range(r-l):
    for j in range(i+1,r-l+1):
        ans=min((s[i]%2019)*(s[j]%2019),ans)
        if ans==0:
            break
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
l,r=map(int,input().split())
s=list(range(l,r+1))
ans=[2018]
for i in range(r-l):
    for j in range(i+1,r-l+1):
        ans=min((s[i]%2019)*(s[j]%2019),ans)
        if ans==0:
            break
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
l,r=map(int,input().split())
s=np.array(range(l,r+1))
ans=[2018]
for i in range(r-l):
    for j in range(i+1,r-l+1):
        ans=min((s[i]%2019)*(s[j]%2019),ans)
        if ans==0:
            break
print(ans)

Fixed submission:
l,r=[int(i) for i in input().split()]
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        ans=min(i*j%2019,ans)
        if ans==0:
            print(ans)
            exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n=>1:
    print('Bad')
else:
    print('Good')

Fixed submission:
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>=1:
    print('Bad')
else:
    print('Good')

Buggy python submission (verdict: Runtime Error):
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>0
    print('Bad')
else:
    print('Good')

Fixed submission:
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>=1:
    print('Bad')
else:
    print('Good')

Buggy python submission (verdict: Runtime Error):
s=list(input())+['']
n=0
for i in range(4):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>0
    print('Bad')
else:
    print('Good')

Fixed submission:
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>=1:
    print('Bad')
else:
    print('Good')

Buggy python submission (verdict: Runtime Error):
s=input()+['']
n=0
for i in range(4):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>0
    print('Bad')
else:
    print('Good')

Fixed submission:
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>=1:
    print('Bad')
else:
    print('Good')

Buggy python submission (verdict: Runtime Error):
s=input()
n=0
for i in range(4):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>0
    print('Bad')
else:
    print('Good')

Fixed submission:
s=input()
n=0
for i in range(3):
    if s[i]==s[i+1]:
        n+=1
    else:
        n+=0
if n>=1:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
aji=[]
for i in range(n):
    aji+=[l+i]
su=sum(aji)
c=[su]
for i in range(n):
    c=[abs(su-aji[i])]
c.sort()
print(s)

Fixed submission:
n,l=map(int,input().split())
aji=[l+i for i in range(n)]
aji.sort(key=abs)
print(sum(aji[1:]))
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
import fractions
cd_gcd=c*d/gcd(c,d)
l=b-a+1
print(l-(l//c+l//d-l//(cd_gcd)))#c*d←ここをc.dの最小公倍数にする


Fixed submission:
import fractions

a,b,c,d=map(int,input().split())

cd_lcm=int(c*d/fractions.gcd(c,d))

b_count=b-(b//c+b//d-b//cd_lcm)
a_count=a-1-((a-1)//c+(a-1)//d-(a-1)//cd_lcm)

print(int(b_count-a_count))
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
if x=w/2 and y=h/2:
    print(w*h/2,1,sep=' ')
else:
    print(w*h/2,0,sep=' ')

Fixed submission:
w,h,x,y=map(int,input().split())
if x==w/2 and y==h/2:
    print(w*h/2,1,sep=' ')
else:
    print(w*h/2,0,sep=' ')
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[0]*(n+2)
num=10**9+7
dp[0]=1
for i in range(n):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i]%num
        if i<n:
            dp[i+1]+=dp[i]
            dp[i+2]+=dp[i]
print(dp[-2]%num)

Fixed submission:
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[1]*(n+1)
for i in a:
    dp[i]=0
    
k=10**9+7
for i in range(2,n+1):
    if dp[i]!=0:
        dp[i]=(dp[i-1]+dp[i-2])%k
        
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[0]*(n+2)
num=10**9+7
dp[0]=1
for i in range(n):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i]%num
        if i<n:
            dp[i+1]+=dp[i]
            dp[i+2]+=dp[i]
print(dp[-2]%num)

Fixed submission:
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[1]*(n+1)
for i in a:
    dp[i]=0
    
k=10**9+7
for i in range(2,n+1):
    if dp[i]!=0:
        dp[i]=(dp[i-1]+dp[i-2])%k
        
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[1]*(n+1)
k=10**9+7
for i in range(1,n+1):
    
    if i in a:
        
        dp[i]=0
    else:
        if i!=1:   
            dp[i]=(dp[i-1]+dp[i-2])%k
        
print(dp[-1])

Fixed submission:
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[1]*(n+1)
for i in a:
    dp[i]=0
    
k=10**9+7
for i in range(2,n+1):
    if dp[i]!=0:
        dp[i]=(dp[i-1]+dp[i-2])%k
        
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
from collections import deque
from heapq import *
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for a in range(k + 1):
    for b in range(k + 1 - a):
        trash = k - (a + b)
        get = v[:a] + v[-b:] if b != 0 else v[:a]
        heapify(get)
        for _ in range(min(trash, a + b)):
            heappop(get)
        SUM = sum(get)
        if ans < SUM:ans = SUM
print(ans)

Fixed submission:
from collections import deque
from heapq import *
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
num = min(k, n)
for a in range(num + 1):
    for b in range(num + 1 - a):
        trash = k - (a + b)
        get = v[:a] + v[-b:] if b != 0 else v[:a]
        heapify(get)
        for _ in range(min(trash, a + b)):
            temp = heappop(get)
            if temp > 0:
                heappush(get, temp)
                break
        SUM = sum(get)
        if ans < SUM:ans = SUM
print(ans)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
import math
def GCD(a, b):
    if a * b == 0:
        return a + b
    return math.gcd(a, b)

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

L = [0] * n
R = [0] * n

for i in range(n - 1):
    L[i + 1] = GCD(a[i], L[i])
    R[-(i + 2)] = GCD(a[-(i + 1)], R[-(i + 1)])

M = [0] * n
for i in range(n):
    M[i] = GCD(L[i], R[i])
print(max(M))

Fixed submission:
import fractions
def GCD(a, b):
    if a * b == 0:
        return a + b
    return fractions.gcd(a, b)

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

L = [0] * n
R = [0] * n

for i in range(n - 1):
    L[i + 1] = GCD(a[i], L[i])
    R[-(i + 2)] = GCD(a[-(i + 1)], R[-(i + 1)])

M = [0] * n
for i in range(n):
    M[i] = GCD(L[i], R[i])
print(max(M))