#include <bits/stdc++.h>
using namespace std;
int i, j, k, l, r, cnt, a, b;
long long s, p[52], f[52][102][2], ans;
int count(long long x) {
  int ans = 0;
  for (long long i = 0; (1LL << i) <= x; i++) {
    if (x & (1LL << i)) ans++;
  }
  return ans;
}
signed main() {
  scanf("%lld", &s);
  int h = log2(1.0 * s) + 1;
  for (i = p[0] = 1; i <= h; i++) p[i] = p[i - 1] * 2;
  for (l = 1; l <= h; l++) {
    long long x = s / (p[l] - 1);
    if (x == 0) break;
    for (cnt = 0; cnt <= l - 1; cnt++) {
      long long tmp = s - x * (p[l] - 1) + cnt;
      if (tmp % 2 == 0 && count(tmp) == cnt) ans++;
    }
  }
  for (l = 2; l <= h; l++) {
    for (r = 2; r <= h; r++) {
      long long x = (s - p[r - 1] + 1) / (p[l] + p[r] - 3);
      if (x == 0) break;
      for (cnt = 0; cnt <= l + r - 4; cnt++) {
        long long tmp = s - x * (p[l] + p[r] - 3) - p[r - 1] + 1 + cnt;
        if (tmp % 2 != 0) continue;
        memset(f, 0, sizeof(f));
        f[0][0][0] = 1;
        for (i = 1; i <= max(l, r); i++) {
          for (j = 0; j <= min(cnt, 2 * (i - 1)); j++) {
            for (k = 0; k <= 1; k++) {
              for (a = 0; a <= 1; a++) {
                for (b = 0; b <= 1; b++) {
                  if ((k + a + b) % 2 == (tmp >> i) % 2 &&
                      (a == 0 || i < l - 1) && (b == 0 || i < r - 1)) {
                    f[i][j + a + b][(k + a + b) / 2] += f[i - 1][j][k];
                  }
                }
              }
            }
          }
        }
        ans += f[max(l, r)][cnt][0];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
