#include #include #include using lint = long long; bool judge(const std::vector& hs) { return ((hs[0] < hs[1] && hs[1] > hs[2]) || (hs[0] > hs[1] && hs[1] < hs[2])) && hs[0] != hs[2]; } constexpr lint INF = 1LL << 60; void solve() { lint d; std::cin >> d; std::vector hs(3); for (auto& h : hs) std::cin >> h; if (d == 0) { std::cout << (judge(hs) ? 0 : -1) << "\n"; return; } lint ans = INF; { auto nhs = hs; lint cost = 0; for (int i = 0; i < 3; i += 2) { lint x = (nhs[i] < nhs[1] ? 0 : (nhs[i] - nhs[1]) / d + 1); nhs[i] = std::max(0LL, nhs[i] - x * d); cost += x; } if (nhs[0] == nhs[2]) { nhs[0] = std::max(0LL, nhs[0] - d); ++cost; } if (judge(nhs)) ans = std::min(ans, cost); } { auto nhs = hs; lint cost = 0; if (nhs[0] == nhs[2]) { nhs[0] = std::max(0LL, nhs[0] - d); ++cost; } for (int i = 0; i < 3; i += 2) { lint x = (nhs[1] < nhs[i] ? 0 : (nhs[1] - nhs[i]) / d + 1); nhs[1] = std::max(0LL, nhs[1] - x * d); cost += x; } if (judge(nhs)) ans = std::min(ans, cost); } std::cout << (ans == INF ? -1 : ans) << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }