#include #define REP(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) using namespace std; typedef int64_t ll; const int INF = 1e8; const double EPS = 1e-10; int main() { ios_base::sync_with_stdio(false); ll a, b, sum = 0, ans = 0, x = 0; cin >> a; b = a; while(a) { sum += a; a /= 2LL; } while(b) { x += b; ans = max(ans, x+b-sum); b /= 2LL; } cout << ans << endl; }