#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
long long s, f[MAXN][MAXN * 2][2], pw[MAXN];
inline long long dp(long long s, int a, int b, int t) {
  memset(f, 0, sizeof(f));
  f[1][0][0] = 1;
  for (int i = 1; i <= log2(s) + 1; i++) {
    int v = (s >> i) & 1;
    for (int j = 0; j <= 2 * i - 2; j++)
      for (int k = 0; k <= 1; k++)
        if (f[i][j][k])
          for (int x = 0; x <= 1; x++)
            if (!x || i < a)
              for (int y = 0; y <= 1; y++)
                if (!y || i < b)
                  if ((k + x + y) % 2 == v)
                    f[i + 1][j + x + y][(k + x + y) / 2] += f[i][j][k];
  }
  return f[(int)log2(s) + 2][t][0];
}
int main() {
  cin >> s;
  pw[0] = 1;
  for (int i = 1; i <= 60; i++) pw[i] = pw[i - 1] << 1;
  long long ans = 0;
  for (int h = 1; (pw[h] - 1) <= s; h++) {
    long long x = s / (pw[h] - 1);
    long long y = s - x * (pw[h] - 1);
    for (int i = 60; i >= 1; i--)
      if (y >= pw[i] - 1) y -= pw[i] - 1;
    if (!y) ans++;
  }
  for (int i = 1; (pw[i] - 1) <= s; i++)
    for (int j = 1; (pw[j] - 1) <= s; j++) {
      long long x = (s - pw[j] + 1) / (pw[i + 1] + pw[j + 1] - 3);
      if (!x) continue;
      long long y = (s - pw[j] + 1) - x * (pw[i + 1] + pw[j + 1] - 3);
      if (!y) {
        ans++;
        continue;
      }
      if (i == 1 && j == 1) {
        if (y == 5 * x + 1) ans++;
        continue;
      }
      for (int k = 1; k <= i + j; k++)
        if ((y + k) % 2 == 0) ans += dp(y + k, i, j, k);
    }
  cout << ans << endl;
  return 0;
}
