#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cache;
long long msb(long long n) {
  assert(n > 0);
  long long res = -1;
  while (n > 0) {
    n /= 2, res++;
  }
  return res;
}
long long solve(long long n) {
  if (n <= 1)
    return 0;
  else if (n == 2)
    return 1;
  if (cache.count(n)) return cache[n];
  long long L = 1ll << (msb(n - 1));
  return cache[n] = (1ll << (msb(n - 1))) + solve(L) + solve(n - L);
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
  return 0;
}
