#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c > 57 || c < 48) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c > 47 && c < 58) x = x * 10 + c - 48, c = getchar();
  return x * f;
}
long long s, ans;
long long f[140][2], g[140][2];
long long solve(int o, int l0, int l1, long long tot) {
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int i = 0; 1LL << i <= tot; i++) {
    memcpy(g, f, sizeof(f));
    memset(f, 0, sizeof(f));
    for (int d0 = 0; d0 <= 1; d0++)
      if (d0 == 0 || i < l0)
        for (int d1 = 0; d1 <= 1; d1++)
          if (d1 == 0 || i < l1)
            for (int jw = 0; jw <= 1; jw++) {
              int dig = d0 + d1 + jw;
              if (dig % 2 != ((tot >> i) & 1)) continue;
              for (int k = 0; k + d0 + d1 <= o; k++)
                f[k + d0 + d1][dig / 2] += g[k][jw];
            }
  }
  return f[o][0];
}
int main() {
  s = read();
  for (int a = 0; a <= 58; a++)
    for (int b = 0; b <= 58; b++) {
      long long mul = (1LL << (a + 1)) - 1 + (1LL << (b + 1)) - 1 - 1;
      long long lca = s / mul;
      if (lca == 0) continue;
      long long rem = s - lca * mul - (1LL << b) + 1;
      for (int o = 0; o <= a + b; o++) {
        long long tot = rem + o;
        if (tot < 0 || (tot & 1)) continue;
        tot /= 2;
        ans += solve(o, max(a - 1, 0), max(b - 1, 0), tot);
      }
    }
  printf("%I64d", ans);
  return 0;
}
