#include <bits/stdc++.h>
long long popsum(long long value, long long limit, long long length1,
                 long long length2) {
  const long long length = (long long)ceil(log(1 + value) / log(2));
  long long t[1 + 50LL][1 + 2 * 50LL][2] = {{{1}}};
  for (long long i = 1; i <= length; i++) {
    for (long long j = 0; j <= limit; j++) {
      if (((value >> (i - 1)) & 1) == 0) {
        t[i][j][0] = t[i - 1][j][0];
        if (j >= 1 and i <= length1) t[i][j][1] += t[i - 1][j - 1][1];
        if (j >= 1 and i <= length2) t[i][j][1] += t[i - 1][j - 1][1];
        if (j >= 2 and i <= length1 and i <= length2)
          t[i][j][1] += t[i - 1][j - 2][0];
      } else {
        t[i][j][0] = t[i - 1][j][1];
        if (j >= 1 and i <= length1) t[i][j][0] += t[i - 1][j - 1][0];
        if (j >= 1 and i <= length2) t[i][j][0] += t[i - 1][j - 1][0];
        t[i][j][1] = 0;
        if (j >= 2 and i <= length1 and i <= length2)
          t[i][j][1] += t[i - 1][j - 2][1];
      }
    }
  }
  return t[length][limit][0];
}
int main(void) {
  long long s;
  scanf("%lld", &s);
  long long total = 0;
  for (long long i = 0; i <= 50LL; i++) {
    for (long long j = 0; j <= 50LL; j++) {
      long long n, d, l;
      n = s + 1 - (1LL << j);
      d = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
      l = n / d;
      if (l <= 0) {
        continue;
      }
      fputs("====", stderr);
      fprintf(stderr,
              "Suppose the left arm has length %lld and the right arm has "
              "length %lld; then the LCA is %lld\n",
              i, j, l);
      long long ts =
          s - ((l - 1) * ((1LL << (i + 1)) + (1LL << (j + 1)) - 2) - (l - 1));
      fprintf(
          stderr,
          "This is equivalent to seeking a path with sum %lld rooted at 1\n",
          ts);
      for (long long pops = 0; pops <= 2 * 50LL; pops++) {
        long long vs =
            4LL + ts - (1LL << (i + 1)) - 3LL * (1LL << (j + 1)) / 2 + pops;
        if (vs % 2 != 0) continue;
        vs /= 2;
        long long delta = popsum(vs, pops, i - 1, j - 1);
        if (delta > 0)
          fprintf(stderr,
                  "Suppose the values of x and y together have %lld pops; then "
                  "there exist(s) %lld ways of reaching the required sum "
                  "(%lld) with lengths %lld and %lld\n",
                  pops, delta, vs, i - 1, j - 1);
        total += delta;
      }
    }
  }
  printf("%lld\n", total);
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

The New Year tree is an infinite perfect binary tree rooted in the node 1. Each node v has two children: nodes indexed (2·v) and (2·v + 1).

<image>

Polar bears love decorating the New Year tree and Limak is no exception. As he is only a little bear, he was told to decorate only one simple path between some pair of nodes. Though he was given an opportunity to pick the pair himself! Now he wants to know the number of unordered pairs of indices (u, v) (u ≤ v), such that the sum of indices of all nodes along the simple path between u and v (including endpoints) is equal to s. Can you help him and count this value?

Input

The only line of the input contains a single integer s (1 ≤ s ≤ 1015).

Output

Print one integer, denoting the number of unordered pairs of nodes indices defining simple paths with the sum of indices of vertices equal to s.

Example

Input

10


Output

4

Note

In sample test, there are 4 paths with the sum of indices equal to 10:

<image>

### Response

```cpp
#include <bits/stdc++.h>
long long popsum(long long value, long long limit, long long length1,
                 long long length2) {
  const long long length = (long long)ceil(log(1 + value) / log(2));
  long long t[1 + 50LL][1 + 2 * 50LL][2] = {{{1}}};
  for (long long i = 1; i <= length; i++) {
    for (long long j = 0; j <= limit; j++) {
      if (((value >> (i - 1)) & 1) == 0) {
        t[i][j][0] = t[i - 1][j][0];
        if (j >= 1 and i <= length1) t[i][j][1] += t[i - 1][j - 1][1];
        if (j >= 1 and i <= length2) t[i][j][1] += t[i - 1][j - 1][1];
        if (j >= 2 and i <= length1 and i <= length2)
          t[i][j][1] += t[i - 1][j - 2][0];
      } else {
        t[i][j][0] = t[i - 1][j][1];
        if (j >= 1 and i <= length1) t[i][j][0] += t[i - 1][j - 1][0];
        if (j >= 1 and i <= length2) t[i][j][0] += t[i - 1][j - 1][0];
        t[i][j][1] = 0;
        if (j >= 2 and i <= length1 and i <= length2)
          t[i][j][1] += t[i - 1][j - 2][1];
      }
    }
  }
  return t[length][limit][0];
}
int main(void) {
  long long s;
  scanf("%lld", &s);
  long long total = 0;
  for (long long i = 0; i <= 50LL; i++) {
    for (long long j = 0; j <= 50LL; j++) {
      long long n, d, l;
      n = s + 1 - (1LL << j);
      d = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
      l = n / d;
      if (l <= 0) {
        continue;
      }
      fputs("====", stderr);
      fprintf(stderr,
              "Suppose the left arm has length %lld and the right arm has "
              "length %lld; then the LCA is %lld\n",
              i, j, l);
      long long ts =
          s - ((l - 1) * ((1LL << (i + 1)) + (1LL << (j + 1)) - 2) - (l - 1));
      fprintf(
          stderr,
          "This is equivalent to seeking a path with sum %lld rooted at 1\n",
          ts);
      for (long long pops = 0; pops <= 2 * 50LL; pops++) {
        long long vs =
            4LL + ts - (1LL << (i + 1)) - 3LL * (1LL << (j + 1)) / 2 + pops;
        if (vs % 2 != 0) continue;
        vs /= 2;
        long long delta = popsum(vs, pops, i - 1, j - 1);
        if (delta > 0)
          fprintf(stderr,
                  "Suppose the values of x and y together have %lld pops; then "
                  "there exist(s) %lld ways of reaching the required sum "
                  "(%lld) with lengths %lld and %lld\n",
                  pops, delta, vs, i - 1, j - 1);
        total += delta;
      }
    }
  }
  printf("%lld\n", total);
  return 0;
}

```