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>
const int MAXN = 100005;
struct data {
  int u, l, w;
  data() {}
  data(int u, int l, int w) : u(u), l(l), w(w) {}
};
int n, l, w;
int edgey[2 * MAXN];
int edgew[2 * MAXN];
int enext[2 * MAXN];
int ehead[MAXN];
int vis[MAXN];
data cc[MAXN];
int cn;
int ss[MAXN];
long long ans;
void addedge(int x, int y, int w) {
  static int edgen;
  edgey[edgen] = y;
  edgew[edgen] = w;
  enext[edgen] = ehead[x];
  ehead[x] = edgen++;
}
void add(int x, int y, int w) {
  addedge(x, y, w);
  addedge(y, x, w);
}
void init() {
  scanf("%d%d%d", &n, &l, &w);
  memset(ehead, -1, sizeof(ehead));
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    add(i, u, v);
  }
}
int getroot(int x) {
  static int que[MAXN];
  static int fa[MAXN];
  static int sz[MAXN];
  static int msz[MAXN];
  int qb = 0, qe = 1;
  que[0] = x;
  fa[x] = -1;
  sz[x] = 1;
  while (qb < qe) {
    int x = que[qb++];
    for (int i = ehead[x]; i != -1; i = enext[i])
      if (edgey[i] != fa[x] && !vis[edgey[i]]) {
        fa[edgey[i]] = x;
        sz[edgey[i]] = 1;
        que[qe++] = edgey[i];
      }
  }
  for (int i = qe - 1; i >= 1; --i) sz[fa[que[i]]] += sz[que[i]];
  for (int i = 0; i < qe; ++i) {
    msz[que[i]] = sz[que[0]] - sz[que[i]];
    if (sz[que[i]] > msz[fa[que[i]]]) msz[fa[que[i]]] = sz[que[i]];
  }
  for (int i = 0; i < qe; ++i)
    if (msz[que[i]] * 2 <= sz[que[0]]) return que[i];
  return -1;
}
void getdist(int x) {
  static int que[MAXN];
  static int fa[MAXN];
  static int rr[MAXN];
  static int dist[MAXN];
  static int dist_w[MAXN];
  int qb = 0, qe = 1;
  que[0] = x;
  fa[x] = -1;
  rr[x] = -1;
  dist[x] = 0;
  dist_w[x] = 0;
  while (qb < qe) {
    int x = que[qb++];
    for (int i = ehead[x]; i != -1; i = enext[i])
      if (edgey[i] != fa[x] && !vis[edgey[i]]) {
        fa[edgey[i]] = x;
        if (rr[x] == -1)
          rr[edgey[i]] = edgey[i];
        else
          rr[edgey[i]] = rr[x];
        dist[edgey[i]] = dist[x] + 1;
        dist_w[edgey[i]] = dist_w[x] + edgew[i];
        que[qe++] = edgey[i];
      }
  }
  cn = qe;
  for (int i = 0; i < qe; ++i)
    cc[i] = data(rr[que[i]], dist[que[i]], dist_w[que[i]]);
}
void insert(int x, int y) {
  if (x > l) return;
  ++x;
  while (x <= l + 1) {
    ss[x] += y;
    x += x & -x;
  }
}
int query(int x) {
  if (x < 0) return 0;
  ++x;
  int sum = 0;
  while (x) {
    sum += ss[x];
    x -= x & -x;
  }
  return sum;
}
void getans(const data *a, int n, int vv) {
  for (int i = 0, j = n - 1; i <= n; ++i) {
    while (j >= 0 && (i == n || a[j].w + a[i].w > w)) {
      ans += query(l - a[j].l);
      --j;
    }
    if (i == n) break;
    insert(a[i].l, vv);
  }
  for (int i = 0; i < n; ++i) insert(a[i].l, -vv);
}
bool cmp1(const data &x, const data &y) { return x.w < y.w; }
bool cmp2(const data &x, const data &y) { return x.u < y.u; }
void work(int x) {
  x = getroot(x);
  vis[x] = 1;
  getdist(x);
  std::sort(cc, cc + cn, cmp1);
  getans(cc, cn, 1);
  std::stable_sort(cc, cc + cn, cmp2);
  for (int i = 1; i < cn;) {
    int l = i;
    while (i < cn && cc[i].u == cc[l].u) ++i;
    getans(cc + l, i - l, -1);
  }
  for (int i = ehead[x]; i != -1; i = enext[i])
    if (!vis[edgey[i]]) work(edgey[i]);
}
void solve() {
  work(1);
  printf(
      "%ll"
      "d\n",
      (ans - n) / 2);
}
int main() {
  init();
  solve();
  return 0;
}