Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n=int(input())
l=np.array(list(map(int, input().split())))
l.sort()
counter=0
for i in range(2, n):
  for j in range(1, i):
    counter+=j-np.sum(l[:j]<=(l[i]-l[j]))
                      
print(counter)

Fixed submission:
def f(list, n):
  length=len(list)
  if list[-1]<n:
    return length
  elif list[0]>=n:
    return 0
  else:
    a=length//2
    b=length//4
    while b>=1:
      if list[a]<n:
        a+=b
      else:
        a-=b
      b=b//2
      
    if list[a]<n:
      while list[a+1]<n:
        a+=1
    else:
      while list[a]>=n:
        a-=1
        
    return a+1  

n=int(input())
l=list(map(int, input().split()))
l.sort()
counter=0
for i in range(n-2):
  for j in range(i+1, n-1):
    counter+=f(l[(j+1):], l[i]+l[j]) #f(list, n) counts num in the sorted list under n
    
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int, input().split()))

L.sort()

counter=0
i=0
while i<N-2:
  j=i+1
  k=j+1
  while j<N-1:
    if L[i]+L[j]>L[k]:
      if k<N-1:
        counter+=1
        k+=1
      else:
        counter+=1
        j+=1
        k=j+1
    else:
      j+=1
      if j==k:
        k+=1
  i+=1
  
print(counter)

Fixed submission:
def f(list, n):
  length=len(list)
  if list[-1]<n:
    return length
  elif list[0]>=n:
    return 0
  else:
    a=length//2
    b=length//4
    while b>=1:
      if list[a]<n:
        a+=b
      else:
        a-=b
      b=b//2
      
    if list[a]<n:
      while list[a+1]<n:
        a+=1
    else:
      while list[a]>=n:
        a-=1
        
    return a+1  

n=int(input())
l=list(map(int, input().split()))
l.sort()
counter=0
for i in range(n-2):
  for j in range(i+1, n-1):
    counter+=f(l[(j+1):], l[i]+l[j]) #f(list, n) counts num in the sorted list under n
    
print(counter)
Buggy python submission (verdict: Runtime Error):
S=input()
K=int(input())

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
while S[0]==S[a+1]:
  a+=1
  
b=-1
while S[0]==S[b]:
  b-=1
  
if b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*(-b-1)//2+K*f(S[1:b+1])
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)

Fixed submission:
S=input()
K=int(input())

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n-1:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
n=len(S)
while a<n-1 and S[0]==S[a+1]:
  a+=1
  
b=-1
while a<n-1 and S[0]==S[b]:
  b-=1
  
if a==n-1:
  ans=n*K//2
elif b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*((-b-1)//2)+K*f(S[1:b+1])+(-b-1)//2
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)

Buggy python submission (verdict: Runtime Error):
S=input()
K=int(input())

i=0
c=0
while i<len(S)-1:
  if S[i]==S[i+1]:
    c+=1
    i+=2
  else:
    i+=1
    
if S[0]==S[-1] and S[-2]!=S[-1]:
  print((c+1)*K-1)
else:
  print(c*K)

Fixed submission:
S=input()
K=int(input())

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n-1:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
n=len(S)
while a<n-1 and S[0]==S[a+1]:
  a+=1
  
b=-1
while a<n-1 and S[0]==S[b]:
  b-=1
  
if a==n-1:
  ans=n*K//2
