#include <bits/stdc++.h>
inline long long calcmn(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x + (1ll << (h2)) - 1;
}
inline long long calcmx(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x +
         ((1ll << (h1)) + (1ll << (h2 + 1)) - h1 - h2 - 3);
}
inline long long calc(long long S, int h1, int h2) {
  if (S < (1ll << (h2)) - 1) return -1;
  long long ret =
      (S - (1ll << (h2)) + 1) / ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
  if (!ret) return -1;
  return S <= calcmx(ret, h1, h2) ? ret : -1;
}
long long dp[80][160][2];
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  long long S;
  std::cin >> S;
  int lim = 65 - __builtin_clzll(S);
  long long ans = 0;
  for (int h1 = 0, h1_ = lim; h1 < h1_; ++h1)
    for (int h2 = 0, h2_ = lim; h2 < h2_; ++h2) {
      long long rt = calc(S, h1, h2);
      if (!~rt) continue;
      long long w = calcmn(rt, h1, h2);
      for (int k = 0, k_ = std::max(h1 - 1, 0) + std::max(h2 - 1, 0) + 1;
           k < k_; ++k) {
        long long x = S - w + k;
        int lim = 65 - (x ? __builtin_clzll(x) : 0);
        if (x & 1) continue;
        memset(dp, 0, sizeof(dp));
        dp[0][0][0] = 1;
        for (int i = 1, i_ = lim; i < i_; ++i)
          for (int j = 0, j_ = k + 1; j < j_; ++j) {
            if (x >> i & 1)
              dp[i][j][0] =
                  dp[i - 1][j][1] +
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][0] : 0),
              dp[i][j][1] =
                  j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][1] : 0;
            else
              dp[i][j][0] = dp[i - 1][j][0],
              dp[i][j][1] =
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][1] : 0) +
                  (j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][0] : 0);
          }
        ans += dp[lim - 1][k][0];
      }
    }
  std::cout << ans << std::endl;
}

### 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>
inline long long calcmn(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x + (1ll << (h2)) - 1;
}
inline long long calcmx(long long x, int h1, int h2) {
  return ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3) * x +
         ((1ll << (h1)) + (1ll << (h2 + 1)) - h1 - h2 - 3);
}
inline long long calc(long long S, int h1, int h2) {
  if (S < (1ll << (h2)) - 1) return -1;
  long long ret =
      (S - (1ll << (h2)) + 1) / ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
  if (!ret) return -1;
  return S <= calcmx(ret, h1, h2) ? ret : -1;
}
long long dp[80][160][2];
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  long long S;
  std::cin >> S;
  int lim = 65 - __builtin_clzll(S);
  long long ans = 0;
  for (int h1 = 0, h1_ = lim; h1 < h1_; ++h1)
    for (int h2 = 0, h2_ = lim; h2 < h2_; ++h2) {
      long long rt = calc(S, h1, h2);
      if (!~rt) continue;
      long long w = calcmn(rt, h1, h2);
      for (int k = 0, k_ = std::max(h1 - 1, 0) + std::max(h2 - 1, 0) + 1;
           k < k_; ++k) {
        long long x = S - w + k;
        int lim = 65 - (x ? __builtin_clzll(x) : 0);
        if (x & 1) continue;
        memset(dp, 0, sizeof(dp));
        dp[0][0][0] = 1;
        for (int i = 1, i_ = lim; i < i_; ++i)
          for (int j = 0, j_ = k + 1; j < j_; ++j) {
            if (x >> i & 1)
              dp[i][j][0] =
                  dp[i - 1][j][1] +
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][0] : 0),
              dp[i][j][1] =
                  j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][1] : 0;
            else
              dp[i][j][0] = dp[i - 1][j][0],
              dp[i][j][1] =
                  (j ? ((i < h1) + (i < h2)) * dp[i - 1][j - 1][1] : 0) +
                  (j > 1 && (i < h1) + (i < h2) > 1 ? dp[i - 1][j - 2][0] : 0);
          }
        ans += dp[lim - 1][k][0];
      }
    }
  std::cout << ans << std::endl;
}

```