#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const double PI = 3.14159265358979323846; const double EPS = 1e-12; typedef pair P; typedef long long ll; typedef unsigned long long ull; ll INF = 1e12; int main(){ ll d, a, b, c; cin>>d>>a>>b>>c; if(a>c) swap(a, c); ll res = INF; if(b > c && c > a) res = 0; if(b < a && c > a) res = 0; if(d==0){ cout<<(res==INF?-1:res)< max(a, c) ll t1 = 0, t2 = 0; if(a>=b){ t1 = (a-b)/d+1; a -= d*t1; if(a<0) a = 0; } if(c>=b){ t2 = (c-b)/d+1; c -= d*t2; if(c<0) c = 0; if(c==a){ t2++; c -= d; } if(c<0) c = 0; } if(a==c) t2 = INF; res = min(res, t1+t2); } cerr<