Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def countAB(S):
  ct=0
  flg = True
  pos=0
  while flg:
    idx = S.find('AB',pos)
    if idx!=-1:
      ct+=1
    else:
      flg = False
    pos = idx + 2
  return ct

N = int(input())

num_AB = 0
num_A = 0
for n in range(N):
  S = input()
  num_AB += countAB(S)
  if S[len(S)-1]=='A':
    num_A += 1
  if S[0]=='B':
    num_B += 1

num_AB_cmb = min(num_A,num_B)
if num_A == N and num_B == N:
  num_AB_cmb = N-1

print("{0}".format(num_AB + num_AB_cmb))
  
  
  

Fixed submission:
def countAB(S):
  ct=0
  flg = True
  pos=0
  while flg:
    idx = S.find('AB',pos)
    if idx!=-1:
      ct+=1
    else:
      flg = False
    pos = idx + 2
  return ct
 
N = int(input())
 
num_AB = 0
num_A = 0
num_B = 0
num_BA = 0
for n in range(N):
  S = input()
  num_AB += countAB(S)
  if S[len(S)-1]=='A':
    num_A += 1
  if S[0]=='B':
    num_B += 1
  if S[len(S)-1]=='A' and S[0]=='B': 
    num_BA += 1
    
num_AB_cmb = min(num_A,num_B)
if num_A == num_BA and num_B == num_BA and num_BA!=0:
  num_AB_cmb = num_BA-1
 
print("{0}".format(num_AB + num_AB_cmb))
Buggy python submission (verdict: Runtime Error):
 a,b = map(int,input().split())
 i ="Even" if a * b % 2 == 0 else "Odd"
 print(i)

Fixed submission:
a,b = map(int,input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        return print('Yes')
print('No')

Fixed submission:
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        break
print('Yes' if  x == i * i else 'No')

Buggy python submission (verdict: Runtime Error):
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        return print('Yes')
print('No')

Fixed submission:
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        break
print('Yes' if  x == i * i else 'No')

Buggy python submission (verdict: Runtime Error):
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        return print('Yes')
print('No')

Fixed submission:
x = int(''.join(input().split()))
for i in range(int(x/2) + 1):
    if x == i * i:
        break
print('Yes' if  x == i * i else 'No')
Buggy python submission (verdict: Runtime Error):
n=input()

if n%2==0:
  print(n/2-1)
else:
  print(n//2)

Fixed submission:
n=int(input())

if n%2==0:
  print(int(n/2-1))
else:
  print(int(n/2))
Buggy python submission (verdict: Runtime Error):
s=input()

if s =="Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else s == "Rainy":
    print("Sunny")

Fixed submission:
s=input()

if s =="Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
elif s == "Rainy":
    print("Sunny")
Buggy python submission (verdict: Runtime Error):
s=input()

def evenjudge(obj):
    if obj %2!=0:
        return 1
    else:
        return 2
def oddjudge(obj):
    if obj %2!=0:
        return 2
    else:
        return 1

lo=[i for i in range(0,110,2)]
le=[i for i in range(1,110,2)]

oeflag=evenjudge(len(s))
eoflag=oddjudge(len(s))
for j in lo:
    if s[j] == "L":
        print("No")
        exit(0)
    if j == len(s)-oeflag:
        break


for k in le:
    if s[k] == "R":
        print("No")
        exit(0)
    if k == len(s)-eoflag:
        break


print("Yes")

Fixed submission:
s=input()

def evenjudge(obj):
    if obj %2!=0:
        return 1
    else:
        return 2
def oddjudge(obj):
    if obj %2!=0:
        return 2
    else:
        return 1

lo=[i for i in range(0,110,2)]
le=[i for i in range(1,110,2)]

oeflag=evenjudge(len(s))
eoflag=oddjudge(len(s))
for j in lo:
    if s[j] == "L":
        print("No")
        exit(0)
    if j == len(s)-oeflag:
        break


for k in le:
    if len(s)==1:
        break
    if s[k] == "R":
        print("No")
        exit(0)
    if k == len(s)-eoflag:
        break


print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=(int(x) for x in input().split())
a=[]
for i in range(q):
    a.append(int(input()))
p=[0]*n
for i in range(k):
    for j in range(n):
        p[j]+=1
for i in range(n):
    for j in range(q):
        p[i]-=1
        if a[j]-1 == i:
            p[i]+=1


for i in range(n):
    if p[i]>0:
        print("Yes")
    else:
        print("No")


Fixed submission:
n,k,q=(int(x) for x in input().split())
a=[]
for i in range(q):
    a.append(int(input()))
p=[k-q]*n

for i in range(q):
    p[a[0]-1]+=1
    del a[0]

for i in range(n):
    if p[i]>0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(x) for x in input().split())
l = [int(i) for i in input().split()]

l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    l.sort(reverse=True)
total=sum(l)

print(total)
 

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(x) for x in input().split())
l = [int(i) for i in input().split()]

