#include <bits/stdc++.h>
using namespace std;
long long dp[41];
void prec() {
  dp[0] = 0;
  long long x = 1;
  for (int i = int(1); i < int(41); i++) {
    dp[i] = 2 * dp[i - 1] + x;
    x = x << 1;
  }
}
int main(int argc, const char* argv[]) {
  long long n;
  cin >> n;
  prec();
  n--;
  long long ans = 0;
  long long original = n;
  while (n) {
    long long r = n & (-n);
    ans += dp[(int)log2(r)];
    n -= r;
  }
  long long i = 1;
  while (i <= original) {
    ans += i & original;
    i = i << 1;
  }
  cout << ans << endl;
  return 0;
}
