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;
int n, l, w, pp, ww, un, uk, x;
vector<int> a[100005], b[100005], c[100005], cc[100005];
long long z = 0;
vector<pair<int, int> > h[100005], vv[100005];
pair<int, int> r[100005];
int fenvic[100005];
map<int, int> qqq;
map<int, int>::iterator it;
void output(int xx, int yy) {
  cout << xx << " " << yy;
  for (int i = 0; i < h[xx].size(); i++) cout << " " << h[xx][i].first;
  cout << "****";
  for (int i = 0; i < h[yy].size(); i++) cout << " " << h[yy][i].first;
  cout << " ";
  return;
}
inline void merge(int vx, int vy, int pp) {
  qqq.clear();
  for (int i = 0; i < h[vy].size(); i++) qqq[h[vy][i].second] = 1;
  int x, y, zz = 0, un = 0, uk = 0, kk = h[vy].size() - 1;
  for (it = qqq.begin(); it != qqq.end(); it++) {
    zz++;
    fenvic[zz] = 0;
    it->second = zz;
  }
  for (int i = 0; i < h[vy].size(); i++) {
    x = qqq[h[vy][i].second];
    while (x <= zz) {
      fenvic[x]++;
      x = (x << 1) - (x & (x - 1));
    }
  }
  vector<int> qq, lev, dist, p;
  for (int i = 0; i < vv[vx].size(); i++) {
    qq.push_back(vv[vx][i].first);
    lev.push_back(1);
    dist.push_back(vv[vx][i].second);
    p.push_back(-1);
    uk++;
  }
  int i;
  while (un != uk) {
    x = qq[un];
    while (kk >= 0 && h[vy][kk].first > l - lev[un]) {
      y = qqq[h[vy][kk].second];
      while (y <= zz) {
        fenvic[y]--;
        y = (y << 1) - (y & (y - 1));
      }
      kk--;
    }
    it = qqq.upper_bound(w - dist[un]);
    if (it == qqq.begin())
      y = 0;
    else {
      it--;
      y = it->second;
    }
    while (y > 0) {
      z += fenvic[y];
      y &= y - 1;
    }
    un++;
    for (i = 0; i < a[x].size(); i++) {
      if (a[x][i] != pp && c[x][i] && a[x][i] != p[un - 1]) {
        qq.push_back(a[x][i]);
        p.push_back(x);
        uk++;
        lev.push_back(lev[un - 1] + 1);
        dist.push_back(dist[un - 1] + b[x][i]);
      }
    }
  }
  for (int i = 0; i < h[vy].size(); i++) h[vx].push_back(h[vy][i]);
  for (int i = 0; i < vv[vy].size(); i++) vv[vx].push_back(vv[vy][i]);
  vv[vy].clear();
  sort(h[vx].begin(), h[vx].end());
  h[vy].clear();
  return;
}
void solve(int v, int pp = 0, int ddist = 2000000000, int lev = 200000) {
  vector<int> p, f, g, q, ff;
  vector<pair<int, int> > hh;
  int un, uk, x, y;
  q.clear();
  f.clear();
  g.clear();
  p.clear();
  ff.clear();
  q.push_back(v);
  un = 0;
  uk = 1;
  p.push_back(0);
  r[v] = make_pair(0, 0);
  ff.push_back(-1);
  g.push_back(0);
  f.push_back(0);
  hh.push_back(make_pair(0, 0));
  if (lev < 2 && ddist <= w) z++;
  while (un != uk) {
    x = q[un];
    un++;
    for (int i = 0; i < a[x].size(); i++)
      if (a[x][i] != p[un - 1] && c[x][i]) {
        p.push_back(x);
        ff.push_back(un - 1);
        q.push_back(a[x][i]);
        g.push_back(0);
        f.push_back(0);
        r[a[x][i]] = make_pair(r[x].first + 1, r[x].second + b[x][i]);
        if (r[a[x][i]].first <= l - lev && r[a[x][i]].second <= w - ddist) {
          z++;
          hh.push_back(r[a[x][i]]);
        }
        uk++;
      }
  }
  if (uk == 1) {
    h[v] = hh;
    return;
  }
  sort(h[v].begin(), h[v].end());
  for (int i = uk - 1; i >= 0; i--) {
    f[i]++;
    g[i] = max(g[i], uk - f[i]);
    if (ff[i] == -1) continue;
    f[ff[i]] += f[i];
    g[ff[i]] = max(g[ff[i]], f[i]);
  }
  x = 0;
  y = 2000000000;
  for (int i = 0; i < uk; i++)
    if (g[i] < y) y = g[i], x = q[i];
  g.clear();
  f.clear();
  for (int i = 0; i < a[x].size(); i++) {
    y = a[x][i];
    if (y == pp || c[x][i] == 0) continue;
    c[x][i] = 0;
    c[y][cc[x][i]] = 0;
    g.push_back(y);
    f.push_back(y);
    solve(y, x, b[x][i], 1);
    vv[y].clear();
    vv[y].push_back(make_pair(y, b[x][i]));
    for (int j = 0; j < h[y].size(); j++) {
      h[y][j].second += b[x][i];
      h[y][j].first++;
    }
  }
  int sh = 2, m = 1;
  for (; m < g.size(); sh *= 2, m *= 2) {
    for (int i = 0; i + m < g.size(); i += sh) {
      merge(g[i], g[i + m], x);
    }
  }
  m = 0;
  for (int i = 0; i < a[x].size(); i++) {
    if (m < f.size() && f[m] == a[x][i]) {
      c[x][i] = 1;
      c[a[x][i]][cc[x][i]] = 1;
      m++;
    }
  }
  h[v] = hh;
  return;
}
int main() {
  scanf("%d%d%d", &n, &l, &w);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &pp, &ww);
    a[pp].push_back(i);
    b[pp].push_back(ww);
    c[pp].push_back(1);
    c[i].push_back(1);
    cc[pp].push_back(c[i].size() - 1);
    cc[i].push_back(c[pp].size() - 1);
    a[i].push_back(pp);
    b[i].push_back(ww);
  }
  solve(1);
  printf("%I64d\n", z);
  return 0;
}