A, B, N, M = gets.split.map(&:to_i) def f(x) a = A b = B if a < x b -= (x - a) * M a += (x - a) end if b < x a -= (x - b) * N b += (x - b) end a >= x && b >= x end ok = 0 ng = 10 ** 19 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if f(x) ok = x else ng = x end end puts ok