#include <bits/stdc++.h>
using namespace std;
long long solve(long long n, long long points) {
  if (n == 0LL) return 0LL;
  long long numPairs = (n / 2 + (n % 2 ? 1 : 0));
  return solve(n / 2, points * 2) + numPairs * points;
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n - 1, 1LL) << endl;
  return 0;
}
