Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

def gcd(m,n):
    temp=0
    while m%n!=0:
        temp=n
        n=m%n
        m=temp
    return n
def lcm(m,n):
    return m*n/gcd(m,n)


temp=[]
for j in range(L,min([L+2*2019+1,R])):
    temp.append([(j*i)%2019 for i in range(j+1,min([j+2*2019+1,R+1]))])

#print(temp)
print(min([min(e) for e in temp]))






### FIXED CODE ###

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

def gcd(m,n):
    temp=0
    while m%n!=0:
        temp=n
        n=m%n
        m=temp
    return n
def lcm(m,n):
    return m*n/gcd(m,n)


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

#print(temp)
print(min([min(e) for e in temp]))
### BUGGY CODE ###

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n, q = map(int, input().split())
c = list(map(int, input().split()))

rli = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l, r
    rli.append((r, l, i))
rli.sort()

last = [-1] * (n + 1)

bit = Bit(n)
ans = [0] * q
cur = 1
for r, l, i in rli:
    for j in range(cur, r + 1):
        if last[c[j - 1]] != -1:
            bit.add(last[c[j - 1]], -1)
        last[c[j - 1]] = j
        bit.add(j, 1)
    cur = r + 1
    ans[i] = str(bit.sum(r) - bit.sum(l - 1))
print(' '.join(ans))


### FIXED CODE ###

import sys
input = sys.stdin.readline


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0 for _ in range(n + 2)]
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n, q = map(int, input().split())
c = list(map(int, input().split()))

rli = []
for i in range(q):
    l, r = map(int, input().split())
    rli.append((r, l, i))
rli.sort(key=lambda x: x[0])

last = [-1 for _ in range(n + 1)]

bit = Bit(n)
ans = [-1 for _ in range(q)]
cur = 1
for r, l, i in rli:
    for j in range(cur, r + 1):
        if last[c[j - 1]] != -1:
            bit.add(last[c[j - 1]], -1)
        last[c[j - 1]] = j
        bit.add(j, 1)
    cur = r + 1
    ans[i] = bit.sum(r) - bit.sum(l - 1)
print(*ans, sep="\n")
### BUGGY CODE ###

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
P = set(A)
cnt = Counter(A)

def divisors(n):
    divisors = []
    R = int(n**(0.5)) + 1
    for i in range(1, R):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    # divisors.sort(reverse=True)  # ソート
    return divisors

ans = 0
for a in A:
    if cnt[a] > 1:
        continue
    for d in divisors(a):
        if d != a and d in P:
            break
    else:
        ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)

A.sort()
V = set()

ans = 0
mx = max(A)
for a in A:
    if a in V:
        continue
    if cntA[a] == 1:
        ans += 1

    p = a
    while p <= mx:
        V.add(p)
        p += a

print(ans)
### BUGGY CODE ###

import bisect
a,b,c,k = map(int,input().split())

aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = list(map(int,input().split()))
aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
al = []

for i in range(a):
    for j in range(b):
        for l in range(c):
            kk = aa[i]+bb[j]+cc[l]
            bisect.insort_left(al,kk)
al.reverse()
for i in range(k):
    print(al[i])

### FIXED CODE ###

a,b,c,k = map(int,input().split())

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)
### BUGGY CODE ###

import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
sum = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
for i in range(K,tmp,1):
    sum += li.most_common()[i][1]
print(sum)

### FIXED CODE ###

import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
value,counts = zip(*li.most_common())
for i in range(K,tmp,1):
    ans += counts[i]
print(ans)
### BUGGY CODE ###

import sys
import copy
sys.setrecursionlimit(10**7)
n,m,k=map(int,input().split())
friend=[[]for i in range(n)]
block=[[]for i in range(n)]
G=[[]for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for i in range(k):
    c,d=map(int,input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

def dfs(now):
    global group
    for next in friend[now]:
        if visited[next]==False:
            visited[next]=True
            group.append(next)
            dfs(next)
            
    return group
group=[]
visited=[False]*n
for i in range(n):
    if visited[i]==False:
        visited[i]=True
        g=set(dfs(i))|{i}
        

        for x in g:
            G[x]=list(g-{x})
        group=[]
for i in range(n):
    ans=set(G[i])-set(friend[i])-set(block[i])
    print(len(ans))



### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ
 
    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]
 
    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
 
    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)
 
    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]
 

n,m,k=map(int,input().split())
friend=[[]for i in range(n)]
block=[[]for i in range(n)]
group=[[]for i in range(n)]
uf=UnionFind(n)

