#include #include #include using namespace std; const int inf = int(1e9) + 100; void bye(string s) { puts(s.c_str()); exit(0); } bool ok(int x, int y, int z) { bool ok1 = x > y && y < z, ok2 = x < y && y > z; return x != z && (ok1 || ok2); } // myをyour未満にする回数 int count(int my, int your, int d) { if(your == 0) { return inf; } if(my < your) { return 0; } return (my - your + d) / d; } // myをtimes回切る void cut(int& my, int d, int times) { my = max(0, my-d*times); } int main(void) { int d, h1, h2, h3; scanf("%d%d%d%d", &d, &h1, &h2, &h3); assert(0 <= d && d <= int(1e9)); assert(0 <= h1 && h1 <= int(1e9)); assert(0 <= h2 && h2 <= int(1e9)); assert(0 <= h3 && h3 <= int(1e9)); if(ok(h1, h2, h3)) { bye("0"); } if(d == 0) { bye("-1"); } int x, y, z, p, q; // h2(=y)を最大にする int r1 = 0; x = h1, y = h2, z = h3; if(x == z) { cut(x, d, 1); ++r1; } p = count(x, y, d); r1 += p; cut(x, d, p); q = count(z, y, d); r1 += q; cut(z, d, q); if(!ok(x, y, z)) { r1 = inf; } // h2(=y)を最小にする int r2 = 0; x = h1, y = h2, z = h3; if(x == z) { cut(x, d, 1); ++r2; } p = count(y, x, d); r2 += p; cut(y, d, p); q = count(y, z, d); r2 += q; cut(y, d, q); if(!ok(x, y, z)) { r2 = inf; } int res = min(r1, r2); if(res >= inf) { res = -1; } printf("%d\n", res); return 0; }