Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
mod = 10 ** 9 + 7

if (x + y) % 3 != 0:
    print(0)
else:
    time = (x + y) // 3
    if time > x or time > y:
        print(0)
    else:
        move_time = sorted([x - time, y - time])
        
        ans = 1
        for i in range(2, time+1):
            ans *= i
            ans %= mod
        
        const = 1
        for i in range(1, move_time[1]+1):
            const *= i
            const %= mod
            
            if i == move_time[0]:
                inv0 = pow(const, mod-2, mod)
            
        inv1 = pow(const, mod-2, mod)
    
        print((ans * inv0 * inv1) % mod)

Fixed submission:
x, y = map(int, input().split())
mod = 10 ** 9 + 7

if (x + y) % 3 != 0:
    print(0)
else:
    time = (x + y) // 3
    if time > x or time > y:
        print(0)
    else:
        move_time = sorted([x - time, y - time])
        
        if move_time[0] == 0:
            print(1)
        else:
            ans = 1
            for i in range(2, time+1):
                ans *= i
                ans %= mod
            
            const = 1
            for i in range(1, move_time[1]+1):
                const *= i
                const %= mod
                
                if i == move_time[0]:
                    inv0 = pow(const, mod-2, mod)
                
            inv1 = pow(const, mod-2, mod)
        
            print((ans * inv0 * inv1) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n+1):
    if i != n:
        print(a.index(i)+1, end=" ")
    else:
        print(a.index(i)+1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i, j in enumerate(a):
    b[j-1] = i+1

print(*b)
Buggy python submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
points = [k-q]*n

for i in range(q):
    points[int(input())-1] += 1

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

Fixed submission:
n, k, q = map(int, input().split())
points = [k-q]*n

for i in range(q):
    points[int(input())-1] += 1

for i in range(n):
    if points[i] > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
l = list(s)
#n = len(l)
i = 0
j = n-1
cnt = 0
while(i < j):
    if l[i] == "W" and l[j] == "R":
        l[j] = 'W'
        l[i] = 'R'
        i = i+1
        j = j-1
        cnt = cnt+1
        continue

    if l[i] == "R":
        i = i+1

    if l[j] == "W":
        j = j-1

f = 0
while(len(l) > 0):
    if l[-1] == "W":
        l.pop()

    if l[-1] == "R":
        break

k = "".join(l)
print(k.count("W")+cnt)

Fixed submission:
n = int(input())
s = input()
l = list(s)
#n = len(l)
i = 0
j = n-1
cnt = 0
while(i < j):
    if l[i] == "W" and l[j] == "R":
        l[j] = 'W'
        l[i] = 'R'
        i = i+1
        j = j-1
        cnt = cnt+1
        continue

    if l[i] == "R":
        i = i+1

    if l[j] == "W":
        j = j-1


while(len(l) > 0):
    if l[-1] == "W":
        l.pop()
        continue

    if l[-1] == "R":
        break

k = "".join(l)
print(k.count("W")+cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input()):
if n <= 599:
    print(8)
    exit()

if n <= 799:
    print(7)
    exit()

if n <= 999:
    print(6)
    exit()

if n <= 1199:
    print(5)
    exit()

if n <= 1399:
    print(4)
    exit()

if n <= 1599:
    print(3)
    exit()

if n <= 1799:
    print(2)
    exit()

if n <= 1999:
    print(1)
    exit()


Fixed submission:
n = int(input())
if n <= 599:
    print(8)
    exit()

if n <= 799:
    print(7)
    exit()

if n <= 999:
    print(6)
    exit()

if n <= 1199:
    print(5)
    exit()

if n <= 1399:
    print(4)
    exit()

if n <= 1599:
    print(3)
    exit()

if n <= 1799:
    print(2)
    exit()

if n <= 1999:
    print(1)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = k-1
i = 0
while(i < k-1):
    cnt = cnt*l[g-1]
    g = g-1
    i = i+1

g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")
    g = g+1
    pr = l[g-1]
    k = k+1


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

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = 0
g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")

    g = g+1
    pr = l[g-1]
    k = k+1

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
l = list(map(int,input().split()))
cnt = l[k-1]
p = 1
g = k-1
i = 0
while(i < k-1):
    cnt = cnt*l[g-1]
    g = g-1
    i = i+1

g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        print("Yes")

    else:
        print("No")
    g = g+1
    pr = l[g-1]
    k = k+1


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

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = 0
g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")

    g = g+1
    pr = l[g-1]
    k = k+1

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
l = list(map(int,input().split()))
cnt = l[k-1]
p = 1
g = k-1
i = 0
while(i < k-1):
    cnt = cnt*l[g-1]
    g = g-1
    i = i+1

g = g+1
pr = l[g-1]
while(k < n):
    cur = cnt*l[k]
    cur = cur//pr
    g = g+1
    pr = l[g-1]
    if cur > cnt:
        print("Yes")

    else:
        print("No")

    cnt = cur
    k = k+1


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

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = 0
g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")

    g = g+1
    pr = l[g-1]
    k = k+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()))
