Harryxun/stf_run huggingface dataset:
import sys

H,W,M = list(map(int, input().split()))

hw = [[0] * (W+1) for _ in range(H+1)]

w = [0] * (W+1)
h = [0] * (H+1)


for i in range(M):
    h_i, w_j = list(map(int, input().split()))
    hw[h_i][w_j] = 1
    h[h_i] += 1
    w[w_j] += 1

a = 0
for i in [i for i, x in enumerate(h) if x == max(h)]:
    for j in [j for j, y in enumerate(w) if y == max(w)]:
        d = hw[i][j]
        a = max(a, h[i]+w[j]-d)
print(a)

### FIXED CODE ###

H,W,M = list(map(int, input().split()))

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
n = int(input())
a = list(map(int,input().split()))
a.sort()
print(a)
p = 0

for i in range(n):
    for j in range(n):
        if i == j:
            pass
        elif a[i] % a[j] == 0:
            break
        else:
            pass
        if j == n - 1:
                p += 1

print(p)

### FIXED CODE ###

x1,x2,x3,x4,x5 = map(int,input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)
if [input(),input()].count("H") == 1:
  print("D")
else:
  print("H")

### FIXED CODE ###

if [ v for v in input().split() ].count("H") == 1:
	print("D")
else:
	print("H")
h,w=map(int,input().split())
s=[[] for j in range(h)]
t=[[0]*w for k in range(h)]
t[0][0]=1
q=0
u=[]
for i in range(h):
    s[i]+=list(input())
    q+=s[i].count("#")
u.append((0,0))
while t[h-1][w-1]==0:
    (x,y)=u[0]
    if x!=h-1:
        if t[x+1][y]==0 and s[x+1][y]==".":
            t[x+1][y]=t[x][y]+1
            u.append((x+1,y))
    if y!=w-1:        
        if t[x][y+1]==0 and s[x][y+1]==".":
            t[x][y+1]=t[x][y]+1
            u.append((x,y+1))
    if x!=0:        
        if t[x-1][y]==0 and s[x-1][y]==".":
            t[x-1][y]=t[x][y]+1
            u.append((x-1,y))
    if y!=0:        
        if t[x][y-1]==0 and s[x][y-1]==".":
            t[x][y-1]=t[x][y]+1
            u.append((x,y-1))
    u.pop(0)    
print((h*w-t[h-1][w-1])-q)    
        
        
    
    


### FIXED CODE ###

h,w=map(int,input().split())
s=[[] for j in range(h)]
t=[[0]*w for k in range(h)]
t[0][0]=1
q=0
u=[]
for i in range(h):
    s[i]+=list(input())
    q+=s[i].count("#")
u.append((0,0))
while u!=[]:
    (x,y)=u[0]
    if x!=h-1:
        if t[x+1][y]==0 and s[x+1][y]==".":
            t[x+1][y]=t[x][y]+1
            u.append((x+1,y))
    if y!=w-1:        
        if t[x][y+1]==0 and s[x][y+1]==".":
            t[x][y+1]=t[x][y]+1
            u.append((x,y+1))
    if x!=0:        
        if t[x-1][y]==0 and s[x-1][y]==".":
            t[x-1][y]=t[x][y]+1
            u.append((x-1,y))
    if y!=0:        
        if t[x][y-1]==0 and s[x][y-1]==".":
            t[x][y-1]=t[x][y]+1
            u.append((x,y-1))
    u.pop(0)
if t[h-1][w-1]==0:
    print(-1)
else:    
    print((h*w-t[h-1][w-1])-q)
N, K = list(map(int, input().split()))

buff = []
a = []
ans = 0
b = 0
for i in range(N):
    _a, _b = list(map(int, input().split()))
    b += _b
    a.append((_a, _b))
    # if b >= K and ans == 0:
    #     ans = _a
    # buff += [_a]*_b


a = a.sort()

for i in range(N):
    buff += [a[i][0]] * a[i][1]

