Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N= input()
a = raw_input().split()
#print a

d=deque()
for i,val in enumerate(a):
	if i%2==1:
		d.append(val)
	else:
		d.appendleft(val)
else:
	#print d
	d_str=""
	if N%2==0:
		for j in range(N):
			d_str=d_str+d.pop()+" "
	else:
		for j in range(N):
			d_str=d_str+d.popleft()+" "		
	print d_str[0:-1]

Fixed submission:
n= input()
a = map(int,raw_input().split())
#print a

l=[ i for i in range(n)]
l_gusu=l[0::2]
l_kisu=l[1::2]

ans=[]
for i in reversed(list(l_gusu)):
	#print i,a[i]
	ans.append(a[i])

for i in l_kisu:
	ans.append(a[i])


ans_str=""
if n%2==0:
	for i in reversed(list(ans)):
		ans_str+=(str(i)+" ")
	print ans_str.strip()
else:
	for i in ans:
		ans_str+=(str(i)+" ")
	print ans_str.strip()

Buggy python submission (verdict: Time Limit Exceeded):
N= input()
a = raw_input().split()
#print a

b=""
for i,val in enumerate(a):
	if i%2==1:
		if b[-1]==" ":
			b=b+val
		else:
			b=b+" "+val
	else:
		b=val+" "+b
else:
	if N%2==0:
		print b[::-1]
	else:
		print b


Fixed submission:
n= input()
a = map(int,raw_input().split())
#print a

l=[ i for i in range(n)]
l_gusu=l[0::2]
l_kisu=l[1::2]

ans=[]
for i in reversed(list(l_gusu)):
	#print i,a[i]
	ans.append(a[i])

for i in l_kisu:
	ans.append(a[i])


ans_str=""
if n%2==0:
	for i in reversed(list(ans)):
		ans_str+=(str(i)+" ")
	print ans_str.strip()
else:
	for i in ans:
		ans_str+=(str(i)+" ")
	print ans_str.strip()

Buggy python submission (verdict: Time Limit Exceeded):
#Python

N= input()
#print N
a = map(int, raw_input().split())
#print a


b=[]
for i in range(N):
	if i%2==0:
		b.append(a[i])
	elif i%2==1:
		b.insert(0,a[i])
	#print b

#print b

if N%2==1:
	b.reverse()

for j in range(N):
	print b[j],

Fixed submission:
n= input()
a = map(int,raw_input().split())
#print a

l=[ i for i in range(n)]
l_gusu=l[0::2]
l_kisu=l[1::2]

ans=[]
for i in reversed(list(l_gusu)):
	#print i,a[i]
	ans.append(a[i])

for i in l_kisu:
	ans.append(a[i])


ans_str=""
if n%2==0:
	for i in reversed(list(ans)):
		ans_str+=(str(i)+" ")
	print ans_str.strip()
else:
	for i in ans:
		ans_str+=(str(i)+" ")
	print ans_str.strip()

Buggy python submission (verdict: Time Limit Exceeded):
#Python

N= input()
#print N
a = map(int, raw_input().split())
#print a


b=[]
for i in range(N):
	b.append(a[i])
	b.reverse()
	#print b

#print b

for j in range(N):
	print b[j],

Fixed submission:
n= input()
a = map(int,raw_input().split())
#print a

l=[ i for i in range(n)]
l_gusu=l[0::2]
l_kisu=l[1::2]

ans=[]
for i in reversed(list(l_gusu)):
	#print i,a[i]
	ans.append(a[i])

for i in l_kisu:
	ans.append(a[i])


ans_str=""
if n%2==0:
	for i in reversed(list(ans)):
		ans_str+=(str(i)+" ")
	print ans_str.strip()
else:
	for i in ans:
		ans_str+=(str(i)+" ")
	print ans_str.strip()
Buggy python submission (verdict: Time Limit Exceeded):
#Python
import sys

N = input()
a = []
for i in range(N):
	a.append(input())
#print a

if 2 not in a:
	print "-1"
	sys.exit()

i=1
#cnt=0
b=[]

while a[i-1]!=2:
	#cnt+=1
	#print a[i-1]
	if i in b:
		print "-1"
		sys.exit()
	b.append(i)
	i=a[i-1]
	#print i,a[i]

#print b
print len(b)+1
#print cnt+1

Fixed submission:
#python
import sys

