#include <bits/stdc++.h>
using namespace std;
long long sum, t = 1, n;
int main() {
  cin >> n;
  while (n >= 2) {
    sum += (n / 2) * t;
    n -= (n / 2);
    t *= 2;
  }
  cout << sum << endl;
  return 0;
}
