#include <bits/stdc++.h>
using namespace std;
long long dp[150][2], old[150][2];
inline long long DP(int ones, int len0, int len1, long long tot) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0; (1LL << i) <= tot; i++) {
    for (int j = 0; j <= ones; j++)
      for (int p = 0; p <= 1; p++) {
        old[j][p] = dp[j][p];
        dp[j][p] = 0;
      }
    for (int d0 = 0; d0 <= 1; d0++)
      if (!d0 || i < len0)
        for (int d1 = 0; d1 <= 1; d1++)
          if (!d1 || i < len1)
            for (int p = 0; p <= 1; p++) {
              int dig = d0 + d1 + p;
              if ((dig & 1) != bool(tot & (1LL << i))) continue;
              for (int j = 0; j + d0 + d1 <= ones; j++)
                dp[j + d0 + d1][dig / 2] += old[j][p];
            }
  }
  return dp[ones][0];
}
int main() {
  long long sum;
  scanf("%lld", &sum);
  long long ans = 0;
  for (int i = 0; i <= 55; i++)
    for (int j = 0; j <= 55; j++) {
      long long mul = ((1LL << (i + 1)) - 1) + ((1LL << (j + 1)) - 1) - 1;
      long long lca = sum / mul;
      if (!lca) continue;
      long long rsum = sum - lca * mul - ((1LL << j) - 1);
      if (rsum < 0) continue;
      for (int ones = 0; ones <= i + j; ones++) {
        long long tmp = rsum + ones;
        if (tmp & 1 || tmp < 0) continue;
        ans += DP(ones, max(i - 1, 0), max(j - 1, 0), tmp >> 1);
      }
    }
  printf("%lld\n", ans);
  return 0;
}
