#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k = p - 2) {
  register long long re = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) re = re * x % p;
  return re;
}
long long S;
long long mul[77];
long long ans = 0;
long long calc(long long re, int l, int r, int n) {
  if (l > r) swap(l, r);
  static long long f[55][105][2];
  if (re & 1) return 0;
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  for (int i = 0; i <= 52; i++)
    for (int j = 0; j <= n; j++)
      if (re >> (i + 1) & 1) {
        f[i + 1][j][0] += f[i][j][1];
        if (i + 1 <= r) f[i + 1][j + 1][0] += f[i][j][0];
        if (i + 1 <= l) f[i + 1][j + 1][0] += f[i][j][0];
        if (i + 1 <= l) f[i + 1][j + 2][1] += f[i][j][1];
      } else {
        f[i + 1][j][0] += f[i][j][0];
        if (i + 1 <= r) f[i + 1][j + 1][1] += f[i][j][1];
        if (i + 1 <= l) f[i + 1][j + 1][1] += f[i][j][1];
        if (i + 1 <= l) f[i + 1][j + 2][1] += f[i][j][0];
      }
  return f[53][n][0];
}
int main() {
  read(S);
  for (int i = 0; i <= 50; i++) mul[i] = 1ll << i;
  for (int i = 1; i <= 50; i++) {
    long long x = S / (mul[i] - 1);
    if (x == 0) break;
    if ((x + 1) * (mul[i] - 1) - i < S) continue;
    long long re = S - x * (mul[i] - 1);
    for (int j = i - 1; j >= 1; j--)
      if (re >= mul[j] - 1) re -= mul[j] - 1;
    if (re == 0) ans++;
  }
  for (int l = 2; l <= 50; l++)
    for (int r = 2; r <= 50; r++) {
      long long Base = mul[l] + mul[r] - 3;
      long long x = (S - (mul[r - 1] - 1)) / Base;
      if (x <= 0) continue;
      long long re = S - (x * Base + mul[r - 1] - 1);
      for (int n = 0; n <= l + r - 3; n++) ans += calc(re + n, l - 2, r - 2, n);
    }
  printf("%lld\n", ans);
  return 0;
}