N = input()
a = []
for i in range(N):
	a.append(input())
#print a

if 2 not in a:
	print "-1"
	sys.exit()

i=1

while a[i-1]!=2:

	if a[i-1]==0:
		print "-1"
		sys.exit()

	#print i,a[i-1]
	before=i
	i=a[i-1]
	a[before-1]=0
	#print a
	

print a.count(0)+1
Buggy python submission (verdict: Runtime Error):
#Python

A = map(int, raw_input().split())
if A[0]+A[1]>=10:
	print ‘error’
else:
	print A[0]+A[1]

Fixed submission:
#Python

A = map(int, raw_input().split())
if A[0]+A[1]>=10:
	print 'error'
else:
	print A[0]+A[1]
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import copy
N=input()
a=[]
a=map(int, raw_input().split())
#print N
#print a

n_l=[ i for i in range(len(a))]
#print n_l
c = list(itertools.combinations(n_l,N))
#c=[(3,1)]
#print c

score=0.1
for i in c:
	a_t=copy.deepcopy(a)
	#print "#Loop start"
	#print i
	for j in range(N):
		a_t.pop(i[j]-j)
	#print a_t
	a1=zip(*[iter(a_t)]*N)
	#print a1
	if score==0.1 or score<sum(a1[0])-sum(a1[1]):
		score=sum(a1[0])-sum(a1[1])
		#print "score::"+str(score)

print score

Fixed submission:
import itertools
from heapq import heapify,heappush,heappop

N=input()
a=[]
a=map(int, raw_input().split())
a1=a[0:N]
#print a1

heapify(a1)

l1=[]
sum_a1=sum(a1)
l1.append(sum_a1)

# Max
for i in range(N,2*N):
	if a[i]>a1[0]:
		sum_a1=sum_a1+a[i]-a1[0]
		heappop(a1)
		heappush(a1, a[i])

	l1.append(sum_a1)


l2=[]
a2=[ -x for x in a[2*N:3*N]]
heapify(a2)
sum_a2=-1*sum(a2)
l2.append(sum_a2)

# Min
for i in reversed(range(N,2*N)):
	if a[i]<-1*a2[0]:
		sum_a2=sum_a2+a[i]-(-1*a2[0])
		heappop(a2)
		heappush(a2,-1*a[i])
	l2.append(sum_a2)


ans=[]
for i in range(N+1):
	ans.append(l1[i]-l2[N-i])

print max(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for _ in range(N+1) ]   #隣接リスト
rev_al=[ [] for _ in range(N+1) ]   #戻りを調べる用の隣接リスト
edge=[] #辺の集合
for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    al[a].append(b)
    rev_al[b].append(a) #逆向きにも辺を張る
    edge.append((a,b,c))


go=[0 for _ in range(N+1)]
back=[0 for _ in range(N+1)]

#頂点１からNに行くまでに使用する頂点を調べる
q=deque()
q.append(1) #スタート地点
go[1]=1

while q:
    fro=q.popleft()
    for to in al[fro]:
        if go[to]==0:
            go[to]=1
            q.append(to)


#頂点Nから1に戻る際に使用する頂点を調べる
q=deque()
q.append(N) #スタート地点
back[N]=1

while q:
    fro=q.popleft()
    for to in rev_al[fro]:
        if back[to]==0:
            back[to]=1
            q.append(to)


new_edge=[]     #有効な辺のみ抽出

for a,b,c in edge:
    if go[a]==1 and back[b]==1:
        new_edge.append((a,b,c))


#ベルマンフォード
dp=[ float("-inf") for _ in range(N+1) ]
dp[1]=0

for i in range(N):
    for fro,to,cost in new_edge:
        alt=dp[fro]+cost
        if dp[to]<alt:
            if i==N-1:
                print float("inf")
                quit()
            dp[to]=alt

print dp[N]

Fixed submission:
A,B,C=map(int,raw_input().split())
print "Yes" if A<=C and C<=B else "No"
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N,K=map(int,raw_input().split())
c=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	for j in range(b):
		heapq.heappush(c,a)

for i in range(len(c)):
	val=heapq.heappop(c)
	if i==K-1:
		print val
		break


Fixed submission:
import heapq
N,K=map(int,raw_input().split())
c=[]
for i in range(N):
	heapq.heappush(c, tuple( map(int,raw_input().split()) ) )

