#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, sum = 0;
  cin >> n;
  long long fact = 1;
  while (n != (long long)1) {
    if (n % (long long)2 == (long long)0) {
      n = n / (long long)2;
      sum += fact * n;
    } else {
      n = n / (long long)2 + (long long)1;
      sum += fact * (n - 1);
    }
    fact *= (long long)2;
  }
  cout << sum;
  return 0;
}
