#include <bits/stdc++.h>
using namespace std;
long long ara[41];
int main() {
  ara[0] = 1;
  for (long long i = 1; i < 41; i++) {
    ara[i] = (ara[i - 1] * 2) + (1LL << (i - 1));
  }
  long long n;
  cin >> n;
  n--;
  long long sum = 0;
  for (long long i = 40; i >= 0; i--) {
    if (n >= (1LL << i)) {
      n -= (1LL << i);
      sum += ara[i];
    }
  }
  cout << sum << endl;
  return 0;
}
