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

from itertools import combinations

n, m = map(int, input().split())
arr = []
ans = 0
for i in range(n):
    ##[[x, y, z], ..., [x, y, z]]
    arr.append(list(map(int, input().split())))

cmb = combinations(arr, m)#[[x, y, z],[x, y, z],[x, y, z]]
for xyz in cmb:
    sumXYZ = [0, 0, 0]
    for i in range(m):
        for j in range(3):
            sumXYZ[j] += xyz[i][j]
    ans = max(ans, sum(list(map(abs, sumXYZ))))    

print(ans)

### FIXED CODE ###

from operator import mul
from itertools import product

n, m = map(int, input().split())
arr = []
for i in range(n):
    ##[[x, y, z], ..., [x, y, z]]
    arr.append(list(map(int, input().split())))

ans = 0
for opList in list(product(list((1, -1)), repeat=3)):
    bufArr = []
    for xyz in arr:
        bufArr.append(sum(map(mul, opList, xyz)))
    ans = max(ans, sum(sorted(bufArr, reverse = True)[:m]))

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n, m, q = map(int, input().split())
    d = defaultdict(list)
    for i in range(m):
        l, r = map(int, input().split())
        d[l].append(r)
    for i in range(q):
        l, r = map(int, input().split())
        ans = 0
        for k in [q for q in d.keys() if l <= q <= r]:
            ans += len([q for q in d[k] if q <= r])
        print(ans)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


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