a.sort(reverse = True)
b.sort(reverse = True)
cnt = 0
while(min(a[-1],b[-1]) <= k):
    if a[-1] == min(a[-1],b[-1]):
        k = k-min(a[-1],b[-1])
        a.pop()

    else:
        k = k-min(a[-1],b[-1])
        b.pop()

    cnt = cnt+1

print(cnt)

Fixed submission:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])

i = 0
ans = 0
j = m
while(i < len(a)):
    if a[i] > k:
        break

    else:
        while(b[j] > k-a[i]):
            j = j-1

        ans = max(ans,i+j)

    i = i+1

print(ans)
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(1,101):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])

Fixed submission:
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(-1000,1000):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])
Buggy python submission (verdict: Runtime Error):
a,b = map(input().split())
a = int(a)
b = int(b*100)
print((a*b)//100)

Fixed submission:
a,b = map(float,input().split())
a = int(a)
b = round(float(b)*100)
print((a*b)//100)

Buggy python submission (verdict: Runtime Error):
a,b = map(input().split())
a = int(a)
b = float(b)
b = b*100
s = (a*b)//100
print(int(s))

Fixed submission:
a,b = map(float,input().split())
a = int(a)
b = round(float(b)*100)
print((a*b)//100)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
l = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(l[1]-l[0])+dp[0]
for i in range(2,n):
    r = i-k
    if r < 0:
        r = 0

    mi = 9999999999
    for j in range(r,i):
        t = dp[j]+abs(l[j]-l[i])
        if t < mi:
            mi = t

    dp[i] = mi

print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
l = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(l[1]-l[0])+dp[0]
for i in range(2,n):
    r = i-k
    if r < 0:
        r = 0

    mi = 9999999999
    for j in range(r,i):
        t = dp[j]+abs(l[j]-l[i])
        if t < mi:
            mi = t

    dp[i] = mi

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
d = {}
p = []
for i in range(n):
    k,v = map(int,input().split())
    d[k] = v
    p.append(k)

dp = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    dp.append(o)


for i in range(n):
    for j in range(w+1):
        if p[i] > j:
            dp[i+1][j] = dp[i][j]

        else:
            dp[i+1][j] = max(d[p[i]] + dp[i][j - p[i]], dp[i][j])

print(dp[n][w])n,w = map(int,input().split())
d = {}
p = []
for i in range(n):
    k,v = map(int,input().split())
    d[k] = v
    p.append(k)

dp = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    dp.append(o)


for i in range(n):
    for j in range(w+1):
        if p[i] > j:
            dp[i+1][j] = dp[i][j]

        else:
            dp[i+1][j] = max(d[p[i]] + dp[i][j - p[i]], dp[i][j])

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    w_, v_ = wv[i]
    for j in range(w+1):
        if j < w_:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w_]+v_, dp[i][j])
print(dp[n][w])

Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
d = {}
p = [0]
for i in range(n):
    k,v = map(int,input().split())
    d[k] = v
    p.append(k)

l = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    l.append(o)

# MAIN DP MATRIX OPERATION
for i in range(1,n+1):
    for j in range(0,w+1):
        if p[i] > j:
            l[i][j] = l[i-1][j]

        else:
            l[i][j] = max(d[p[i]] + l[i-1][j-p[i]],l[i-1][j])
            #l[i][j] = max(d[p[i]] + l[i - 1][j - p[i]], l[i - 1][j])

#print(l)
print(l[n][w])







Fixed submission:
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    w_, v_ = wv[i]
    for j in range(w+1):
        if j < w_:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w_]+v_, dp[i][j])
print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))


H,W,M=map(int, input().split())
#P = [list(map(int,input().split())) for i in range(M)]
Hlist=[0] * M
Wlist=[0] * M
P = []
for i in range(M):
    Hlist[i],Wlist[i]=map(int, input().split())
    P.append([Hlist[i],Wlist[i]])


HC = Counter(Hlist)
HD = HC.most_common()
WC = Counter(Wlist)
WD = WC.most_common()

Hmax = HD[0][1]
Wmax = WD[0][1]
ans = Hmax + Wmax


for i in range(len(HD)):
    if HD[i][1] != Hmax:
        break
    for j in range(len(WD)):
        if WD[j][1] != Wmax:
            break
        tmp = [HD[i][0],WD[j][0]]
        if (tmp in P) == False:
            print(ans)
            sys.exit()
        

print(ans-1)


Fixed submission:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))


H,W,M=map(int, input().split())
#P = [list(map(int,input().split())) for i in range(M)]
Hlist=[0] * M
Wlist=[0] * M
P = []
for i in range(M):
    Hlist[i],Wlist[i]=map(int, input().split())
    P.append([Hlist[i],Wlist[i]])

Pset = set(map(tuple, P))

HC = Counter(Hlist)
HD = HC.most_common()
WC = Counter(Wlist)
WD = WC.most_common()

Hmax = HD[0][1]
Wmax = WD[0][1]
ans = Hmax + Wmax

# print(P)
# print(Pset)
# print("H----")
# print(Hlist)
# print(HC)
# print(HD)
# print("Hmax=",Hmax)
# print("W----")
# print(Wlist)
# print(WC)
# print(WD)
# print("Wmax=",Wmax)

