#include <bits/stdc++.h>
using namespace std;
const int N = 53;
long long S, L, ans;
long long P[N] = {1};
long long f[N][N * 2][2];
int main() {
  scanf("%lld", &S);
  L = log2(S + 1);
  for (int i = 1; i < N; ++i) P[i] = P[i - 1] << 1;
  for (int h = 1; h <= L; ++h) {
    long long x = S % (P[h] - 1);
    for (int i = h; i; --i)
      if (x >= P[i] - 1) x -= P[i] - 1;
    ans += (!x);
  }
  for (int h0 = 1; h0 < L; ++h0)
    for (int h1 = 1; S + 1 - P[h1] >= P[h0 + 1] + P[h1 + 1] - 3; ++h1) {
      long long x = (S + 1 - P[h1]) / (P[h0 + 1] + P[h1 + 1] - 3);
      long long r = (S + 1 - P[h1]) % (P[h0 + 1] + P[h1 + 1] - 3);
      if (!r) {
        ans++;
        continue;
      }
      if (h0 == 1 && h1 == 1) {
        ans += (S == x * 5 + 1);
        continue;
      }
      for (int n = 1; n <= h0 + h1; ++n) {
        long long C = r + n, L = log2(C);
        if (C & 1) continue;
        memset(f[0], 0, sizeof f[0]);
        f[0][0][0] = 1;
        for (int i = 1; i <= L; ++i) {
          int d = (C >> i) & 1;
          memset(f[i], 0, sizeof f[i]);
          for (int j = 0; j <= i + i - 2 && j <= n; ++j)
            for (int k = 0; k < 2; ++k)
              if (f[i - 1][j][k])
                for (int x = 0; x < 2; ++x)
                  if (!x || i < h0)
                    for (int y = 0; y < 2; ++y)
                      if (!y || i < h1)
                        if (((k + x + y) & 1) == d)
                          f[i][j + x + y][(k + x + y) >> 1] += f[i - 1][j][k];
        }
        ans += f[L][n][0];
      }
    }
  printf("%lld\n", ans);
  return 0;
}