# buff = sorted(buff)
print(buff[K-1])


### FIXED CODE ###

amax = 100000
cnt = [0 for i in range(amax+1)]


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

for i in range(N):
    a, b = list(map(int, input().split()))
    cnt[a] += b


for ans in range(1, amax+1):
    if K <= cnt[ans]:
        print(ans)
        break
    K -= cnt[ans]
N, M = [int(i) for i in input().split(' ')]
mod = pow(10, 9) + 7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    c = 0
    while n % i == 0:
      n /= i
      c+=1
    if c!=0:
        table.append(c)
    i += 1
  if n > 1:
    table.append(1)
  return table

xxs = prime_decomposition(M)

result = 1
for xx in xxs:
    result = mul(result, cmb(xx+N-1,xx,mod))
print(result)


### FIXED CODE ###

N, M = [int(i) for i in input().split(' ')]
mod = pow(10, 9) + 7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**5) * 2
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    c = 0
    while n % i == 0:
      n /= i
      c+=1
    if c!=0:
        table.append(c)
    i += 1
  if n > 1:
    table.append(1)
  return table

xxs = prime_decomposition(M)

result = 1
for xx in xxs:
    result = mul(result, cmb(xx+N-1,xx,mod))
print(result)
H,W = map(int,input().split())
mass = [list(input()) for _ in range(H)]

for i in range(H):
  if "#" not in mass[i]:
    mass.pop(i)
  
H = len(mass)

new_mass = [[] for _ in range(W)]

for j in mass:
  for i, k in enumerate(j):
    new_mass[i].append(k)
    
for l in range(W):
  if "#" not in new_mass[l]:
    new_mass.pop(l)
    
mass = [[] for _ in range(H)]

for n in new_mass:
  for i, m in enumerate(n):
    mass[i].append(m)
    
print(mass)

### FIXED CODE ###

H,W = map(int,input().split())
A = [""] * H
for i in range(H):
  A[i] = input()
  
row = [False] * H
col = [False] * W

for j in range(H):
  for k in range(W):
    if A[j][k] == "#":
      row[j] = True
      col[k] = True
      
for l in range(H):
  if row[l]:
    for m in range(W):
      if col[m]:
        print(A[l][m], end = "")
    print()
N, K = map(int, input().split())
S = input()
if S[K-1] == "A":
  S[K-1] = "a"
elif S[K-1] == "B":
  S[K-1] = "b"
elif S[K-1] == "C":
  S[K-1] = "c"
else:
  continue
print(S)


### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
if S[K-1] == "A":
  S[K-1] = "a"
elif S[K-1] == "B":
  S[K-1] = "b"
else:
  S[K-1] = "c"
ans = "".join(S)
print(ans)
import numpy as np
S = input()
n = len(S)
A, C, L, R = np.zeros(n), np.zeros(n), np.zeros(n), np.zeros(n)
a, c, l, r = 0, 0, 0, 0
for i in range(n):
	A[i] = a
	L[i] = l
	C[n-1-i] = c
	R[n-1-i] = r
	if(S[i] == 'A'):
		a += 1
	elif(S[i] == '?'):
		l += 1
	if(S[n-1-i] == 'C'):
		c += 1
	elif(S[n-1-i] == '?'):
		r += 1
ans = 0
for i in range(n):
	if(S[i] == 'B' or S[i] == '?'):
		left  = A[i] if L[i] == 0 else A[i]*(3**L[i])+3**(L[i]-1)
		right = C[i] if R[i] == 0 else C[i]*(3**R[i])+3**(R[i]-1)
		ans += left*right
		ans %= 10**9+7

print(int(ans))
#print(A, C, L, R)
#print(n)

### FIXED CODE ###

S = input()
m = 10**9+7
d = "ABC".index

dp = [0]*4
dp[0] = 1

