#include <bits/stdc++.h>
using namespace std;
const int N = 51;
long long rd() {
  long long x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
unordered_map<long long, long long> f[N][N];
long long sb[N], n;
long long dp(long long x, int l, int r) {
  if (f[l][r].find(x) != f[l][r].end()) return f[l][r][x];
  if (!l && !r) return 0;
  f[l][r][x] = 0;
  if (sb[l] + sb[r] < x) return 0;
  if (l > r) {
    f[l][r][x] = dp(x, l - 1, r);
    if (x - ((1ll << l) - 1) >= 0)
      f[l][r][x] += dp(x - ((1ll << l) - 1), l - 1, r);
  } else if (l < r) {
    f[l][r][x] = dp(x, l, r - 1);
    if (x - ((1ll << r) - 1) >= 0)
      f[l][r][x] += dp(x - ((1ll << r) - 1), l, r - 1);
  } else {
    f[l][r][x] = dp(x, l - 1, r - 1);
    if (x - ((1ll << l) - 1) >= 0)
      f[l][r][x] += 2 * dp(x - ((1ll << l) - 1), l - 1, r - 1);
    if (x - (((1ll << l) - 1) << 1) >= 0)
      f[l][r][x] += dp(x - (((1ll << l) - 1) << 1), l - 1, r - 1);
  }
  return f[l][r][x];
}
int main() {
  for (int i = 1; i < N; ++i) sb[i] = sb[i - 1] + (1ll << i) - 1;
  for (int l = 0; l < N; ++l)
    for (int r = 0; r < N; ++r) f[l][r][0] = 1;
  n = rd();
  long long ans = 0;
  for (int l = 0; l < N; ++l)
    for (int r = 0; r < N; ++r) {
      long long k = (1ll << (l + 1)) + (1ll << (r + 1)) - 3, b = (1ll << r) - 1;
      if (n < b + k) continue;
      long long m = n - k * ((n - b) / k) - b;
      ans += dp(m, max(l - 1, 0), max(r - 1, 0));
    }
  printf("%lld\n", ans);
  return 0;
}