l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    l.sort(reverse=True)
total=sum(l)

print(total)
 

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(x) for x in input().split())
l = [int(i) for i in input().split()]

l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    l.sort(reverse=True)
total=0
for j in range(len(l)):
    total+=l[j]

print(total)


Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(x) for x in input().split())
l = [int(i) for i in input().split()]

l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    l.sort(reverse=True)
total=0
for j in range(len(l)):
    total+=l[j]

print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

#単入力
n=int(input())

l=[i for i in range(1,n+1)]
ll=l
ans=0
for i in range(len(l)):
    if i==n-1:
        break
    ans+=ll[i]%l[i+1]
    #if i==0:
        #del ans[0]

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

#単入力
n=int(input())
print(n*(n-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

#単入力
n=int(input())

l=[i for i in range(1,n+1)]
ll=l
ans=[]
for i in range(len(l)):
    if i==n-1:
        break
    ans.append(ll[i]%l[i+1])
    #if i==0:
        #del ans[0]

print(sum(ans))

Fixed submission:
import sys
input = sys.stdin.readline

#単入力
n=int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
import numpy as np

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/np.gcd(x,y))

print(int(lcm(a,b)))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/math.gcd(x,y))

print(int(lcm(a,b)))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/math.gcd(x, y))

print(int(lcm(a, b)))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x,y):
    return x*y/math.gcd(x, y)

print(int(lcm(a, b)))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x, y):
    return (x * y)/math.gcd(x, y)

print(int(lcm(a, b)))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x, y):
    return (x * y)//math.gcd(x, y)

print(lcm(a, b))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))

Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))

Buggy python submission (verdict: Runtime Error):
import math

a, b= map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))


Fixed submission:
import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
leng=len(s)
slist=[s]
#print(slist)
alphabet=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
#        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            slist[i]=alphabet[j+n]
#            print(slist[i])

print(slist)

Fixed submission:
n=int(input())
s=input()
leng=len(s)
slist=[]
#print(slist)
alphabet=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
#        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            #print(j)
            slist.append(alphabet[j+n])
            #print(alphabet[j+n])
            #print(slist[i])

print(''.join(slist))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
leng=len(s)
slist=[s]
#print(slist)
alphabet=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            slist[i]=alphabet[j+n]
#            print(slist[i])

print(slist)

Fixed submission:
n=int(input())
s=input()
leng=len(s)
slist=[]
#print(slist)
alphabet=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
#        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            #print(j)
            slist.append(alphabet[j+n])
            #print(alphabet[j+n])
            #print(slist[i])

print(''.join(slist))
Buggy python submission (verdict: Runtime Error):
a, b= map(int, input().split())

if a-b*2<=0:
  print(0)
 else:
  print(a-b*2)

Fixed submission:
a, b= map(int, input().split())

c=a-b*2

if c<=0:
    print(0)
else:
    print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
k=int(input())
h = list(map(int, input().split()))
sum = 0
for i in range(0,n):
    if h[i] >= k:
        sum =sum +1
print(sum)

Fixed submission:
n = list(map(int, input().split()))
h = list(map(int, input().split()))
sum = 0
for i in range(0,n[0]):
    if h[i] >= n[1]:
        sum =sum +1
