#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
  a += b;
  if (a < 0) a += MOD;
  if (a >= MOD) a -= MOD;
}
void FastIn(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double din() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long p2[64];
void initP2() {
  p2[0] = 1;
  for (int i = (1); i <= (63); ++i) {
    p2[i] = p2[i - 1] * 2;
  }
}
int countBitsBaseB(long long n, long long b) {
  if (n == 0) return 1;
  int ret = 0;
  while (n) {
    ret++;
    n /= b;
  }
  return ret;
}
int count1(long long n) {
  int ret = 0;
  while (n) {
    ret += n & 1;
    n >>= 1;
  }
  return ret;
}
long long c[1024][1024] = {0};
void initC() {
  for (int i = 0; i < (1024); ++i) {
    for (int j = 0; j < (i + 1); ++j) {
      if (j == 0 || j == i) {
        c[i][j] = 1;
      } else {
        c[i][j] = c[i - 1][j - 1];
        add(c[i][j], c[i - 1][j]);
      }
    }
  }
}
bool IsPrime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void init() {
  initP2();
  initC();
}
const long long INF = 1000000000;
map<pair<int, long long>, int> sg;
int DFS(int sum, long long mask) {
  if (sum == 0) return 0;
  pair<int, long long> p = make_pair(sum, mask);
  if (sg.find(p) != sg.end()) {
    return sg[p];
  }
  vector<int> v;
  for (int i = (1); i <= (sum); ++i) {
    if (p2[i] & mask) continue;
    v.push_back(DFS(sum - i, mask | p2[i]));
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ans = -1;
  if (v.empty() || v[0] > 0) ans = 0;
  for (int i = 0; i < ((int)v.size() - 1); ++i) {
    if (v[i] + 1 < v[i + 1]) {
      ans = v[i] + 1;
      break;
    }
  }
  if (ans == -1) ans = v.back() + 1;
  sg[p] = ans;
  return ans;
}
long long dp[64][2][128] = {0};
long long calc(int deepL, int deepR, int totalBits, long long sum) {
  if (p2[deepL - 1] + p2[deepR - 1] > sum) return 0;
  if (p2[deepL] - 1 + p2[deepR] - 1 < sum) return 0;
  int len = max(deepL, deepR);
  for (int i = (63) - 1; i >= 0; --i) {
    if (p2[i] & sum) {
      len = i + 1;
      break;
    }
  }
  if (max(deepL, deepR) > len) return 0;
  for (int i = 0; i < (len + 1); ++i) {
    for (int mask = 0; mask < (2); ++mask) {
      for (int j = 0; j < (totalBits + 1); ++j) {
        dp[i][mask][j] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < (len); ++i) {
    for (int mask = 0; mask < (2); ++mask) {
      for (int j = 0; j < (totalBits + 1); ++j) {
        if (dp[i][mask][j] == 0) continue;
        for (int add = 0; add < (4); ++add) {
          int add0 = (add & 1) > 0;
          int add1 = (add & 2) > 0;
          if (i + 1 > deepL && add0) {
            continue;
          }
          if (i + 1 == deepL && add0 == 0) {
            continue;
          }
          if (i + 1 == deepL - 1 && add0 == 1) {
            continue;
          }
          if (i + 1 > deepR && add1) {
            continue;
          }
          if (i + 1 == deepR && add1 == 0) {
            continue;
          }
          if (i + 1 == deepR - 1 && add1 == 0) {
            continue;
          }
          if (add0 + add1 + j > totalBits) continue;
          int tot = mask + add0 + add1;
          int bb = tot & 1;
          if (((sum >> i) & 1) == bb) {
            dp[i + 1][tot >> 1][j + add0 + add1] += dp[i][mask][j];
          }
        }
      }
    }
  }
  return dp[len][0][totalBits];
}
int main() {
  init();
  long long s;
  cin >> s;
  clock_t start = clock();
  long long ans = 0;
  for (int L = 0; L < (64); ++L) {
    if (p2[L + 1] - 3 > s) break;
    for (int R = 0; R < (64); ++R) {
      long long down = p2[L + 1] + p2[R + 1] - 3;
      if (down > s) {
        break;
      }
      long long x = (s - (p2[R] - 1)) / down;
      if (x < 1) continue;
      long long newS = s - down * (x - 1);
      if (newS < 1) continue;
      for (int bits = 0; bits < (L + R + 2 + 1); ++bits) {
        if (((newS + 1 + bits) & 1) == 0) {
          ans += calc(L + 1, R + 1, bits, (newS + 1 + bits) / 2);
        }
      }
    }
  }
  cout << ans << endl;
  clock_t end = clock();
  return 0;
}
