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 = 1e5 + 7;
using namespace std;
int n, l, d, x, w, cnt, root, sum, head, tail;
int t[maxn];
long long ans;
int size[maxn], vis[maxn], dis[maxn], len[maxn], f[maxn];
int ls[maxn];
struct edge {
  int y, w, next;
} g[maxn * 2];
struct rec {
  int l, d;
} h[maxn];
queue<int> q;
void add(int x, int y, int w) {
  g[++cnt] = (edge){y, w, ls[x]};
  ls[x] = cnt;
}
bool cmp1(rec x, rec y) { return x.d < y.d; }
bool cmp2(rec x, rec y) { return x.d > y.d; }
void findroot(int x, int fa) {
  size[x] = 1;
  f[x] = 0;
  for (int i = ls[x]; i > 0; i = g[i].next) {
    int y = g[i].y;
    if ((y == fa) || (vis[y])) continue;
    findroot(y, x);
    size[x] += size[y];
    f[x] = max(f[x], size[y]);
  }
  f[x] = max(f[x], sum - size[x]);
  if ((f[x] < f[root]) || (!root)) root = x;
}
int lowbit(int x) { return x & (-x); }
void updata(int x, int k) {
  while (x <= n) {
    t[x] += k;
    x += lowbit(x);
  }
}
int getsum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += t[x];
    x -= lowbit(x);
  }
  return sum;
}
void dfs(int x, int fa) {
  size[x] = 1;
  for (int i = ls[x]; i > 0; i = g[i].next) {
    int y = g[i].y;
    if ((y == fa) || (vis[y])) continue;
    len[y] = len[x] + 1;
    dis[y] = dis[x] + g[i].w;
    h[++tail] = (rec){len[y], dis[y]};
    dfs(y, x);
    size[x] += size[y];
    if (x == root) {
      sort(h + 1, h + head + 1, cmp1);
      sort(h + head + 1, h + tail + 1, cmp2);
      int k = 1;
      for (int j = head + 1; j <= tail; j++) {
        while ((h[k].d + h[j].d <= d) && (k <= head)) {
          updata(h[k].l + 1, 1);
          k++;
        }
        ans += (long long)getsum(l - h[j].l + 1);
      }
      for (int g = 1; g < k; g++) updata(h[g].l + 1, -1);
      head = tail;
      q.push(y);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &l, &d);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &x, &w);
    add(i, x, w);
    add(x, i, w);
  }
  q.push(1);
  size[1] = n;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    sum = size[x];
    root = 0;
    findroot(x, 0);
    len[root] = dis[root] = 0;
    head = 1;
    tail = 1;
    h[1] = (rec){0, 0};
    dfs(root, 0);
    vis[root] = 1;
  }
  printf("%lld", ans);
}