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