elif b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*((-b-1)//2)+K*f(S[1:b+1])+(-b-1)//2
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K, Q=map(int, input().split())
A=[int(input()) for i in range(Q)]

point=[0]+[K for i in range(N)]
point=np.array(point)

for i in range(Q):
  point=point-1
  point[A[i]]+=1
  
for i in range(1, N+1):
  if point[i]>0:
    print('Yes')
  else:
    print('No')

Fixed submission:
N, K, Q=map(int, input().split())
A=[int(input()) for i in range(Q)]
point=[K]*(N+1)

for i in range(Q):
  point[A[i]]+=1
  
for i in range(1, N+1):
  if point[i]>Q:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[''.join(sorted(input())) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)

Fixed submission:
N=int(input())
s=[''.join(sorted(input())) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)

Buggy python submission (verdict: Runtime Error):
N=int(input())
s=[sorted(list(input())) for i in range(N)]
s.sort()

counter=long(0)

i=0
while i<N-1:
  j=i+1
  while j<N:
    if s[i]==s[j]:
	    counter+=1
	    j+=1
    else:
      break
    
  i+=1
  
print(counter)

Fixed submission:
N=int(input())
s=[''.join(sorted(input())) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[''.join(sorted(list(input()))) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)

Fixed submission:
N=int(input())
s=[''.join(sorted(input())) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[sorted(list(input())) for i in range(N)]
s.sort()

counter=0

i=0
while i<N-1:
  j=i+1
  while j<N:
    if s[i]==s[j]:
	    counter+=1
	    j+=1
    else:
      break
    
  i+=1
  
print(counter)

Fixed submission:
N=int(input())
s=[''.join(sorted(input())) for i in range(N)]


dic={}
counter=0
for i in range(N):
  if (s[i] in dic.keys())==True:
    counter+=dic[s[i]]
    dic[s[i]]=dic[s[i]]+1
  else:
    dic[s[i]]=1

print(counter)
Buggy python submission (verdict: Runtime Error):
import numpy as np

temp=list(map(int, input().split()))
N=temp[0]
M=temp[1]

AB=np.array([list(map(int, input().split())) for i in range(N)])
AB=np.c_[AB, np.zeros((AB.shape[0], 1))]

money=0
for i in range(1, M+1):
  temp=AB[AB[:, 0]<=i]
  temp=temp[temp[:, 2]==0]
  temp=temp[np.argmax(temp[:, 1])]
  money+=temp[1]
  
  x=0
  while x<AB.shape[0]:
    if sum(AB[x, :]==temp)==3:
      AB[x, 2]=1
      break
    x+=1
    
print(int(money))

Fixed submission:
import heapq

N, M=map(int, input().split())
AB=[list(map(int, input().split())) for i in range(N)]
AB=sorted(AB, key=lambda x:x[0])
h=[0]*M
heapq.heapify(h)

out=0
j=0
for i in range(1, M+1):
  while j<N and AB[j][0]<=i:
    heapq.heappush(h, -1*AB[j][1])
    j+=1
    
  out+=-1*heapq.heappop(h)
  
print(out)
Buggy python submission (verdict: Runtime Error):
temp=list(map(int, input().stlip()))
a=temp[2]-(temp[0]-temp[1])
if a>=0:
  print(a)
else:
  print(0)

Fixed submission:
temp=list(map(int, input().split()))
a=temp[2]-(temp[0]-temp[1])
if a>=0:
  print(a)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())

counter=0
for i in range(1, N+1):
  if int(np.log10(i))%2==0:
    counter+=1
    
print(counter)

Fixed submission:
N=int(input())

counter=0
for i in range(1, N+1):
  if len(str(i))%2==1:
    counter+=1
    
print(counter)
Buggy python submission (verdict: Runtime Error):
S=input()
N=len(S)
ans=[0]*N

a=0
x=0
y=0
while a<N-1:
  x=a+1
  while S[x]=='R':
    x+=1
    
  y=x+1
  while S[y]=='L' and y<N:
    y+=1
    if y==N:
      break
    
  ans[x]+=(x-a)//2
  ans[x-1]+=(x-a-1)//2
  
  ans[x]+=(y-x-1)//2
  ans[x-1]+=(y-x)//2
  
  ans[x]+=1
  ans[x-1]+=1
  
  a=y
  
print(' '.join(map(str, ans)))

Fixed submission:
S=input()
N=len(S)
c=[1]*N
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='R':
    c[i+2]+=c[i]
    c[i]=0
    
for i in range(N-1, 1, -1):
  if S[i]=='L' and S[i-1]=='L':
    c[i-2]+=c[i]
    c[i]=0
    
print(' '.join(map(str, c)))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
ans=[0 for i in range(len(S))]

for i in range(len(S)):
  if S[i]=='R':
    counter=0
    while S[i+counter]=='R':
      counter+=1
      
    if counter%2==0:
      ans[i+counter]+=1
    else:
      ans[i+counter-1]+=1
      
  else:
    counter=0
    while S[i-counter]=='L':
      counter+=1
      
    if counter%2==0:
      ans[i-counter]+=1
    else:
      ans[i-counter+1]+=1
      
ans=map(str, ans)
print(' '.join(ans))

Fixed submission:
S=input()
N=len(S)
c=[1]*N
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='R':
    c[i+2]+=c[i]
    c[i]=0
    
for i in range(N-1, 1, -1):
  if S[i]=='L' and S[i-1]=='L':
    c[i-2]+=c[i]
    c[i]=0
    
print(' '.join(map(str, c)))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
ans=[0 for i in range(len(S))]

for i in range(len(S)):
  if S[i]=='R':
    counter=0
    while S[i+counter]=='R':
      counter+=1
      
    if counter%2==0:
      ans[i+counter]+=1
    else:
      ans[i+counter-1]+=1
      
  else:
    counter=0
    while S[i-counter]=='L':
      counter+=1
      
    if counter%2==0:
      ans[i-counter]+=1
    else:
      ans[i-counter+1]+=1
      
ans=map(str, ans)
print(' '.join(ans))

Fixed submission:
S=input()
N=len(S)
c=[1]*N
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='R':
    c[i+2]+=c[i]
    c[i]=0
    
for i in range(N-1, 1, -1):
  if S[i]=='L' and S[i-1]=='L':
    c[i-2]+=c[i]
    c[i]=0
    
print(' '.join(map(str, c)))
Buggy python submission (verdict: Runtime Error):
import numpy as np

temp=list(map(int, input().split()))
temp=np.mean(temp)
if temp-int(temp)>0:
  output='IMPOSSIBLE'
else:
  output=temp
  
print(int(output))

Fixed submission:
temp=input().split()
A=int(temp[0])
B=int(temp[1])

m=int((A+B)/2)

if m==(A+B)/2 and m>=0:
  print(int(m))
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
N=int(input())
p=np.array(list(map(int, input().split())))
q=np.arange(N)+1

temp=np.sum(p==q)
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')
  

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

counter=0
for i in range(N):
  if p[i]!=int(i+1):
    counter+=1
    
if counter==0 or counter==2:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
S=int(input())
X1=0
Y1=0
if S==10**18:
  print(' '.join(['0', '0', '0', '1000000000', '1000000000', '0']))
else:
  X2=10**9
  Y2=1
  Y3=S//(10**9)+1
  X3=Y3*(10**9)-S

print(' '.join(map(str, [X1, Y1, X2, Y2, X3, Y3])))

Fixed submission:
S=int(input())
X1=0
Y1=0
if S==10**18:
  print(' '.join(['0', '0', '0', '1000000000', '1000000000', '0']))
else:
  X2=10**9
  Y2=1
  Y3=S//(10**9)+1
  X3=Y3*(10**9)-S
  print(' '.join(map(str, [X1, Y1, X2, Y2, X3, Y3])))
Buggy python submission (verdict: Runtime Error):
value=input().split()

print(3*value*value)

Fixed submission:
r=int(input())
print(3*r*r)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
  N=int(input())
  a=[int(input())]
  for _ in range(N-1):
    num=int(input())
    if num<=a[0]:
      a=[num]+a
    else:
      a[bisect.bisect_left(a, num)-1]=num
  print(len(a))
if __name__=='__main__':
  main()

Fixed submission:
import bisect
from collections import deque
N=int(input())
a=deque([int(input())])
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a.appendleft(num)
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
a=[int(input())]
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a=[num]+a
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))

