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 double eps = 1e-8;
const double pi = acos(-1.0);
struct TA {
  int a[100111];
  int n;
  void init(int _n) {
    n = _n;
    memset(a, 0, sizeof(int) * (_n + 1));
  }
  void add(int x, int v) {
    for (x++; x <= n; x += ((x) & (-(x)))) a[x] += v;
  }
  int get(int x) {
    x = min(x, n - 1);
    int ret = 0;
    for (x++; x; x -= ((x) & (-(x)))) ret += a[x];
    return ret;
  }
} ta;
vector<pair<int, int> > vec[100111];
long long ans;
int W, L;
bool del[100111];
int size[100111], opt[100111];
vector<int> all;
void calc(int u, int fa) {
  int i, v;
  size[u] = 1;
  opt[u] = 0;
  all.push_back(u);
  for (i = 0; i < vec[u].size(); i++) {
    if ((v = vec[u][i].first) == fa || del[v]) continue;
    calc(v, u);
    size[u] += size[v];
    opt[u] = max(opt[u], size[v]);
  }
}
int GetHeart(int u) {
  int i, minOpt = 1e9, heart, v;
  all.clear();
  calc(u, -1);
  for (i = 0; i < all.size(); i++) {
    v = all[i];
    opt[v] = max(opt[v], size[u] - size[v]);
    if (opt[v] < minOpt) {
      minOpt = opt[v];
      heart = v;
    }
  }
  return heart;
}
vector<pair<int, int> > allp;
void dfs(int u, int w, int l, int fa, vector<pair<int, int> >& v) {
  v.push_back(make_pair(w, l));
  allp.push_back(make_pair(w, l));
  for (vector<pair<int, int> >::iterator e = vec[u].begin(); e != vec[u].end();
       ++e) {
    if (del[e->first] || e->first == fa) continue;
    dfs(e->first, w + e->second, l + 1, u, v);
  }
}
long long calc(vector<pair<int, int> > a) {
  int mm = 0;
  sort(a.begin(), a.end());
  for (vector<pair<int, int> >::iterator e = a.begin(); e != a.end(); ++e) {
    mm = max(mm, e->second);
  }
  ta.init(mm + 1);
  vector<pair<int, int> >::iterator v = a.begin();
  long long ret = 0;
  for (vector<pair<int, int> >::reverse_iterator e = a.rbegin(); e != a.rend();
       ++e) {
    while (v != a.end() && v->first + e->first <= W) ta.add(v->second, 1), ++v;
    if (e->second <= L) ret += ta.get(L - e->second);
  }
  return ret;
}
vector<pair<int, int> > ch[100111];
void dfs(int u) {
  u = GetHeart(u);
  int nCh = 0, i;
  allp.clear();
  allp.push_back(make_pair(0, 0));
  ch[nCh].clear();
  ch[nCh++].push_back(make_pair(0, 0));
  for (vector<pair<int, int> >::iterator e = vec[u].begin(); e != vec[u].end();
       ++e) {
    if (del[e->first]) continue;
    ch[nCh].clear();
    dfs(e->first, e->second, 1, u, ch[nCh++]);
  }
  ans += calc(allp);
  for (i = 0; i < nCh; i++) ans -= calc(ch[i]);
  del[u] = true;
  for (vector<pair<int, int> >::iterator e = vec[u].begin(); e != vec[u].end();
       ++e)
    if (!del[e->first]) dfs(e->first);
}
int main() {
  int i, n, pi, wi;
  scanf("%d%d%d", &n, &L, &W);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &pi, &wi);
    vec[i + 1].push_back(make_pair(pi, wi));
    vec[pi].push_back(make_pair(i + 1, wi));
  }
  ans = 0;
  dfs(1);
  cout << ans / 2 << endl;
  return 0;
}