print(sum)
Buggy python submission (verdict: Runtime Error):
tmp = list(map(int,(input().split())))
n = tmp[0]
m = tmp[1]

ai = list(map(int,(input().split())))

while (m > 0): 
  ai.sort(reverse=True)
  for i in range(n-1):
    if ai[i] >= ai[i+1] :
      m -= 1
      ai[i] = ai[i] // 2

for i in range(n):
  sum += ai[i]

# print(ai)
print(sum)

Fixed submission:
import heapq

tmp = list(map(int,(input().split())))
n = tmp[0]
m = tmp[1]

ai = []
tmp = list(map(int,(input().split())))
for i in range(n):
  heapq.heappush(ai, -tmp[i])

for i in range(m):
  maxp = - heapq.heappop(ai)
  maxp = maxp // 2
  heapq.heappush(ai, -maxp)
  
sum = 0
for i in range(n):
  sum += -ai[i]

#print(ai)
print(sum)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

swap = False
for i in range(n):
  if p[i] != i+1:
    if swap == False and p[p[i]-1] == i+1:
      swap = True
      p[p[i]-1] = p[i]
    else:
      print('NO')
      sys.exit()

print('YES')


Fixed submission:
import sys

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

swap = False
for i in range(n):
  if p[i] != i+1:
    if swap == False and p[p[i]-1] == i+1:
      swap = True
      p[p[i]-1] = p[i]
    else:
      print('NO')
      sys.exit()

print('YES')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
  ptr = n - 1 - i
  if a[ptr] % 2 == 1:
    for j in range(1, int(math.sqrt(ptr+1))+1):
      if (ptr + 1) % (j + 1) == 0:
        a[j] += 1
      
cnt = 0
que = []
for  i in range(n):
  if a[i]:
    cnt += 1
    que.append(a[i])

print(cnt)
if cnt > 0:
  print(' '.join(map(str, que)))

Fixed submission:
import math

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