Fixed submission:
import bisect
from collections import deque
N=int(input())
a=deque([int(input())])
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a.appendleft(num)
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
def f(a, num):
  if a[0]>=num:
    a=[num]+a
    return a
  if a[-1]<num:
    a[-1]=num
    return a
  x=0
  y=len(a)
  while y-x>1:
    z=(x+y)//2
    if a[z]>=num:
      y=z
    else:
      x=z
  a=a[:x]+[num]+a[y:]
  return a
      
  
N=int(input())
a=[int(input())]
for _ in range(N-1):
  a=f(a, int(input()))
print(len(a))

Fixed submission:
import bisect
from collections import deque
N=int(input())
a=deque([int(input())])
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a.appendleft(num)
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))
Buggy python submission (verdict: Runtime Error):
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

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

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i][x]-points[j][x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

Buggy python submission (verdict: Runtime Error):
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.add([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

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

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i][x]-points[j][x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

Buggy python submission (verdict: Runtime Error):
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.add([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l==int(l):
      counter+=1
      
print(counter)

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

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i][x]-points[j][x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
temp=input().split()
L=int(temp[0])
R=int(temp[1])

#print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))
temp=2019
for i in range(L, R):
  for j in range(i+1, R+1):
    if (i*j)%2019<temp:
      temp=(i*j)%2019
      
print(temp)

Fixed submission:
temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
temp=input().split()
L=int(temp[0])
R=int(temp[1])

print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Fixed submission:
temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
temp=input().split()
L=int(temp[0])
R=int(temp[1])

print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Fixed submission:
temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Buggy python submission (verdict: Runtime Error):
temp=input().split()
L=int(temp[0])
R=int(temp[1])

print(min([(i*j)%2019 for i in range(L, R-1) for j in range(i, R)]))

Fixed submission:
temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Buggy python submission (verdict: Runtime Error):
temp=input().split()
L=int(temp[0])
R=int(temp[1])

print(min([(i*j)%2019 for i in range(L, R-1) for j in range(i, R)]))

Fixed submission:
temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int, input().split()))

d.sort()

print(int(d[n/2]-d[n/2-1]))

Fixed submission:
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=d[int(N/2-1)]
b=d[int(N/2)]
print(int(b-a))

Buggy python submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=dd[int(N/2-1)]
b=dd[int(N/2)]
print(int(b-a))

Fixed submission:
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=d[int(N/2-1)]
b=d[int(N/2)]
print(int(b-a))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
dd=[]
for i in range(int(N/2)+1):
  dd.append(min(d))
  d.remove(min(d))
  
a=dd[int(N/2-1)]
b=dd[int(N/2)]
print(int(b-a))

Fixed submission:
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=d[int(N/2-1)]
b=d[int(N/2)]
print(int(b-a))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
dd=[]
for i in range(N):
  dd.append(min(d))
  d.remove(min(d))
  
a=dd[int(N/2-1)]
b=dd[int(N/2)]
print(int(b-a))

Fixed submission:
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=d[int(N/2-1)]
b=d[int(N/2)]
print(int(b-a))
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D=map(int, input().split())
x=math.gcd(C, D)
p=B//C-(A-1)//C
q=B//D-(A-1)//D
r=B//x-(A-1)//x
print(B-(A-1)-(p+q-r))

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

x=B//C-(A-1)//C
y=B//D-(A-1)//D
s=lcm(C, D)
z=B//s-(A-1)//s

print(int(B-A+1-x-y+z))

Buggy python submission (verdict: Runtime Error):
temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

for i in range(A, B+1):
  if i%C==0 and i%D==0:
    counter+=1
    
print(counter)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

x=B//C-(A-1)//C
y=B//D-(A-1)//D
s=lcm(C, D)
z=B//s-(A-1)//s

print(int(B-A+1-x-y+z))
Buggy python submission (verdict: Runtime Error):
N=int(input())
W=list(map(int, input().split()))

output=abs(W[0]-sum(W[1:]))
for i in range(2, N-1):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output<temp:
    output=temp.copy()
    
print(output)

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:])) for t in range(1, N-1)]))

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:]))) for t in range(1, N-1)]))

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:]))) for t in range(N)]))

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)
Buggy python submission (verdict: Runtime Error):
N, M=map(int, input().split())
if M>0:
  a=[int(input()) for i in range(M)]

  if a[0]==1:
    way=[1, 0]
    a.remove(1)
  else:
    way=[1, 1]
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

