#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  scanf("%I64d", &n);
  long long ans = 0;
  for (int i = 0; (1LL << i) < n; ++i)
    ans += ((n - 1 - (1LL << i)) / (1LL << (i + 1)) + 1) * (1LL << i);
  printf("%I64d", ans);
}
