#include <bits/stdc++.h>
long solve(long n) {
  if (n == 0) return 1;
  if (n == 1) return 2;
  if (n % 2) {
    return 2 * solve(n / 2) + solve(n / 2 - 1);
  } else {
    return 2 * solve(n / 2 - 1) + solve(n / 2);
  }
}
int main() {
  long N;
  long i, j;
  long ans;
  scanf("%ld", &N);
  printf("%ld\n", solve(N));
  return 0;
}