Fixed submission:
temp=input().split()
N=int(temp[0])
M=int(temp[1])

index=[int(1) for i in range(N)]
for i in range(M):
  index[int(int(input())-1)]=0

temp=[0, 1]
for i in range(N):
  if index[i]==1:
    temp=[temp[1], temp[0]+temp[1]]
  else:
    temp=[temp[1], 0]
    
print(temp[1]%1000000007)

Buggy python submission (verdict: Runtime Error):
N, M=map(int, input().split())
a=[int(input()) for i in range(M)]

if a[0]==1:
  way=[1, 0]
  a.remove(1)
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

Fixed submission:
temp=input().split()
N=int(temp[0])
M=int(temp[1])

index=[int(1) for i in range(N)]
for i in range(M):
  index[int(int(input())-1)]=0

temp=[0, 1]
for i in range(N):
  if index[i]==1:
    temp=[temp[1], temp[0]+temp[1]]
  else:
    temp=[temp[1], 0]
    
print(temp[1]%1000000007)

Buggy python submission (verdict: Runtime Error):
N, M=map(int, input().split())
a=[int(input()) for i in range(M)]

if a[0]==1:
  way=[1, 0]
  a.remove(1)
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

Fixed submission:
temp=input().split()
N=int(temp[0])
M=int(temp[1])

