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