#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : ~x + 1;
}
long long s, ans;
long long f[70][210][2];
long long calc(long long tar, long long cnt, long long l1, long long l2) {
  if (tar & 1) return 0;
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  for (long long i = 1; i <= 60; ++i) {
    long long mx = (i <= l1) + (i <= l2);
    for (long long j = 0; j <= cnt; ++j) {
      if (!(tar & (1ll << i))) {
        f[i][j][0] += f[i - 1][j][0];
        if (j >= 2 && mx == 2) f[i][j][1] += f[i - 1][j - 2][0];
        if (j >= 1 && mx >= 1) f[i][j][1] += 1ll * mx * f[i - 1][j - 1][1];
      } else {
        f[i][j][0] += f[i - 1][j][1];
        if (j >= 1 && mx >= 1) f[i][j][0] += 1ll * mx * f[i - 1][j - 1][0];
        if (j >= 2 && mx == 2) f[i][j][1] += f[i - 1][j - 2][1];
      }
    }
  }
  return f[60][cnt][0];
}
signed main() {
  s = read();
  for (long long i = 1; (1ll << i - 1) <= s; ++i) {
    long long t = s / ((1ll << i) - 1);
    long long tmp = s - (t * ((1ll << i) - 1));
    if (t == 0 || tmp < 0) continue;
    for (long long j = i - 1; j > 0; --j) {
      if (tmp >= ((1ll << j) - 1)) tmp -= ((1ll << j) - 1);
    }
    if (tmp == 0) ++ans;
  }
  for (long long h1 = 1; (1ll << h1) <= s; ++h1) {
    for (long long h2 = 1; (1ll << h1) + (1ll << h2) <= s; ++h2) {
      long long x =
          (s - (1ll << h2) + 1) / ((1ll << h1 + 1) + (1ll << h2 + 1) - 3);
      long long tmp =
          x * ((1ll << h1 + 1) + (1ll << h2 + 1) - 3) + (1ll << h2) - 1;
      tmp = s - tmp;
      if (x == 0) continue;
      if (tmp < 0) continue;
      if (tmp == 0) {
        ++ans;
        continue;
      }
      for (long long k = 0; k < h1 + h2 - 1; ++k) {
        ans += calc(tmp + k, k, h1 - 1, h2 - 1);
      }
    }
  }
  printf("%lld\n", ans);
}
