#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> memo;
long long solve(long long n) {
  if (memo.find(n) != memo.end()) return memo[n];
  if (n == 0) return 0;
  int i;
  for (i = 60; i >= 0; --i)
    if (n & (1ll << i)) break;
  long long ans = 0;
  ans += solve((1ll << i) - 1);
  ans += solve((1ll << i) ^ n);
  ans += 1ll << i;
  return memo[n] = ans;
}
int main(void) {
  long long n;
  scanf("%lld", &n);
  printf("%lld\n", solve(n - 1));
}
