#include using namespace std; int a,b,c,d,i,x = 0,i2 = 0; int main(){ scanf("%d %d %d %d",&a,&b,&c,&d); if(a * c <= b && a + (a * c) <= d){ printf("%d\n", a); return 0; } for(i = a; i * c >= b; i--){ x = i; } if(x * c > b){ printf("%d\n", 0); return 0; } while( x + (x * c) > d){ x--; } printf("%d\n",x); return 0; }