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 int Maxn = int(1e5);
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Node {
  int to, nxt, w;
} Edge[Maxn * 2 + 5];
int tot, Head[Maxn + 5];
inline void Addedge(int x, int y, int z) {
  Edge[++tot] = (Node){y, Head[x], z};
  Head[x] = tot;
}
long long ans;
int n, l, w, rt, sum;
int siz[Maxn + 5], maxs[Maxn + 5], vis[Maxn + 5];
int dis1[Maxn + 5], dis2[Maxn + 5], cur, allcur;
struct Point {
  int a, b, c;
} tmp[Maxn + 5], all[Maxn + 5];
inline int cmp1(Point x, Point y) { return x.a < y.a; }
inline int cmp2(Point x, Point y) { return x.a > y.a; }
int t[Maxn + 5], top;
inline void Add(int x, int y) {
  while (x <= l) t[x] += y, x += (x & -x);
}
inline int Query(int x) {
  int res = 0;
  while (x > 0) res += t[x], x -= (x & -x);
  return res;
}
inline void dfs1(int x, int f) {
  siz[x] = 1, maxs[x] = 0;
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (y == f || vis[y]) continue;
    dfs1(y, x);
    siz[x] += siz[y];
    maxs[x] = max(maxs[x], siz[y]);
  }
  maxs[x] = max(maxs[x], sum - siz[x]);
  rt = maxs[x] < maxs[rt] ? x : rt;
}
inline void dfs2(int x, int f, int grand) {
  tmp[++cur] = (Point){dis1[x], dis2[x], grand};
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (y == f || vis[y]) continue;
    dis1[y] = dis1[x] + Edge[i].w;
    dis2[y] = dis2[x] + 1;
    dfs2(y, x, grand);
  }
}
inline void Count(int x) {
  int it = 1;
  allcur = 0;
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (vis[y]) continue;
    dis1[y] = Edge[i].w, dis2[y] = 1;
    cur = 0, dfs2(y, x, y);
    for (register int j = 1; j <= cur; ++j)
      if (tmp[j].a <= w) all[++allcur] = tmp[j];
  }
  sort(all + 1, all + allcur + 1, cmp1);
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (vis[y]) continue;
    dis1[y] = Edge[i].w, dis2[y] = 1;
    it = 1, cur = 0, dfs2(y, x, y);
    sort(tmp + 1, tmp + cur + 1, cmp2);
    for (register int j = 1; j <= cur; ++j) {
      while (it <= allcur && tmp[j].a + all[it].a <= w) {
        if (all[it].c < y) Add(all[it].b, 1);
        it++;
      }
      if (tmp[j].a <= w && tmp[j].b <= l) ans++;
      if (tmp[j].b < l) ans += Query(l - tmp[j].b);
    }
    for (register int j = 1; j < it; ++j)
      if (all[j].c < y) Add(all[j].b, -1);
  }
}
inline void Divide(int x) {
  vis[x] = 1;
  Count(x);
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (vis[y]) continue;
    rt = 0, maxs[0] = sum = siz[y];
    dfs1(y, 0), dfs1(rt, 0);
    Divide(rt);
  }
}
int main() {
  n = read(), l = read(), w = read();
  for (register int i = 1; i < n; ++i) {
    int a = read(), b = read();
    Addedge(i + 1, a, b), Addedge(a, i + 1, b);
  }
  maxs[0] = sum = n;
  dfs1(1, 0), dfs1(rt, 0);
  Divide(rt);
  printf("%I64d", ans);
  return 0;
}