Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
for i in range(1,n+2): t[i]+=t[i-1]
T,ans = 2*t[-1]+1,0
for i in range(T):
	num = i/2
	for j in range(n+1):
		if i/2<t[j]-100: break
		num = min(num,f(i/2,v[j],t[j],t[j+1]))
	ans+=num/2
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
for i in range(1,n+2): t[i]+=t[i-1]
T,ans = t[-1],0
for i in range(2*T+1):
	num = min(i/2,T-i/2)
	for j in range(max(0,bisect_left(t,i/2-100)-1),n+1):
		if i/2<t[j]-100: break
		num = min(num,f(i/2,v[j],t[j],t[j+1]))
	ans+=num/2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
for i in range(1,n+2): t[i]+=t[i-1]
T,ans = 2*t[-1]+1,0
for i in range(T):
	num = i/2
	for j in range(n+1): num = min(num,f(i/2,v[j],t[j],t[j+1]))
	ans+=num/2
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
for i in range(1,n+2): t[i]+=t[i-1]
T,ans = t[-1],0
for i in range(2*T+1):
	num = min(i/2,T-i/2)
	for j in range(max(0,bisect_left(t,i/2-100)-1),n+1):
		if i/2<t[j]-100: break
		num = min(num,f(i/2,v[j],t[j],t[j+1]))
	ans+=num/2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
a,ans = [],0
for i in range(1,n+2): t[i]+=t[i-1]
for i in range(2*t[-1]+1):
	num = i/2
	for j in range(n+1): num = min(num,f(i/2,v[j],t[j],t[j+1]))
	a.append(num)
for i in range(len(a)-1): ans+=(a[i]+a[i+1])/4
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
t = [0]+[int(i) for i in input().split()]+[0]
v = [int(i) for i in input().split()]+[0]
def f(x,v,t1,t2):
	if x<t1: return v+(t1-x)
	elif t1<=x<=t2: return v
	else: return v+(x-t2)
for i in range(1,n+2): t[i]+=t[i-1]
T,ans = t[-1],0
for i in range(2*T+1):
	num = min(i/2,T-i/2)
	for j in range(max(0,bisect_left(t,i/2-100)-1),n+1):
		if i/2<t[j]-100: break
		num = min(num,f(i/2,v[j],t[j],t[j+1]))
	ans+=num/2
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
l,r,ans = 0,len(s)-1,0
while l!=r:
	if s[l]==s[r]: l,r = l+1,r-1
	elif s[l]=="x": l,ans = l+1,ans+1
	elif s[r]=="x": r,ans = r-1,ans+1
	else: break
if l==r: print(ans)
else: print(-1)

Fixed submission:
s = input()
l,r,ans = 0,len(s)-1,0
while l<r:
	if s[l]==s[r]: l,r = l+1,r-1
	elif s[l]=="x": l,ans = l+1,ans+1
	elif s[r]=="x": r,ans = r-1,ans+1
	else: break
if l>=r: print(ans)
else: print(-1)
Buggy python submission (verdict: Runtime Error):
def connect(blist, a):
	x = []
	for i in range(len(blist)):
		if blist[i][0]==a:
			x.append(blist[i][1])
		elif blist[i][0]>a:
			break
	for j in range(len(blist)):
		if blist[j][1]==a:
			x.append(blist[j][0])
	return(x)

n,m = (int(i) for i in input().split())
y = [[int(i) for i in input().split()] for i in range(m)]
answer = 0
for j in range(len(y)):
	y2,z = [],set()
	for k in range(1,n+1):
		y2.append(connect(y[:j]+y[min(j+1,len(y)):],k))
	for j2 in y2[y[j][0]-1]:
		z.add(j2)
	num = 0
	while y[j][1] not in z and len(z) != num:
		num,z2 = len(z),list(z)
		for k in z2:
			for k2 in y2[k-1]:
				z.add(k2)
	if y[j][1] not in z:
		answer += 1
