#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x;
}
long long n, ans;
long long f[140][2], g[140][2];
long long dp(int one, int lena, int lenb, long long sum) {
  for (int j = 0; j <= one; ++j) f[j][0] = f[j][1] = 0;
  f[0][0] = 1;
  for (int i = 0; (1ll << i) <= sum; ++i) {
    for (int j = 0; j <= one; ++j)
      g[j][0] = f[j][0], f[j][0] = 0, g[j][1] = f[j][1], f[j][1] = 0;
    for (int j = 0; j <= 1; ++j)
      if (i < lena || !j)
        for (int k = 0; k <= 1; ++k)
          if (i < lenb || !k)
            for (int l = 0; l <= 1; ++l) {
              int d = j + k + l;
              if (((sum >> i) & 1) ^ (d & 1)) continue;
              for (int m = 0; m + j + k <= one; ++m)
                f[m + j + k][d >> 1] += g[m][l];
            }
  }
  return f[one][0];
}
int main() {
  n = read();
  for (int i = 0; i <= 58; ++i)
    for (int j = 0; j <= 58; ++j) {
      long long mul = (1ll << i + 1) + (1ll << j + 1) - 3;
      if (n < mul) break;
      long long now = n % mul - (1ll << j) + 1;
      if (now < 0) continue;
      int cnt = i + j;
      for (int k = now & 1; k <= cnt; k += 2) {
        long long tot = now + k;
        ans += dp(k, i - 1, j - 1, tot >> 1);
      }
    }
  printf("%I64d\n", ans);
}
