Problem: You've got a weighted tree, consisting of n vertices. Each edge has a non-negative weight. The length of the path between any two vertices of the tree is the number of edges in the path. The weight of the path is the total weight of all edges it contains. 

Two vertices are close if there exists a path of length at most l between them and a path of weight at most w between them. Count the number of pairs of vertices v, u (v < u), such that vertices v and u are close.

Input

The first line contains three integers n, l and w (1 ≤ n ≤ 105, 1 ≤ l ≤ n, 0 ≤ w ≤ 109). The next n - 1 lines contain the descriptions of the tree edges. The i-th line contains two integers pi, wi (1 ≤ pi < (i + 1), 0 ≤ wi ≤ 104), that mean that the i-th edge connects vertex (i + 1) and pi and has weight wi.

Consider the tree vertices indexed from 1 to n in some way.

Output

Print a single integer — the number of close pairs.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

4 4 6
1 3
1 4
1 3


Output

4


Input

6 2 17
1 3
2 5
2 13
1 6
5 9


Output

9

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long n, m, nn, cnt, tot, k, k_, x, y, ww, rt, ans;
long long to[N], nextn[N], h[N];
long long mxsize[N], size[N];
long long w[N];
struct dis {
  long long d, d_;
  bool operator<(const dis &x) const { return x.d > d; }
} tmp[N], q[N], q0[N];
long long t[N];
bool b[N];
long long lowbit(long long x) { return x & (-x); }
void update(long long x, long long v) {
  for (long long i = x; i <= n; i += lowbit(i)) t[i] += v;
}
long long inquiry(long long x) {
  long long res = 0;
  for (long long i = x; i; i -= lowbit(i)) res += t[i];
  return res;
}
void add(long long x, long long y, long long ww) {
  cnt++;
  to[cnt] = y;
  nextn[cnt] = h[x];
  h[x] = cnt;
  w[cnt] = ww;
}
void findrt(long long x, long long anc) {
  mxsize[x] = 0;
  size[x] = 1;
  for (long long i = h[x]; i; i = nextn[i]) {
    long long y = to[i];
    if (y == anc || b[y]) continue;
    findrt(y, x);
    size[x] += size[y];
    mxsize[x] = max(mxsize[x], size[y]);
  }
  mxsize[x] = max(mxsize[x], nn - size[x]);
  if (mxsize[x] < mxsize[rt]) rt = x;
}
void dfs(long long x, long long anc, long long dis1, long long dis_) {
  tmp[++tot] = (dis){dis1, dis_};
  if (dis1 <= k && dis_ <= k_) ans++;
  for (long long i = h[x]; i; i = nextn[i]) {
    long long y = to[i];
    if (y == anc || b[y]) continue;
    dfs(y, x, dis1 + w[i], dis_ + 1);
  }
}
void work(long long x) {
  cnt = 0;
  for (long long i = h[x]; i; i = nextn[i]) {
    long long y = to[i];
    if (b[y]) continue;
    tot = 0;
    dfs(y, x, w[i], 1);
    sort(tmp + 1, tmp + tot + 1);
    long long last = 0;
    for (long long j = tot; j >= 1; j--)
      if (tmp[j].d < k && tmp[j].d_ < k_) {
        long long pos =
            lower_bound(q + 1, q + cnt + 1, dis{k - tmp[j].d + 1, 0}) - q;
        while (q[pos].d > k - tmp[j].d) pos--;
        for (long long l = last + 1; l <= pos && l <= cnt; l++)
          update(q[l].d_, 1);
        ans += inquiry(k_ - tmp[j].d_);
        last = pos;
      }
    for (long long l = 1; l <= last && l <= cnt; l++) update(q[l].d_, -1);
    merge(tmp + 1, tmp + tot + 1, q + 1, q + cnt + 1, q0 + 1);
    cnt += tot;
    for (long long i = 1; i <= cnt; i++) q[i] = q0[i];
  }
}
void solve(long long x) {
  b[x] = 1;
  work(x);
  for (long long i = h[x]; i; i = nextn[i]) {
    long long y = to[i];
    if (b[y]) continue;
    rt = 0, mxsize[0] = n;
    nn = size[y];
    findrt(y, x);
    solve(rt);
  }
}
signed main() {
  scanf("%lld%lld%lld", &n, &k_, &k);
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &y, &ww);
    add(i + 1, y, ww), add(y, i + 1, ww);
  }
  rt = 0, nn = n;
  mxsize[0] = n;
  findrt(1, 0);
  solve(rt);
  printf("%lld", ans);
}