//https://ncode.syosetu.com/n4830bu/281/ #include using namespace std; using ll = long long; int main() { ll d; vector H(3); cin >> d; for (auto&& h : H) { cin >> h; } if ((H[0] < H[1] && H[1] > H[2] && H[0] != H[2]) || (H[0] > H[1] && H[1] < H[2] && H[0] != H[2])) { cout << 0 << endl; return 0; } if (d == 0) { cout << -1 << endl; return 0; } ll maine = 1e11; auto book = [&](ll& height, ll threshold) { if (threshold == 0) return (ll)1e11; if (height < threshold) return 0ll; ll ret = (height - threshold + d) / d; height -= ret * d; if (height < 0) return (ll)1e11; return ret; }; { //low-high-low; auto h = H; ll score = book(h[0], h[1]) + book(h[2], h[1]); if (h[0] == h[2]) score += book(h[0], h[2]); maine = min(maine, score); } { //high-low-high auto h = H; ll score = 0; if (h[0] == h[2]) score += book(h[0], h[2]); score += book(h[1], h[0]) + book(h[1], h[2]); maine = min(maine, score); } cout << (maine > 1e10 ? -1 : maine) << endl; }