#include "bits/stdc++.h" using namespace std; int main() { int A,B,C,D,res, resb; cin >> A >> B >> C >> D; res=0,resb=0; if (A >= B/C){ res = B/C; } else{ res = A; B = C * A; } resb = res * C; if (res+resb <= D){ cout << res << endl; } else{ while(res+ resb >= D) { res -= 1; if(res<0){ res = 0; break; } resb = resb - C; } cout << res << endl; } }