cnt=0
for i in range(len(c)):
	val=heapq.heappop(c)
	cnt+=val[1]
	if K<=cnt:
		print val[0]
		break
Buggy python submission (verdict: Runtime Error):
import heapq
N,W=map(int,raw_input().split())
wv=[]

w_sum=0
for i in range(N):
	w,v=map(int,raw_input().split())
	w_sum+=w
	wv.append((w,v))


a=[ float("-inf") for i in range(w_sum*2) ]

i=0
i=1
q=[]
for ind_i, i in enumerate(wv):
	w=i[0]
	v=i[1]
	#Initialize
	if ind_i==0:
		a[0]=0
		a[w]=v
		continue
	#Put queue
	for ind_j, j in enumerate(a):
		if j!=float("-inf"):
			heapq.heappush(q,(ind_j,j))
	
	while len(q)!=0:
		ind_j, j=heapq.heappop(q)
		a[ind_j+w]=max(a[ind_j+w], a[ind_j]+v)
		
print max(a[:W+1])




Fixed submission:
A,B,C=raw_input().split()
print "YES" if A[-1]==B[0] and B[-1]==C[0] else "NO"
Buggy python submission (verdict: Time Limit Exceeded):
n=input()
a=map(int,raw_input().split())
#print n
#print a

a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)

#print a1


#+,-
b=[]
for i,val in enumerate(a1):
	for j in b:
		val+=j
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)

#-,+
b=[]
for i,val in enumerate(a1):
	for j in b:
		val+=j
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)
			
			



Fixed submission:
n=input()
a=map(int,raw_input().split())
#print n
#print a

a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)

#print a1


#+,-
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)

#-,+
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, raw_input().split())
x=map(int, raw_input().split())
y=map(int, raw_input().split())

x1=[]
x_sum=0
for i in range(n):
	x_sum+=( len(x[:i])-len(x[i+1:]) )*x[i]

y_sum=0
for i in range(m):
	y_sum+=( len(y[:i])-len(y[i+1:]) )*y[i]


print x_sum*y_sum%(10**9+7)



Fixed submission:
n,m=map(int, raw_input().split())
x=map(int, raw_input().split())
y=map(int, raw_input().split())

x1=[]
x_sum=0
for i in range(n):
	x_sum+=( (n-i-1)-i )*x[i]

y_sum=0
for i in range(m):
	y_sum+=( (m-i-1)-i )*y[i]


print x_sum*y_sum%(10**9+7)
Buggy python submission (verdict: Runtime Error):
import itertools
import collections
N,M=map(int,raw_input().split())
#print N,M
a=[tuple(map(int,raw_input().split())) for i in range(N)]
#print a
b=list(itertools.combinations(a,N-1))
#print b

#print collections.Counter(b[0])

cnt=0
for i in b:
	c=[]
	for j,k in i:
		#print j,k
		c.append(j)
		c.append(k)
	#print c
	t_c=collections.Counter(c)
	t_c_v=(collections.Counter(c)).values()
	#print t_c,t_c_v
	if t_c[1]==1:
		for m in t_c_v:
			if m>=3:
				break
		else:
			cnt+=1

print cnt  
	
	 


Fixed submission:
import itertools
import collections
N,M=map(int,raw_input().split())
#print N,M
a=[map(int,raw_input().split()) for i in range(M)]
#print a
b=list(itertools.permutations(range(1,N+1)))
#print b

ans=0
for i in b:
	if i[0]!=1:
		continue
	c=[]
	for j in i:
		#print i,j
		if len(c)<2:
			c.append(j)

		if len(c)==2:
			if c in a or c[::-1] in a:
				cnt=1
			else:
				cnt=0
				break
			c.pop(0)
	ans+=cnt
print ans
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
K,S=map(int,raw_input().split())
l=list( itertools.product(range(K+1), repeat=3 ) )

cnt=0
for i,j,k in l:
	if i+j+k==S:
		cnt+=1
print cnt


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

cnt=0
for x in range(K+1):
	for y in range(K+1):
		z=S-x-y
		if z>=0 and z<=K:
			cnt+=1
print cnt
Buggy python submission (verdict: Runtime Error):
x,y=map(int, raw_input().split())
if 0<=x and 0<=y:
    if x<=y:
        print abs(x-y)
    else:
        print min(2+abs(x-y),1+abs(x+y))
