#include <bits/stdc++.h>
using namespace std;
void dec(long long &x, long long y) {
  if (x >= y) x -= y;
}
long long p(int x) { return 1ll << x; }
long long f[51][101][2];
long long calc(long long s, long long x, int a, int b, int n) {
  if (s & 1) return 0;
  if (n == 0) return s == 0 ? 1 : 0;
  if (a == 1 && b == 1) return ((s - n) == (x * 5 + 1)) ? 1 : 0;
  memset(f, 0, sizeof f);
  f[0][0][0] = 1;
  for (int i = 1; i <= 50; ++i) {
    int d = (s >> i) & 1;
    for (int j = 0; j <= 2 * (i - 1); ++j) {
      for (int aa = 0; aa <= 1; ++aa) {
        if (aa == 1 && i >= a) continue;
        for (int bb = 0; bb <= 1; ++bb) {
          if (bb == 1 && i >= b) continue;
          for (int k = 0; k <= 1; ++k) {
            if ((k + aa + bb) % 2 == d)
              f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
          }
        }
      }
    }
  }
  return f[50][n][0];
}
int main() {
  long long s;
  cin >> s;
  long long num = 0;
  for (int i = 1; i <= 50; ++i) {
    long long x = s / (p(i) - 1);
    if (x > 0) {
      long long last = s % (p(i) - 1);
      for (int j = i - 1; j >= 1; --j) dec(last, p(j) - 1);
      if (last == 0) ++num;
    }
  }
  for (int h1 = 1; h1 <= 50; ++h1) {
    for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
      long long x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
      if (x > 0) {
        long long last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
        for (int n = 0; n <= h1 + h2; ++n) {
          long long temp = calc(last + n, x, h1, h2, n);
          num += temp;
        }
      }
    }
  }
  cout << num << endl;
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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>
using namespace std;
void dec(long long &x, long long y) {
  if (x >= y) x -= y;
}
long long p(int x) { return 1ll << x; }
long long f[51][101][2];
long long calc(long long s, long long x, int a, int b, int n) {
  if (s & 1) return 0;
  if (n == 0) return s == 0 ? 1 : 0;
  if (a == 1 && b == 1) return ((s - n) == (x * 5 + 1)) ? 1 : 0;
  memset(f, 0, sizeof f);
  f[0][0][0] = 1;
  for (int i = 1; i <= 50; ++i) {
    int d = (s >> i) & 1;
    for (int j = 0; j <= 2 * (i - 1); ++j) {
      for (int aa = 0; aa <= 1; ++aa) {
        if (aa == 1 && i >= a) continue;
        for (int bb = 0; bb <= 1; ++bb) {
          if (bb == 1 && i >= b) continue;
          for (int k = 0; k <= 1; ++k) {
            if ((k + aa + bb) % 2 == d)
              f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
          }
        }
      }
    }
  }
  return f[50][n][0];
}
int main() {
  long long s;
  cin >> s;
  long long num = 0;
  for (int i = 1; i <= 50; ++i) {
    long long x = s / (p(i) - 1);
    if (x > 0) {
      long long last = s % (p(i) - 1);
      for (int j = i - 1; j >= 1; --j) dec(last, p(j) - 1);
      if (last == 0) ++num;
    }
  }
  for (int h1 = 1; h1 <= 50; ++h1) {
    for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
      long long x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
      if (x > 0) {
        long long last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
        for (int n = 0; n <= h1 + h2; ++n) {
          long long temp = calc(last + n, x, h1, h2, n);
          num += temp;
        }
      }
    }
  }
  cout << num << endl;
  return 0;
}

```