#include <bits/stdc++.h>
using namespace std;
vector<long long int> a;
long long int lim = 1000000000000;
void precalc() {
  long long int cum = 0;
  for (long long int i = 1; i <= lim; i *= 2) {
    long long int newt = cum + i;
    a.push_back(newt);
    cum += newt;
  }
}
long long int foo(long long int n) {
  int p = 0;
  long long int ans = 0;
  while (n > 0) {
    if ((n % 2) == 1) {
      ans += a[p];
    }
    n /= 2;
    p++;
  }
  return ans;
}
int main() {
  precalc();
  long long int n;
  cin >> n;
  cout << foo(n - 1) << endl;
}
