#include using namespace std; void no_1446(void) { long long a, b, n, m; cin >> a >> b >> n >> m; long long ans = min(a, b); a -= ans; b -= ans; if (a != 0) { long long a_div = a / n; long long a_remain = a % n; if(a_remain==0){ a_div--; a_remain = n; } ans += min(a_div, a_remain); } else if(b!=0){ long long b_div = b / m; long long b_remain = b % m; if(b_remain==0){ b_div--; b_remain = m; } ans += min(b_div, b_remain); } cout << ans << endl; } int main(void) { no_1446(); return 0; }