#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int64_t N; cin >> N; function rec = [&](int64_t n, bool c) { if (n == 0) return INT64_C(0); int64_t res = n + rec(n / 2, c); if (c) { res = 0; } else { res = max(res, 2 * n + rec(n / 2, true)); } return res; }; int64_t A = 0, B = rec(N, false); while (N > 0) { A += N; N /= 2; } cout << abs(A - B) << '\n'; return 0; }