for c in S:
	if(c == '?'):
		dp = [(3*dp[0])%m, (3*dp[1]+dp[0])%m, (3*dp[2]+dp[1])%m, (3*dp[3]+dp[2])%m]
	else:
		i = d(c)
		dp[i+1] += dp[i]%m 
print(dp[3]%m)
colatz=1,2,4
colatz.append(list(map(int,input().split())))
b=3
while colatz[b]!=colatz[b-3]:
    if colatz[b]%2==0:
        colatz.append(colatz[b]/2)
    else: colatz.append(3*colatz[b]+1)
    b=b+1
print(b)

### FIXED CODE ###

colatz=[1,2,4]
colatz.append(int(input()))
if colatz[3]==1 or colatz[3]==2 or colatz[3]==4:
    print(4)
else:
    b=3
    while colatz[b]!=4:
        if colatz[b]%2==0:
            colatz.append(colatz[b]/2)
        else: colatz.append(3*colatz[b]+1)
        b=b+1
    print(b+1)
import math
r = int(input())
s = '{:.6f}'.format(r * r * math.pi)
l = '{:.6f}'.format(2 * r * math.pi)
print(s,l)


### FIXED CODE ###

import math
r = float(input())
s = '{:.6f}'.format(r * r * math.pi)
l = '{:.6f}'.format(2 * r * math.pi)
print(s,l)
s = str(input())
for i in range(1, 5):
    if s[i - 1] == s[i]:
        print('Bad')
        exit()
print('Good')

### FIXED CODE ###

s = str(input())
for i in range(3):
    if s[i] == s[i + 1]:
        print('Bad')
        exit()
print('Good')
a,b=map(int,input().split())
if (a+b≧24):
    print(a+b-24)
else:
    print(a+b)

### FIXED CODE ###

a,b=map(int,input().split())
if (a+b>=24):
    print(a+b-24)
else:
    print(a+b)
a = sys.argv[0]
b = sys.argv[1]

print(max(a+b, a-b, a*b))

### FIXED CODE ###

a,b = map(int,input().split())
print(max(a+b,a-b,a*b))
K,N=map(int,input().split())
if 500*K>=X:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

K,N=map(int,input().split())
if 500*K>=N:
    print('Yes')
else:
    print('No')
H, W = [int(s) for s in input().rstrip().split()]
sqare = [list('.' * (W+2)) for _ in range(H+2)]
for i in range(1, H+1):
    S = list(input().rstrip())
    sqare[i][1:H+1] = S

bomb = [[0 for _ in range(W+2)] for _ in range(H+2)]    
for i in range(1, H+1):
    for j in range(1, W+1):
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if not(x == i and y == j) and sqare[x][y] == '#':
                    bomb[i][j] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        if sqare[i][j] == '.':
            print(bomb[i][j], end='')
        else:
            print(sqare[i][j], end='')                        
    print('')

### FIXED CODE ###

