#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
template <typename T>
void add(T &x, T y, T mod) {
  x = x + y > mod ? x + y - mod : x + y;
}
template <typename T>
void sub(T &x, T y, T mod) {
  x = x - y < 0 ? x - y + mod : x - y;
}
template <typename T>
void multi(T &x, T y, T mod) {
  x = 1ll * x * y % mod;
}
const int INF = (1ll << 30);
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 50 + 5;
long long s, ans, f[N][N << 1][2];
int n;
inline bool check(long long res, long long x) {
  for (int i = x - 1; i >= 0; i--)
    if (res >= ((1ll << i) - 1)) res -= ((1ll << i) - 1);
  return res == 0;
}
inline long long dp(long long bit, long long n, long long m, long long ret) {
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  int pos = 1;
  for (int i = 1; (1ll << i) <= ret; i++) {
    pos = i;
    for (int j = 0; j <= bit; j++) {
      for (int x = 0; x < 2; x++) {
        if (!x || i < n) {
          for (int y = 0; y < 2; y++) {
            if (!y || i < m) {
              if (((x + y) & 1) == (ret >> i & 1))
                f[i][j + x + y][(x + y) >> 1] += f[i - 1][j][0];
              else
                f[i][j + x + y][(x + y + 1) >> 1] += f[i - 1][j][1];
            }
          }
        }
      }
    }
  }
  return f[pos][bit][0];
}
int main() {
  read(s);
  for (int i = 1; i < 55; i++) {
    long long x = s / ((1ll << i) - 1);
    long long res = s - ((1ll << i) - 1) * x;
    if (!x) continue;
    if (check(res, i)) ans++;
  }
  for (int h1 = 1; h1 < 55; h1++) {
    for (int h2 = 1; h2 < 55; h2++) {
      long long x =
          (s - (1ll << h2) + 1) / ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
      if (!x) continue;
      long long ret =
          s - (1ll << h2) + 1 - x * ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
      if (!ret) {
        ans++;
        continue;
      }
      for (int k = 1; k <= h1 + h2; k++)
        if ((ret + k) % 2 == 0) ans += dp(k, h1, h2, ret + k);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
