#include <bits/stdc++.h>
using namespace std;
long long f[55][110][2];
long long work(long long s, int l1, int l2, int tot) {
  if (l1 == -1) l1 = 0;
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  for (int i = 1; i <= max(l1, l2); i++)
    for (int j = 0; j <= tot; j++)
      for (int k = 0; k <= 1; k++)
        if (f[i - 1][j][k]) {
          int cnt = (i <= l1) + (i <= l2);
          for (int t = 0; t <= 2; t++)
            if (t <= cnt && ((t + k) & 1) == (s >> i & 1)) {
              int w = 1;
              if (t == 1 && cnt == 2) w = 2;
              f[i][j + t][(k + t) >> 1] += w * f[i - 1][j][k];
            }
        }
  return f[max(l1, l2)][tot][s >> max(l1 + 1, l2 + 1) & 1];
}
int main() {
  long long s, ans = 0;
  cin >> s;
  for (int lc = 1; lc <= 50; lc++) {
    for (int rc = 2; rc <= 50; rc++) {
      long long t = (1LL << lc) + (1LL << rc) - 3;
      long long s0 = s / t;
      if (!s0) continue;
      for (int tot = 0; tot <= lc + rc - 2; tot++) {
        long long sum = s % t + tot;
        int k = max(lc - 1, rc - 1);
        if (sum & 1) continue;
        long long s2 = sum - (1LL << (rc - 1));
        if (0 <= s2 && s2 < 1LL << (k + 1)) {
          if (tot) ans += work(s2, lc - 2, rc - 2, tot - 1);
        }
        if (lc == 1) {
          long long s1 = sum;
          if (s1 < 0 || s1 > 1LL << (k + 1)) continue;
          ans += work(s1, lc - 2, rc - 2, tot);
        }
      }
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