for i in range(n-1):
  ptr = n - 1 - i
  if a[ptr] % 2 == 1:
    a[0] += 1
    for j in range(2, int(math.sqrt(ptr+1))+1):
      if (ptr + 1) % j == 0:
        a[j-1] += 1
        if (ptr + 1) // j != j:
          a[(ptr + 1) // j - 1] += 1
      
cnt = 0
que = []
for  i in range(n):
  if a[i] % 2 == 1:
    cnt += 1
    que.append(i+1)

print(cnt)
if cnt > 0:
  print(' '.join(map(str, que)))

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

for i in range(n):
  ptr = n - 1 - i
  if a[ptr] % 2 == 1:
    for j in range(1, int(math.sqrt(ptr+1))+1):
      if (ptr + 1) % (j + 1) == 0:
        a[j] += 1
      
cnt = 0
que = []
for  i in range(n):
  if a[i]:
    cnt += 1
    que.append(a[i])

print(cnt)
print(' '.join(map(str, que)))

Fixed submission:
import math

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

for i in range(n-1):
  ptr = n - 1 - i
  if a[ptr] % 2 == 1:
    a[0] += 1
    for j in range(2, int(math.sqrt(ptr+1))+1):
      if (ptr + 1) % j == 0:
        a[j-1] += 1
        if (ptr + 1) // j != j:
          a[(ptr + 1) // j - 1] += 1
      
cnt = 0
que = []
for  i in range(n):
  if a[i] % 2 == 1:
    cnt += 1
    que.append(i+1)

print(cnt)
if cnt > 0:
  print(' '.join(map(str, que)))
Buggy python submission (verdict: Runtime Error):
tmp = list(map(int, input().split()))
n = tmp[0]
d = tmp[1]

x = [[0] * d for i in range(n)]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(d):
    x[i][j] = tmp[j]

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    len = 0
    for k in range(d):
      len += (x[i][k] - x[j][k]) ** 2
    len = math.sqrt(len)
#    print('I=' + str(i) + ' J=' + str(j) + ' LEN=' + str(len))
    if len.is_integer():
      cnt += 1

print (cnt)

Fixed submission:
import math

tmp = list(map(int, input().split()))
n = tmp[0]
d = tmp[1]

x = [[0] * d for i in range(n)]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(d):
    x[i][j] = tmp[j]

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    len = 0
    for k in range(d):
      len += (x[i][k] - x[j][k]) ** 2
    len = math.sqrt(len)
#    print('I=' + str(i) + ' J=' + str(j) + ' LEN=' + str(len))
    if len.is_integer():
      cnt += 1

print (cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

minv = 0
maxv = 1000000000

nxt = [0] * (n + 1)
while minv != maxv:
  nxt[0] = (minv + maxv) // 2
  for i in range(n):
    nxt[i+1] = a[i] * 2 - nxt[i]
#  print(nxt)
  if nxt[0] == nxt[n]:
    break
  elif nxt[0] > nxt[n]:
    maxv = nxt[0]
  else:
    minv = nxt[0]
    
for i in range(n):
  print(nxt[i], end=' ')

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

minv = 0
maxv = 1000000000

nxt = [0] * (n + 1)
for i in range(n):
  nxt[i+1] = a[i] * 2 - nxt[i]

ans = [0] * (n + 1)
ans[0] = nxt[n] // 2

for i in range(n):
  ans[i+1] = a[i] * 2 - ans[i]
    
for i in range(n):
  print(ans[i], end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

for i in range(1, k+1):
  co = 1
  for j in range(i):
    co *= (n-k+1-j)
#    co %= MOD
  for j in range(i):
    co //= (j+1)
#    co %= MOD
  ci = 1
  for j in range(i-1):
    ci *= (k-1-j)
#    ci %= MOD
  for j in range(i-1):
    ci //= (j+1)
#    ci %= MOD
  print (int(co * ci) % MOD)

Fixed submission:
MOD = 1000000007
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

co = 1
ci = 1
for i in range(k):
  co *= (n-k+1-i)
  co //= (i+1)
  if i == 0:
    ci *= 1
  else:
    ci *= (k-i)
    ci //= (i)
#  print (str(ci)+' '+str(co)+' '+str(int(co * ci) % MOD))
  print (int(co * ci) % MOD)

Buggy python submission (verdict: Runtime Error):
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

c = 1
for i in range(1, k+1):
  co = 1
  for j in range(i):
    co *= (n-k+1-j) / (j+1)
  ci = 1
  for j in range(i-1):
    ci *= (k-1-j) / (j+1)

  print (int(co * ci) % (10**9+7))

Fixed submission:
MOD = 1000000007
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

co = 1
ci = 1
for i in range(k):
  co *= (n-k+1-i)
  co //= (i+1)
  if i == 0:
    ci *= 1
  else:
    ci *= (k-i)
    ci //= (i)
#  print (str(ci)+' '+str(co)+' '+str(int(co * ci) % MOD))
  print (int(co * ci) % MOD)
Buggy python submission (verdict: Runtime Error):
s = input()

for i in range(1,len(s)):
  if s[i] == s[i-1]:
    print('Bad')
    sys.exit()

print('Good')

Fixed submission:
import sys

s = input()

for i in range(1,len(s)):
  if s[i] == s[i-1]:
    print('Bad')
    sys.exit()

print('Good')
Buggy python submission (verdict: Runtime Error):
tmp = list(map(int, input().split()))
a = tmp[0]
b = tmp[1]
c = tmp[2]
d = tmp[3]

divc = b // c - (a-1) // c
divd = b // d - (a-1) // d

lcmcd = c * d // math.gcd(c,d)
divcd = b // lcmcd - (a-1) // lcmcd

print(b - a + 1 - divc - divd + divcd)

Fixed submission:
import fractions

tmp = list(map(int, input().split()))
a = tmp[0]
b = tmp[1]
c = tmp[2]
d = tmp[3]

divc = b // c - (a-1) // c
divd = b // d - (a-1) // d

lcmcd = c * d // fractions.gcd(c,d)
divcd = b // lcmcd - (a-1) // lcmcd

print(b - a + 1 - divc - divd + divcd)
Buggy python submission (verdict: Time Limit Exceeded):
tmp = list(map(int, input().split()))
h = tmp[0]
w = tmp[1] 

s = ['None'] * (h + 1)
for i in range(h):
  s[i] = input()
  s[i] = s[i] + '#'
s[h] = '#' * w

ans = 0

sta = -1
cnt = 0
pt = [[0] * w for i in range(h)]
for i in range(h):
  for j in range(w+1):
    if s[i][j] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[i][k] = cnt
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

for i in range(w):
  for j in range(h+1):
    if s[j][i] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[k][i] += cnt - 1
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

ans = 0
for i in range(h):
  for j in range(w):
    if ans < pt[i][j]:
      ans = pt[i][j]
print(ans)


Fixed submission:
tmp = list(map(int, input().split()))
h = tmp[0]
w = tmp[1] 

s = ['None'] * (h + 1)
for i in range(h):
  s[i] = input()
  s[i] = s[i] + '#'
s[h] = '#' * w

ans = 0

sta = -1
cnt = 0
pt = [[0] * w for i in range(h)]
for i in range(h):
  for j in range(w+1):
    if s[i][j] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[i][k] = cnt
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

for i in range(w):
  for j in range(h+1):
    if s[j][i] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[k][i] += cnt - 1
          if pt[k][i] > ans:
            ans = pt[k][i]
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
import heapq

tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]
v = list(map(int, input().split()))

a = [[0] * (k+1) for i in range(n+1)]
b = [[0] * (k+1) for i in range(n+1)]
ha = []
hb = []
for i in range(1, n+1):
  a[i][0] = a[i-1][0] + v[i-1]
  b[i][0] = b[i-1][0] + v[n-i]
  if v[i-1] < 0:
    heapq.heappush(ha, v[i-1])
  if v[n-i] < 0:
    heapq.heappush(hb, v[n-i])
  cha = copy.deepcopy(ha)
  chb = copy.deepcopy(hb)
  for j in range(1, k+1):
    if len(cha) != 0:
      a[i][j] = a[i][j-1] - heapq.heappop(cha)
    else:
      a[i][j] = a[i][j-1]
  for j in range(1, k+1):
    if len(chb) != 0:
      b[i][j] = b[i][j-1] - heapq.heappop(chb)
    else:
      b[i][j] = b[i][j-1]

maxv = 0
for i in range(0, k+1):
  maxa = 0
  maxb = 0
  for j in range(0,i+1):
    if a[j][i-j] > maxa:
      maxa = a[j][i-j]
  for j in range(0,k-i+1):
    if b[j][k-i-j] > maxb:
      maxb = b[j][k-i-j]
#  print('MAXA=' + str(maxa) + ' MAXB=' + str(maxb))    
  if (maxa + maxb) > maxv:
    maxv = maxa + maxb
print (maxv)

Fixed submission:
import copy
import heapq

tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]
v = list(map(int, input().split()))

a = [[0] * (k+1) for i in range(n+1)]
b = [[0] * (k+1) for i in range(n+1)]
ha = []
hb = []
for i in range(1, n+1):
  a[i][0] = a[i-1][0] + v[i-1]
  b[i][0] = b[i-1][0] + v[n-i]
  if v[i-1] < 0:
    heapq.heappush(ha, v[i-1])
  if v[n-i] < 0:
    heapq.heappush(hb, v[n-i])
  cha = copy.deepcopy(ha)
  chb = copy.deepcopy(hb)
  for j in range(1, k+1):
    if len(cha) != 0:
      a[i][j] = a[i][j-1] - heapq.heappop(cha)
    else:
      a[i][j] = a[i][j-1]
  for j in range(1, k+1):
    if len(chb) != 0:
      b[i][j] = b[i][j-1] - heapq.heappop(chb)
    else:
      b[i][j] = b[i][j-1]

maxv = 0
for i in range(0, k+1):
  for j in range(0,min(n+1, i+1)):
    for l in range(0,min(n+1, k-i+1)):
      tmp = a[j][i-j] + b[l][k-i-l]
      if (j+l) <= n and tmp > maxv:
        maxv = tmp
print (maxv)