#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3c3c3c3c;
const long long infl = 0x3c3c3c3c3c3c3c3c;
long long N;
bool isSqr(long long x) {
  long long lo = 0, hi = 50;
  while (lo < hi) {
    long long mid = lo + hi >> 1;
    if ((1ll << mid) < x)
      lo = mid + 1;
    else if (x < (1ll << mid))
      hi = mid;
    else
      return true;
  }
  return lo * lo == x;
}
long long go(long long x) {
  if (!x) return 0;
  if (x == 2) return 1;
  int cnt = 0;
  long long tmp = x;
  while (x) {
    cnt++;
    x >>= 1;
  }
  cnt--;
  x = tmp;
  if (isSqr(x)) return cnt * x / 2;
  return go(x - (1ll << cnt)) + go(1ll << cnt) + (1ll << cnt);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> N;
  cout << go(N);
}
