#include <bits/stdc++.h>
long long n, ans = 0;
long long solve(long long n) {
  int p = __builtin_ctzll(n);
  return p * n >> 1;
}
int main() {
  std::cin >> n;
  ans = -(n & -n);
  for (; n; n &= n - 1) {
    long long tmp = n & -n;
    ans += tmp + solve(tmp);
  }
  std::cout << ans << std::endl;
  return 0;
}
