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