n = int(input())
s = input()
r = 0
g = 0
b = 0
for x in s:
    if x =="R":
        r += 1
    elif x == "G":
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(1, 1+n//2):
    for j in range(1, n-1):
        if j + i*2 <= n:
            if s[j-1] != s[j+i-1] and s[j-1] != s[j+i*2-1] and s[j+i-1] != s[j+i*2-1]:
                ans -= 1
print(ans)


### FIXED CODE ###

n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(1, 1+n//2):
    for j in range(1, n-i*2+1):
        if s[j-1] != s[j+i-1] and s[j-1] != s[j+i*2-1] and s[j+i-1] != s[j+i*2-1]:
                ans -= 1
print(ans)
### BUGGY CODE ###

def multiplyList(myList) : 
      
    # Multiply elements one by one 
    result = 1
    for x in myList: 
         result = result * x
         if result == 0:
             return 0
    return result

n = int(input())
l = list(map(int, input().split()))
res = multiplyList(l)
if(res > 10**18):
    print(-1)
else:
    print(res)


### FIXED CODE ###

def multiplyList(myList) : 
      
    # Multiply elements one by one 
    result = 1
    for x in myList: 
        result = result * x
        if result == 0:
             return 0 
        if result > 10**18:
             return -1
    return result
 
n = int(input())
l = list(map(int, input().split()))
l.sort()
res = multiplyList(l)
print(res)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    B=[0]+A[0:i]+A[i+1:N]+[0]
    print(sum([abs(B[j]-B[j+1]) for j in range(N)]))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A=[0]+A+[0]
cost=sum([abs(A[k]-A[k+1]) for k in range(N+1)])
for i in range(1,N+1):
    if A[i-1]<=A[i]<=A[i+1] or A[i-1]>=A[i]>=A[i+1]:
        print(cost)
    else:
        print(cost-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
### BUGGY CODE ###

def divisors(n: int)->list:
    ans = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans.append(i)
            if i != n // i:
                ans.append(n // i)
    return ans


def preparing_boxes(N: int, A: list)->list:
    B = []
    # C = [0] * N

    for i in range(N, 0, -1):
        # print('=== {} ==='.format(i))
        a = A[i-1]
        if a == 0:
            continue
        B.append(i)
        # C[i-1] = 1

        for div in divisors(i):
            # print(div)
            A[div-1] = 1 - A[div-1]

    # print(''.join(str(i) for i in C))

    return B


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = preparing_boxes(N, A)
    print(len(ans))
    print(' '.join(str(i) for i in ans))


### FIXED CODE ###

def divisors(n: int)->list:
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


def preparing_boxes(N: int, A: list)->list:
    B = []
    # C = [0] * N

    for i in range(N, 0, -1):
        # print('=== {} ==='.format(i))
        a = A[i-1]
        if a == 0:
            continue
        B.append(i)
        # C[i-1] = 1

        for div in divisors(i):
            # print(div)
            A[div-1] = 1 - A[div-1]

    # print(''.join(str(i) for i in C))

    return B


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = preparing_boxes(N, A)
    print(len(ans))
    print(' '.join(str(i) for i in ans))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
A.sort()
c= 0
if N>1:
    if A[0]%A[1] >0:
        count+=1

for k in range(1, len(A)):
    if k<N-1:
        if A[k] == A[k+1]:
            continue
    for j in range(c, k):
        if A[k]%A[j] ==0:
            del A[k]
            A.insert(0, 0)
            c +=1
            break
    else:
        count +=1
        #print(A[k])

    
if N ==1:
    count = 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
A.sort()
c=0
"""
for k in range(len(A)-1):
    if A[k] == A[k+1]:
        del A[k]
        A.insert(0,0)
        c+=1
        if k <len(A)-2:
            if A[k+1] != A[k+2]:
                del A[k+1]
                A.insert(0,0)
                c+=1
        else:
            del A[k+1]
            A.insert(0,0)
            c+=1
del A[:c]
if len(A)>0:
    saidai = A[-1]
else:
    saidai=0
#print(A)
"""
saidai = A[-1]
foo = [0 for k in range(saidai+1)]
for k in range(len(A)):
    if foo[A[k]] == 1:
        continue
    else:
        for j in range(A[k], saidai+1, A[k]):
            foo[j] = 1
        if k < len(A)-1:
            if A[k] == A[k+1]:
                continue
        if 0 < k < len(A):
            if A[k] == A[k-1]:
                continue
        count+=1
print(count)
### BUGGY CODE ###

from collections import deque

def main():
    N = int(input())
    A = [None] + [deque(map(int, input().split())) for i in range(N)]
    
    ans = 0
    finish = False
    base_used = {i for i in range(1, N+1)}
        
    while not finish and base_used:
        finish = True
        ans += 1
        used = set()
        delete_used = set()
        
        for n in base_used:
            if n in delete_used:
                continue
            
            a = A[n][0]
            if not a in used and not n in used and A[a][0] == n:
                for x in [n, a]:
                    used.add(x)
                    A[x].popleft()
    
                    if not A[x]:
                        delete_used.add(x)
                finish = False     
        base_used -= delete_used
        
    if base_used:
        ans = -1
    print(ans)
    
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    
    Id = {}
    
    cur = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            Id[(i,j)] = cur
            cur += 1
            
    G = [[] for i in range(N*(N-1)//2)]
    size = [0] * (N*(N-1)//2)
    
    for i in range(1, N+1):
        for idx, j in enumerate(list(map(int, input().split()))):
            if i < j: k = Id[(i, j)]
            else: k = Id[(j, i)]
            if idx: 
                G[par].append(k)
                size[k] += 1
            par = k
            
    g = [idx for idx, s in enumerate(size) if s == 0]
    
    ans = 0
    while g:
        ans += 1
        n_g = []
        
        for v in g:
            length = len(G[v])
            if not length: continue
            
            size[G[v][0]] -= 1
            if not size[G[v][0]]: n_g.append(G[v][0])
    
            if length == 2:
                size[G[v][1]] -= 1
                if not size[G[v][1]]: n_g.append(G[v][1])
        g = n_g
        
    for s in size:
        if s != 0:
            print(-1)
            sys.exit()
    print(ans)
            
if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = input()
Q = int(input())
N = len(S)

rev = []
for i in range(N):
	rev.append(S[N-i-1])
S_rev = ''.join(rev)

for i in range(Q):
	q = list(map(str, input().split()))
	if q[0] == '1':
		S, S_rev = S_rev, S
	else:
		if q[1] == '1':
			s = [q[2], S]
			s_rev = [S_rev, q[2]]
			S = ''.join(s)
			S_rev = ''.join(s_rev)
		else:
			s = [S, q[2]]
			s_rev = [q[2], S_rev]
			S = ''.join(s)
			S_rev = ''.join(s_rev)

print(S)

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())
N = len(S)

flag = 0
for i in range(Q):
	q = list(map(str, input().split()))
	if q[0] == '1':
		flag = 1 - flag
	else:
		if (q[1] == '1' and flag == 1) or (q[1] == '2' and flag == 0):
			S.append(q[2])
		else:
			S.appendleft(q[2])
if flag == 1:
	S.reverse()
ans = ''.join(S)
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
p_ = {}
for i in set(p):
  p_[i] = sum(range(i+1))/i

ans = 0
for i in range(n-k+1):
  ans = max(ans,sum([p_[j] for j in p[i:i+k]]))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
p_ = [(i+1)/2 for i in p]
d = [0]
for i in p_:
  d.append(d[-1]+i)
ans = 0
for i in range(k,n+1):
  if ans < d[i]-d[i-k]:
    ans = d[i]-d[i-k]
print(ans)
### BUGGY CODE ###

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
q = int(input())
rl = [map(int, input().split()) for _ in range(q)]

li = get_sieve_of_eratosthenes(10**5)
# print(li)
for l, r in rl:
  cnt = 0
  for j in range(l, r + 1):
    if j % 2 == 1 and j in li and (j + 1) // 2 in li:
      cnt += 1
  print(cnt)

### FIXED CODE ###

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
q = int(input())
rl = [map(int, input().split()) for _ in range(q)]

li = get_sieve_of_eratosthenes(10**5+1)
pli = [False] * (10**5+1)

for i in li:
  pli[i] = True

# print(pli)
  
# print(li)
cpli = [0] * (10**5+1)

cnt = 0
for i in range(10**5+1):
  if i % 2 == 1 and pli[i] and pli[(i + 1) // 2]:
    cnt += 1
  cpli[i] = cnt

# print(cpli)
  
for l, r in rl:
  print(cpli[r] - cpli[l-1])
### BUGGY CODE ###

import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a_s = set(a)
s = set()
s1 = set()
same_s = set()
ans = 0
for i in a:
    if i in s1:
        same_s.add(i)
    if i not in s:
        s1.add(i)
        for j in range(i, max(a)+1, i):
            s.add(j)
        ans += 1

print(ans - len(same_s))


### FIXED CODE ###

import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
maxa = max(a)
a_s = set(a)
s = set()
s1 = set()
same_s = set()
ans = 0
for i in a:
    if i in s1:
        same_s.add(i)
    if i not in s:
        s1.add(i)
        for j in range(i, maxa+1, i):
            s.add(j)
        ans += 1

print(ans - len(same_s))
### BUGGY CODE ###

n,a,b = map(int,input().split())
count = 0
for i in range(1,n):
  c = 0
  while True:
    if i == 0:
      break
    else:
      c += i%10
      i//10
  if a <= c <= b:
    count += 1
print(count)

### FIXED CODE ###

n,a,b = map(int,input().split())
count = 0
for i in range(1,n+1):
  c = 0
  d = i
  while i != 0:
    c += i%10  
    i //=10
  if a <= c <= b:
    count += d
print(count)
### BUGGY CODE ###

def main():
  h, w, d = map(int, input().split())
  dic = {}
  for i in range(1, h + 1):
    alst = list(map(int, input().split()))
    for j in range(w):
      dic[alst[j]] = (i, j + 1)
  
  q = int(input())
  for _ in range(q):
    l, r = map(int, input().split())
    ans = 0
    tmpx, tmpy = dic[l]
    while r > l:
      ldx, ldy = dic[l + d]
      ans += abs(tmpx - ldx) + abs(tmpy - ldy)
      l += d
      tmpx, tmpy = ldx, ldy
    print(ans)
  
main()

### FIXED CODE ###

def main():
  h, w, d = map(int, input().split())
  dic = {}
  for i in range(1, h + 1):
    alst = list(map(int, input().split()))
    for j in range(w):
      dic[alst[j]] = (i, j + 1)
  
  acc = []
  for i in range(d):
    lst = [0]
    a = 0
    x, y = dic[(i - 1) % d + 1]
    for j in range((i - 1) % d + 1 + d, h * w + 1, d):
      x2, y2 = dic[j]
      a += abs(x - x2) + abs(y - y2)
      x, y = x2, y2
      lst.append(a)
    acc.append(lst)
  q = int(input())
  ans = 0
  for _ in range(q):
    l, r = map(int, input().split())
    ld = l // d
    rd = r // d
    if l % d == 0:
      ld -= 1
      rd -= 1
    ans = acc[l % d][rd] - acc[l % d][ld]
    print(ans)

  
main()
### BUGGY CODE ###

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

mod = 10**9+7
ans = 0

for k in range(60):
    x, y = 0, 0
    for a in A:
        if a & 1<<k:
            x += 1
    ans += x*(n-x)*pow(2, k, mod)
    ans %= mod
print(ans)

### FIXED CODE ###

def main():
    n = int(input())
    A = list(map(int, input().split()))

    mod = 10**9+7
    ans = 0

    for k in range(60):
        x, y = 0, 0
        for a in A:
            x += 1 & a>>k
        tmp = x*(n-x)%mod
        tmp *= pow(2, k, mod)
        ans += tmp
        ans %= mod
    print(ans)


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

N,K = map(int,input().split())
A = [-1] + [int(i) for i in input().split()]
i = 1
tele = 1
telelist = [1]
while not A[i] in telelist:
    telelist.append(A[i])
    i = A[i]

k = 0
for s in telelist:
    if s == A[i]:
        break
    k += 1
if K<=k:
    print(telelist[K])
else:
    l = len(telelist)-k
    K -= k
    s = K%l
    print(telelist[k+s])

### FIXED CODE ###

N,K = map(int,input().split())
A = [-1] + [int(i) for i in input().split()]
deta = [False for i in range(N+1)]
i = 1
tele = 1
telelist = [1]
while not deta[A[i]]:
    telelist.append(A[i])
    deta[A[i]] = True
    i = A[i]

k = 0
for s in telelist:
    if s == A[i]:
        break
    k += 1
if K<=k:
    print(telelist[K])
else:
    l = len(telelist)-k
    K -= k
    s = K%l
    print(telelist[k+s])
### BUGGY CODE ###

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

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

N, M = map(int, input().split())
S = list(input())
T = list(input())

lcm_num = lcm(N,M)

X = [0 for i in range(lcm_num)]

for i in range(N):
    tmp = i*lcm_num // N + 1
    X[tmp-1] = S[i]

for i in range(M):
    tmp = i*lcm_num // M + 1
    if X[tmp-1] == 0 or X[tmp-1] == T[i]:
        continue
    else:
        print(-1)
        exit()

print(lcm_num)


### FIXED CODE ###

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

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

N, M = map(int, input().split())
S = input()
T = input()

lcm_num = lcm(N,M)
lN = lcm_num // N
lM = lcm_num // M
gcd_num = lN * lM

for i in range(0,lcm_num,gcd_num):
    if S[i//lN] == T[i//lM]:
        continue
    else:
        print(-1)
        exit()

print(lcm_num)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a.append(0)
count = 0
for i in range(n):
    b = a[i]
    del a[i]
    for j in range(n-1):
        count += abs(a[j]-a[j+1])
    print(count + abs(a[0]))
    count = 0
    a.insert(i,b)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.insert(0,0)
b = 0
for i in range(n+1):
    b += abs(a[i]-a[i+1])
for i in range(1,n+1):
    c = b + abs(a[i-1]-a[i+1]) - abs(a[i]-a[i+1])-abs(a[i]-a[i-1])
    print(c)
### BUGGY CODE ###

def main():
    s = input()
    ans = 0
    n = len(s)
    m = 2019
    for i in range(n - 3):
        for j in range(i + 3, n):
            t = int(s[i:j + 1])
            if t % m == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import Counter
    s = input()

    n = 2019
    l = [0]
    t = 1
    for i, x in enumerate(s[::-1]):
        t = t * 10 % n
        y = (l[-1] + int(x) * t) % n
        l.append(y)

    c = Counter(l)
    ans = sum([v * (v - 1) // 2 for v in c.values()])
    print(ans)


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

N = int(input())
H = list(map(int,input().split()))
maxc = 0
for i in range(N):
    count = 0
    for j in range(i,N):
        if j == i:
            continue
        if H[j] <= H[j-1]:
            count += 1
        else:
            break
    maxc = max(maxc,count)
print(maxc)

### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
dp = {N-1:0}
def f(n):
    if n in dp:
        return dp[n]
    if H[n] >= H[n+1]:
        dp[n] = 1+dp[n+1]
        return dp[n]
    else:
        dp[n] = 0
        return 0
maxc = 0
for i in range(N-1,-1,-1):
    maxc = max(maxc, f(i))
print(maxc)
### BUGGY CODE ###

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

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                cnt += 1

print(cnt)

### FIXED CODE ###

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

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - (i + j) <= K:
            cnt += 1 

print(cnt)
### BUGGY CODE ###

def main():
    from itertools import permutations

    n, m, r, *x = map(int, open(0).read().split())
    to = x[:r]

    m = [[0 if i == j else float("Inf") for j in range(n + 1)] for i in range(n + 1)]

    for a, b, c in zip(*[iter(x[r:])] * 3):
        m[a][b] = c
        m[b][a] = c

    def f(d):
        for k in range(1, n + 1):
            for i in range(1, n + 1):
                for j in range(1, n + 1):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d

    ans = float("Inf")
    dis = f(m)
    for p in permutations(to):
        tmp = 0
        nw = p[0]
        for nx in p[1:]:
            tmp += dis[nw][nx]
            nw = nx

        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
read = sys.stdin.read
from itertools import permutations
def main():
    def warshall_floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d
 
    n, m, r = map(int, input().split())
    rs = tuple(map(int, input().split()))
    d = [[10**9] * n for _ in range(n)]
    m = map(int, read().split())
    mmm = zip(m, m, m)
    for s, t, dis in mmm:
        s -= 1
        t -= 1
        d[t][s] = d[s][t] = dis
    for j1 in range(n):
        d[j1][j1] = 0
    res = warshall_floyd(d)
    rsp = tuple(permutations(rs))
    result = float('inf')
    for rspe in rsp:
        res_t = 0
        for i1 in range(r - 1):
            res_t += res[rspe[i1]-1][rspe[i1+1]-1]
        result = min(result, res_t)
    print(result)
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

#D問題
N = int(input())
L = list(map(int,input().split()))
L.sort()
T = []

for i in range(N):
    for j in range(N):
        if j <= i:
            pass
        else:
            for k in range(N):
                if k <= j:
                    pass
                else:
                    I,J,K = L[i],L[j],L[k]
                    if I < J+K and J < I+K and K < I+J:
                        if [I,J,K] not in T:
                            T.append([I,J,K])
                                
                                
print(len(T))
            



### FIXED CODE ###

#D問題
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a,b = L[i],L[j]
        left = bisect.bisect_left(L,b-a+1)
        right = bisect.bisect_right(L,a+b-1)
        if i >= left and i <= right:
            ans-=1
        if j >= left and j <= right:
            ans-=1
        ans+=right-left

print(ans//3)
### BUGGY CODE ###

n = int(input())
a = 0
b = 0

if n % 2 != 0 or n < 10:
  print(0)
else:
  while n % 10 != 0:
    n = n-2
  
  while n >= 10:
    b = n
    while b % 10 == 0:
      a += 1
      b = int(b/10)
    else:
      n = n-10
  
  print(a)

### FIXED CODE ###

n = int(input())
a = 0

if n % 2 != 0 or n < 10:
  print(0)
else:
  i = 10
  while i <= n:
    a += n//i
    i *= 5
  print(a)
### BUGGY CODE ###

# 多分TLRE
a,b,c,d = map(int,input().split())

ans_L = []
for val in range(a,b+1):
    if val % c !=0 and val % d!=0:
        ans_L.append(val)
print(len(ans_L))


### FIXED CODE ###

import fractions
A,B,C,D=map(int,input().split())
A-=1
f=fractions.gcd(C,D)
f2=C*D//f
ans = B-A-(B//C-A//C+B//D-A//D-B//f2+A//f2)
print(ans)
### BUGGY CODE ###

n = int(input())
xs = list(map(int,input().split()))
xs.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if xs[i] + xs[j] <= xs[k]:
        break
      ans += 1
print(ans)

### FIXED CODE ###

import bisect

n = int(input())
xs = list(map(int,input().split()))
xs.sort()
ans = 0

for i in range(n-2):
  for j in range(i+1,n-1):
    k = bisect.bisect_left(xs[j+1:], xs[i]+xs[j])
    #print(xs[j+1:], k, xs[i]+xs[j])
    ans += k
print(ans)
### BUGGY CODE ###

n = int(input())

a = [int(x) for x in input().split()]


ans = []

for i in range(n):
	idx = a.index(min(a))
	a[idx] = n+100
	ans.append(idx+1)

print(*ans)




### FIXED CODE ###

n = int(input())

a = [int(x) for x in input().split()]

ans = [0 for i in range(n)]

for i in range(n):
	ans[a[i]-1] = i+1

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

N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K+1):
    wa = 0
    for j in range(i,i+K):
        wa += Ex[j]
    maxi = max(maxi,wa)
print(maxi)

### FIXED CODE ###

N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K):
    wa = wa - Ex[i] + Ex[K+i]
    maxi = max(maxi,wa)
print(maxi)