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