#include #include #include #include #include #include #include #include #include #include using namespace std; bool check(vector& h){ if(h[0] == h[1] || h[1] == h[2] || h[2] == h[0]) return false; if(h[1] > h[0] && h[1] > h[2]) return true; if(h[1] < h[0] && h[1] < h[2]) return true; return false; } int main(){ long long d; cin >> d; vector h(3); for(int i=0; i<3; i++){ cin >> h[i]; } if(check(h)){ cout << 0 << endl; return 0; } long long ans = -1; { // h[1] > h[0],h[2] vector h_ = h; long long tmp = 0; long long lb = -1; long long ub = 1e10; while(ub-lb>1){ long long mid = (ub+lb)/2; long long len = max(0LL, h_[0] - d*mid); if(len >= h_[1]){ lb = mid; }else{ ub = mid; } } h_[0] = max(0LL, h_[0] - d*ub); tmp += ub; lb = -1; ub = 1e10; while(ub-lb>1){ long long mid = (ub+lb)/2; long long len = max(0LL, h_[2] - d*mid); if(len >= h_[1]){ lb = mid; }else{ ub = mid; } } h_[2] = max(0LL, h_[2] - d*ub); tmp += ub; if(h_[0] == h_[2]){ h_[0] = max(0LL, h_[0] - d*ub); tmp++; } if(check(h_)){ ans = tmp; } } { // h[1] < h[0],h[2] vector h_ = h; long long tmp = 0; long long lb = -1; long long ub = 1e10; while(ub-lb>1){ long long mid = (ub+lb)/2; long long len = max(0LL, h_[1] - d*mid); if(len >= h_[0] || len >= h_[2]){ lb = mid; }else{ ub = mid; } } h_[1] = max(0LL, h_[1] - d*ub); tmp += ub; if(h_[0] == h_[2]){ h_[0] = max(0LL, h_[0] - d*ub); tmp++; } if(h_[0] == h_[1]){ h_[1] = max(0LL, h_[1] - d*ub); tmp++; } if(check(h_)){ if(ans == -1){ ans = tmp; }else{ ans = min(ans, tmp); } } } cout << ans << endl; return 0; }