#include using namespace std; // Macro Tools ///////////////////////////////////////////////////////////////// #define GET_MACRO_09(A1, A2, A3, A4, A5, A6, A7, A8, A9, NAME, ...) NAME #define EXPAND_01(FIRST, NEXT, A) \ FIRST(A) #define EXPAND_02(FIRST, NEXT, A, B) \ FIRST(A) NEXT(B) #define EXPAND_03(FIRST, NEXT, A, B, C) \ FIRST(A) NEXT(B) NEXT(C) #define EXPAND_04(FIRST, NEXT, A, B, C, D) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) #define EXPAND_05(FIRST, NEXT, A, B, C, D, E) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) #define EXPAND_06(FIRST, NEXT, A, B, C, D, E, F) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) #define EXPAND_07(FIRST, NEXT, A, B, C, D, E, F, G) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G) #define EXPAND_08(FIRST, NEXT, A, B, C, D, E, F, G, H) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G) NEXT(H) #define EXPAND_09(FIRST, NEXT, A, B, C, D, E, F, G, H, I) \ FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G) NEXT(H) NEXT(I) #define EXPAND_ADD(FIRST, NEXT, ...) \ GET_MACRO_09(__VA_ARGS__, EXPAND_09, EXPAND_08, EXPAND_07, EXPAND_06, \ EXPAND_05, EXPAND_04, EXPAND_03, EXPAND_02, EXPAND_01) \ (FIRST, NEXT, __VA_ARGS__) #define EXPAND(MACRO, ...) EXPAND_ADD(MACRO, MACRO, __VA_ARGS__) #define Q(x) #x #define QUOTE(x) Q(x) // Input /////////////////////////////////////////////////////////////////////// #define RIGHT_SHIFT_BEFORE(a) >>a #define CAMMA_AND_ADDRESS(a) , &a #define INT_FORMATTER(a) %d #define SCANF_INT(a) scanf("%d", &(a)); // #define SCANF_LL(a) scanf("%I64d", &(a)); #define I(...) int __VA_ARGS__; EXPAND(SCANF_INT, __VA_ARGS__); // #define L(...) long long __VA_ARGS__; EXPAND(SCANF_LL, __VA_ARGS__); #define input(t,v) t v;cin>>v; #define input2(t,v1,v2) t v1,v2;cin>>v1>>v2; #define input3(t,v1,v2,v3) t v1,v2,v3;cin>>v1>>v2>>v3; #if __cplusplus > 199711L //C++11 template #else template #endif T read() { T t; cin >> t; return t; } // Types /////////////////////////////////////////////////////////////////////// typedef long long ll; typedef pair pii; typedef pair pll; typedef set si; typedef set sll; typedef vector vi; typedef vector vll; typedef list li; typedef list lll; typedef map mii; typedef map mil; typedef map mli; typedef map mll; // Loop & Iteration //////////////////////////////////////////////////////////// #define FOR(i, a, b) for(int i = (a), loop_end_##i=(b); i < (loop_end_##i); i++) #define REP(i, n) FOR(i, 0, n) #define rep(v,n) for(int (v)=0;(v)<(n);(v)++) #define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define SORT(c) sort((c).begin(),(c).end()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define PB push_back // Range /////////////////////////////////////////////////////////////////////// #define IN(x, a, b) (a<=x && xh2 && h2h3)) && h1!=h3){ printf("0\n"); return 0; } if(d==0){ printf("-1\n"); return 0; } if((h1==0 && h2<=d && h3<=d) || (h1<=d && h2<=d && h3==0)){ printf("-1\n"); return 0; } int ans0=0; if(h1==h3){ ans0=1; if(h1>0) h1=max(0, h1-d); if(h3>0) h3=max(0, h3-d); } int ans1=INT_MAX; if (min(h1, h3)){ int low = min(h1, h3)-1; ans1=(h2-low+d-1)/d; } int ans2=INT_MAX; ans2=(max(h1, h3)-(h2-1)+d-1)/d; printf("%d\n", ans0+min(ans1, ans2)); }