#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
  if (_a < _b) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T& _a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
long long solve(int nx, int ny, long long s) {
  if (s < 0) return 0;
  long long ans = 0;
  for (int pop = int(2); pop <= int(nx + ny + 2); ++pop) {
    long long desire = s + 1 + pop;
    if (desire % 2 != 0) continue;
    desire /= 2;
    {
      long long minx, miny, maxx, maxy;
      if (nx == 0) {
        minx = maxx = 1;
      } else {
        minx = 1ll << nx, maxx = (3ll << (nx - 1)) - 1;
      }
      if (ny == 0) {
        miny = maxy = 1;
      } else {
        miny = 3ll << (ny - 1), maxy = (1ll << (ny + 1)) - 1;
      }
      if (minx + miny > desire || maxx + maxy < desire) continue;
    }
    static long long f[55][120][2];
    memset(f, 0, sizeof(f));
    f[0][0][0] = 1;
    for (int i = int(0); i <= int(max(nx, ny)); ++i) {
      int cur = int(desire % 2);
      desire /= 2;
      int x1 = 0, x2 = 1, y1 = 0, y2 = 1;
      if (i == nx - 1 || i > nx) {
        x1 = x2 = 0;
      } else if (i == nx) {
        x1 = x2 = 1;
      }
      if (i == ny - 1 || i == ny) {
        y1 = y2 = 1;
      } else if (i > ny) {
        y1 = y2 = 0;
      }
      for (int c = int(0); c <= int(pop); ++c)
        for (int carry = int(0); carry <= int((2) - 1); ++carry)
          if (f[i][c][carry]) {
            for (int x = int(x1); x <= int(x2); ++x) {
              int y = cur ^ x ^ carry;
              if (y >= y1 && y <= y2 && c + x + y <= pop) {
                f[i + 1][c + x + y][(x + y + carry) >> 1] += f[i][c][carry];
              }
            }
          }
    }
    if (desire < 2) {
      ans += f[max(nx, ny) + 1][pop][desire];
    }
  }
  return ans;
}
int main() {
  long long s;
  cin >> s;
  long long ans = 0;
  for (int nx = int(0); nx <= int(50); ++nx)
    for (int ny = int(0); ny <= int(50); ++ny) {
      long long coeff = (1ll << (nx + 1)) + (1ll << (ny + 1)) - 3;
      long long p = s / coeff;
      if (p >= 1) {
        ans += solve(nx, ny, s - coeff * (p - 1));
      }
    }
  cout << ans << endl;
  return 0;
}
