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 N = 356438;
int from[N], to[N], limL, nextp[N], headp[N], p[N], Lcnt[N], chcnt[N], num,
    a[N], b[N], sz, c[N];
bool taboo[N], boo[N];
long long limW, W[N], Wcnt[N], ans;
inline int lowbit(int x) { return x & (-x); }
inline int ask(int x) {
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
inline void add(int x, int y) {
  while (x < N) {
    c[x] += y;
    x += lowbit(x);
  }
}
inline void addedge(int x, int y, long long z, int &tot) {
  from[tot] = x;
  to[tot] = y;
  W[tot] = z;
  nextp[tot] = headp[x];
  headp[x] = tot;
  ++tot;
}
void dfs(int x) {
  a[sz] = x;
  ++sz;
  chcnt[x] = 1;
  for (int i = headp[x]; i != -1; i = nextp[i]) {
    if (taboo[i]) continue;
    int y = to[i];
    if (p[x] != -1 && from[p[x]] == y) continue;
    p[y] = i;
    dfs(y);
    chcnt[x] += chcnt[y];
  }
}
void dfs2(int x, bool b) {
  boo[x] = b;
  for (int i = headp[x]; i != -1; i = nextp[i]) {
    if (taboo[i]) continue;
    int y = to[i];
    if (p[x] != -1 && from[p[x]] == y) continue;
    p[y] = i;
    Lcnt[y] = Lcnt[x] + 1;
    Wcnt[y] = Wcnt[x] + W[i];
    dfs2(y, b);
  }
}
inline bool cmpb(int x, int y) {
  if (Wcnt[x] != Wcnt[y]) return Wcnt[x] < Wcnt[y];
  if (Lcnt[x] != Lcnt[y]) return Lcnt[x] < Lcnt[y];
  return boo[x] < boo[y];
}
void work(int root) {
  p[root] = -1;
  Lcnt[root] = 0;
  Wcnt[root] = 0;
  sz = 0;
  dfs(root);
  if (sz == 1) return;
  int tempsz = 0, tempedge = -1;
  for (int i = 1; i < sz; ++i) {
    int x = a[i];
    if (min(chcnt[x], sz - chcnt[x]) > tempsz) {
      tempsz = min(chcnt[x], sz - chcnt[x]);
      tempedge = p[x];
    }
  }
  taboo[tempedge] = taboo[tempedge ^ 1] = true;
  Lcnt[from[tempedge]] = 0;
  Wcnt[from[tempedge]] = 0;
  p[from[tempedge]] = -1;
  dfs2(from[tempedge], true);
  Lcnt[to[tempedge]] = 0;
  Wcnt[to[tempedge]] = 0;
  p[to[tempedge]] = -1;
  dfs2(to[tempedge], false);
  for (int i = 0; i < sz; ++i) {
    int x = a[i];
    if (boo[x]) {
      Lcnt[x] = limL - Lcnt[x] - 1;
      Wcnt[x] = limW - Wcnt[x] - W[tempedge];
    }
    b[i] = x;
  }
  sort(b, b + sz, cmpb);
  for (int i = 0; i < sz; ++i) {
    int x = b[i];
    if (boo[x]) {
      if (Lcnt[x] < 0) continue;
      ans += ask(Lcnt[x] + 1);
    } else {
      add(Lcnt[x] + 1, 1);
    }
  }
  for (int i = 0; i < sz; ++i) {
    int x = b[i];
    if (boo[x]) {
    } else {
      add(Lcnt[x] + 1, -1);
    }
  }
  work(to[tempedge]);
  work(from[tempedge]);
}
int main() {
  int n;
  scanf("%d%d%I64d", &n, &limL, &limW);
  int tot = 0;
  memset(headp, -1, sizeof(headp));
  for (int i = 2; i <= n; ++i) {
    int j;
    long long temp;
    scanf("%d %I64d", &j, &temp);
    addedge(i, j, temp, tot);
    addedge(j, i, temp, tot);
  }
  work(1);
  printf("%I64d\n", ans);
}