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 = 100005, maxm = maxn << 1;
int n, e, cnt, L, w;
int start[maxn], to[maxm], then[maxm], worth[maxm], size[maxn], val[maxn],
    fin[maxn], p[maxn], dis[maxn], dep[maxn], t[maxn];
long long ans;
inline void add(int x, int y, int z) {
  then[++e] = start[x], start[x] = e, to[e] = y, worth[e] = z;
}
inline int cmp(int a, int b) { return dis[a] < dis[b]; }
void update(int x, int v) {
  if (x == 0) return;
  for (int i = x; i <= n + 1; i += i & -i) t[i] += v;
}
int query(int x) {
  if (x < 0) return 0;
  int res = 0;
  for (int i = x; i; i -= i & -i) res += t[i];
  return res;
}
void getrt(int x, int last, int sz, int &res) {
  size[x] = 1, val[x] = 0;
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (y == last || fin[y]) continue;
    getrt(y, x, sz, res);
    val[x] = max(val[x], size[y]), size[x] += size[y];
  }
  val[x] = max(val[x], sz - size[x]);
  if (val[x] < val[res]) res = x;
}
void dfs(int x, int last) {
  p[++cnt] = x;
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (y == last || fin[y]) continue;
    dis[y] = dis[x] + worth[i];
    dep[y] = dep[x] + 1;
    dfs(y, x);
  }
}
long long calc(int x, int d, int dd) {
  cnt = 0, dis[x] = d, dep[x] = dd, dfs(x, 0);
  sort(p + 1, p + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) update(dep[p[i]] + 1, 1);
  int l = 1, r = cnt;
  long long res = 0;
  while (l <= r) {
    if (dis[p[l]] + dis[p[r]] <= w) {
      update(dep[p[l]] + 1, -1);
      res += query(L - dep[p[l]] + 1);
      l++;
    } else {
      update(dep[p[r]] + 1, -1);
      r--;
    }
  }
  return res;
}
void solve(int x, int sz) {
  int res = 0;
  val[res] = 1000050000, getrt(x, 0, sz, res);
  x = res, fin[x] = 1, ans += calc(x, 0, 0);
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (fin[y]) continue;
    ans -= calc(y, worth[i], 1);
    solve(y, size[y]);
  }
}
int main() {
  scanf("%d%d%d", &n, &L, &w);
  for (int i = 2; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, i, y), add(i, x, y);
  }
  solve(1, n);
  printf("%lld\n", ans);
  return 0;
}