#include <bits/stdc++.h>
using namespace std;
inline long long digit_dp(int c, int a, int b, long long s) {
  long long dp[2][105][2] = {0};
  dp[1][0][0] = 1;
  int i;
  for (i = 0; (1ll << i) <= s; i++) {
    memset(dp[i & 1], 0, sizeof dp[i & 1]);
    for (int p = 0; p <= c; p++)
      for (int xx = 0; !xx || xx <= 1 && i < a; xx++)
        for (int yy = 0; !yy || yy <= 1 && i < b; yy++) {
          int t = ((s >> i) & 1) ^ yy ^ xx;
          dp[i & 1][p + xx + yy][(t + xx + yy) >> 1] += dp[(i & 1) ^ 1][p][t];
        }
  }
  return dp[(i & 1) ^ 1][c][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long ans = 0, s;
  cin >> s;
  for (int L = 0; s >= (1ll << (L + 1)) - 1; L++)
    for (int R = 0;; R++) {
      long long x =
          (s - (1ll << R) + 1) / ((1ll << (L + 1)) + (1ll << (R + 1)) - 3);
      if (x < 1) break;
      long long r =
          s + 3 * x + (R >= 1) -
          2 * ((x << L) + ((R == 0) ? x : (((x << 1) | 1) << (R - 1))));
      for (int c = 0; c <= max(0, L - 1) + max(0, R - 1); c++)
        if (!((r + c) & 1))
          ans += digit_dp(c, max(0, L - 1), max(0, R - 1), (r + c) >> 1);
    }
  cout << ans << endl;
  return 0;
}
