#include <bits/stdc++.h>
using namespace std;
int IN() {
  int x = 0, f = 0, ch;
  for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-');
  for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0';
  return f ? -x : x;
}
int A[105];
long long S, T, Ans, F[105][105][2];
long long Work(int h1, int h2) {
  long long ret = 0;
  for (int s = 0, lim = h1 + h2; s <= lim; s++) {
    T += s;
    for (int i = 0, lim = 50; i <= lim; i++) A[i] = ((1ll << i) & T) > 0;
    if (A[0]) {
      T -= s;
      continue;
    }
    for (int i = 0, lim = 50; i <= lim; i++)
      for (int j = 0, lim = s; j <= lim; j++)
        for (int k = 0, lim = 1; k <= lim; k++) F[i][j][k] = 0;
    F[0][0][0] = 1;
    for (int i = 1, lim = 50; i <= lim; i++)
      for (int j = 0, lim = s; j <= lim; j++)
        for (int k = 0, lim = 1; k <= lim; k++)
          if (F[i - 1][j][k]) {
            for (int a = 0, lim = i < h1; a <= lim; a++)
              for (int b = 0, lim = i < h2; b <= lim; b++) {
                int c = k + a + b;
                if ((c & 1) != A[i]) continue;
                F[i][j + a + b][c >> 1] += F[i - 1][j][k];
              }
          }
    ret += F[50][s][0];
    T -= s;
  }
  return ret;
}
int main(int argc, char* argv[]) {
  cin >> S;
  for (int h1 = 0, lim = 50; h1 <= lim; h1++)
    for (int h2 = 0, lim = 50; h2 <= lim; h2++) {
      long long x = S + 1 - (1ll << h2);
      x /= ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
      if (x <= 0) break;
      T = ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x + (1ll << h2) - 1;
      T = S - T;
      Ans += Work(h1, h2);
    }
  cout << Ans << endl;
  return 0;
}
