#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main() {
  long long n, on;
  scanf("%lld", &n);
  n--;
  on = n;
  long long ans = 0;
  long long now = 1;
  while (now <= on) {
    ans += max((n + 1) >> 1, 1LL) * now;
    n >>= 1;
    now <<= 1;
  }
  if (now & on) ans += now;
  printf("%lld\n", ans);
  return 0;
}
