/** author: shobonvip created: 2026.08.06 03:40:39 **/ #include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } pair dp[70][140][70]; bool seen[70][140][70]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; auto f = [&](auto F, ll a, ll b, ll c) -> pair { if (seen[a][b][c]) return dp[a][b][c]; if (b >= (1LL<= 1 && b >= (1LL<<(c-1))) { auto [cnt_v, toc_v] = F(F, a+1, b-(1LL<<(c-1)), c-1); cnt = cnt_v; toc = toc_v + (1LL<<(c-1)); } else { auto [cnt_v, toc_v] = F(F, a, b, c-1); auto [cnt_w, toc_w] = F(F, a+1, toc_v - (1LL<<(c-1)), c-1); cnt = cnt_v + cnt_w; toc = toc_w + (1LL<<(c-1)); } dp[a][b][c] = pair(cnt, toc); seen[a][b][c] = 1; return dp[a][b][c]; }; ll a = 0; ll b = 1; ll ans = 0; rrep(c, 0, 60) { if (n >> c & 1) { auto [cnt, toc] = f(f, a, b, c); b = toc - (1LL << c); ans += cnt; a++; } } if (b == 0) { cout << ans + 1 << endl; } else { cout << -1 << endl; } }