H, W = [int(s) for s in input().rstrip().split()]
S = [list(input().rstrip()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        bomb = 0
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if 0 <= x < H and 0 <= y < W and S[x][y] == '#':
                    bomb += 1
        S[i][j] = str(bomb)

for s in S:
    print(''.join(s))
x = int(input())
y = int(input())
z = int(input())

if x + y + z <= 21:
	print('win')
else:
	print('bust')


### FIXED CODE ###

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

if (a+b+c<=21):
  print('win')
else:
  print('bust')
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
if k<=len(non):
    print(non[k])
    exit()
k-=len(non)
k%=len(cy)


print(cy[k])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
if k<len(non):
    print(non[k])
    exit()
k-=len(non)
k%=len(cy)


print(cy[k])
from collections import deque


ans = {1:1}

def dfs(tree,nodes):
    for node in nodes:
        nexts = tree[node]
        for next,l in nexts.items():
            if l% 2 == 0 :
                ans[next] = ans[node]
            else:
                ans[next] = 1 - ans[node]
            tree[next].pop(node)

        dfs(tree,nexts)

    return 0




if __name__ == "__main__":
    tree= {}
    N = int(input())
    for i in range(N-1):
        u,v,w = list(map(int,input().split(" ")))

        if u not in tree:
            tree[u] = {}
        tree[u][v] = w

        if v not in tree:
            tree[v] = {}
        tree[v][u] = w

    dfs(tree,[1])
    for i in range(1,N+1):
        print(ans[i])


### FIXED CODE ###

from collections import deque
import sys

sys.setrecursionlimit(50000000)


ans = {1: 1}


def dfs(tree, nodes):
    for node in nodes:
        nexts = tree[node]
        for next, l in nexts.items():
            if l % 2 == 0:
                ans[next] = ans[node]
            else:
                ans[next] = 1 - ans[node]
            tree[next].pop(node)

        dfs(tree, nexts)

    return 0


if __name__ == "__main__":
    tree = {}
    N = int(input())
    if N == 1:
        u, v, w = list(map(int, input().split(" ")))
        if w % 2 == 1:
            print(1)
            print(0)
        else:
            print(0)
            print(0)
    else:
        for i in range(N - 1):
            u, v, w = list(map(int, input().split(" ")))

            if u not in tree:
                tree[u] = {}
            tree[u][v] = w

            if v not in tree:
                tree[v] = {}
            tree[v][u] = w
        dfs(tree, [1])
        for i in range(1, N + 1):
            print(ans[i])
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
Ans = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b ,c = map(int, input().split())
  Ans.append(Ans[i] + (c-b) * cnt[b])
  cnt[c] += cnt[b]
  cnt[b] = 0

print(Ans)

### FIXED CODE ###

import collections

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

CNT = collections.Counter(A)
ANS = []
ans = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans +=(c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0

for i in ANS:
    print(i)
x = list(map(int, input().split()))
num = x.sort()
print(num[0], num[1], num[2])

### FIXED CODE ###

x = list(map(int, input().split()))
x.sort()
print(x[0], x[1], x[2])
X, K, D = map(int, input().split())

ans_list = []

if X+K*D <= 0:
    ans = abs(X+K*D)
else:
    if D>0:
        a = int((X+K*D)/(2*D))
        for i in range(-2,3):
            if a+i <= K and a+i >= 0:
                ans_list.append(abs(X+(K-(a+i))*D - (a+i)*D))
        ans = min(ans_list)
print(ans)

### FIXED CODE ###

X, K, D = map(int, input().split())
ans_list = []

if X+K*D <= 0:
    ans = abs(X+K*D)
else:
    a = (X+K*D)//(2*D)
    if a >= K:
        a = K
        ans = abs(X-K*D)
    else:
        ans_1 = abs(X+K*D-2*a*D)
        ans_2 = abs(X+K*D-2*(a+1)*D)
        ans = min(ans_1, ans_2)
print(ans)
S = input()
T = input()

min_count = len(T)
for s in range(len(S) - len(T) + 1):  # T cannot exceed the length of S
    matched = 0
    for i in range(len(T)):
        # print(f'S[{s + i}] == T[{i}]')
        if S[s + i] == T[i]:
            matched += 1
    count = len(T) - matched
    if count < min_count:
        min_count = count
print(min_count)

### FIXED CODE ###

inputs = input().split()
D = int(inputs[0])
T = int(inputs[1])
S = int(inputs[2])

print('Yes' if D / S <= T else 'No')
#AGC033-A-Darker and Darker
from collections import deque

h,w = map(int,input().split())
grid = [input() for i in range(h)]

#初期の黒('#')の位置からの距離
dist = [[-1]*w for _ in range(h)]

p = deque()
d = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            p.append((i,j))
            dist[i][j] = 0

while p:
    x,y = p.popleft()
    d = dist[y][x]
    for dy,dx in ((1,0),(0,1),(-1,0),(0,-1)):
        if 0<= x+dx < w and 0<= y+dy < h and dist[y+dy][x+dx] == -1:
            dist[y+dy][x+dx] = d+1
            p.append((y+dy,x+dx))

    
print(d)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
lst_A = list(input())

ans = "Bad"

for i in range(3):
	if lst_A[i] == lst_A[i + 1]
  		break
else:
  ans = "Good"
  
print(ans)


### FIXED CODE ###

lst_A = list(input())
 
ans = "Bad"
 
for i in range(3):
	if lst_A[i] == lst_A[i + 1]:
  		break
else:
  ans = "Good"
  
print(ans)
a,b,c,d=map(int,raw_input().split())
if c-a < d or a-c<d:
  print "Yes"
elif b-c <d or c-b<d:
  print "Yes":
elif a-b <d or b-a<d:
  print "Yes"
else:
  print "No"


### FIXED CODE ###

a,b,c,d=map(int,raw_input().split())
if abs(c-a) <=d or abs(a-b) <=d and abs(b-c) <=d:
  print "Yes"
else:
  print "No"
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
limit = 10**18
for i in a:
    ans*=i
    if ans > lim:
        print(-1)
        exit()
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
limit = 10**18
for i in a:
    ans*=i
    if ans > limit:
        print(-1)
        exit()
print(ans)
n, k = map(int, input().split())
edges = []
for _ in range(n-1):
  edges.append(list(map(int, input().split())))

# n = 16
# k = 22
# edges = list(map(lambda x: list(map(int, x.split())), """12 1
# 3 1
# 4 16
# 7 12
# 6 2
# 2 15
# 5 16
# 14 16
# 10 11
# 3 10
# 3 13
# 8 6
# 16 8
# 9 12
# 4 3""".split("\n")))

# n = 5
# k = 4
# edges = list(map(lambda x: list(map(int, x.split())), """1 2
# 1 3
# 1 4
# 4 5""".split("\n")))

mod = 10**9+7
edge_dict = {}
for i in range(1, n+1):
  edge_dict[i] = set()

for edge in edges:
  edge_dict[edge[0]].add(edge[1])
  edge_dict[edge[1]].add(edge[0])

# print(edge_dict)
visited = set()

def visit(node, parent):
  num_children = len(edge_dict[node])
  num_available_colors = k-2 if parent is not None else k-1
  
  if num_available_colors < num_children:
    return 0
  
  ans = 1
  
#   print("VISIT {} {} {}".format(node, ans, num_available_colors))
  for child in edge_dict[node]:
    if child is parent:
      continue
    
    ans *= num_available_colors
    num_available_colors -= 1
    ans %= mod
  
#   print("VISIT {} {} {}".format(node, ans, num_available_colors))
  
  for child in edge_dict[node]:
    if child is parent:
      continue
    
    ans *= visit(child, node)
    ans %= mod
  
#   print("VISIT {} from {}, {}, {}".format(node, parent, ans, num_children))
  return ans

print((k*visit(1, None))%mod)

### FIXED CODE ###

import queue

n, k = map(int, input().split())
edges = []
for _ in range(n-1):
  edges.append(list(map(int, input().split())))
mod = 10**9+7

edge_dict = {}
for i in range(1, n+1):
  edge_dict[i] = set()

for edge in edges:
  edge_dict[edge[0]].add(edge[1])
  edge_dict[edge[1]].add(edge[0])

visited = set()
q = queue.LifoQueue()
q.put(1)

num_cases = 1
while not q.empty():
  node = q.get()
  
  visited.add(node)
  num_available_colors = k -2 if node is not 1 else k -1
  
  for child in (edge_dict[node] - visited):
    num_cases *= num_available_colors
    num_available_colors -= 1
    num_cases %= mod
    q.put(child)

print((k*num_cases)%mod)
n, m = map(int, input().split())
num_list = ['X'] * n

def ans():
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1


    if num_list[0] == 'X':
        num_list[0] = '1'

    for i in range(1, m):
        if num_list[i] == 'X':
            num_list[i] = '0'

    return ''.join(num_list)

print(ans())


### FIXED CODE ###

n, m = map(int, input().split())
num_list = ['X'] * n

def ans():
    if n == 1 and m == 0:
        return 0
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1


    if num_list[0] == 'X':
        num_list[0] = '1'

    for i in range(1, n):
        if num_list[i] == 'X':
            num_list[i] = '0'

    return ''.join(num_list)

print(ans())
import numpy as np

# 整数Nを入力する
N = int(input())
print(N)

# 整数A、Bの桁数のうち、大きい方を返す関数F(A, B)を定義
def F(A, B):
    C = np.vstack((A, B))
    digit_C = np.array(np.log10(C) + 1, dtype = int)
    return np.max(digit_C, axis = 0)

# 被除数の配列を作成
dividend = np.ones(N) * N
# 除数の配列を作成
divisor = np.arange(1, N + 1)
# 商および余りを計算
residue = dividend % divisor

# N = A * B となるようなAおよびBの配列を作成
A = divisor[residue == 0]
B = quotient[residue == 0]

# F(A, B)の最小値を返す
print(np.min(F(A, B)))

### FIXED CODE ###

import numpy as np

# 整数Nを入力する
N = int(input())

# 整数A、Bの桁数のうち、大きい方を返す関数F(A, B)を定義
def F(A, B):
    C = np.vstack((A, B))
    digit_C = np.array(np.log10(C) + 1, dtype = int)
    return np.max(digit_C, axis = 0)

# 除数の配列を作成
divisor = np.arange(1, int(N ** 0.5) + 1)
# 商および余りを計算
quotient = N // divisor
residue = N % divisor

# N = A * B となるようなAおよびBの配列を作成
A = divisor[residue == 0]
B = quotient[residue == 0]

# F(A, B)の最小値を返す
print(np.min(F(A, B)))
while True:
    n=sum(map(int, list(input()))
    if n == 0:
        break
    print(n)

### FIXED CODE ###

while True:
    n=sum(list(map(int, list(input()))))
    if n == 0:
        break
    print(n)
import fileinput

if __name__ == '__main__':

    for i in fileinput.input():
        a.append(i)
    
    for i in a:
        b = i.split()
        b = map(float, b)

        b_a = b[0]
        b_b = b[1]
        b_c = b[2]
        b_d = b[3]
        b_e - b[4]
        b_f = b[5]
 
        b_d = b_a
        b_e = b_a/b_d * b_e
        b_f = b_a/b_d * b_f

        x = (b_c - b_f)/(b_b - b_e)

        y = (b_c - x * b_b)/b_a 

        print round(x, 3)
        print round(y, 3)

### FIXED CODE ###

while 1:
    def solver(a, b, c, d, e, f):
        answer = []

        if d == 0:
            y = f / e
            x = (c - b * y)/a

        else:
            m = a / d

            d = d * m
            e = e * m
            f = f * m

            y = (c - f)/(b - e)

            x = (c - b * y)/a

            if x == -0:
                x = 0
            if y == -0:
                y = 0

        answer.append(x)
        answer.append(y)
        return answer

    try:
        p_1, p_2, p_3, p_4, p_5, p_6 = map(float, raw_input().split())

        ans = []
        ans = solver(p_1, p_2, p_3, p_4, p_5, p_6)

        print "%.3f %.3f" % (ans[0], ans[1])

    except:
        break
a, b, c, d = list(map(int, input().split())
b - (a - 1) - ((b - a) // c) - ((b - a) // d) + ((b - a) // c * d)

### FIXED CODE ###

from fractions import gcd
a,b,c,d=map(int,input().split())
count=0
x=b-a+1
def cal(x):
    return x//c+x//d-x//(c*d//gcd(c,d))
print(b-a+1-(cal(b)-cal(a-1)))