# print(ans)


for i in range(len(HD)):
    if HD[i][1] != Hmax:
        break
    for j in range(len(WD)):
        if WD[j][1] != Wmax:
            break
        tmp = tuple([HD[i][0],WD[j][0]])
        if (tmp in Pset) == False:
            print(ans)
            sys.exit()
        
print(ans-1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

N,K = map(int, input().split())

## Logic

print(min(N%K,abs(K-N%K))


Fixed submission:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

N,K = map(int, input().split())

## Logic

print(min(N%K,abs(K-N%K)))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

N = int(input())
A = list(map(int, input().split()))

## Logic

ans = [0,0,0,0,0,0,0,0]
tmp = 0

for i in range(0,N):
    if A[i]//400 >= 8:
        tmp += 1
    else:
        ans[A[i]//400] = 1

print(max(1,sum(ans)),min(8,sum(ans)+tmp))



Fixed submission:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

K,N=map(int, input().split())
A = list(map(int, input().split()))

## Logic

A.append(A[0]+K)

tmp = 0
for i in range(0,N):
    tmp = max(tmp,A[i+1]-A[i])
print(K-tmp)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N=int(input())
P = list(map(int, input().split()))

count = 1

for i in range(N):
    for j in range(i):
        if P[j] < P[i]:
            break
        if j == i-1:
            count += 1

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N=int(input())
P = list(map(int, input().split()))

count = 1
min = P[0]

for i in range(1,N):
    if min > P[i]:
        count+=1
        min = P[i]

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import copy

N = int(input())
A = [int(input()) for i in range(N)]

Amax = max(A)

for i in range(N):
        if A[i] == Amax:
                TMP = copy.deepcopy(A)
                TMP.pop(i)
                print(max(TMP))
        else:
                print(Amax)
                

Fixed submission:
# -*- coding: utf-8 -*-

import copy

N = int(input())
A = [int(input()) for i in range(N)]

Amax = max(A)
TMP = copy.deepcopy(A)
TMP.remove(Amax)
Amax2 = max(TMP)

for i in range(N):
        if A[i] == Amax:
                print(Amax2)
        else:
                print(Amax)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import copy

N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
        TMP = copy.deepcopy(A)
        TMP.pop(i)
        print(max(TMP))



Fixed submission:
# -*- coding: utf-8 -*-

import copy

N = int(input())
A = [int(input()) for i in range(N)]

Amax = max(A)
TMP = copy.deepcopy(A)
TMP.remove(Amax)
Amax2 = max(TMP)

for i in range(N):
        if A[i] == Amax:
                print(Amax2)
        else:
                print(Amax)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,R+1):
    for j in range(i+1,min(R+1,2*L)):
        ans = min(ans, ((i%2019)*(j%2019)%2019))

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,min(R+1,L+2019)):
    for j in range(i+1,min(R+1,L+2019)):
        ans = min(ans, ((i%2019)*(j%2019)%2019))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans = min(ans, ((i%2019)*(j%2019)%2019))

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,min(R+1,L+2019)):
    for j in range(i+1,min(R+1,L+2019)):
        ans = min(ans, ((i%2019)*(j%2019)%2019))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans = min(ans, (i*j)%2019)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

L,R=map(int, input().split())

ans = 2 * (10**9)

for i in range(L,min(R+1,L+2019)):
    for j in range(i+1,min(R+1,L+2019)):
        ans = min(ans, ((i%2019)*(j%2019)%2019))

print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N,L=map(int, input().split())

ans = 0
for i in range(N):
    ans = ans + L + i

if L > 0:
    ans = ans - L
if (L + N - 1) < 0:
    ans = ans - (L + N - 1)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

S=input()

ans = 'Good'

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3] :
    ans = 'Bad'

print(ans)
Buggy python submission (verdict: Runtime Error):
(L + N - 1)

Fixed submission:
# -*- coding: utf-8 -*-

N,L=map(int, input().split())

ans = 0
for i in range(N):
    ans = ans + L + i

if L > 0:
    ans = ans - L
if (L + N - 1) < 0:
    ans = ans - (L + N - 1)

print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import fractions

A,B,C,D=map(int, input().split())

ans = 0

Cans = fractions.floor(B/C) - fractions.ceil(A/C) + 1
Dans = fractions.floor(B/D) - fractions.ceil(A/D) + 1

CD = C * D / fractions.gcd(C,D)
CDans = fractions.floor(B/CD) - fractions.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D

CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

A,B,C,D=map(int, input().split())

ans = 0

Cans = math.floor(B/C) - math.ceil(A/C) + 1
Dans = math.floor(B/D) - math.ceil(A/D) + 1

CD = C * D / math.gcd(C,D)
CDans = math.floor(B/CD) - math.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D

CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

A,B,C,D=map(int, input().split())

ans = 0

Cans = math.floor(B/C) - math.ceil(A/C) + 1
Dans = math.floor(B/D) - math.ceil(A/D) + 1

CD = C * D / math.gcd(C,D)
CDans = math.floor(B/CD) - math.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D

CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

A,B,C,D=map(int, input().split())

ans = 0

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

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D

CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)