#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long ans = 0;
  ans += ((n + 3) / 4) * 4;
  if (n % 4 == 1) ans -= 4;
  if (n % 4 == 2) ans -= 3;
  if (n % 4 == 3) ans -= 1;
  n = (n + 3) / 4 - 1;
  long long k = 4;
  while (n) {
    long long x = (n + 1) / 2;
    ans += k * x;
    n -= x;
    k *= 2;
  }
  cout << ans << endl;
}
