#include #include #include using namespace std; int main() { long long A,B,N,M; cin >> A >> B >> N >> M; unsigned long long ans=0; ans += min(A,B); unsigned long long tmp=0; if(A < B) { while(tmp <= (B-A-tmp)/M) tmp++; } if(A > B) { while(tmp <= (A-B-tmp)/N) tmp++; } ans += tmp-1; cout << ans; return 0; }