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 N = 100005, INF = 1e9 + 7;
long long ans;
int n, m, Ql, Qw, Mx, Rt;
int siz[N], vis[N];
std::vector<std::pair<int, int> > all, sub[N];
namespace TR {
int tr[N], lim;
inline void Init(int _lim) {
  lim = _lim;
  for (int i = 0; i <= lim; ++i) tr[i] = 0;
}
inline void Add(int x, int v) {
  for (; x <= lim; x += x & -x) tr[x] += v;
}
inline int Query(int x, int re = 0) {
  for (; x > 0; x -= x & -x) re += tr[x];
  return re;
}
}  // namespace TR
int yun, las[N], to[N << 1], pre[N << 1], wi[N << 1];
inline void Add(int a, int b, int c) {
  to[++yun] = b;
  wi[yun] = c;
  pre[yun] = las[a];
  las[a] = yun;
}
inline void Ma(int &a, int b) {
  if (a < b) a = b;
}
void Dfs_siz(int x, int Fa) {
  siz[x] = 1;
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]] && to[i] != Fa) {
      Dfs_siz(to[i], x);
      siz[x] += siz[to[i]];
    }
}
void Get_core(int x, int Fa, int size) {
  int mx = size - siz[x];
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]] && to[i] != Fa) {
      Get_core(to[i], x, size);
      Ma(mx, siz[to[i]]);
    }
  if (mx < Mx) Mx = mx, Rt = x;
}
inline long long Calc(std::vector<std::pair<int, int> > &v, int nl, int nw) {
  std::sort(v.begin(), v.end());
  int up = 0;
  long long re = 0;
  for (int i = 0; i < (int)v.size(); ++i) Ma(up, v[i].second);
  TR::Init(up);
  for (int i = 0; i < (int)v.size(); ++i) TR::Add(v[i].second, 1);
  for (int i = 0, j = (int)v.size() - 1; i < (int)v.size(); ++i) {
    while (j >= i && v[i].first + v[j].first > nw) {
      TR::Add(v[j].second, -1);
      --j;
    }
    if (j < i) break;
    re += TR::Query(std::min(up, nl - v[i].second));
    TR::Add(v[i].second, -1);
  }
  return re;
}
void Dfs_ins(int gr, int x, int Fa, int nl, int nw) {
  all.push_back(std::make_pair(nw, nl));
  sub[gr].push_back(std::make_pair(nw, nl));
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]] && to[i] != Fa) {
      Dfs_ins(gr, to[i], x, nl + 1, nw + wi[i]);
    }
}
void Solve(int x) {
  Dfs_siz(x, 0);
  all.clear();
  vis[x] = 1;
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]]) {
      sub[to[i]].clear();
      Dfs_ins(to[i], to[i], x, 1, wi[i]);
    }
  ans += Calc(all, Ql, Qw);
  for (int i = 0; i < (int)all.size(); ++i) {
    if (all[i].first <= Qw && all[i].second <= Ql) ++ans;
  }
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]]) {
      ans -= Calc(sub[to[i]], Ql, Qw);
    }
  for (int i = las[x]; i; i = pre[i])
    if (!vis[to[i]]) {
      Mx = INF;
      Get_core(to[i], x, siz[to[i]]);
      Solve(Rt);
    }
}
int main() {
  scanf("%d%d%d", &n, &Ql, &Qw);
  for (int i = 2, x, y; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    Add(x, i, y);
    Add(i, x, y);
  }
  Dfs_siz(1, 0);
  Mx = INF;
  Get_core(1, 0, n);
  Solve(Rt);
  printf("%lld\n", ans);
  return 0;
}