#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = n / 2, div = 4, mul = 2, val, rem;
  while (1) {
    val = n / div;
    rem = (n % div);
    if (rem > div / 2) val++;
    if (val == 0) break;
    ans += (val * mul);
    mul *= 2;
    div *= 2;
  }
  printf("%lld\n", ans);
  return 0;
}
