#include <bits/stdc++.h>
int main() {
  long long int n, temp = 1, now;
  long long int ans = 0;
  scanf("%lld", &n);
  now = n;
  for (long long int i = 2; now > 1; i <<= 1) {
    ans += (now / 2) * temp;
    now -= now / 2;
    temp <<= 1;
  }
  printf("%lld\n", ans);
}
