#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e6 + 10;
long long dp[60][110][2];
void main() {
  long long S = qread(), ans = 0;
  for (int L1 = (0), I = (50); L1 <= I; L1++)
    for (int L2 = (0), I = (50); L2 <= I; L2++) {
      long long tt = (1ll << (L1 + 1)) + (1ll << (L2 + 1)) - 3,
                ul = max(
                    (S - (1ll << (L1)) - (1ll << (L2 + 1)) + L1 + L2 + 3) / tt,
                    1ll),
                ur = (S - (1ll << (L2)) + 1) / tt;
      for (long long LCA = ul; LCA <= ur; LCA++)
        for (int cnt = (0), I = (L1 + L2); cnt <= I; cnt++) {
          long long wt = S - LCA * tt - (1ll << (L2)) + 1 + cnt;
          if (wt < 0 or wt & 1) continue;
          memset(dp, 0, sizeof dp);
          dp[1][0][0] = 1;
          int ln = ceil(log2(max(1ll, wt)));
          for (int i = (1), I = (ln); i <= I; i++)
            for (int c = (0), I = (min(i + i, L1 + L2)); c <= I; c++) {
              if (i >= max(L1, L2)) {
                dp[i + 1][c][0] += dp[i][c][(wt & (1ll << (i))) > 0];
                continue;
              }
              if (wt & (1ll << (i))) {
                dp[i + 1][c + 1][0] += dp[i][c][0] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][1],
                    dp[i + 1][c + 2][1] += dp[i][c][1] * (i < min(L1, L2));
              } else {
                dp[i + 1][c + 1][1] += dp[i][c][1] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][0],
                    dp[i + 1][c + 2][1] += dp[i][c][0] * (i < min(L1, L2));
              }
            }
          ans += dp[ln + 1][cnt][0];
        }
    }
  write(ans);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}

### Prompt

Please formulate a CPP solution to the following problem:

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;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e6 + 10;
long long dp[60][110][2];
void main() {
  long long S = qread(), ans = 0;
  for (int L1 = (0), I = (50); L1 <= I; L1++)
    for (int L2 = (0), I = (50); L2 <= I; L2++) {
      long long tt = (1ll << (L1 + 1)) + (1ll << (L2 + 1)) - 3,
                ul = max(
                    (S - (1ll << (L1)) - (1ll << (L2 + 1)) + L1 + L2 + 3) / tt,
                    1ll),
                ur = (S - (1ll << (L2)) + 1) / tt;
      for (long long LCA = ul; LCA <= ur; LCA++)
        for (int cnt = (0), I = (L1 + L2); cnt <= I; cnt++) {
          long long wt = S - LCA * tt - (1ll << (L2)) + 1 + cnt;
          if (wt < 0 or wt & 1) continue;
          memset(dp, 0, sizeof dp);
          dp[1][0][0] = 1;
          int ln = ceil(log2(max(1ll, wt)));
          for (int i = (1), I = (ln); i <= I; i++)
            for (int c = (0), I = (min(i + i, L1 + L2)); c <= I; c++) {
              if (i >= max(L1, L2)) {
                dp[i + 1][c][0] += dp[i][c][(wt & (1ll << (i))) > 0];
                continue;
              }
              if (wt & (1ll << (i))) {
                dp[i + 1][c + 1][0] += dp[i][c][0] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][1],
                    dp[i + 1][c + 2][1] += dp[i][c][1] * (i < min(L1, L2));
              } else {
                dp[i + 1][c + 1][1] += dp[i][c][1] * (1 + (i < min(L1, L2)));
                dp[i + 1][c][0] += dp[i][c][0],
                    dp[i + 1][c + 2][1] += dp[i][c][0] * (i < min(L1, L2));
              }
            }
          ans += dp[ln + 1][cnt][0];
        }
    }
  write(ans);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}

```