#include <bits/stdc++.h>
using namespace std;
const long long N = 42;
long long n, ans, t, q;
int32_t main() {
  cin >> n;
  for (long long i = 0; i < N; i++) {
    q = (n + (1LL << i) - 1) / (1LL << i);
    q /= 2;
    ans += q * (1LL << i);
  }
  cout << ans;
}
