#include <bits/stdc++.h>
using namespace std;
long long solve(long long n) {
  if (n == 0) return 1;
  if (n == 1) return 2;
  return solve(n / 2) + solve((n - 1) / 2) + solve((n - 2) / 2);
}
int main() {
  long long n;
  while (~scanf("%lld", &n)) {
    printf("%lld\n", solve(n));
  }
  return 0;
}
