#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
  a += b;
  if (a < 0) a += MOD;
  if (a >= MOD) a -= MOD;
}
void FastIn(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double din() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long p2[64];
void initP2() {
  p2[0] = 1;
  for (int i = (1); i <= (63); ++i) {
    p2[i] = p2[i - 1] * 2;
  }
}
int countBitsBaseB(long long n, long long b) {
  if (n == 0) return 1;
  int ret = 0;
  while (n) {
    ret++;
    n /= b;
  }
  return ret;
}
int count1(long long n) {
  int ret = 0;
  while (n) {
    ret += n & 1;
    n >>= 1;
  }
  return ret;
}
long long c[1024][1024] = {0};
void initC() {
  for (int i = 0; i < (1024); ++i) {
    for (int j = 0; j < (i + 1); ++j) {
      if (j == 0 || j == i) {
        c[i][j] = 1;
      } else {
        c[i][j] = c[i - 1][j - 1];
        add(c[i][j], c[i - 1][j]);
      }
    }
  }
}
bool IsPrime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void init() {
  initP2();
  initC();
}
const long long INF = 1000000000;
map<pair<int, long long>, int> sg;
int DFS(int sum, long long mask) {
  if (sum == 0) return 0;
  pair<int, long long> p = make_pair(sum, mask);
  if (sg.find(p) != sg.end()) {
    return sg[p];
  }
  vector<int> v;
  for (int i = (1); i <= (sum); ++i) {
    if (p2[i] & mask) continue;
    v.push_back(DFS(sum - i, mask | p2[i]));
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ans = -1;
  if (v.empty() || v[0] > 0) ans = 0;
  for (int i = 0; i < ((int)v.size() - 1); ++i) {
    if (v[i] + 1 < v[i + 1]) {
      ans = v[i] + 1;
      break;
    }
  }
  if (ans == -1) ans = v.back() + 1;
  sg[p] = ans;
  return ans;
}
int base[71][32] = {0};
int dp[16] = {0};
int pos[1024];
void Split(int n) {
  int mask = 0;
  for (int i = 2; i * i <= 70; i++) {
    while (n % i == 0) {
      mask ^= p2[pos[i]];
      n /= i;
    }
  }
  int *v = base[n];
  int z[32] = {0};
  for (int i = 0; i < (32); ++i) {
    int tmp = i;
    tmp ^= p2[4];
    tmp ^= mask;
    add(z[tmp], v[i]);
  }
  for (int i = 0; i < (32); ++i) {
    add(v[i], z[i]);
  }
}
long long calc(long long deepL, long long deepR, long long totalBits,
               long long sum) {
  if (p2[deepL - 1] + p2[deepR - 1] > sum) return 0;
  if (p2[deepL] - 1 + p2[deepR] - 1 < sum) return 0;
  long long dp[64][128][2] = {0};
  dp[0][0][0] = 1;
  int len = max(deepL, deepR);
  for (int i = (63) - 1; i >= 0; --i) {
    if (p2[i] & sum) {
      len = i + 1;
      break;
    }
  }
  if (max(deepL, deepR) > len) return 0;
  for (int i = 0; i < (len); ++i) {
    for (int j = 0; j < (totalBits + 1); ++j) {
      for (int mask = 0; mask < (2); ++mask) {
        if (dp[i][j][mask] == 0) continue;
        for (int add = 0; add < (4); ++add) {
          int add0 = (add & 1) > 0;
          int add1 = (add & 2) > 0;
          if (i + 1 > deepL && add0) {
            continue;
          }
          if (i + 1 == deepL && add0 == 0) {
            continue;
          }
          if (i + 1 == deepL - 1 && add0 == 1) {
            continue;
          }
          if (i + 1 > deepR && add1) {
            continue;
          }
          if (i + 1 == deepR && add1 == 0) {
            continue;
          }
          if (i + 1 == deepR - 1 && add1 == 0) {
            continue;
          }
          if (add0 + add1 + j > totalBits) continue;
          long long tot = mask + add0 + add1;
          long long bb = (tot & 1) * p2[i];
          if ((p2[i] & sum) == bb) {
            dp[i + 1][j + add0 + add1][tot >> 1] += dp[i][j][mask];
          }
        }
      }
    }
  }
  return dp[len][totalBits][0];
}
int main() {
  init();
  long long s;
  cin >> s;
  clock_t start = clock();
  long long ans = 0;
  for (int L = 0; L < (64); ++L) {
    if (p2[L + 1] - 3 > s) break;
    for (int R = 0; R < (64); ++R) {
      long long down = p2[L + 1] + p2[R + 1] - 3;
      if (down > s) {
        break;
      }
      long long x = (s - (p2[R] - 1)) / down;
      if (x < 1) continue;
      long long newS = s - down * (x - 1);
      if (newS < 1) continue;
      for (int bits = 0; bits < (L + R + 2 + 1); ++bits) {
        if ((newS + 1 + bits) % 2 == 0) {
          ans += calc(L + 1, R + 1, bits, (newS + 1 + bits) / 2);
        }
      }
    }
  }
  cout << ans << endl;
  clock_t end = clock();
  return 0;
}

### 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;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
  a += b;
  if (a < 0) a += MOD;
  if (a >= MOD) a -= MOD;
}
void FastIn(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double din() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long p2[64];
void initP2() {
  p2[0] = 1;
  for (int i = (1); i <= (63); ++i) {
    p2[i] = p2[i - 1] * 2;
  }
}
int countBitsBaseB(long long n, long long b) {
  if (n == 0) return 1;
  int ret = 0;
  while (n) {
    ret++;
    n /= b;
  }
  return ret;
}
int count1(long long n) {
  int ret = 0;
  while (n) {
    ret += n & 1;
    n >>= 1;
  }
  return ret;
}
long long c[1024][1024] = {0};
void initC() {
  for (int i = 0; i < (1024); ++i) {
    for (int j = 0; j < (i + 1); ++j) {
      if (j == 0 || j == i) {
        c[i][j] = 1;
      } else {
        c[i][j] = c[i - 1][j - 1];
        add(c[i][j], c[i - 1][j]);
      }
    }
  }
}
bool IsPrime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void init() {
  initP2();
  initC();
}
const long long INF = 1000000000;
map<pair<int, long long>, int> sg;
int DFS(int sum, long long mask) {
  if (sum == 0) return 0;
  pair<int, long long> p = make_pair(sum, mask);
  if (sg.find(p) != sg.end()) {
    return sg[p];
  }
  vector<int> v;
  for (int i = (1); i <= (sum); ++i) {
    if (p2[i] & mask) continue;
    v.push_back(DFS(sum - i, mask | p2[i]));
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ans = -1;
  if (v.empty() || v[0] > 0) ans = 0;
  for (int i = 0; i < ((int)v.size() - 1); ++i) {
    if (v[i] + 1 < v[i + 1]) {
      ans = v[i] + 1;
      break;
    }
  }
  if (ans == -1) ans = v.back() + 1;
  sg[p] = ans;
  return ans;
}
int base[71][32] = {0};
int dp[16] = {0};
int pos[1024];
void Split(int n) {
  int mask = 0;
  for (int i = 2; i * i <= 70; i++) {
    while (n % i == 0) {
      mask ^= p2[pos[i]];
      n /= i;
    }
  }
  int *v = base[n];
  int z[32] = {0};
  for (int i = 0; i < (32); ++i) {
    int tmp = i;
    tmp ^= p2[4];
    tmp ^= mask;
    add(z[tmp], v[i]);
  }
  for (int i = 0; i < (32); ++i) {
    add(v[i], z[i]);
  }
}
long long calc(long long deepL, long long deepR, long long totalBits,
               long long sum) {
  if (p2[deepL - 1] + p2[deepR - 1] > sum) return 0;
  if (p2[deepL] - 1 + p2[deepR] - 1 < sum) return 0;
  long long dp[64][128][2] = {0};
  dp[0][0][0] = 1;
  int len = max(deepL, deepR);
  for (int i = (63) - 1; i >= 0; --i) {
    if (p2[i] & sum) {
      len = i + 1;
      break;
    }
  }
  if (max(deepL, deepR) > len) return 0;
  for (int i = 0; i < (len); ++i) {
    for (int j = 0; j < (totalBits + 1); ++j) {
      for (int mask = 0; mask < (2); ++mask) {
        if (dp[i][j][mask] == 0) continue;
        for (int add = 0; add < (4); ++add) {
          int add0 = (add & 1) > 0;
          int add1 = (add & 2) > 0;
          if (i + 1 > deepL && add0) {
            continue;
          }
          if (i + 1 == deepL && add0 == 0) {
            continue;
          }
          if (i + 1 == deepL - 1 && add0 == 1) {
            continue;
          }
          if (i + 1 > deepR && add1) {
            continue;
          }
          if (i + 1 == deepR && add1 == 0) {
            continue;
          }
          if (i + 1 == deepR - 1 && add1 == 0) {
            continue;
          }
          if (add0 + add1 + j > totalBits) continue;
          long long tot = mask + add0 + add1;
          long long bb = (tot & 1) * p2[i];
          if ((p2[i] & sum) == bb) {
            dp[i + 1][j + add0 + add1][tot >> 1] += dp[i][j][mask];
          }
        }
      }
    }
  }
  return dp[len][totalBits][0];
}
int main() {
  init();
  long long s;
  cin >> s;
  clock_t start = clock();
  long long ans = 0;
  for (int L = 0; L < (64); ++L) {
    if (p2[L + 1] - 3 > s) break;
    for (int R = 0; R < (64); ++R) {
      long long down = p2[L + 1] + p2[R + 1] - 3;
      if (down > s) {
        break;
      }
      long long x = (s - (p2[R] - 1)) / down;
      if (x < 1) continue;
      long long newS = s - down * (x - 1);
      if (newS < 1) continue;
      for (int bits = 0; bits < (L + R + 2 + 1); ++bits) {
        if ((newS + 1 + bits) % 2 == 0) {
          ans += calc(L + 1, R + 1, bits, (newS + 1 + bits) / 2);
        }
      }
    }
  }
  cout << ans << endl;
  clock_t end = clock();
  return 0;
}

```