#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a;
}
long long poww2[51];
unordered_map<long long, long long> ans[51][51];
long long dfs(long long l1, long long l2, long long val) {
  if (val < 0) return 0;
  if (l1 <= 0 && l2 <= 0) return val == 0;
  if (poww2[l1 + 1] - l1 - 2 + poww2[l2 + 1] - l2 - 2 < val) return 0;
  if (l1 < l2) l1 ^= l2 ^= l1 ^= l2;
  if (ans[l1][l2].find(val) != ans[l1][l2].end()) return ans[l1][l2][val];
  return ans[l1][l2][val] =
             dfs(l1 - 1, l2, val) + dfs(l1 - 1, l2, val - poww2[l1] + 1);
}
signed main() {
  poww2[0] = 1;
  for (long long i = 1; i <= 50; ++i) poww2[i] = poww2[i - 1] << 1;
  long long sum = 0, val = read();
  for (long long i = 0; i < 50; ++i)
    for (long long j = 0; j < 50; ++j)
      if (poww2[i + 1] + 3 * poww2[j] - 4 <= val) {
        long long pos =
            (val - poww2[j] + 1) / (poww2[i + 1] + poww2[j + 1] - 3);
        sum +=
            dfs(i - 1, j - 1,
                val - poww2[j] + 1 - pos * (poww2[i + 1] + poww2[j + 1] - 3));
      }
  printf("%lld\n", sum);
  return 0;
}
