#include <bits/stdc++.h>
using namespace std;
unsigned long long int n;
unsigned long long int dp[500];
unsigned long long int buscale(unsigned long long int val) {
  unsigned long long int pw = 1;
  while (pw <= val) pw *= 2;
  return pw /= 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  n--;
  unsigned long long int res = 0;
  while (n) {
    unsigned long long int i = 0;
    unsigned long long int pow = 1;
    for (; pow * 2 - 1 < n; i++) {
      dp[i] = pow;
      for (unsigned long long int j = 0; j < i; j++) dp[i] += dp[j];
      res += dp[i];
      pow *= 2;
    }
    pow = buscale(n);
    res += pow;
    n -= pow;
  }
  cout << res << endl;
  return 0;
}
