#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  long long curr = 1;
  n--;
  while (n) {
    int extra = n % 4;
    long long coll = n / 4;
    ans += coll * 4 * curr;
    n /= 4;
    long long t = 0;
    if (extra == 1)
      t += 1;
    else if (extra == 2)
      t += 3;
    else if (extra == 3)
      t += 4;
    t *= curr;
    curr *= 4;
    ans += t;
  }
  cout << ans << endl;
  return 0;
}
