#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long #define let const auto #define var auto #define all(c) c.begin(), c.end() #define repeat(i, n) for (int i = 0; i < static_cast(n); i++) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif typedef complex point; template ostream &operator<<(ostream &os, const vector &v) { os << "{"; for(auto it = v.begin(); it != v.end(); ++it){ if(it != v.begin()){ os << ","; } os << *it; } return os << "}"; } template void isort(std::vector& v, std::function comp=less()){ sort(v.begin(), v.end(), comp); } template std::vector sort(std::vector v, std::function comp=less()){ isort(v); return v; } template std::vector rmap(const std::vector& v, std::function f){ std::vector t; t.reserve(v.size()); for(const auto& i: v) t.push_back(f(i)); return t; } std::vector split(std::string str, char delim){ std::vector res; size_t current = 0, found; while((found = str.find_first_of(delim, current)) != std::string::npos){ res.push_back(std::string(str, current, found - current)); current = found + 1; } res.push_back(std::string(str, current, str.size() - current)); return res; } string join(const std::vector& v, string delim){ string ret = ""; for(auto it = v.begin(); it != v.end(); ++it){ if(it != v.begin()){ ret += delim; } ret += *it; } return ret; } int min_solve(int d, vector h){ int ret = 0; if(h[0] == h[2]){ ret++; h[0] -= d; } int diff = h[1] - min(h[0], h[2]); if(diff < 0) return ret; int needs = (diff / d) + 1; h[1] -= d * needs; if(h[0] >= 0 && h[1] >= 0 && h[2] >= 0) return ret + needs; else return -1; } int max_solve(int d, vector h){ int ret = 0; vector k = {0,2}; for(int i : k){ int diff = h[i] - h[1]; if(diff >= 0){ int needs = (diff / d) + 1; ret += needs; h[i] -= d * needs; } } if(h[0] == h[2]){ ret++; h[0] -= d; } if(h[0] >= 0 && h[1] >= 0 && h[2] >= 0) return ret; else return -1; } int solve(int d, vector 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[1] && h[1] < h[2]))) return 0; if(d == 0) return -1; int mis = min_solve(d,h); int mas = max_solve(d,h); if(mis == -1 && mas == -1) return -1; if(mis == -1) return mas; if(mas == -1) return mis; return min(mis,mas); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int d; cin >> d; vector h(3); for(int& i: h) cin >> i; cout << solve(d, h) << endl; return 0; }