#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { ll n; cin >> n; vector a(0); while (n) { a.push_back(n); n >>= 1; } ll sum = accumulate(a.begin(), a.end(), 0LL); ll sum2 = sum; ll ans = 0; while (a.size() > 1) { sum2 -= a.back(); a.pop_back(); ans = max(ans, sum2 + a.back() - sum); } cout << ans << endl; return 0; }