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