#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[60][120][2];
long long solve(long long sum, int lena, int lenb, int bit) {
  memset(dp, 0, sizeof(dp));
  int i;
  dp[0][0][0] = 1;
  for (i = 1; 1LL << i <= sum; ++i) {
    int d = sum >> i & 1;
    for (int j = 0; j <= bit; ++j)
      for (int x = 0; x < 2; ++x)
        if (!x || i < lena)
          for (int y = 0; y < 2; ++y)
            if (!y || i < lenb) {
              if ((x + y) % 2 == d)
                dp[i][j + x + y][x + y >> 1] += dp[i - 1][j][0];
              else
                dp[i][j + x + y][x + y + 1 >> 1] += dp[i - 1][j][1];
            }
  }
  return dp[i - 1][bit][0];
}
int main() {
  cin >> n;
  long long ans = 0;
  for (int i = 0; i <= 58; ++i) {
    for (int j = 0; j <= 58; ++j) {
      long long x =
          (n - (1LL << j) + 1) / ((1LL << i + 1) + (1LL << j + 1) - 3);
      if (!x) continue;
      long long res =
          n - (1LL << j) + 1 - x * ((1LL << i + 1) + (1LL << j + 1) - 3);
      if (!res) {
        ++ans;
        continue;
      }
      for (int k = 1; k <= i + j - (!i) - (!j); ++k)
        if ((res + k) % 2 == 0) ans += solve(res + k, i, j, k);
    }
  }
  cout << ans;
  return 0;
}
