#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> p(50), hm(50);
  p[0] = 1;
  for (long long i = 1; i < 50; i++) p[i] = p[i - 1] * 2;
  hm[0] = 0;
  for (long long i = 1; i < 50; i++) hm[i] = 2 * hm[i - 1] + p[i - 1];
  long long sum = 0;
  for (long long i = 0; i < 49; i++) {
    if ((p[i] & n) != 0) {
      sum += hm[i] + p[i];
    }
  }
  for (long long i = 0; i < 49; i++) {
    if ((p[i] & n) != 0) {
      sum -= p[i];
      break;
    }
  }
  cout << sum;
  return 0;
}
