#include <bits/stdc++.h>
using namespace std;
void dec(long long &x, long long y) {
  if (x >= y) x -= y;
}
long long p(int x) { return 1ll << x; }
long long f[51][101][2];
long long calc(long long s, long long x, int a, int b, int n) {
  if (s & 1) return 0;
  if (n == 0) return s == 0 ? 1 : 0;
  if (a == 1 && b == 1) return ((s - n) == (x * 5 + 1)) ? 1 : 0;
  memset(f, 0, sizeof f);
  f[0][0][0] = 1;
  for (int i = 1; i <= 50; ++i) {
    int d = (s >> i) & 1;
    for (int j = 0; j <= 2 * (i - 1); ++j) {
      for (int aa = 0; aa <= 1; ++aa) {
        if (aa == 1 && i >= a) continue;
        for (int bb = 0; bb <= 1; ++bb) {
          if (bb == 1 && i >= b) continue;
          for (int k = 0; k <= 1; ++k) {
            if ((k + aa + bb) % 2 == d)
              f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
          }
        }
      }
    }
  }
  return f[50][n][0];
}
int main() {
  long long s;
  cin >> s;
  long long num = 0;
  for (int i = 1; i <= 50; ++i) {
    long long x = s / (p(i) - 1);
    if (x > 0) {
      long long last = s % (p(i) - 1);
      for (int j = i - 1; j >= 1; --j) dec(last, p(j) - 1);
      if (last == 0) ++num;
    }
  }
  for (int h1 = 1; h1 <= 50; ++h1) {
    for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
      long long x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
      if (x > 0) {
        long long last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
        for (int n = 0; n <= h1 + h2; ++n) {
          long long temp = calc(last + n, x, h1, h2, n);
          num += temp;
        }
      }
    }
  }
  cout << num << endl;
  return 0;
}