for i in range(m):
    a,b=map(int,input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
    uf.unite(a-1,b-1)

for i in range(k):
    c,d=map(int,input().split())
    if uf.is_same(c-1,d-1):
        block[c-1].append(d-1)
        block[d-1].append(c-1)

for i in range(n):
    ans=uf.group_size(i)-1-len(friend[i])-len(block[i])
    print(ans)
### BUGGY CODE ###

class DoublyLinkedList:
    def __init__(self):
        self.nil = self.make_node(None)
        self.nil['next'] = self.nil
        self.nil['prev'] = self.nil

    def make_node(self,v):
        return {'key':v, 'next':None, 'prev':None}

    def dump(self):
        n = self.nil['next']
        while True:
            if n['key'] == None:
                break
            else:
                print str(n['key']),
                n = n['next']
        print


    def insert(self,v):
        n = self.make_node(v)
        n['next'] = self.nil['next']
        self.nil['next']['prev'] = n
        n['prev'] = self.nil
        self.nil['next'] = n

    def delete(self,v):
        self.delete_node(self.list_search(v))

    def delete_node(self,n):
        if n['key'] == None: return
        n['next']['prev'] = n['prev']
        n['prev']['next'] = n['next']

    def list_search(self,v):
        cur = self.nil['next']
        while (cur['key'] != None) and (cur['key'] != v):
            cur = cur['next']
        return cur

    def deleteFirst(self):
        self.delete_node(self.nil['next'])

    def deleteLast(self):
        self.delete_node(self.nil['prev'])

n = int(raw_input())
commands = []
for i in range(n):
    commands.append(raw_input())

l = DoublyLinkedList()
for c in commands:
    a = c[6]
    if a == "F":
        l.deleteFirst()
    elif a == "L":
        l.deleteLast()
    else:
        val = int(c[7:])
        op = c[0]
        if op == "i":
            l.insert(val)
        else:
            l.delete(val)

l.dump()

### FIXED CODE ###

class DoublyLinkedList:
    def __init__(self):
        self.nil = self.make_node(None)
        self.nil['next'] = self.nil
        self.nil['prev'] = self.nil

    def make_node(self,v):
        return {'key':v, 'next':None, 'prev':None}

    def dump(self):
        n = self.nil['next']
        while True:
            if n['key'] == None:
                break
            else:
                print str(n['key']),
                n = n['next']
        print


    def insert(self,v):
        n = self.make_node(v)
        n['next'] = self.nil['next']
        self.nil['next']['prev'] = n
        n['prev'] = self.nil
        self.nil['next'] = n

    def delete(self,v):
        self.delete_node(self.list_search(v))

    def delete_node(self,n):
        if n['key'] == None: return
        n['next']['prev'] = n['prev']
        n['prev']['next'] = n['next']

    def list_search(self,v):
        cur = self.nil['next']
        while (cur['key'] != None) and (cur['key'] != v):
            cur = cur['next']
        return cur

    def deleteFirst(self):
        self.delete_node(self.nil['next'])

    def deleteLast(self):
        self.delete_node(self.nil['prev'])

n = int(raw_input())
commands = []
for i in range(n):
    commands.append(raw_input())

l = DoublyLinkedList()
for c in commands:
    a = c[6]
    if a == "F":
        l.deleteFirst()
    elif a == "L":
        l.deleteLast()
    else:
        val = int(c[7:])
        op = c[0]
        if op == "i":
            l.insert(val)
        else:
            l.delete(val)

l.dump()
### BUGGY CODE ###

N,M = map(int, input().split())
H = list(map(int, input().split()))
michi = [[False] * N for i in range(N)]

for _ in range(M):
	a,b = map(int, input().split())
	michi[a-1][b-1] = True
	michi[b-1][a-1] = True

count = 0
for n in range(N):
	goodFlag = True
	for i in range(N):
		if michi[n][i]:
			if H[n] <= H[i]:
				goodFlag = False
				break
	if goodFlag: count += 1

print(count)

### FIXED CODE ###

N,M = map(int, input().split())
H = list(map(int, input().split()))
goodTowerFlag = [True] * N

for _ in range(M):
	a,b = map(int, input().split())
	if H[a-1] <= H[b-1]:
		goodTowerFlag[a-1] = False
	if H[b-1] <= H[a-1]:
		goodTowerFlag[b-1] = False

print(goodTowerFlag.count(True))
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class SparseTable:
    def __init__(self, aa):
        w = len(aa)
        h = w.bit_length()
        table = [aa] + [[-1] * w for _ in range(h - 1)]
        tablei1 = table[0]
        for i in range(1, h):
            tablei = table[i]
            for j in range(w-(1<<i)+1):
                rj = j + (1 << (i - 1))
                tablei[j] = tablei1[j]|tablei1[rj]
            tablei1 = tablei
        self.table = table

    def val(self, l, r):
        i = (r - l).bit_length() - 1
        tablei = self.table[i]
        L = tablei[l]
        R = tablei[r - (1 << i)]
        return L|R

n,q=MI()
cc=MI()
aa=[1<<c for c in cc]
sp=SparseTable(aa)
for _ in range(q):
    l,r=MI()
    print(bin(sp.val(l-1,r)).count("1"))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

n,q=MI()
cc=LI()
lri=[]
mx=500005
#mx=10
for i in range(q):
    l,r=MI()
    l-=1
    lri.append((l,r-1,i))

lri.sort(key=lambda x:x[1])

#print(lri)
last=[-1]*mx
st=BitSum(mx)
ans=[0]*q
now=0
for l,r,i in lri:
    for j in range(now,r+1):
        c=cc[j]
        pre=last[c]
        if pre!=-1:st.add(pre,-1)
        last[c]=j
        st.add(j,1)
    #print(l,r,st.tree,last)
    now=r+1
    ans[i]=st.sum(r)-st.sum(l-1)
print(*ans,sep="\n")
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0] * (n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def get(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s


    N,Q = map(int,input().split())
    C = list(map(int,input().split()))
    LR = [list(map(int,input().split()))+[i] for i in range(Q)]
    LR.sort(key=lambda x: x[1])
    bit = BIT(N)
    stone = [0]*(N+1)
    cur = 1
    ans = []
    for l,r,i in LR:
        while cur <= r:
            c = C[cur-1]
            if stone[c]:
                bit.add(stone[c],-1)
            stone[c] = cur
            bit.add(stone[c],1)
            cur += 1
        ans.append([bit.get(r)-bit.get(l-1),i])
    ans.sort(key=lambda x: x[1])
    for a,i in ans:
        print(a)
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    ans = [0]*Q
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    cur = 1
    for q in query:
        l,r,j = q
        #良い玉の情報を更新する
        for i in range(cur,r+1):
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
        cur = r + 1
        ans[j]=bit.sum(r)-bit.sum(l-1)

    print(*ans, sep="\n")
main()
### BUGGY CODE ###

from collections import defaultdict as dd
from itertools import izip


def sol(n, w, wis, vis):
    rv = 0
    best = dd(int)
    for i, (wi, vi) in enumerate(izip(wis, vis)):
        if wi < w:
            best[(wi, i)] = max(best[(wi, i)], vi)
            rv = max(vi, rv)

    frontline = [(i, wis[i], vis[i]) for i in xrange(n - 1, -1, -1)]
    while frontline:
        last, cw, cv = frontline.pop()
        for i in xrange(last + 1, n):
            nw, nv = cw + wis[i], cv + vis[i]
            if nw <= w and best[(nw, i)] < nv:
                best[(nw, i)] = nv
                frontline.append((i, nw, nv))
                rv = max(rv, nv)

    return rv


if __name__ == "__main__":
    n, w = map(int, raw_input().strip().split())
    wis, vis = [], []
    for _ in xrange(n):
        wi, vi = map(int, raw_input().strip().split())
        wis.append(wi)
        vis.append(vi)
    print sol(n, w, wis, vis)



### FIXED CODE ###

from itertools import izip


def sol(n, w, wis, vis):
    rv = 0
    w1 = wis[0]
    coll = [[] for _ in xrange(n)]
    for wi, vi in izip(wis, vis):
        coll[wi - w1].append(vi)
    coll = map(lambda x: sorted(x, reverse=True), coll)
    lis = map(len, coll)
    for k1 in xrange(min(lis[0] + 1, n + 1)):
        for k2 in xrange(min(lis[1] + 1, n + 1 - k1)):
            for k3 in xrange(min(lis[2] + 1, n + 1 - k1 - k2)):
                for k4 in xrange(min(lis[3] + 1, n + 1 - k1 - k2 - k3)):
                    kis = [k1, k2, k3, k4]
                    if sum([(w1 + i) * kis[i] for i in xrange(4)]) > w:
                        continue
                    rv = max(rv, sum([sum(coll[i][:kis[i]]) for i in xrange(4)]))

    return rv


if __name__ == "__main__":
    n, w = map(int, raw_input().strip().split())
    wis, vis = [], []
    for _ in xrange(n):
        wi, vi = map(int, raw_input().strip().split())
        wis.append(wi)
        vis.append(vi)
    print(sol(n, w, wis, vis))
### BUGGY CODE ###

n,q=map(int,input().split())
S=input()
l=[]
r=[]
for i in range(q):
  li,ri=map(int,input().split())
  l.append(li)
  r.append(ri)
ans=[]
for i in range(q):
  s=S[l[i]-1:r[i]]
  cnt=s.count('AC')
  ans.append(cnt)
for i in range(q):
  print(ans[i])

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]*(n)
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    a[i+1]=a[i]+1
  else:
    a[i+1]=a[i]
for i in range(q):
  l,r=map(int,input().split())
  ans=a[r-1]-a[l-1]
  print(ans)
### BUGGY CODE ###

def test():
    n,q = map(int,input().split())
    s = input()
    l = []
    for i in range(q):
        l.append(list(map(int,input().split())))
    for i in range(q):
        print(s[l[i][0]-1:l[i][1]].count("AC"))


if __name__ == "__main__":
    test()


### FIXED CODE ###

def test():
    n,q = map(int,input().split())
    s = input()
    t = [0] * (n+1)
    for i in range(n):
        t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
    for i in range(q):
        l,r = map(int,input().split())
        print(t[r-1]-t[l-1])


if __name__ == "__main__":
    test()
### BUGGY CODE ###

import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M >= p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if not [cand_h[i], cand_w[j]] in object:
            ans = h_max + w_max            
else:
   ans += 1
print(ans) 

### FIXED CODE ###

import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max
c = 0
p = len(cand_h)*len(cand_w)
cand_h = set(cand_h)
cand_w = set(cand_w)
if M >= p:
   for i in range(len(object)):
      if object[i][0] in cand_h and object[i][1] in cand_w:
         c += 1
print(ans - (c == p))
### BUGGY CODE ###

n = int(input())
ls = list(map(int,input().split()))
p = 0
for i in list(set(ls)):
    a = ls.count(i)
    if a > i:
        p += a-i
    elif a < i:
        p += a
print(p)

### FIXED CODE ###

from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
c = Counter(ls)
p = 0
for s,t in c.items():
    if s > t:
        p += t
    elif s < t:
        p += t - s
print(p)
### BUGGY CODE ###

N,K = map(int,input().split())
FA = list(map(int,input().split()))
A = [0]*N
ANS = [N]*N
for i in range(N):
    mi = max(0,i-FA[i])
    ma = min(N-1,i+FA[i])
    for i in range(mi,ma+1):
        A[i] +=1

for i in range(N):
    mi = i-A[i]-K+1
    ma = i+A[i]+K-1
    if mi>=0:
        for j in range(0,mi+1):
            ANS[j] -=1
    if ma<=N-1:
        for j in range(ma,N):
            ANS[j] -=1

if K == 1:
    print(*A)
else:
    print(*ANS)


### FIXED CODE ###

import itertools

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

for i in range(K):
    TEMP = [0]*(N+1)
    for j in range(N):
        TEMP[max(0,j-A[j])] +=1
        TEMP[min(N,j+A[j]+1)] -=1
    A = list(itertools.accumulate(TEMP))
    if A[0] == N and A[N-1] == N:
        break

A.pop()
print(*A)
### BUGGY CODE ###

def main():
    N = int(input())
    P = list(map(int,input().split()))

    count = 0
    flag = True

    for i in range(N):
        Pj = P[0:i+1]
        min_P = min(Pj)
        if(P[i] <= min_P):
            count+=1

    print(count)
'''
    for i in range(N):
        for j in range(i):
            if(P[i] > P[j]):
                flag = False
                break
        if(flag):
            count += 1
        flag = True
    print(count)
    '''

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline

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

    #result = list()

    minimum = P[0]
    count = 1
    for i in range(N):
        if(minimum > P[i]):
            minimum = P[i]
            count += 1
    print(count)
#        Pj = list(P[j] for j in range(i+1))
        #print(Pj)
        #Pj = P[0:i+1]
#        min_P = min(Pj)
#        result.append(min_P)
#        print(min_P)
#        if(P[i] == min_P):
#            count += 1

    '''
    count = 0
    flag = True

    for i in range(N):
        for j in range(i):
            if(P[i] > P[j]):
                flag = False
                break
        if(flag):
            count += 1
        flag = True
    print(count)
    '''

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import Counter
def is_anagram(s1,s2):
    if Counter(s1)==Counter(s2):
        return True
    else:
        return False

n=int(input())
s=[]
ans=0
for _ in range(n):
    s.append(input())
for i in range(n):
    for j in range(i):
        if is_anagram(s[i],s[j]):
            ans+=1
print(ans)

### FIXED CODE ###

from collections import defaultdict
n=int(input())
d=defaultdict(int)
ans=0
for _ in range(n):
    d["".join(sorted(input()))]+=1
# print(d)
for key,i in d.items():
    ans+=i*(i-1)//2
print(ans)
### BUGGY CODE ###

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

cnt = 0
for i in range(A, B + 1):
    #print(i)
    if i % C != 0 and i % D != 0:
        #print("CONT!")
        cnt = cnt + 1

print(cnt)


### FIXED CODE ###

""" import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


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

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_d))
 """

a, b, c, d = map(int, input().split())

total = b - a + 1


def lem(A, B):
	AB = A * B
	while B != 0:
		A, B = B, A % B
	return AB // A


bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = total - bsep + asep
print(ans)