#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
signed split(long long x) {
  long long cnt = 0;
  for (long long i = 0; i <= 50; i++)
    if ((x >> i) & 1) cnt++;
  return cnt;
}
long long case1(long long n) {
  long long ret = 0;
  for (long long i = 1; i <= 50; i++) {
    long long x = n / ((1ll << (i)) - 1);
    if (!x) break;
    for (long long j = 0; j < i; j++)
      if (((n - 1ll * x * ((1ll << (i)) - 1) + j) % 2 == 0) &&
          split((n - x * ((1ll << (i)) - 1) + j)) == j)
        ret++;
  }
  return ret;
}
long long f[55][55 * 3][2];
long long case2(long long n) {
  long long ret = 0;
  for (long long l = 2; l <= 50; l++)
    for (long long r = 2; r <= 50; r++) {
      long long x =
          (n - (1ll << (r - 1)) + 1) / ((1ll << (l)) + (1ll << (r)) - 3);
      if (!x) break;
      long long res =
          n - (1ll << (r - 1)) + 1 - x * ((1ll << (l)) + (1ll << (r)) - 3);
      for (long long cnt = 0; cnt <= l + r - 4; cnt++)
        if ((res + cnt) % 2 == 0) {
          for (long long i = 0; i <= max(l, r); i++)
            for (long long j = 0; j <= min(cnt, 2 * i); j++)
              f[i][j][0] = f[i][j][1] = 0;
          f[0][0][0] = 1;
          for (long long i = 1; i <= max(l, r); i++)
            for (long long j = 0; j <= min(cnt, 2 * (i - 1)); j++) {
              for (long long k = 0; k <= 1; k++)
                for (long long a = 0; a <= 1; a++)
                  for (long long b = 0; b <= 1; b++) {
                    if ((i >= l - 1 && a == 1) || (i >= r - 1 && b == 1))
                      continue;
                    if ((k + a + b) % 2 == ((res + cnt) >> i) % 2)
                      f[i][j + a + b][(k + a + b) / 2] += f[i - 1][j][k];
                  }
            }
          ret += f[max(l, r)][cnt][0];
        }
    }
  return ret;
}
signed main() {
  long long s = read();
  printf("%lld", case1(s) + case2(s));
  return 0;
}
