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