#include <bits/stdc++.h>
inline long long calcmn(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x + (1ll << (h2)) - 1;
}
inline long long calcmx(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x +
         ((1ll << (h1)) + (1ll << (h2 + 1)) - h1 - h2 - 3);
}
inline long long calc(long long S, int h1, int h2) {
  if (S < (1ll << (h2)) - 1) return -1;
  long long ret =
      (S - (1ll << (h2)) + 1) / ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
  if (!ret) return -1;
  return S <= calcmx(ret, h1, h2) ? ret : -1;
}
long long dp[80][160][2];
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  long long S;
  std::cin >> S;
  int lim = 65 - __builtin_clzll(S);
  long long ans = 0;
  for (int h1 = 0, h1_ = lim; h1 < h1_; ++h1)
    for (int h2 = 0, h2_ = lim; h2 < h2_; ++h2) {
      long long rt = calc(S, h1, h2);
      if (!~rt) continue;
      long long w = calcmn(rt, h1, h2);
      for (int k = 0, k_ = std::max(h1 - 1, 0) + std::max(h2 - 1, 0) + 1;
           k < k_; ++k) {
        long long x = S - w + k;
        int lim = 65 - (x ? __builtin_clzll(x) : 0);
        if (x & 1) continue;
        memset(dp, 0, sizeof(dp));
        dp[0][0][0] = 1;
        for (int i = 1, i_ = lim; i < i_; ++i)
          for (int j = 0, j_ = k + 1; j < j_; ++j) {
            if (x >> i & 1)
              dp[i][j][0] =
                  dp[i - 1][j][1] +
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][0] : 0),
              dp[i][j][1] =
                  j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][1] : 0;
            else
              dp[i][j][0] = dp[i - 1][j][0],
              dp[i][j][1] =
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][1] : 0) +
                  (j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][0] : 0);
          }
        ans += dp[lim - 1][k][0];
      }
    }
  std::cout << ans << std::endl;
}
