#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans;
long long f[150][2], g[150][2];
long long solve(int pos, int lena, int lenb, long long sum) {
  for (int i = 0; i <= pos; i++) {
    f[i][0] = f[i][1] = 0;
  }
  f[0][0] = 1;
  for (int i = 0; (1ll << i) <= sum; i++) {
    for (int j = 0; j <= pos; j++) {
      g[j][0] = f[j][0];
      f[j][0] = 0;
      g[j][1] = f[j][1];
      f[j][1] = 0;
    }
    for (int j = 0; j <= 1; j++) {
      for (int k = 0; k <= 1; k++) {
        if ((i < lena || !j) && (i < lenb || !k)) {
          for (int l = 0; l <= 1; l++) {
            int d = j + k + l;
            if (((sum >> i) & 1) ^ (d & 1)) continue;
            for (int o = 0; o + j + k <= pos; o++) {
              f[o + j + k][d >> 1] += g[o][l];
            }
          }
        }
      }
    }
  }
  return f[pos][0];
}
int main() {
  scanf("%I64d", &n);
  for (int i = 0; i <= 58; i++) {
    for (int j = 0; j <= 58; j++) {
      long long mul = (1ll << i + 1) + (1ll << j + 1) - 3;
      if (n < mul) break;
      long long now = n % mul - (1ll << j) + 1;
      if (now < 0) continue;
      for (int k = now & 1; k <= i + j; k += 2) {
        ans += solve(k, i - 1, j - 1, (now + k) >> 1);
      }
    }
  }
  printf("%I64d\n", ans);
}
