#include <bits/stdc++.h>
using namespace std;
long long qpow[60], f[60][60 << 1][2];
long long calc1(long long a, long long b) {
  long long lca = a, tmp = b, sum = 0;
  int la = log2(a), lb = log2(b);
  for (int i = la; i < lb; i++) tmp >>= 1;
  for (int i = lb; i < la; i++) lca >>= 1;
  while (tmp != lca) tmp >>= 1, lca >>= 1;
  int LLCA = log2(lca);
  if (a == lca && b == lca) return lca;
  if (a == lca || b == lca) {
    if (b == lca) swap(a, b), swap(la, lb);
    sum = lca * ((1ll << (lb - LLCA + 1)) - 1);
    for (int i = 1; b > lca; i++, b >>= 1) sum += (b & 1) * ((1ll << i) - 1);
  } else {
    if ((a >> (la - LLCA - 1)) & 1) swap(a, b), swap(la, lb);
    sum = lca * ((1ll << (la - LLCA + 1)) + (1ll << (lb - LLCA + 1)) - 3) +
          (1ll << (lb - LLCA)) - 1;
    lca = lca << 1 | 1;
    for (int i = 1; a > lca; i++, a >>= 1) sum += (a & 1) * ((1ll << i) - 1);
    for (int i = 1; b > lca; i++, b >>= 1) sum += (b & 1) * ((1ll << i) - 1);
  }
  return sum;
}
long long calc2(long long S, int d) {
  long long ans = 0;
  int L = min((int)log2(S + 1), d);
  for (int h = 1; h <= L; h++) {
    long long x = S / (qpow[h] - 1);
    if (h + (int)log2(x) > d) continue;
    x = S % (qpow[h] - 1);
    for (int i = h; i; i--)
      if (x >= qpow[i] - 1) x -= qpow[i] - 1;
    ans += (!x);
  }
  for (int h0 = 1; h0 < L; h0++)
    for (int h1 = 1; S + 1 - qpow[h1] >= qpow[h0 + 1] + qpow[h1 + 1] - 3;
         h1++) {
      long long x = (S + 1 - qpow[h1]) / (qpow[h0 + 1] + qpow[h1 + 1] - 3);
      long long r = (S + 1 - qpow[h1]) % (qpow[h0 + 1] + qpow[h1 + 1] - 3);
      if (max(h0, h1) + 1 + (int)log2(x) > d) continue;
      if (!r) {
        ans++;
        continue;
      }
      if (h0 == 1 && h1 == 1) {
        ans += (S == x * 5 + 1);
        continue;
      }
      for (int n = 1; n <= h0 + h1; n++) {
        long long C = r + n, L = log2(C);
        if (C & 1) continue;
        memset(f[0], 0, sizeof f[0]);
        f[0][0][0] = 1;
        for (int i = 1; i <= L; i++) {
          int d = (C >> i) & 1;
          memset(f[i], 0, sizeof f[i]);
          for (int j = 0; j <= i * 2 - 2 && j <= n; j++)
            for (int k = 0; k < 2; k++)
              if (f[i - 1][j][k])
                for (int x = 0; x < 2; x++)
                  if (!x || i < h0)
                    for (int y = 0; y < 2; y++)
                      if (!y || i < h1)
                        if (((k + x + y) & 1) == d)
                          f[i][j + x + y][(k + x + y) >> 1] += f[i - 1][j][k];
        }
        ans += f[L][n][0];
      }
    }
  return ans;
}
int main() {
  qpow[0] = 1;
  for (int i = 1; i < 60; i++) qpow[i] = qpow[i - 1] << 1;
  long long S;
  scanf("%lld\n", &S);
  printf("%lld\n", calc2(S, 100));
}
