#include <bits/stdc++.h>
int main() {
  long long n, res = 0, x;
  scanf("%I64d", &n);
  --n;
  for (int i = 0; (x = 1ll << i) <= n; ++i) res += x * ((n - x) / (x << 1) + 1);
  printf("%I64d\n", res);
  return 0;
}
