#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; ll tot = 0; vector divs; for (ll i = 59; i >= 1; --i) { ll div = 1ll << i; divs.push_back(div); tot += N / div - tot; } auto f = [&](ll x) { if (!x)return 0; for (int i = 0; i < sz(divs); ++i) if (x%divs[i] == 0) return 59 - i; return 0; }; ll ans = N + 1; ll cnt = tot; for (ll x = 0; x <= ((N + 1) >>1); ++x) { ll y = N - x; if (x > y || cnt < tot)break; if (x == y)ans--; else ans -= 2; cnt += f(x + 1); cnt -= f(y); } cout << ans << endl; }