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 = 1e5 + 5, M = 2 * N;
int n, nn, nl, nw, i;
long long ans;
int read() {
  char c = getchar();
  int k = 0;
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) k = (k << 3) + (k << 1) + c - 48;
  return k;
}
int v, et, he[N];
struct edge {
  int l, to, v;
} e[M];
void line(int x, int y) {
  e[++et].l = he[x];
  he[x] = et;
  e[et].to = y;
  e[et].v = v;
}
int size[N], p, mp, ap, t1, t2;
struct arr {
  int v, l;
} q1[N], q2[N];
bool operator<(arr A, arr B) { return A.v < B.v; }
bool f[N];
void find(int x, int fa) {
  size[x] = 1;
  int i, y, k = 0;
  for (i = he[x]; i; i = e[i].l) {
    y = e[i].to;
    if (y == fa || f[y]) continue;
    find(y, x);
    size[x] += size[y];
    k = max(k, size[y]);
  }
  k = max(k, p - size[x]);
  if (k < mp) mp = k, ap = x;
}
void dfs(int x, int fa, int w, int l) {
  q1[++t1] = q2[++t2] = (arr){w, l};
  for (int i = he[x]; i; i = e[i].l) {
    int y = e[i].to;
    if (y == fa || f[y]) continue;
    dfs(y, x, w + e[i].v, l + 1);
  }
}
int g[N];
void add(int x) {
  for (; x <= nn; x += x & -x) g[x]++;
}
int ask(int x) {
  int k = 0;
  for (; x; x -= x & -x) k += g[x];
  return k;
}
void clear(int x) {
  for (; x <= nn && g[x]; x += x & -x) g[x] = 0;
}
long long cal(arr *a, int n) {
  long long sum = 0;
  int i, j = 1;
  sort(a + 1, a + n + 1);
  for (i = n; i; i--) {
    for (; j <= n && a[i].v + a[j].v <= nw; j++) add(a[j].l + 1);
    if (a[i].l <= nl) sum += ask(nl - a[i].l + 1);
  }
  for (i = 1; i < j; i++) clear(a[i].l + 1);
  return sum;
}
void divide(int x) {
  f[x] = 1;
  int i, y;
  q2[t2 = 1] = (arr){0, 0};
  for (i = he[x]; i; i = e[i].l)
    if (!f[y = e[i].to]) {
      t1 = 0;
      dfs(y, 0, e[i].v, 1);
      ans -= cal(q1, t1);
    }
  ans += cal(q2, t2) - 1;
  for (i = he[x]; i; i = e[i].l)
    if (!f[y = e[i].to]) {
      p = size[y];
      mp = p + 1;
      find(y, 0);
      divide(ap);
    }
}
int main() {
  n = read();
  nn = n + 1;
  nl = read();
  nw = read();
  for (i = 2; i <= n; i++) {
    int x = read();
    v = read();
    line(i, x);
    line(x, i);
  }
  p = n;
  mp = p + 1;
  find(1, 0);
  divide(ap);
  printf("%I64d", ans / 2);
}