#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 rt return #define FOR(i,j,k) for(int i=j; i<(int)k;++i) #define rep(i,j) for(int i=0;i<(int)j;++i) #define rep1(i,j) for(int i=1;i<=(int)j;++i) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define pb_ push_back #define eb_ emplace_back #define fi_ first #define se_ second #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; int D, H1, H2, H3; void f(){ if(D == 0){ if(H1 != H2&&H2 != H3&&H3 != H1 && ((H2

H1&&H2 > H3))){ cout << 0 << endl; } else{ cout << -1 << endl; } rt; } // h2が低い ll h1 = H1, h2 = H2, h3 = H3, ans = LLONG_MAX; if(h1 != 0 && h3 != 0){ ll tmp = 0; if(h1 > h3)swap(h1, h3); if(h1 == h3) h1 = max(0ll, h1 - D), tmp = 1; if(h1){ if(h2 >= h1){ tmp += (h2 - h1 + D) / D; h2 = max(0ll, h2 - (h2 - h1 + D) / D*D); } if(h1 != h2 && h2 != h3&&h3 != h1){ smin(ans, tmp); } } } //h2が高い ll tmp = 0; h1 = H1, h2 = H2, h3 = H3; if(h1 >= h2){ ll cost = (h1 - h2 + D) / D; h1 = max(0ll, h1 - cost*D); tmp += cost; } if(h3 >= h2){ ll cost = (h3 - h2 + D) / D; h3 = max(0ll, h3 - cost*D); tmp += cost; } if(h1 > h3)swap(h1, h3); if(h1 == h3){ ++tmp; h1 = max(0ll, h1 - D); } if(h1 != h2&&h2 != h3&&h3 != h1)smin(ans, tmp); if(ans != LLONG_MAX)cout << ans << endl; else cout << -1 << endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); while(cin >> D >> H1 >> H2 >> H3){ f(); } }