elif x<0 and y<0:
    if x<=y:
        print min(abs(x-y),1+abs(x-y*-1)
    else:
        print min(2+abs(x-y), 1+abs(x-y*-1))
elif x<0 and 0<=y:
    if x*-1<=y:
        print min(1+abs(y-x*-1),1+abs(x-y*-1))
    else:
       print min(abs(x-y),1+abs(x-y*-1))
elif y<0 and 0<=x:
    if y*-1<x:
        print min(abs(x-y),1+abs(x*-1-y))
    else:
        print min(abs(x-y),1+abs(x-y*-1))


Fixed submission:
x,y=map(int, raw_input().split())
if 0<=x and 0<=y:
    if x<=y:
        print abs(x-y)
    else:
        print min(1+abs(x*-1-y),2+abs(x-y))
elif x<0 and y<0:
    if x<=y:
        print abs(x-y)
    else:
        print min(2+abs(x-y), 1+abs(x-y*-1))
elif x<0 and y==0:
    print abs(x-y)
elif x<0 and 0<y:
    if x*-1<=y:
        print 1+abs(y-x*-1)
    else:
        print 1+abs(x*-1-y)
elif y<0 and x==0:
    print 1+abs(x-y)
elif y<0 and 0<x:
        print 1+abs(x*-1-y)

Buggy python submission (verdict: Runtime Error):
x,y=map(int, raw_input().split())
if 0<=x and 0<=y:
    if x<=y:
        print abs(x-y)
    else:
        print min(2+abs(x-y),1+abs(x+y))
elif x<0 and y<0:
    if x<=y:
        print abs(x-y)
    else:
        print min(2+abs(x-y), 1+abs(x-y*-1))
elif x<0 and 0<=y:
    if x*-1<=y:
        print min(1+abs(y-x*-1),1+abs(x-y*-1)
    else:
       print abs(x-y)
elif y<0 and 0<=x:
    if y*-1<x:
        print min(abs(x-y),1+abs(x*-1-y))
    else:
        print min(abs(x-y),1+abs(x-y*-1))


Fixed submission:
x,y=map(int, raw_input().split())
if 0<=x and 0<=y:
    if x<=y:
        print abs(x-y)
    else:
        print min(1+abs(x*-1-y),2+abs(x-y))
elif x<0 and y<0:
    if x<=y:
        print abs(x-y)
    else:
        print min(2+abs(x-y), 1+abs(x-y*-1))
elif x<0 and y==0:
    print abs(x-y)
elif x<0 and 0<y:
    if x*-1<=y:
        print 1+abs(y-x*-1)
    else:
        print 1+abs(x*-1-y)
elif y<0 and x==0:
    print 1+abs(x-y)
elif y<0 and 0<x:
        print 1+abs(x*-1-y)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

S_pointer=0

V=set()
V.add(0)

cnt=0
while cnt<len(S)/5+1:
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				if i+len(j)==len(S):
					tmp.add(i+len(j))
					print "YES"
					sys.exit()
				else:
					tmp.add(i+len(j))

	V=V|tmp
	cnt+=1

#print V

print "YES" if max(V)==len(S) else "NO"

Fixed submission:
import sys
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				tmp.add(i+len(j))
				if i+len(j)==len(S):
					print "YES"
					sys.exit()
	V=tmp
	cnt+=1
else:
	print "NO"

Buggy python submission (verdict: Time Limit Exceeded):
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

S_pointer=0

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:	
				tmp.add(i+len(j))

	V=V|tmp
	cnt+=1

#print V

print "YES" if max(V)==len(S) else "NO"

Fixed submission:
import sys
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				tmp.add(i+len(j))
				if i+len(j)==len(S):
					print "YES"
					sys.exit()
	V=tmp
	cnt+=1
else:
	print "NO"
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque,Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

q=deque(A)
max_n=max(q)


b=[]
for i in range(N-1):
	q.popleft()
	if A[i]==max_n:
		max_n=max(q)

	b.append(max_n-A[i])

C=Counter(b)
max_key=max(C.keys())

print C[max_key]

Fixed submission:
from collections import Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

A_r=[None for i in range(N)]
n=0
for i in range(N-1,-1,-1):
	n=max(A[i],n)
	A_r[i]=n

B=[]
for i in range(N-1):
	B.append(A_r[i+1]-A[i])


C=Counter(B)

print C[max(B)]

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque,Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

q=deque( sorted(A, key=lambda x: x,reverse=True) )


b=[]
for i in range(N-1):
	q.remove(A[i])
	max_n=q[0]
	b.append(max_n-A[i])

C=Counter(b)
max_key=max(C.keys())

print C[max_key]

Fixed submission:
from collections import Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

A_r=[None for i in range(N)]
n=0
for i in range(N-1,-1,-1):
	n=max(A[i],n)
	A_r[i]=n

B=[]
for i in range(N-1):
	B.append(A_r[i+1]-A[i])


C=Counter(B)

print C[max(B)]

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter 
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

b=[]
for i in range(N-1):
	max_n=max(A[i+1::])
	b.append(max_n-A[i])

C=Counter(b)
max_key=max(C.keys())

print C[max_key]

Fixed submission:
from collections import Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

A_r=[None for i in range(N)]
n=0
for i in range(N-1,-1,-1):
	n=max(A[i],n)
	A_r[i]=n

B=[]
for i in range(N-1):
	B.append(A_r[i+1]-A[i])


C=Counter(B)

print C[max(B)]
Buggy python submission (verdict: Runtime Error):
import math
n=input()
s=input()

def f(b,n):
	if n<b:
		return n
	elif n>=b:
		return f(b, math.floor(n/b))+n%b

if s==n:
	print n+1
	quit()


# 2 <= b <= sqrt(n)
n_sqrt=int(math.sqrt(n))
for i in range(2, n_sqrt+1):
	if f(i,n)==s:
		print i
		quit()



# sqrt(n) < b <= n
# yakusuu
l=[]
for i in range(1, n_sqrt+1):
	if (n-s)%i==0:
		l.append(i)
		l.append((n-s)/i)


for i in l:
	b=i+1
	p=n/b
	q=n%b
	if p+q==s:
		print b
		quit()

print -1
	
	

Fixed submission:
import math
n=input()
s=input()

def f(b,n):
	if n<b:
		return n
	elif n>=b:
		return f(b, math.floor(n/b))+n%b

if s==n:
	print n+1
	quit()


# 2 <= b <= sqrt(n)
n_sqrt=int(math.sqrt(n))
for i in range(2, n_sqrt+1):
	if f(i,n)==s:
		print i
		quit()



# sqrt(n) < b <= n
# yakusuu
l=[]
for i in range(1, n_sqrt+1):
	if (n-s)%i==0:
		l.append(i)
		l.append((n-s)/i)
l.sort()

for i in l:
	b=i+1
	if b**2<=n:
		continue
	p=n/b
	q=n%b
	if p+q==s:
		print b
		quit()

print -1

Buggy python submission (verdict: Runtime Error):
import math
n=input()
s=input()

def f(b,n):
	if n<b:
		return n
	elif n>=b:
		return f(b, math.floor(n/b))+n%b

if s==1:
	print n
	quit()
if n==1:
	print -1
	quit()



for i in range(2,s+1):
	if f(i,n)==s:
		print i
		quit()
else:
	print -1

Fixed submission:
import math
n=input()
s=input()

def f(b,n):
	if n<b:
		return n
	elif n>=b:
		return f(b, math.floor(n/b))+n%b

if s==n:
	print n+1
	quit()


# 2 <= b <= sqrt(n)
n_sqrt=int(math.sqrt(n))
for i in range(2, n_sqrt+1):
	if f(i,n)==s:
		print i
		quit()



# sqrt(n) < b <= n
# yakusuu
l=[]
for i in range(1, n_sqrt+1):
	if (n-s)%i==0:
		l.append(i)
		l.append((n-s)/i)
l.sort()

for i in l:
	b=i+1
	if b**2<=n:
		continue
	p=n/b
	q=n%b
	if p+q==s:
		print b
		quit()

print -1
Buggy python submission (verdict: Runtime Error):
import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

#print FACT


def C(n,r):
	return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod

N=(H-A-1)+B
M=(H-1)+(W-1)-N

p=0
for i in range(H-A,H):
	#print N,i,M,(H-1)-i,C(N,i), C(M,(H-1)-i)
	p+=C(N,i)*C(M,(H-1)-i)		#Count patterens via prohibited point.
	p=p%mod


if C(N+M,(H-1))-p>=0:
	print C(N+M,(H-1))-p
else:
	print C(N+M,(H-1))-p+10**9+7
    

Fixed submission:
import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

#print FACT

def C(n,r):
	return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod


p=0
for i in range(B,W):
	p+=C(H-A-1+i,i)*C(A-1+W-i-1,W-i-1)
	p=p%mod


print p

Buggy python submission (verdict: Runtime Error):
import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

for x,y in FACT.items():
	FACT_INVERSE[x]=pow(FACT[x],10**9+5 ,mod)


def C(n,r):
	return (FACT[n]*FACT_INVERSE[r]*FACT_INVERSE[n-r]) %mod


N=(H-A-1)+B
M=(H-1)+(W-1)-N

p=0
for i in range(H-A,H):
	#print N,i,M,(H-1)-i,C(N,i), C(M,(H-1)-i)
	p+=C(N,i)*C(M,(H-1)-i)		#Count paterens through prohibited point.
	p=p%mod


if C(N+M,(H-1))-p>=0:
	print C(N+M,(H-1))-p
else:
	print C(N+M,(H-1))-p+10**9+7






Fixed submission:
import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

#print FACT

def C(n,r):
	return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod


p=0
for i in range(B,W):
	p+=C(H-A-1+i,i)*C(A-1+W-i-1,W-i-1)
	p=p%mod


print p
Buggy python submission (verdict: Runtime Error):
n=int(input())
dp=[0]*(n+1)
dp[0]=1
dp[1]=0
dp[3]=0
s=0
for i in range(3,n+1):
    s+=dp[i-3]
    s=s%1000000007
    dp[i]=s
print(dp[n])

Fixed submission:
import sys
n=int(input())
dp=[0]*(n+1)
dp[0]=1
s=0
for i in range(3,n+1):
    s+=dp[i-3]
    s=s%1000000007
    dp[i]=s
dp[0]=0
print(dp[n])

Buggy python submission (verdict: Runtime Error):
n=int(input())
dp=[0]*(n+1)
dp[0]=1
dp[1]=0
dp[3]=0
s=0
for i in range(3,n+1):
    s+=dp[i-3]
    s=s%1000000009
    dp[i]=s
print(dp[n])

Fixed submission:
import sys
n=int(input())
dp=[0]*(n+1)
dp[0]=1
s=0
for i in range(3,n+1):
    s+=dp[i-3]
    s=s%1000000007
    dp[i]=s
dp[0]=0
print(dp[n])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-26 20:52:24 +0900
# LastModified: 2020-09-26 21:18:10 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def BFS(cnt, color, path, u):
    color[u] = cnt
    for v in path[u]:
        if color[v] == -1:
            BFS(cnt, color, path, v)


def main():
    N, M = map(int, input().split())
    path = [[] for _ in range(N+1)]
    for _ in range(M):
        A, B = map(int, input().split())
        path[A].append(B)
        path[B].append(A)
    color = [-1] * (N+1)
    cnt = 0
    for i in range(1, N+1):
        if color[i] == -1:
            BFS(cnt, color, path, i)
            cnt += 1
    print(max(color))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-26 20:52:24 +0900
# LastModified: 2020-09-26 21:19:33 +0900
#


import os
import sys
sys.setrecursionlimit(2000000)
# import numpy as np
# import pandas as pd


def BFS(cnt, color, path, u):
    color[u] = cnt
    for v in path[u]:
        if color[v] == -1:
            BFS(cnt, color, path, v)


def main():
    N, M = map(int, input().split())
    path = [[] for _ in range(N+1)]
    for _ in range(M):
        A, B = map(int, input().split())
        path[A].append(B)
        path[B].append(A)
    color = [-1] * (N+1)
    cnt = 0
    for i in range(1, N+1):
        if color[i] == -1:
            BFS(cnt, color, path, i)
            cnt += 1
    print(max(color))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-08-29 21:20:05 +0900
# LastModified: 2020-08-29 21:22:11 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    A = list(map(int, input().split()))
    amari = 1000000007
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += A[i]*A[j]%amari
            ans %= amari
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix_2
# CreatedDate:  2020-08-29 22:01:34 +0900
# LastModified: 2020-08-29 22:07:06 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    n = int(input())
    A = list(map(int, input().split()))
    amari = 1000000007
    ans = ((sum(A))*(sum(A)) - sum(a**2 for a in A))
    print(ans//2%amari)


if __name__ == "__main__":
    main()