#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e6 + 10;
long long dp[60][110][2];
void main() {
  long long S = qread(), ans = 0;
  for (int L1 = (0), I = (50); L1 <= I; L1++)
    for (int L2 = (0), I = (50); L2 <= I; L2++) {
      long long tt = (1ll << (L1 + 1)) + (1ll << (L2 + 1)) - 3,
                ul = max(
                    (S - (1ll << (L1)) - (1ll << (L2 + 1)) + L1 + L2 + 3) / tt,
                    1ll),
                ur = (S - (1ll << (L2)) + 1) / tt;
      for (long long LCA = ul; LCA <= ur; LCA++)
        for (int cnt = (0), I = (L1 + L2); cnt <= I; cnt++) {
          long long wt = S - LCA * tt - (1ll << (L2)) + 1 + cnt;
          if (wt < 0 or wt & 1) continue;
          memset(dp, 0, sizeof dp);
          dp[1][0][0] = 1;
          int ln = ceil(log2(max(1ll, wt)));
          for (int i = (1), I = (ln); i <= I; i++)
            for (int c = (0), I = (min(i + i, L1 + L2)); c <= I; c++) {
              if (i >= max(L1, L2)) {
                dp[i + 1][c][0] += dp[i][c][(wt & (1ll << (i))) > 0];
                continue;
              }
              if (wt & (1ll << (i))) {
                dp[i + 1][c + 1][0] += dp[i][c][0] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][1],
                    dp[i + 1][c + 2][1] += dp[i][c][1] * (i < min(L1, L2));
              } else {
                dp[i + 1][c + 1][1] += dp[i][c][1] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][0],
                    dp[i + 1][c + 2][1] += dp[i][c][0] * (i < min(L1, L2));
              }
            }
          ans += dp[ln + 1][cnt][0];
        }
    }
  write(ans);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}
