#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) using namespace std; typedef long long ll; ll dp[40][1 << 16]; ll dp2[40][1 << 16]; int main() { ll N; cin >> N; ll mask = 0xffff; rep (i, 40) repr (j, 1 << 16) { ll next = j + __builtin_popcount(j) + i; if (next >= 1 << 16) { dp[i][j] = 1; dp2[i][j] = next & mask; } else { dp[i][j] = dp[i][next] + 1; dp2[i][j] = dp2[i][next]; } } ll ans = 1; ll high = 0, low = 1; while ((high << 16) + low < N) { ll next_high = high + 1; ll next_low = dp2[__builtin_popcount(high)][low]; if (N >= (next_high << 16) + next_low) { ans += dp[__builtin_popcount(high)][low]; high = next_high; low = next_low; } else { low += __builtin_popcount(low) + __builtin_popcount(high); high += low / (1 << 16); low &= mask; ans++; } } if ((high << 16) + low > N) ans = -1; cout << ans << endl; return 0; }