index=[int(1) for i in range(N)]
for i in range(M):
  index[int(int(input())-1)]=0

temp=[0, 1]
for i in range(N):
  if index[i]==1:
    temp=[temp[1], temp[0]+temp[1]]
  else:
    temp=[temp[1], 0]
    
print(temp[1]%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
H, W=map(int, input().split())
S=[input() for _ in range(H)]

tate=[[0]*W for _ in range(H)]
yoko=[[0]*W for _ in range(H)]

for i in range(W):
  j=0
  while j<H:
    x=0
    while j+x<H and S[j+x][i]=='.':
      x+=1
    if x==0:
      tate[j][i]=0
      j+=1
    else:
      for t in range(x):
        tate[j+t][i]=x
      j+=x

for i in range(H):
  j=0
  while j<W:
    x=0
    while j+x<W and S[i][j+x]=='.':
      x+=1
    if x==0:
      yoko[i][j]=0
      j+=1
    else:
      for t in range(x):
        yoko[i][j+t]=x
      j+=x
      
print(max([max([tate[i][j]+yoko[i][j]-1 for j in range(W)]) for i in range(H)]))

Fixed submission:
H, W=map(int, input().split())
S=[input() for _ in range(H)]

tate=[[0]*W for _ in range(H)]
yoko=[[0]*W for _ in range(H)]

for i in range(W):
  j=0
  while j<H:
    x=0
    while j+x<H and S[j+x][i]=='.':
      x+=1
    if x==0:
      tate[j][i]=0
      j+=1
    else:
      for t in range(x):
        tate[j+t][i]=x
      j+=x

for i in range(H):
  j=0
  while j<W:
    x=0
    while j+x<W and S[i][j+x]=='.':
      x+=1
    if x==0:
      yoko[i][j]=0
      j+=1
    else:
      for t in range(x):
        yoko[i][j+t]=x
      j+=x
      
print(max([max([tate[i][j]+yoko[i][j]-1 for j in range(W)]) for i in range(H)]))