Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
hmax=[i for i, x in enumerate(H) if x == max(H)]
wmax=[i for i, x in enumerate(W) if x == max(W)]
ans=0
mh=max(H)
mw=max(W)
for hi in hmax:
    for wi in wmax:
        if not ([hi+1,wi+1] in hw):
            ans=mh+mw
            print(int(ans))
            exit()
ans=mh+mw-1
print(int(ans))

Fixed submission:
import numpy as np
h,w,m=map(int, input().split())
hw=[tuple(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
mh=max(H)
mw=max(W)
hmax=[i for i, x in enumerate(H) if x == mh]
wmax=[i for i, x in enumerate(W) if x == mw]
f=0
for i in range(m):
    hi,wi=hw[i]
    if H[hi-1]==mh and W[wi-1]==mw:
        f+=1
if len(hmax)*len(wmax)-f<1:
    print(int(mh+mw-1))
else:
    print(int(mh+mw))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
h,w,m=map(int, input().split())
hw=[list(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
hmax=[i for i, x in enumerate(H) if x == max(H)]
wmax=[i for i, x in enumerate(W) if x == max(W)]
ans=0
for hi in hmax:
    for wi in wmax:
        if [hi+1,wi+1] in hw:
            ans=max(ans,max(H)+max(W)-1)
        else:
            ans=max(ans,max(H)+max(W))
print(int(ans))

Fixed submission:
import numpy as np
h,w,m=map(int, input().split())
hw=[tuple(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
mh=max(H)
mw=max(W)
hmax=[i for i, x in enumerate(H) if x == mh]
wmax=[i for i, x in enumerate(W) if x == mw]
f=0
for i in range(m):
    hi,wi=hw[i]
    if H[hi-1]==mh and W[wi-1]==mw:
        f+=1
if len(hmax)*len(wmax)-f<1:
    print(int(mh+mw-1))
else:
    print(int(mh+mw))
Buggy python submission (verdict: Runtime Error):
for i in range(d):
  print(i%26+1)

Fixed submission:
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  print(tmp+1)

Buggy python submission (verdict: Time Limit Exceeded):
import time
start=time.time()
import random
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
solution=[]
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  solution.append(tmp)
  t[tmp]=i
  ans+=s[i-1][tmp]
  for j in range(26):
    ans-=c[j]*(i-t[j])
now=time.time()
while now-start<1.85:
  di=random.randrange(1,d+1)
  qi=random.randrange(1,27)
  old=solution[di-1]
  solution[di-1]=qi-1
  tmp2=ans
  for _ in range(26):
    tmp2=tmp2-s[di-1][old]+s[di-1][qi-1]
  if ans-tmp2>=0:
    solution[di-1]=old
    continue
  else:
    ans=tmp2
  now=time.time()
  if now>start+1.5:
    break
for k in solution:
  print(k+1)

Fixed submission:
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  print(tmp+1)

Buggy python submission (verdict: Time Limit Exceeded):
import time
start=time.time()
import random
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
solution=[]
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  solution.append(tmp)
  t[tmp]=i
  ans+=s[i-1][tmp]
  for j in range(26):
    ans-=c[j]*(i-t[j])
now=time.time()
while now-start<1.5:
  di=random.randrange(1,d+1)
  qi=random.randrange(1,27)
  old=solution[di-1]
  solution[di-1]=qi-1
  tmp2=ans
  for _ in range(26):
    tmp2=tmp2-s[di-1][old]+s[di-1][qi-1]
  if ans-tmp2>=0:
    solution[di-1]=old
    continue
  else:
    ans=tmp2
  now=time.time()
for k in solution:
  print(k+1)

Fixed submission:
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  print(tmp+1)

Buggy python submission (verdict: Time Limit Exceeded):
import time
start=time.time()
import random
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
solution=[]
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  solution.append(tmp)
  t[tmp]=i
  ans+=s[i-1][tmp]
  for j in range(26):
    ans-=c[j]*(i-t[j])
now=time.time()
while now-start<1.95:
  di=random.randrange(1,d+1)
  qi=random.randrange(1,27)
  old=solution[di-1]
  solution[di-1]=qi-1
  tmp2=ans
  for _ in range(26):
    tmp2=tmp2-s[di-1][old]+s[di-1][qi-1]
  if ans-tmp2>=0:
    solution[di-1]=old
  else:
    ans=tmp2
  now=time.time()
for k in solution:
  print(k+1)

Fixed submission:
d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  print(tmp+1)
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
a, b=[0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Fixed submission:
a=int(input())
print(a+a*a+a*a*a)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m,k=map(int,input().split())
A=[0]
A.append(list(map(int, input().split())))
B=[0]
B.append(list(map(int, input().split())))
ans=0
a=np.cumsum(np.array(A))
b=np.cumsum(np.array(B))
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
        ans=max(ans,i+j)
print(ans)

Fixed submission:
a=int(input())
print(a+a*a+a*a*a)
Buggy python submission (verdict: Runtime Error):
a=int(input())
print(a+a*a+a*a*a)

Fixed submission:
s=list(input())
t=list(input())
ans=0
for i in range(len(s)):
    if s[i]!=t[i]:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    a=list(map(int, input().split()))
    a.sort()
    arr=[0]*(10**6+1)
    flag=[True]*(10**6+1)
    ans=0
    for i in range(n):
        if flag[a[i]]:
            arr[a[i]]+=1
            for j in range(a[i]*2,10**6+1,a[i]):
                flag[j]=False
    print(arr.count(1))
main()

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int, input().split()))
a.sort()
m=max(a)
arr=[0]*(m+1)
flag=[True]*(m+1)
ans=0
for i in range(n):
    if flag[a[i]]:
        arr[a[i]]+=1
        if not arr[a[i]]==1:
            continue
        for j in range(a[i]*2,m+1,a[i]):
            flag[j]=False
print(arr.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
a.sort()
arr=[0]*(10**6+1)
flag=[True]*(10**6+1)
ans=0
for i in range(n):
    if flag[a[i]]:
        arr[a[i]]+=1
        for j in range(a[i]*2,10**6+1,a[i]):
            flag[j]=False
print(arr.count(1))

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int, input().split()))
a.sort()
m=max(a)
arr=[0]*(m+1)
flag=[True]*(m+1)
ans=0
for i in range(n):
    if flag[a[i]]:
        arr[a[i]]+=1
        if not arr[a[i]]==1:
            continue
        for j in range(a[i]*2,m+1,a[i]):
            flag[j]=False
print(arr.count(1))
Buggy python submission (verdict: Runtime Error):
chokudai
chokudaiz


Fixed submission:
s=str(input())
t=str(input())
if s==t[:len(s)]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
def main():
x=int(input())
for a in range(-250,251):
  for b in range(-250,251):
      if pow(a,5)-pow(b,5)==x:
          print(a,b)
          exit()
main()

Fixed submission:
def main():
  x=int(input())
  for a in range(-250,251):
    for b in range(-250,251):
        if pow(a,5)-pow(b,5)==x:
            print(a,b)
            exit()
main()
Buggy python submission (verdict: Runtime Error):
s.w=map(int,input().split())
if s<=w:
  print('unsafe')
else:
  print('safe')

Fixed submission:
def main():
    s,w=map(int,input().split())
    if s<=w:
      print('unsafe')
    else:
      print('safe')
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  n=len(s)
  ans=0
  for i in range(n-3):
    for j in range(i+3,n+1):
      if int(s[i:j])%2019==0:
        ans+=1
        break
  print(ans)
main()

Fixed submission:
from collections import Counter
s=input()
n=len(s)
ans=0
arr=[0]*(n+1)
if s=='0':
    print(1)
    exit()
elif n==1:
    print(0)
    exit()
for i in reversed(range(n)):
    arr[i]=(arr[i+1]+int(s[i])*pow(10,n-i-1,2019))%2019
m=Counter(arr)
for j in m.keys():
    ans+=m[j]*(m[j]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
ans=0
for i in range(n-3):
  for j in range(i+3,n+1):
    if int(s[i:j])%2019==0:
      ans+=1
print(ans)

Fixed submission:
from collections import Counter
s=input()
n=len(s)
ans=0
arr=[0]*(n+1)
if s=='0':
    print(1)
    exit()
elif n==1:
    print(0)
    exit()
for i in reversed(range(n)):
    arr[i]=(arr[i+1]+int(s[i])*pow(10,n-i-1,2019))%2019
m=Counter(arr)
for j in m.keys():
    ans+=m[j]*(m[j]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
ans=0
for i in range(n-3):
  for j in range(i+3,n+1):
    if int(s[i:j])%2019==0:
      ans+=1
print(ans)

Fixed submission:
from collections import Counter
s=input()
n=len(s)
ans=0
arr=[0]*(n+1)
if s=='0':
    print(1)
    exit()
elif n==1:
    print(0)
    exit()
for i in reversed(range(n)):
    arr[i]=(arr[i+1]+int(s[i])*pow(10,n-i-1,2019))%2019
m=Counter(arr)
for j in m.keys():
    ans+=m[j]*(m[j]-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
  n=int(input())
  print(n*3.1415923535897932)

Fixed submission:
n=int(input())
print(2*n*3.14159235359)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
n,k=map(int,input().split())
a=list(map(int,input().split())) #横一列リスト
ans=0
for i in range(n):
    ans+=a[i]
if ans<=n:
    print(n-ans)
else:
    print('-1')

Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()
Buggy python submission (verdict: Runtime Error):
n=list(map(int,input())
if n[i]==7:
  print('Yes')
else:
  print('No')

Fixed submission:
n=str(input())
for i in range(len(n)):
  if n[i]=='7':
    print('Yes')
    exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      tmp=math.gcd(a,b)
      ans+=math.gcd(tmp,c)
print(ans)

Fixed submission:
import math
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      tmp=math.gcd(a,b)
      ans+=math.gcd(tmp,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
l=int(input())
n=l/3
print(n*n*n)

Fixed submission:
n,m=map(int,input().split())
print(n*(n-1)//2 + m*(m-1)//2)
Buggy python submission (verdict: Runtime Error):
H,W =map(int,input().split())
if H==1 or W==1:
  print(1)
elif H%2==0:
  print(W*H//2)
else:
  if W%2==1:
    print(W*(H//2)+W//2+1)
  else:
    print(W*(H//2)+W//2)

Fixed submission:
K =int(input())
A =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])

Buggy python submission (verdict: Runtime Error):
K =int(input())
A =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K])

Fixed submission:
K =int(input())
A =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])
Buggy python submission (verdict: Runtime Error):
H,W =map(int,input().split())
if H==1 or W==1:
  print(1)
elif H%2==0:
      print(W*H//2)
else:
  if W%2==1:
    print(W*(H//2)+W//2+1)
  else:
    print(W*(H//2)+W//2)

Fixed submission:
import math
a,b,c=map(int,input().split())
if c-a-b>0 and (c-a-b)**2 > 4*a*b:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
A=input
if A='hi' or A='hihi' or A='hihihi' or A='hihihihi' or A='hihihihihi' or A='hih' or A='hihih' or A='hihihih' or A='hihihihih':
    print('Yes')
else:
    print('No')

Fixed submission:
A=input()
if A=='hi' or A=='hihi' or A=='hihihi' or A=='hihihihi' or A=='hihihihihi':
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A=input()
if A='hi' or A='hihi' or A='hihihi' or A='hihihihi' or A='hihihihihi':
    print('Yes')
else:
    print('No')

Fixed submission:
A=input()
if A=='hi' or A=='hihi' or A=='hihihi' or A=='hihihihi' or A=='hihihihihi':
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
for m in range(A):
    for n in range (B):
        price2=int(vecA[m]) + int(vecB[n])
        if price2<=price:
            price=price2
print(price)

Fixed submission:
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
price2=int(min(vecA)) + int(min(vecB))
if price2<=price:
    price=price2
print(price)

Buggy python submission (verdict: Runtime Error):
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
for m in range(M):
    for n in range (M):
        price2=int(vecA[m]) + int(vecB[n])
        if price2<=price:
            price=price2
print(price)

Fixed submission:
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
price2=int(min(vecA)) + int(min(vecB))
if price2<=price:
    price=price2
print(price)
Buggy python submission (verdict: Runtime Error):
S=input()
if S= AAA or BBB
print(No)
 else print(YES)

Fixed submission:
S=input()
if S == 'AAA' or S == 'BBB':
	print('No')
else:
	print('Yes')
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
r=1
S=set()
while r<= 10**100:
	S='b'*A + str(S) +'r'*B
	if len(S)>10**18:
		S = S[1,10**18]
	r=r+1
print(S[1,N],count('b'))

Fixed submission:
n,a,b=map(int,input().split())
q,mod=divmod(n,(a+b))
if mod>a:
  mod=a
print(q*a+mod)

Buggy python submission (verdict: Runtime Error):
N,A,B =int(input())
r = 1
S=string()
while r<=10**100:
	S='b'*B+ S+ 'r'*A
    r += 1


print(S[1:N].count(b))

Fixed submission:
n,a,b=map(int,input().split())
q,mod=divmod(n,(a+b))
if mod>a:
  mod=a
print(q*a+mod)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
list=[list(map(int,input().split())) for _ in range(m)]
flag=False
ans=['0']*n
for i in range(m):
  if list[i][0]==n:
    flag=True
  for j in range(i+1,m):
    if list[i][0]==list[j][0] and list[i][1]!=list[j][1]:
      print('-1')
      exit()
  ans[list[i][0]-1]=str(min(int(ans[list[i][0]-1]),list[i][1]))
if flag==True:
  print(''.join(ans))
else:
  print('-1')

Fixed submission:
n=int(input())
if n%2==0:
  print(n//2)
else:
  print(n//2+1)
Buggy python submission (verdict: Runtime Error):
import math
k=int(input())
ans=0
if k==1:
  print('1')
i=0
while True:
  k=math.floor(k/2)
  ans+=2**i
  i+=1
  if k=<1:
    print(ans)
    exit()

Fixed submission:
import math
k=int(input())
i=0
while k:
  k=math.floor(k/2)
  i+=1
print(2**i-1)

Buggy python submission (verdict: Runtime Error):
import math
k=int(input())
ans=0
if k==1:
  print('1')
i=0
while True:
  k=math.floor(k/2)
  ans+=2**i
  i+=1
  if k=<1:
    print(ans)
    exit()

Fixed submission:
import math
k=int(input())
i=0
while k:
  k=math.floor(k/2)
  i+=1
print(2**i-1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
l=list(map(int, input().split()))
l.sort()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=bisect.bisect_left(l[j+1:],l[i]+l[j])
print(ans)

Fixed submission:
import bisect
n=int(input())
l=list(map(int, input().split()))
l.sort()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=bisect.bisect_left(l[j+1:],l[i]+l[j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m=map(int,input().split())
a=sorted(list(map(int, input().split())))
bc=[list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1])
heapq.heapify(a)
for b,c in bc:
  for j in range(b):
    amin=heapq.heappop(a)
    if amin<c:
      heapq.heappush(a,c)
    else:
      heapq.heappush(a,amin)
      break
print(sum(a))

Fixed submission:
def main():
    import heapq
    n,m=map(int,input().split())
    a=sorted(list(map(int, input().split())))
    bc=[list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:-x[1])
    heapq.heapify(a)
    for b,c in bc:
      for j in range(b):
        amin=heapq.heappop(a)
        if amin<c:
          heapq.heappush(a,c)
        else:
          heapq.heappush(a,amin)
          break
    print(sum(a))
main()
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for j in range(1,k+1):
  for i in a:
    if 0<=j-i and dp[j-1]==False:
      dp[j]=True
if dp[k]:
  print('First')
else:
  print('Second')

Fixed submission:
n=int(input())
h=list(map(int, input().split())) 
dp=[float('inf')]*n
dp[0]=0
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
  if i < n - 2:
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

dp = [0, abs(h[1]-[0])]

for i in range(2,n):
    dp.append(min(dp[i-1] + abs(h[i]-h[i+1]), dp[i] + abs(h[i]-h[i+2])))
    
print(dp[-1])

Fixed submission:
n=int(input())
h=list(map(int, input().split())) 
dp=[float('inf')]*n
dp[0]=0
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
  if i < n - 2:
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
t=str(input())
n,m=len(s),len(t)
ans=''
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1])
    else:
      dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
while m>0 and n>0:
  if s[n-1]==t[m-1]:ans=s[n-1]+ans;n-=1;m-=1
  elif dp[n][m]==dp[n-1][m]:n-=1
  else:m-=1
print(ans)

Fixed submission:
s=str(input())
t=str(input())
n,m=len(s),len(t)
ans=''
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1])
    else:
      dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
while m>0 and n>0:
  if s[n-1]==t[m-1]:ans=s[n-1]+ans;n-=1;m-=1
  elif dp[n][m]==dp[n-1][m]:n-=1
  else:m-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=tuple(map(float,input().split()))
dp=[[0.0]*(n+1) for _ in range(n+1)]
dp[0][0]=1.0
for i in range(1,n+1):
  for j in range(i+1):
    dp[i][j]=dp[i-1][j]*(1-p[i-1])
    if j>0:
      dp[i][j]+=dp[i-1][j-1]*p[i-1]
print(sum(dp[n][n//2+1:]))

Fixed submission:
n=int(input())
p=tuple(map(float,input().split()))
dp=[[0.0]*(n+1) for _ in range(n+1)]
dp[0][0]=1.0
for i in range(1,n+1):
  for j in range(i+1):
    dp[i][j]=dp[i-1][j]*(1-p[i-1])
    if j>0:
      dp[i][j]+=dp[i-1][j-1]*p[i-1]
print(sum(dp[n][n//2+1:]))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf=UnionFind(N)
for a,b in ab:
    uf.union(a,b)
print(uf.group_count()-1)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf=UnionFind(N)
for a,b in ab:
    uf.union(a-1,b-1)
print(uf.group_count()-1)