#include #include #include #include #include using namespace std; int main() { int d; cin >> d; int h1, h2, h3; cin >> h1 >> h2 >> h3; if(h1 != h2 && h1 != h3 && h2 != h3) { if(h1 < h2 && h3 < h2) { cout << 0; return 0; } if(h1 > h2 && h3 > h2) { cout << 0; return 0; } if(h1 > h2 && h1 > h3) // h2 > h3 { int temp = h1; h1 = h3; h3 = temp; } // h1 < h2 < h3 int mh3 = (h3 - h2) / d + 1; int mh2 = (h2 - h1) / d + 1; if(h2 - mh2*d >= 0 && h3 - mh3*d >= 0) { cout << min(mh2, mh3); } else if(h2 - mh2*d >= 0) { cout << mh2; } else if( h3 - mh3*d >= 0) { cout << mh3; } else { cout << -1; } return 0; } if(h1 == h2 == h3) { if(h1 - d*2 >= 0) { cout << 3; } else { cout << -1; } return 0; } if(h1 == h3) { if(h1 < d) { cout << -1; } else { if(h2 > h1) { cout << 1; } else { int mh3 = (h3 - h2) / d + 2; if(h3 - mh3*d <0) { cout << -1; } else { cout << mh3 * 2 - 1; } } } return 0; } if(h1 == h2) { h1 = h3; h3 = h2; } // h1 != h2 == h3 if(h1 < h2) { int mh3 = (h3 - h2) / d + 2; if(h3 - mh3*d == h1) mh3++; if(h3 - mh3*d < 0) { cout << -1; } else { cout << mh3; } return 0; } else { if(h2 >= d) { cout << 1; } else { cout << -1; } return 0; } cout << -1; return 0; }