print(answer)


Fixed submission:
x = [int(i) for i in input().split()]
x.sort()
if x[0]==x[1]: print(x[2])
else: print(x[0])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n,k = (int(i) for i in input().split())
p = [[int(i) for i in input().split()] for i in range(n)]
p,ans = sorted(p),float("inf")
for q in combinations(p,min(4,k)):
	r = sorted(j for i,j in q)
	xa,xb,ya,yb = q[0][0],q[-1][0],r[0],r[-1]
	num = sum(1 for i,j in p if xa<=i<=xb and ya<=j<=yb)
	if num>=k: ans = min(ans,(xb-xa)*(yb-ya))
print(ans)

Fixed submission:
n,k = (int(i) for i in input().split())
p = [[int(i) for i in input().split()] for i in range(n)]
p,ans = sorted(p),float("inf")
q = list(enumerate(p))
for i,(a,b) in q[:n-k+1]:
	for j,(c,d) in q[i+k-1:]:
		r = sorted(y for x,y in p[i:j+1])
		r2 = r[k-1:]
		for i2,j2 in zip(r,r2):
			if i2<=b and d<=j2: ans = min(ans,(c-a)*(j2-i2))
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = (int(i) for i in input().split())
w,s,num,answer = set(),set(),0,[a*100,0]
for i in range((f-f%(a*100))//(a*100)+1):
	for j in range((f-f%(b*100))//(b*100)+1):
		if i*a*100+j*b*100 <= f:
			w.add(i*a*100+j*b*100)
		else:
			break
smax = int(e*f/((100+e)*1.0))
for i in range((smax-smax%c)//c+1):
	for j in range((smax-smax%d)//d+1):
		if i*c+j*d <= smax:
			s.add(i*c+j*d)
		else:
			break
w2,s2 = sorted(list(w))[::-1],sorted(list(s))[::-1]
for i in w2:
	for j in s2:
		if 0 < i+j <= f and e*i>=100*j and num<(j/((i+j)*1.0)):
			num =  j/((i+j)*1.0)
			answer = [i,j]
print(sum(answer),answer[1])


Fixed submission:
n = int(input())
a = int(input())
print(n**2-a)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
n = int(input())
a = np.array([[int(i) for i in input().split()] for i in range(n)])
d,ans = floyd_warshall(a,directed=False),0
if any(a[i][j]!=d[i][j] for i in range(n) for j in range(n)): ans = -1
else:
	inf = float("inf")
	for i in range(n): a[i][i] = inf
	for i in range(n):
		for j in range(i+1,n):
			num = np.min(a[i]+a[j])
			if num>a[i][j]: ans+=a[i][j]
print(int(ans))

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
n = int(input())
a = np.array([[int(i) for i in input().split()] for i in range(n)])
d,ans = floyd_warshall(a,directed=False),0
if any(a[i][j]!=d[i][j] for i in range(n) for j in range(n)): ans = -1
else:
	inf = 10**10
	for i in range(n): a[i][i] = inf
	for i in range(n):
		for j in range(i+1,n):
			num = np.min(a[i]+a[j])
			if num>a[i][j]: ans+=a[i][j]
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = [int(input()) for i in range(n)]
x.sort()
answer = 0
while x != []:
	num,y = 0,x[0]
	while x != [] and x[0] == y:
		num += 1
		x = x[1:]
	if num%2==1:
		answer += 1
print(answer)

Fixed submission:
import collections
n = int(input())
x = [int(input()) for i in range(n)]
a = collections.Counter(x)
answer = 0
for i in a.values():
	if i%2==1:
		answer += 1
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = [int(input()) for i in range(n)]
y,answer = set(x),0
for i in y:
	if x.count(i)%2 == 1:
		answer += 1
print(answer)

Fixed submission:
import collections
n = int(input())
x = [int(input()) for i in range(n)]
a = collections.Counter(x)
answer = 0
for i in a.values():
	if i%2==1:
		answer += 1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
while a != []:
	if x[a[0]]>=4 and num==-1:
		print(a[0]**2)
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			print(answer)
			break
	a = a[x[a[0]]:]
	if a == []:
		print(0)

Fixed submission:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
for i in x.keys():
	if x[i] == 1:
		a.remove(i)
while a != []:
	if x[a[0]]>=4 and num==-1:
		answer = a[0]**2
		num = 1
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			break
	a = a[x[a[0]]:]
print(max(answer*num,0))

Fixed submission:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
while a != []:
	if x[a[0]]>=4 and num==-1:
		answer = a[0]**2
		num = 1
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			break
	a = a[x[a[0]]:]
print(max(answer*num,0))

Fixed submission:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer = collections.Counter(a),[]
while a != []:
	if x[a[0]]>=4 and len(answer)==0:
		answer = [a[0],a[0]]
		break
	elif x[a[0]]>=2:
		answer.append(a[0])
		if len(answer)==2:
			break
	a = a[x[a[0]]:]
if len(answer)==2:
	print(answer[0]*answer[1])
else:
	print(0)

Fixed submission:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = input()
y = input()
place = 0
if x[0]==y[0]: num,flag = 3,True
else: num,flag = 6,False
while place<n-1:
	if flag:
		place += 1
		num = (num*2)%(10**9+7)
		if x[place]!=y[place]: flag = False
	else:
		place += 2
		if x[place]==y[place]: flag=True
		else: num=(num*3)%(10**9+7)
print(num)

Fixed submission:
n = int(input())
x = input()
y = input()
if x[0]==y[0]: num,flag,place = 3,True,1
else: num,flag,place = 6,False,2
while place!=n:
	if flag:
		num = (num*2)%(10**9+7)
		if x[place]!=y[place]:
			flag = False
			place += 2
		else: place+=1
	else:
		if x[place]==y[place]:
			flag = True
			place += 1
		else:
			num = (num*3)%(10**9+7)
			place += 2
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [[int(i) for i in input().split()] for i in range(n-1)]
q,k = (int(i) for i in input().split())
question = [[int(i) for i in input().split()] for i in range(q)]
x = []
for i in range(n):
	subx = []
	for j in range(n):
		subx.append(float("inf"))
	x.append(subx)
for i in range(n): x[i][i] = 0
for i in a: x[i[0]-1][i[1]-1],x[i[1]-1][i[0]-1] = i[2],i[2]
for p in range(n):
	for i in range(n):
		for j in range(n):
			x[i][j] = min(x[i][p]+x[p][j],x[i][j])
for i in question:
	print(x[i[0]-1][k-1]+x[k-1][i[1]-1])

Fixed submission:
n = int(input())
a = [[int(i) for i in input().split()] for i in range(n-1)]
q,k = (int(i) for i in input().split())
question = [[int(i) for i in input().split()] for i in range(q)]
x,ans = [[] for i in range(n)],[False for i in range(n)]
for i in a:
	x[i[0]-1].append([i[1],i[2]])
	x[i[1]-1].append([i[0],i[2]])
visit = [False for i in range(n)]
visit[k-1],now = True,[k]
while now:
	p = now.pop()
	for i in x[p-1]:
		if not visit[i[0]-1]:
			visit[i[0]-1],ans[i[0]-1] = True,ans[p-1]+i[1]
			now.append(i[0])
for i in question:
	print(ans[i[0]-1]+ans[i[1]-1])
Buggy python submission (verdict: Runtime Error):
h,w = (int(i) for i in input().split())
n = int(input())
a = [int(i) for i in input().split()]
x,num = "",0
for i in range(n):
	x += str(i+1)*a[i]
while x != "":
	num += 1
	y = ""
	if num%2==1:
		for i in range(w-1):
			y += x[i]+" "
		y += x[w-1]
		print(y)
		x = x[w:]
	else:
		for i in range(w-1,0,-1):
			y += x[i]+" "
		y += x[0]
		print(y)
		x = x[w:]

Fixed submission:
h,w = (int(i) for i in input().split())
n = int(input())
a = [int(i) for i in input().split()]
x,num = [],0
for i in range(n):
	for j in range(a[i]):
		x.append(str(i+1))
while x != []:
	num += 1
	if num%2==1:
		print(" ".join(x[:w]))
		x = x[w:]
	else:
		print(" ".join(x[:w][::-1]))
		x = x[w:]
Buggy python submission (verdict: Time Limit Exceeded):
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(m)]
x.sort()
a = []
for i in x:
	if i[0]==1:
		a.append(i[1])
	else:
		break
for j in a:
	if [j,n] in x:
		m = 0
		print("POSSIBLE")
		break
if m != 0:
	print("IMPOSSIBLE")

Fixed submission:
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(m)]
a ,b= [],[]
for i in x:
	if i[0]==1:
		a.append(i[1])
	if i[1]==n:
		b.append(i[0])
if len(a)+len(b) == len(set(a+b)): print("IMPOSSIBLE")
else: print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
x.sort()
a = []
for i in x:
	if i[0]==1:
		a.append(i[1])
	else:
		break
for j in a:
	if [j,n] in x:
		m = 0
		print("POSSIBLE")
		break
if m != 0:
	print("IMPOSSIBLE")

Fixed submission:
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(m)]
a ,b= [],[]
for i in x:
	if i[0]==1:
		a.append(i[1])
	if i[1]==n:
		b.append(i[0])
if len(a)+len(b) == len(set(a+b)): print("IMPOSSIBLE")
else: print("POSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
x = sum(a)
answer = abs(x-2*a[0])
for i in range(1,n):
	y = sum(a[i:])
	if answer>abs(x-2*y):
		answer = abs(x-2*y)
print(answer)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
x,y = a[0],sum(a)-a[0]
answer = abs(x-y)
for i in range(1,n-1):
	x += a[i]
	y -= a[i]
	if answer > abs(x-y):
		answer = abs(x-y)
print(answer)
Buggy python submission (verdict: Runtime Error):
r,g,b = input()
if int(g+b)%4==0: print("YES")
else: print("NO")

Fixed submission:
r,g,b = (i for i in input().split())
if int(g+b)%4==0: print("YES")
else: print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,insort
n,k = (int(i) for i in input().split())
a = [int(input())-k for i in range(n)]
b = [[0,0]]
for i in range(n): b.append([-(a[i]-b[-1][0]),-(i+1)])
b.sort()
q,ans,num = [-b[0][1]],0,1
for i,j in b[1:]:
	c = bisect(q,-j)
	ans+=num-c
	num+=1
	insort(q,-j,c,c)
print(ans)

Fixed submission:
n,k = (int(i) for i in input().split())
a = [int(input())-k for i in range(n)]
b = [[0,0]]
for i in range(n): b.append([b[-1][0]+a[i],i+1])
b.sort()
num,c = 1,[[b[0][1],1]]
for i in range(1,n+1):
	if b[i][0]!=b[i-1][0]: num+=1
	c.append([b[i][1],num])
c,d,ans = sorted(c),[0]*(n+2),0
def add(i):
	while i<=n+1:
		d[i] += 1
		i += i & -i
def get(i):
	s = 0
	while i:
		s += d[i]
		i -= i & -i
	return s
for i,j in c:
	ans+=get(j)
	add(j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
x.sort()
num = 0
for i in x:
	num += i[1]
	if num>=k:
		print(i[0])
		break

Fixed submission:
a,b,c = (int(i) for i in input().split())
if a<=c and c<=b: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a>b: print("GREATER")
elif a<b: print("LESS")
else: print("EQUAL")

Fixed submission:
a,b,c = (i for i in input().split())
x = a[0]+b[0]+c[0]
x = x.upper()
print(x)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
num,answer = a[0],0
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
print(answer)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
num,answer1= a[0],0
if a[0]==0:
	num,answer1 = 1,1
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer1 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
if a[0]==0: num,answer2 = -1,1
else: num,answer2 = -a[0]//abs(a[0]),abs(a[0]-(-a[0]//abs(a[0])))
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer2 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
print(min(answer1,answer2))
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer= 1
if n!=1: np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Fixed submission:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
if n!=1: flag = np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer,flag = 1,np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Fixed submission:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
if n!=1: flag = np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
answer = 0
while len(a)>2:
	if a[0]<=a[1]<=a[2] or a[0]>=a[1]>=a[2]:
		a = a[1:]
	else:
		answer += 1
		a = a[2:]
if a != []: answer+=1
print(answer)		

Fixed submission:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
if n!=1: flag = np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
answer = 1
for i in range(1,n+1):
	answer *= i
print(answer%(10**9+7))

Fixed submission:
n = int(input())
answer = 1
for i in range(1,n+1):
	answer = (answer*i)%(10**9+7)
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
num,flag,x = a.index(min(a)),True,float("inf")
while flag:
	a = a[num:]+a[:num]
	for i in range(n):
		a[i] = a[i]-(i+1)
		if x>a[i]: num,x = i,a[i]
		if x<0:
			flag = False
			break
	if all(a[j]==0 for j in range(n)): break
if flag: print("YES")
else: print("NO")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
if sum(a)%(n*(n+1)//2) != 0: print("NO")
else:
	x,flag,num = sum(a)//(n*(n+1)//2),True,0
	for i in range(n):
		if (a[i]-a[i-1]-x)%n!=0:
			flag = False
			break
		else: num+=abs((a[i]-a[i-1]-x)//n)
	if flag and num==x: print("YES")
	else: print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
x,q = [[] for i in range(n)],[-1]*n
for i in range(n-1):
	a = int(input())-1
	x[a].append(i+1)
def f(z):
	y = []
	if x[z]:
		for i in x[z]:
			if q[i]+1: y.append(q(i))
			else: y.append(f(i))
		y = sorted(y)[::-1]
		for i in range(len(y)): y[i]+=i+1
		q[z] = max(y)
		return max(y)
	else:
		q[z] = 0
		return 0
print(f(0))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000)
n = int(input())
x,q = [[] for i in range(n)],[-1]*n
for i in range(n-1):
	a = int(input())-1
	x[a].append(i+1)
def f(z):
	y = []
	if x[z]:
		for i in x[z]:
			if q[i]+1: y.append(q(i))
			else: y.append(f(i))
		y = sorted(y)[::-1]
		for i in range(len(y)): y[i]+=i+1
		q[z] = max(y)
		return max(y)
	else:
		q[z] = 0
		return 0
print(f(0))
Buggy python submission (verdict: Runtime Error):
n,a,b = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
answer = 0
for i in range(n-1):
	if (x[i+1]-x[i])*a < b: answer += (x[i+1]-x[i])*a
	else: answer += b
print(answer)

Fixed submission:
n = int(input())
x,answer = [2],1
if n != 1:
	for i in range(2,n+1):
		if all(i%j != 0 for j in x):
			x.append(i)
	for i in x:
		num,num2 = 1,0
		while i**num<=n:
			a = i**num
			num2 += (n-n%a)//a
			num += 1
		answer = answer*(num2+1)%(10**9+7)
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = (int(i) for i in input().split())
answer = 0
for i in range(((s-s%3)//3)+1):
	n = s-i
	for i2 in range(i,((n-n%2)//2)+1):
		for i3 in range(i2,k+1):
			if i+i2+i3==s:
				if i==i2 and i2==i3: answer += 1
				elif i==i2 or i2==i3: answer += 3
				else: answer += 6
				break
print(answer)

Fixed submission:
k,s = (int(i) for i in input().split())
answer = 0
for i in range(k+1):
	for j in range(k+1):
		if 0<=s-(i+j)<=k: answer += 1
print(answer)
Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in input().split()]
f = lambda x: max(0,x-x%2)
print(max(a[1]+f(a[0])+f(a[3])+f(a[4]),a[1]+f(a[0]-1)+f(a[3]-1)+f(a[4]-1)+3))

Fixed submission:
x,y = (int(i) for i in input().split())
if abs(x)>abs(y):
	if x<0 and y<=0: answer = y-x
	elif (x<0 and y>0) or (x>0 and y<=0): answer = abs(x)-abs(y)+1
	elif x>0 and y>0: answer = abs(x)-abs(y)+2
elif abs(x)==abs(y): answer = 1
elif abs(x)<abs(y):
	if x>=0 and y>0: answer = y-x
	elif (x>=0 and y<0) or (x<0 and y>0): answer = abs(y)-abs(x)+1
	elif x<0 and y<0: answer = abs(y)-abs(x)+2
print(answer)

Buggy python submission (verdict: Runtime Error):
x,y = (int(i) for i in input().split())
if abs(x)>abs(y):
	if x<0 and y<=0: answer = y-x
	elif (x<0 and y>0) or (x>0 and y<=0): answer = abs(x)-abs(y)+1
	elif x>0 and y>0: answer = abs(x)-abs(y)+2
elif abs(x)==abs(y): answer = 1
elif abs(x)<abs(y):
	if x>=0 and y>0: answer = y-x
	elif (x>0 and y<0) or (x<=0 and y>0): answer = abs(y)-abs(x)+1
	elif x<0 and y<0: answer = abs(y)-abs(x)+2
print(answer)

Fixed submission:
x,y = (int(i) for i in input().split())
if abs(x)>abs(y):
	if x<0 and y<=0: answer = y-x
	elif (x<0 and y>0) or (x>0 and y<=0): answer = abs(x)-abs(y)+1
	elif x>0 and y>0: answer = abs(x)-abs(y)+2
elif abs(x)==abs(y): answer = 1
elif abs(x)<abs(y):
	if x>=0 and y>0: answer = y-x
	elif (x>=0 and y<0) or (x<0 and y>0): answer = abs(y)-abs(x)+1
	elif x<0 and y<0: answer = abs(y)-abs(x)+2
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in range(n): b[a[i]-1] = i
ans,c = (b[0]+1)*(n-b[0]),[b[0]]
for i in range(1,n):
	x = bisect.bisect_left(c,b[i])
	if 0<x<len(c): ans += (c[x]-b[i])*(b[i]-c[x-1])*(i+1)
	elif x==0: ans += (c[0]-b[i])*(b[i]+1)*(i+1)
	elif x==len(c): ans += (b[i]-c[-1])*(n-b[i])*(i+1)
	bisect.insort_left(c,b[i])
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b,l,r,ans = [0]*(n+1),[i for i in range(n+2)],[i for i in range(n+2)],0
for i in range(n): b[a[i]]=i
for i in range(n,0,-1):
	m = b[i]
	x,y = l[m],r[m]
	ans+=i*(m-x+1)*(y-m+1)
	l[y+1],r[x-1] = x,y
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	num,num2 = 1,1
	for j in range(i+1,n):
		if a[j]>a[i]: num+=1
		else: break
	for j2 in range(i-1,-1,-1):
		if a[j2]>a[i]: num2+=1
		else: break
	ans += a[i]*num*num2
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b,l,r,ans = [0]*(n+1),[i for i in range(n+2)],[i for i in range(n+2)],0
for i in range(n): b[a[i]]=i
for i in range(n,0,-1):
	m = b[i]
	x,y = l[m],r[m]
	ans+=i*(m-x+1)*(y-m+1)
	l[y+1],r[x-1] = x,y
print(ans)