You have two friends. You want to present each of them several positive integers. You want to present cnt_1 numbers to the first friend and cnt_2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.

In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.

A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.


-----Input-----

The only line contains four positive integers cnt_1, cnt_2, x, y (1 ≤ cnt_1, cnt_2 < 10^9; cnt_1 + cnt_2 ≤ 10^9; 2 ≤ x < y ≤ 3·10^4) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.


-----Output-----

Print a single integer — the answer to the problem.


-----Examples-----
Input
3 1 2 3

Output
5

Input
1 3 2 3

Output
4



-----Note-----

In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. 

In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.

Difficulty: interview

Starter code:

Solutions:
n0, n1, x, y = list(map(int, input().split()))

def f(m, n, x, y):
    return max(0, n - (m // y - m // (x * y)))

lo = -1
hi = x * y * (n0 + n1)
while lo + 1 < hi:
    mid = lo + (hi - lo) // 2
    if f(mid, n0, x, y) + f(mid, n1, y, x) <= mid - mid // x - mid // y + mid // (x * y):
        hi = mid
    else:
        lo = mid
print(hi)


c1, c2, x, y = list(map(int, input().split()))
l, r = 0, 1 << 179
while r - l > 1:
	m = (l + r) >> 1
	if (m - m // x >= c1) and (m - m // y - max(0, c1 - m // y + m // x // y) >= c2):
		r = m
	else:
		l = m
print(r)


__author__ = 'neki'

import sys

#sys.stdin = open("friendsPresents.in", "r")
#sys.stdout = open("friendsPresents.out", "w")

words = input().split()
cnt1 = int(words[0])
cnt2 = int(words[1])
x = int(words[2])
y = int(words[3])
#print(cnt1, cnt2, x, y)

def determine(num, x, y, cnt1, cnt2):
    like1 = num - num // x
    like2 = num - num // y
    like1and2 = like1 + like2 - num + num // (x*y)
    #print(like1, like2, like1and2)

    friend1 = like1 - like1and2
    friend2 = like2 - like1and2
    both = like1and2
    #print(num, friend1, friend2, both)

    cond1 = 0
    cond2 = 0
    if friend1 + both >= cnt1 and friend2 + both >= cnt2:
        cond1 += 1
    if friend1 + friend2 + both >= cnt1 + cnt2:
        cond2 += 1
    if cond1 > 0 and cond2 > 0:
        return 1
    return 0

lim = 0
lim1 = 1
lim2 = -1
while 1:
    if lim2 < 0:
        lim = lim1 * 2
    else:
        lim = (lim1 + lim2) // 2
    if lim == lim1:
        break
    if determine(lim, x, y, cnt1, cnt2) == 1:
        lim2 = lim
    else:
        lim1 = lim
    #print("(", lim1, lim2, ")")
print(lim2)


def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)

cntx, cnty, x, y = list(map(int, input().split()))
d = x * y // gcd(x, y)

v = cnt = 0
while (cntx + cnty > cnt):
    dxy = cntx + cnty - cnt
    
    cx = (v + dxy) // x - v // x
    cy = (v + dxy) // y - v // y
    cxy = (v + dxy) // d - v // d

    cnt += dxy - cx - cy + cxy
    cntx -= min(cy - cxy, cntx)
    cnty -= min(cx - cxy, cnty)
    
    v += dxy

print(v)


a, b, x, y = list(map(int, input().split()))
L, R= 0, 10 ** 18
while R - L > 1:
    M = (L + R) // 2
    if M - M // x < a or min(M - a - M // (x * y), M - M // y) < b:
        L = M
    else:
        R = M
print(R)


from sys import stdin
lines = list([_f for _f in stdin.read().split('\n') if _f])

def parseline(line):
	return list(map(int, line.split()))

lines = list(map(parseline, lines))

def search(f, v, l, r):
	while l + 1 < r:
		p = l + (r - l) // 2
		if f(p) <= v:
			l = p
		else:
			r = p
	return l

c1, c2, x, y = lines[0]

def check(v, debug=False):
	m1 = max(c1 - v // y + v // (x * y), 0) 
	m2 = max(c2 - v // x + v // (x * y), 0)
	f = v - v // x - v // y + v // (x * y)
	if debug:
		print(v, ":", m1, m2, f)
	if m2 <= f - m1:
		return 1
	else:
		return 0
#print([check(v, True) for v in range(20)])
print(1 + search(check, 0, 1, y * c1 + x * c2 + 1))


c1, c2, x, y = map(int, input().split())
xy = x * y 
n = 1
while n - n // x < c1 or n - n // y < c2 or n - n // xy < c1 + c2:
    n = n << 1

l = 1
r = n
while r - l > 1:
    m = (r + l) >> 1
    if m - m // x < c1 or m - m // y < c2 or m - m // xy < c1 + c2:
        l = m
    else:
        r = m
m  = l
if m - m // x < c1 or m - m // y < c2 or m - m // xy < c1 + c2:
    print(r)
else:
    print(l)

def check(v):
    a = v // y - v // (x * y)
    b = v // x - v // (x * y)
    c = v - (a + b + v // (x * y))
    fa = c + a
    fb = min(c, fa - cnt1) + b
    return (fa >= cnt1) and (fb >= cnt2)

cnt1, cnt2, x, y = list(map(int, input().split()))
l, r = 0, (cnt1 + cnt2) * 2
while l <= r:
    mid = (l + r) // 2
    if check(mid):
        ans = mid
        r = mid - 1
    else:
        l = mid + 1
print(ans)


a,b,x,y=list(map(int,input().split()))
l,r=a+b,(a+b)*5
while l<r:
  v = (l+r)//2
  if v-v//x >= a and v-v//y >= b and v-v//(x*y) >= a+b:
    r = v
  else:
    l = v+1
print(r)


c1, c2, x, y = list(map(int, input().split()))
def get(n):
    if (n - n // (x * y)) >= c1 + c2 and (n - n // x >= c1) and (n - n // y >= c2):
        return True
    else:
        return False
l = 0
r = c1 * x + c2 * y
while (r - l > 1):
    m = (l + r) // 2
    if get(m):
        r = m
    else:
        l = m
print(r)


cnt1, cnt2, x, y = map(int, input().split())

upper_limit = (cnt1 + cnt2) * (x*y) // (x*y - x - y + 1)

def bin_search(low, high):
    if low >= high - 1:
        return high
    
    mid = (low + high) // 2
    best_way = max(0, cnt1 - mid//y + mid//(x*y)) + max(0, cnt2 - mid//x + mid//(x*y))
    leftovers = mid - mid//x - mid//y + mid//(x*y)
    if best_way <= leftovers:
        return bin_search(low, mid)
    return bin_search(mid, high)

print(bin_search(1, upper_limit + 10))

cnt1, cnt2, x, y = list(map(int, input().split()))

l = 0
r = (cnt1 // (x - 1) + 1) * x + (cnt2 // (y - 1) + 1) * y + 5

while r - l != 1:
    m = l + (r - l) // 2
    t_cnt1 = m // y - m // (x * y)
    t_cnt2 = m // x - m // (x * y)

    if max(0, cnt1 - t_cnt1) + max(0, cnt2 - t_cnt2) <= m - (m // x + m // y - m // (x * y)):
        r = m
    else:
        l = m

print(r)


a,b,x,y=map(int,input().split());
l=0
r=10000000000000;
res=0;
def judge(n,a,b,x,y):
    return (n - n // (x * y)) >= a + b and (n - n // x >= a) and (n - n // y >= b);
while l<=r:
    m=(l+r)//2;
    if judge(m,a,b,x,y):
        r=m-1;
        res=m;
    else :l=m+1;
print(res);

import math
def expr(N,x,y,cnt1,cnt2):
    cnt1 = max(cnt1res - math.floor(N/y)+math.floor(N/(y*x)),0)
    cnt2 = max(cnt2res - math.floor(N/x)+math.floor(N/(y*x)),0)
    b = N-math.floor(N/x)-math.floor(N/y)+math.floor(N/(x*y)) >= cnt1+cnt2
    return b
    
cnt1,cnt2,x,y = map(int,list(input().split()))
cnt1res = cnt1
cnt2res = cnt2
N = math.ceil((cnt1 + cnt2+1)/(1-1/x-1/y+1/(y*x)))

start,last = 1,N
while last>start:
    mid = start + (last-start)//2
    if expr(mid, x, y, cnt1, cnt2):
        last = mid
    else:
        start = mid
    if start+1==last:
        break
    
print(last)

a,b,x,y=list(map(int,input().split()))
l,r=a+b,(a+b)*5
while l<r:
  v = (l+r)//2
  if v-v//x >= a and v-v//y >= b and v-v//(x*y) >= a+b:
    r = v
  else:
    l = v+1
print(r)


s = input()
arrIn = s.split()
n = int(arrIn[0])
m = int(arrIn[1])
x = int(arrIn[2])
y = int(arrIn[3])


l = 1
r = 2e9
while l < r:
    mid = int((r+l)/2)
    if n <= mid - int(mid/x) and m <= mid - int(mid/y) and m+n <= mid - int(mid/(x*y)):
        r = mid
    else:
        l = mid+1
else:
    print(r)



3

from fractions import gcd

cnt1, cnt2, a, b = tuple(map(int, input().split()))
lcm = a*b // gcd(a, b)

def check(v):
    c1 = int(v/b) - int(v/lcm)
    c2 = int(v/a) - int(v/lcm)
    rest = v - c1 - c2 - int(v/lcm)
    c1 = min(c1, cnt1)
    c2 = min(c2, cnt2)
    return rest >= cnt1+cnt2-c1-c2

left, right = 1, 10**18
while left + 1 < right:
    mid = (left+right) // 2
    if (check(mid)):
        right = mid
    else:
        left = mid
print(right)


a,b,c,d=map(int,input().split());l=1;r=10**10
while r-l>1:
    m=(r+l)//2
    both=m//(c*d)
    f=[m//c,m//d]
    other=m-f[0]-f[1]+both
    f[0]-=both;f[1]-=both
    if max(0,b-f[0])+max(0,a-f[1])<=other:
        r=m
    else:
        l=m
print(r)

cnt1, cnt2, x, y = list(map(int, input().split(' ')))

lo = 1
hi = 10**10

while lo < hi:
    xx = cnt1
    yy = cnt2
    
    mid = (lo + hi) // 2
    intx = mid // x
    inty = mid // y
    intxy = mid // (x*y)
    notxy = mid - intx - inty + intxy
    notx = mid - intx - notxy
    noty = mid - inty - notxy
    
    xx -= notx
    yy -= noty

    
    if max(xx,0) + max(yy,0) > notxy:
        lo = mid + 1
    else:
        hi = mid
print(lo)


def main():
    cnt1, cnt2, x, y = list(map(int, input().split()))
    lo = cnt3 = cnt1 + cnt2
    hi, z = 10 ** 10, x * y
    while lo < hi:
        v = (lo + hi) // 2
        if (v - v // x < cnt1) or (v - v // y < cnt2) or (v - v // z < cnt3):
            lo = v + 1
        else:
            hi = v
    print(lo)


def __starting_point():
    main()

__starting_point()

a,b,x,y=map(int,input().split())
l,r=a+b,(a+b)*5
while l<r:
  v = (l+r)//2
  if v-v//x >= a and v-v//y >= b and v-v//(x*y) >= a+b:
    r = v
  else:
    l = v+1
print(r)

def valid(n1, n2, p1, p2, mid):
    x = mid - mid//p1
    y = mid - mid//p2
    rem = mid - mid//(p1*p2)
    return x < n1 or y < n2 or rem < n1+n2
    
def binary_search(n1, n2, p1, p2):
    l, r = 0, 1<<61
    while (l <= r):
        mid = l+r >> 1
        if (valid(n1, n2, p1, p2, mid)):
            l = mid+1
        else:
            r = mid-1
    return l

def main():
    n1, n2, p1, p2 = map(int, input().split())
    print(binary_search(n1, n2, p1, p2))

main()

a,b,x,y=list(map(int,input().split()))

l,r=a+b,(a+b)*5

while l<r:

  v = (l+r)//2

  if v-v//x >= a and v-v//y >= b and v-v//(x*y) >= a+b:

    r = v

  else:

    l = v+1

print(r)





# Made By Mostafa_Khaled


R = lambda: map(int, input().split())
c1, c2, x, y = R()
l, r = c1 + c2, 2 * 10**9 + 7
while l < r:
    m = (l + r) // 2
    r1 = max(0, c1 - m // y + m // (x * y))
    r2 = max(0, c2 - m // x + m // (x * y))
    if m - m // x - m // y + m // (x * y) < r1 + r2:
        l = m + 1
    else:
        r = m
print(l)

s=input()
c1, c2, x, y = list(map(int, s.split()))

l = 0
r = int(1e18)

while r - l > 1:
    m = (l + r) // 2

    d1 = m // x
    d2 = m // y
    b = m // (x * y)

    k1 = d2 - b
    k2 = d1 - b

    rr = m - d1 - d2 + b

    r1 = max(0, c1 - k1)
    r2 = max(0, c2 - k2)

    if rr >= r1 + r2:
        r = m
    else:
        l = m

print(r)