#include <bits/stdc++.h>
using namespace std;
long long n, ans, x, tmp, pw[55], f[55][55 << 1][2];
int m, now;
long long Calc(int cnt, int l1, int l2, long long x) {
  memset(f[now], 0, sizeof(f[now])), f[now][0][0] = 1, now ^= 1;
  for (int i = 1, tmp, j, mx = log2(x) + 1; i <= mx; ++i, now ^= 1) {
    memset(f[now], 0, sizeof(f[now]));
    for (tmp = x >> i & 1, j = 0; j <= (i - 1 << 1); ++j)
      for (int jw = 0; jw < 2; ++jw)
        if (f[now ^ 1][j][jw])
          for (int a = 0; a < 2; ++a)
            if (!a || i < l1)
              for (int b = 0; b < 2; ++b)
                if ((!b || i < l2) && (jw + a + b & 1) == tmp)
                  f[now][j + a + b][jw + a + b >> 1] += f[now ^ 1][j][jw];
  }
  return f[now ^ 1][cnt][0];
}
int main() {
  scanf("%lld", &n), pw[0] = m = 1;
  for (int i = 1; i <= 51; ++i)
    if ((pw[i] = pw[i - 1] << 1) <= n) m = i + 1;
  for (int i = 1, j; i <= m; ans += !tmp, ++i)
    if ((x = n / (pw[i] - (tmp = 1))) > 0)
      for (tmp = n - x * (pw[i] - 1), j = i - 1; ~j; --j)
        if (tmp >= pw[j] - 1) tmp -= pw[j] - 1;
  for (int i = 1; i <= m; ++i)
    for (int j = 1; pw[j] - 1 <= n; ++j)
      if ((x = (n - pw[j] + 1) / (pw[i + 1] + pw[j + 1] - 3)) > 0) {
        if (!(tmp = (n - pw[j] + 1) - x * (pw[i + 1] + pw[j + 1] - 3)))
          ++ans;
        else if (i == 1 && j == 1)
          ans += (tmp == 5 * x + 1);
        else
          for (int k = 1; k <= i + j; ++k)
            if (tmp + k + 1 & 1) ans += Calc(k, i, j, tmp + k);
      }
  printf("%lld", ans);
  return 0;
}
