#include <bits/stdc++.h>
using namespace std;
const long long int N = 65;
long long int n, Memo[65], pw[65], ans;
int32_t main() {
  cin >> n;
  for (long long int i = 0; i <= 50; ++i) {
    Memo[i] = (1LL << i);
    for (long long int j = 0; j < i; ++j) Memo[i] += Memo[j];
  }
  --n;
  for (long long int i = 50; i >= 0 and n; --i)
    if (n & (1LL << i)) {
      for (long long int j = 0; j < i; ++j) ans += Memo[j];
      ans += (1LL << i), n ^= (1LL << i), i = 51;
    }
  cout << ans << endl;
  return 0;
}
