#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010, mod = 998244353;
inline int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
long long n, f[55][111][2];
int bitcnt(long long x) {
  int c = 0;
  for (; x; x &= x - 1) c++;
  return c;
}
long long solve1() {
  long long ans = 0;
  for (int i = (1); i <= (50); i++) {
    long long x = n / ((1ll << i) - 1);
    if (!x) break;
    long long res = n - x * ((1ll << i) - 1);
    for (int j = (0); j <= (i - 1); j++)
      if ((res + j) % 2 == 0 && bitcnt(res + j) == j) ans++;
  }
  return ans;
}
long long solve2() {
  long long ans = 0;
  for (int l = (2); l <= (50); l++)
    for (int r = (2); r <= (50); r++) {
      long long x = (n - (1ll << (r - 1)) + 1) / ((1ll << l) + (1ll << r) - 3);
      if (!x) break;
      long long res =
          n - (1ll << (r - 1)) + 1 - x * ((1ll << l) + (1ll << r) - 3);
      for (int cnt = (0); cnt <= (l + r - 4); cnt++)
        if ((res + cnt) % 2 == 0) {
          for (int i = (0); i <= (max(l, r)); i++)
            for (int j = (0); j <= (min(cnt, 2 * i)); j++)
              f[i][j][0] = f[i][j][1] = 0;
          f[0][0][0] = 1;
          for (int i = (1); i <= (max(l, r)); i++)
            for (int j = (0); j <= (min(cnt, 2 * (i - 1))); j++) {
              for (int k = (0); k <= (1); k++)
                for (int a = (0); a <= (1); a++)
                  for (int b = (0); b <= (1); b++) {
                    if (i >= l - 1 && a == 1) continue;
                    if (i >= r - 1 && b == 1) continue;
                    if ((k + a + b) % 2 == ((res + cnt) >> i) % 2)
                      f[i][j + a + b][(k + a + b) / 2] += f[i - 1][j][k];
                  }
            }
          ans += f[max(l, r)][cnt][0];
        }
    }
  return ans;
}
int main() {
  scanf("%lld", &n);
  printf("%lld\n", solve1() + solve2());
}
