#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},
                        {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <typename t, typename t1>
t min1(t a, t1 b) {
  return a < b ? a : b;
}
template <typename t, typename... arg>
t min1(t a, arg... arr) {
  return min1(a, min1(arr...));
}
template <typename t, typename t1>
t max1(t a, t1 b) {
  return a > b ? a : b;
}
template <typename t, typename... arg>
t max1(t a, arg... arr) {
  return max1(a, max1(arr...));
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
template <typename t>
inline int jud(t a, t b) {
  if (a < b) return -1;
  if (a == b) return 0;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  if (na == 0) return 0;
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1) be--;
    if (!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1) be--;
    if (f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}
template <class T>
inline T lowb(T num) {
  return num & (-num);
}
inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(unsigned long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitnum(long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitmaxl(unsigned int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(unsigned long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
inline int bitmaxl(long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
long long pow(long long n, long long m, long long mod = 0) {
  if (m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if (mod == -1) mod = 1000000007;
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);
}
long long dp[55][55][55];
long long upd[55][55];
long long arr[55];
vector<long long> getl(long long l, long long rl = -1) {
  long long st[55];
  long long sum = 0;
  l--;
  for (int i = 0; i <= 55; i++) {
    st[i] = sum + 1;
    if (l & (1ll << i)) sum += 1ll << i;
  }
  l++;
  memset(dp[0], 0, sizeof(dp[0]));
  dp[0][0][0] = 1;
  for (long long i = 1; 1ll << i <= l; i++) {
    memset(upd, 0, sizeof(upd));
    memset(arr, -1, sizeof(arr));
    arr[i] = (1ll << i) - st[i];
    long long delta = 0;
    for (int j = i; j > 0; j--) {
      if (arr[i] >= 1ll << (j - 1)) {
        int rd = delta;
        int maxv = j - 1;
        for (int k = j; k <= i; k++)
          if (arr[k] != -1) {
            if (arr[k] >= 1ll << (j - 1)) {
              rd++;
              arr[k] -= 1ll << (j - 1);
            } else {
              maxv = k;
              arr[k] = -1;
            }
          }
        for (int rk = 0; rk <= j; rk++) upd[j][rk + rd] += dp[maxv][j - 1][rk];
      } else {
        int maxv = j - 1;
        int rd = delta;
        for (int k = j; k <= i; k++)
          if (arr[k] != -1) {
            if (arr[j] >= 1ll << (j - 1)) {
              delta++;
              arr[j] = -1;
              maxv = k;
            }
          }
        for (int rk = 0; rk <= j; rk++) upd[j][rk + rd] += dp[maxv][j - 1][rk];
      }
      arr[j - 1] = (1ll << (j - 1)) - st[j - 1];
    }
    upd[0][delta] = 1;
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k <= i; k++) upd[j][k] += upd[j - 1][k];
      for (int k = 0; k <= i; k++) dp[i][j][k] = upd[j][k];
    }
  }
  vector<long long> ans = vector<long long>(55, 0);
  for (int i = 0; 1ll << i <= l; i++)
    if (l & (1ll << i)) {
      for (int j = 0; j < 55; j++) ans[j] += dp[i][i][j];
    }
  if (rl != -1) {
    long long rb = bitmaxl(l) - 1;
    while (st[rb] >= rl && rb > 0) rb--;
    for (long long i = 0; i < 55; i++) {
      ans[i] = dp[rb][bitmaxl(rl) - 1][i];
      if (bitmaxl(rl) - 1 > rb)
        ans[i] = dp[rb][rb][i] << (bitmaxl(rl) - 1 - rb);
    }
  }
  return ans;
}
long long n;
long long gsum(long long num) {
  long long ans = 0;
  while (num) {
    ans += num / 2;
    num /= 2;
  }
  return ans;
}
long long gsum(long long num1, long long num2) {
  long long ans = 0;
  while (num1 != num2) {
    if (num1 > num2) {
      ans += num1;
      num1 /= 2;
    } else {
      ans += num2;
      num2 /= 2;
    }
  }
  return ans + num1;
}
inline long long minx(long long h, int tuo) { return (h << tuo); }
inline long long maxx(long long h, int tuo) {
  return (h << tuo) + (tuo > 0) * ((1ll << (tuo - 1)) - 1);
}
inline long long miny(long long h, int tuo) {
  return (h << tuo) + (tuo > 0) * ((1ll << (tuo - 1)));
}
inline long long maxy(long long h, int tuo) {
  return (h << tuo) + (1ll << tuo) - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  long long ans = 0;
  for (int i = 0; 1ll << i <= n; i++) {
    for (int j = 0; 1ll << j <= n; j++) {
      for (int h = 0; h <= min(i, j); h++) {
        long long be = 1ll << h, en = (1ll << (h + 1)) - 1;
        while (be != en) {
          long long mid = (be + en) / 2;
          if (gsum(maxx(mid, i - h), maxy(mid, j - h)) >= n) {
            en = mid;
          } else
            be = mid + 1;
        }
        if (gsum(minx(be, i - h), miny(be, j - h)) > n ||
            gsum(maxx(be, i - h), maxy(be, j - h)) < n)
          continue;
        long long stx, sty;
        if (gsum(minx(be, i - h), maxy(be, j - h)) > n) {
          long long bey = miny(be, j - h), eny = maxy(be, j - h);
          while (bey != eny) {
            long long mid = (bey + eny + 1) / 2;
            if (gsum(minx(be, i - h), mid) <= n)
              bey = mid;
            else
              eny = mid - 1;
          }
          stx = minx(be, i - h), sty = bey;
        } else {
          long long bex = minx(be, i - h), enx = maxx(be, i - h);
          while (bex != enx) {
            long long mid = (bex + enx + 1) / 2;
            if (gsum(maxy(be, j - h), mid) <= n)
              bex = mid;
            else
              enx = mid - 1;
          }
          stx = bex, sty = maxy(be, j - h);
        }
        long long pstx = stx, psty = sty;
        for (int rd = 0; rd <= 30; rd++) {
          if (stx > maxx(be, i - h)) break;
          long long rk = gsum(stx, sty) - n;
          if (sty == maxy(be, j - h)) rk = -rk;
          if (abs(rk) > (max(i, j) - h)) break;
          if (rk >= 0) {
            long long rl = maxx(be, i - h) - stx + 1;
            if (stx == minx(be, i - h)) rl = sty - miny(be, j - h) + 1;
            long long rl1 =
                min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
            if (rl1 == rl) rl1 = -1;
            auto tans = getl(rl, rl1);
            ans += tans[rk];
          }
          if (sty == maxy(be, j - h))
            stx++;
          else
            sty++;
        }
        stx = pstx, sty = psty;
        for (int rd = 1; rd <= 30; rd++) {
          if (stx == minx(be, i - h))
            sty--;
          else
            stx--;
          if (sty < miny(be, j - h)) break;
          long long rk = gsum(stx, sty) - n;
          if (sty == maxy(be, j - h)) rk = -rk;
          if (abs(rk) > (max(i, j) - h)) break;
          if (rk >= 0) {
            long long rl = maxx(be, i - h) - stx + 1;
            if (stx == minx(be, i - h)) rl = sty - miny(be, j - h) + 1;
            long long rl1 =
                min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
            if (rl1 == rl) rl1 = -1;
            auto tans = getl(rl, rl1);
            ans += tans[rk];
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Generate 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 double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},
                        {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <typename t, typename t1>
t min1(t a, t1 b) {
  return a < b ? a : b;
}
template <typename t, typename... arg>
t min1(t a, arg... arr) {
  return min1(a, min1(arr...));
}
template <typename t, typename t1>
t max1(t a, t1 b) {
  return a > b ? a : b;
}
template <typename t, typename... arg>
t max1(t a, arg... arr) {
  return max1(a, max1(arr...));
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
template <typename t>
inline int jud(t a, t b) {
  if (a < b) return -1;
  if (a == b) return 0;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  if (na == 0) return 0;
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1) be--;
    if (!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1) be--;
    if (f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}
template <class T>
inline T lowb(T num) {
  return num & (-num);
}
inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(unsigned long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitnum(long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitmaxl(unsigned int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(unsigned long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
inline int bitmaxl(long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
long long pow(long long n, long long m, long long mod = 0) {
  if (m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if (mod == -1) mod = 1000000007;
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);
}
long long dp[55][55][55];
long long upd[55][55];
long long arr[55];
vector<long long> getl(long long l, long long rl = -1) {
  long long st[55];
  long long sum = 0;
  l--;
  for (int i = 0; i <= 55; i++) {
    st[i] = sum + 1;
    if (l & (1ll << i)) sum += 1ll << i;
  }
  l++;
  memset(dp[0], 0, sizeof(dp[0]));
  dp[0][0][0] = 1;
  for (long long i = 1; 1ll << i <= l; i++) {
    memset(upd, 0, sizeof(upd));
    memset(arr, -1, sizeof(arr));
    arr[i] = (1ll << i) - st[i];
    long long delta = 0;
    for (int j = i; j > 0; j--) {
      if (arr[i] >= 1ll << (j - 1)) {
        int rd = delta;
        int maxv = j - 1;
        for (int k = j; k <= i; k++)
          if (arr[k] != -1) {
            if (arr[k] >= 1ll << (j - 1)) {
              rd++;
              arr[k] -= 1ll << (j - 1);
            } else {
              maxv = k;
              arr[k] = -1;
            }
          }
        for (int rk = 0; rk <= j; rk++) upd[j][rk + rd] += dp[maxv][j - 1][rk];
      } else {
        int maxv = j - 1;
        int rd = delta;
        for (int k = j; k <= i; k++)
          if (arr[k] != -1) {
            if (arr[j] >= 1ll << (j - 1)) {
              delta++;
              arr[j] = -1;
              maxv = k;
            }
          }
        for (int rk = 0; rk <= j; rk++) upd[j][rk + rd] += dp[maxv][j - 1][rk];
      }
      arr[j - 1] = (1ll << (j - 1)) - st[j - 1];
    }
    upd[0][delta] = 1;
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k <= i; k++) upd[j][k] += upd[j - 1][k];
      for (int k = 0; k <= i; k++) dp[i][j][k] = upd[j][k];
    }
  }
  vector<long long> ans = vector<long long>(55, 0);
  for (int i = 0; 1ll << i <= l; i++)
    if (l & (1ll << i)) {
      for (int j = 0; j < 55; j++) ans[j] += dp[i][i][j];
    }
  if (rl != -1) {
    long long rb = bitmaxl(l) - 1;
    while (st[rb] >= rl && rb > 0) rb--;
    for (long long i = 0; i < 55; i++) {
      ans[i] = dp[rb][bitmaxl(rl) - 1][i];
      if (bitmaxl(rl) - 1 > rb)
        ans[i] = dp[rb][rb][i] << (bitmaxl(rl) - 1 - rb);
    }
  }
  return ans;
}
long long n;
long long gsum(long long num) {
  long long ans = 0;
  while (num) {
    ans += num / 2;
    num /= 2;
  }
  return ans;
}
long long gsum(long long num1, long long num2) {
  long long ans = 0;
  while (num1 != num2) {
    if (num1 > num2) {
      ans += num1;
      num1 /= 2;
    } else {
      ans += num2;
      num2 /= 2;
    }
  }
  return ans + num1;
}
inline long long minx(long long h, int tuo) { return (h << tuo); }
inline long long maxx(long long h, int tuo) {
  return (h << tuo) + (tuo > 0) * ((1ll << (tuo - 1)) - 1);
}
inline long long miny(long long h, int tuo) {
  return (h << tuo) + (tuo > 0) * ((1ll << (tuo - 1)));
}
inline long long maxy(long long h, int tuo) {
  return (h << tuo) + (1ll << tuo) - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  long long ans = 0;
  for (int i = 0; 1ll << i <= n; i++) {
    for (int j = 0; 1ll << j <= n; j++) {
      for (int h = 0; h <= min(i, j); h++) {
        long long be = 1ll << h, en = (1ll << (h + 1)) - 1;
        while (be != en) {
          long long mid = (be + en) / 2;
          if (gsum(maxx(mid, i - h), maxy(mid, j - h)) >= n) {
            en = mid;
          } else
            be = mid + 1;
        }
        if (gsum(minx(be, i - h), miny(be, j - h)) > n ||
            gsum(maxx(be, i - h), maxy(be, j - h)) < n)
          continue;
        long long stx, sty;
        if (gsum(minx(be, i - h), maxy(be, j - h)) > n) {
          long long bey = miny(be, j - h), eny = maxy(be, j - h);
          while (bey != eny) {
            long long mid = (bey + eny + 1) / 2;
            if (gsum(minx(be, i - h), mid) <= n)
              bey = mid;
            else
              eny = mid - 1;
          }
          stx = minx(be, i - h), sty = bey;
        } else {
          long long bex = minx(be, i - h), enx = maxx(be, i - h);
          while (bex != enx) {
            long long mid = (bex + enx + 1) / 2;
            if (gsum(maxy(be, j - h), mid) <= n)
              bex = mid;
            else
              enx = mid - 1;
          }
          stx = bex, sty = maxy(be, j - h);
        }
        long long pstx = stx, psty = sty;
        for (int rd = 0; rd <= 30; rd++) {
          if (stx > maxx(be, i - h)) break;
          long long rk = gsum(stx, sty) - n;
          if (sty == maxy(be, j - h)) rk = -rk;
          if (abs(rk) > (max(i, j) - h)) break;
          if (rk >= 0) {
            long long rl = maxx(be, i - h) - stx + 1;
            if (stx == minx(be, i - h)) rl = sty - miny(be, j - h) + 1;
            long long rl1 =
                min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
            if (rl1 == rl) rl1 = -1;
            auto tans = getl(rl, rl1);
            ans += tans[rk];
          }
          if (sty == maxy(be, j - h))
            stx++;
          else
            sty++;
        }
        stx = pstx, sty = psty;
        for (int rd = 1; rd <= 30; rd++) {
          if (stx == minx(be, i - h))
            sty--;
          else
            stx--;
          if (sty < miny(be, j - h)) break;
          long long rk = gsum(stx, sty) - n;
          if (sty == maxy(be, j - h)) rk = -rk;
          if (abs(rk) > (max(i, j) - h)) break;
          if (rk >= 0) {
            long long rl = maxx(be, i - h) - stx + 1;
            if (stx == minx(be, i - h)) rl = sty - miny(be, j - h) + 1;
            long long rl1 =
                min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
            if (rl1 == rl) rl1 = -1;
            auto tans = getl(rl, rl1);
            ans += tans[rk];
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

```