#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int sum, suf, pre, max;
} Node;
int toint(const string &s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
const int N = 1e6 + 10;
const int inf = 1e9;
const int lim = 1e18 + 1;
const int mod = 1e9 + 7;
const double pi = 3.141592653589793238462643383;
const int M = 1e6 + 10;
const double Phi = 1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
long long int dp[50];
int main() {
  long long int n;
  cin >> n;
  for (int i = 1; i <= 50; ++i) dp[i] = 2 * dp[i - 1] + ((1LL) << (i - 1));
  n--;
  long long int ans = 0;
  for (int i = 0; i < 50; ++i) {
    if (n & (1LL << i)) {
      ans += (dp[i] + (1LL << i));
    }
  }
  cout << ans << endl;
  return 0;
}
