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;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
struct SegmTree {
  const static int maxn = (1 << 17);
  int n;
  int *ar, *a;
  SegmTree() : n(0), ar(0), a(0) {}
  ~SegmTree() {
    delete[] ar;
    delete[] a;
  }
  void build(int _n, pair<int, int> *tmpY) {
    for (n = 1; n < _n; n <<= 1)
      ;
    ar = new int[n], a = new int[2 * n];
    for (int i = 0; i < n; i++)
      if (i < _n)
        ar[i] = tmpY[i].first, a[i + n] = tmpY[i].second;
      else
        ar[i] = ((int)1e9) + i, a[i + n] = 0;
    for (int i = n - 1; i; i--) a[i] = a[2 * i] + a[2 * i + 1];
  }
  int get(int v, int l, int r, int l0, int r0) {
    if (l >= r0 || l0 >= r) return 0;
    if (l0 <= l && r <= r0) return a[v];
    int m = (l + r) / 2;
    return get(2 * v, l, m, l0, r0) + get(2 * v + 1, m, r, l0, r0);
  }
  int get(int l, int r) { return get(1, 0, n, l, r); }
};
struct SegmTree2D {
  const static int maxn = (1 << 17);
  int n;
  pair<int, int> *ar;
  SegmTree *a;
  SegmTree2D() : n(0), ar(0), a(0) {}
  ~SegmTree2D() {
    delete[] a;
    delete[] ar;
  }
  static pair<int, int> sortedY[maxn], tmpY[maxn];
  void build(int v, int l, int r) {
    if (r - l > 1) {
      int m = (l + r) / 2;
      build(2 * v, l, m);
      build(2 * v + 1, m, r);
      merge(sortedY + l, sortedY + m, sortedY + m, sortedY + r, tmpY);
      memcpy(sortedY + l, tmpY, sizeof(tmpY[0]) * (r - l));
    } else
      sortedY[l] = make_pair(ar[l].second, ar[l].first);
    int cnt = 0;
    for (int i = l; i < r;) {
      int i0 = i;
      while (i < r && sortedY[i].first == sortedY[i0].first) i++;
      tmpY[cnt++] = make_pair(sortedY[i0].first, i - i0);
    }
    a[v].build(cnt, tmpY);
  }
  void build() {
    assert(n <= maxn);
    sort(ar, ar + n);
    a = new SegmTree[2 * n];
    build(1, 0, n);
  }
  int get(int v, int l, int r, int l0, int r0, int yl, int yr) {
    if (l0 >= r || l >= r0) return 0;
    if (l0 <= l && r <= r0)
      return a[v].get(lower_bound(a[v].ar, a[v].ar + a[v].n, yl) - a[v].ar,
                      lower_bound(a[v].ar, a[v].ar + a[v].n, yr) - a[v].ar);
    int m = (l + r) / 2;
    return get(2 * v, l, m, l0, r0, yl, yr) +
           get(2 * v + 1, m, r, l0, r0, yl, yr);
  }
  int get(int x, int y) {
    int res = get(1, 0, n, 0,
                  lower_bound(ar, ar + n, make_pair(x + 1, -((int)1e9))) - ar,
                  -((int)1e9), y + 1);
    return res;
  }
};
pair<int, int> SegmTree2D::sortedY[SegmTree2D::maxn],
    SegmTree2D::tmpY[SegmTree2D::maxn];
struct MergableSet {
  const static int maxLog = 18;
  SegmTree2D *ss[maxLog];
  MergableSet() { memset(ss, 0, sizeof(ss)); }
  void add(int x, int y) {
    int cnt = 0;
    for (cnt = 0; cnt < maxLog && ss[cnt]; cnt++)
      ;
    assert(cnt < maxLog);
    ss[cnt] = new SegmTree2D();
    ss[cnt]->n = (1 << cnt);
    ss[cnt]->ar = new pair<int, int>[ss[cnt]->n];
    for (int iter = 0, r = 1; iter < cnt; iter++) {
      for (int i = 0; i < ss[iter]->n; i++) ss[cnt]->ar[r++] = ss[iter]->ar[i];
      delete ss[iter];
      ss[iter] = 0;
    }
    ss[cnt]->ar[0] = make_pair(x, y);
    ss[cnt]->build();
  }
  int get(int x, int y) {
    int ans = 0;
    for (int iter = 0; iter < maxLog; iter++)
      if (ss[iter]) ans += ss[iter]->get(x, y);
    return ans;
  }
};
struct Info {
  MergableSet m;
  vector<pair<int, int> > points;
  int toaddx, toaddy;
  Info() {
    m = MergableSet();
    toaddx = toaddy = 0;
    points.clear();
  }
  void add(int x, int y) {
    points.push_back(make_pair(x - toaddx, y - toaddy));
    m.add(x - toaddx, y - toaddy);
  }
  int get(int x, int y) { return m.get(x - toaddx, y - toaddy); }
};
const int maxn = (int)1e5;
Info *infos[maxn];
vector<vector<int> > es, cs;
int pr[maxn];
int n, len, weight;
long long dfs(int v) {
  long long ans = 0;
  Info *cur = new Info();
  cur->add(0, 0);
  for (int it = 0; it < ((int)(es[v]).size()); it++) {
    int u = es[v][it];
    ans += dfs(u);
    Info *toadd = infos[u];
    assert(toadd);
    toadd->toaddx += 1, toadd->toaddy += cs[v][it];
    if (((int)(cur->points).size()) < ((int)(toadd->points).size()))
      swap(cur, toadd);
    for (int i = 0; i < ((int)(toadd->points).size()); i++) {
      pair<int, int> newPair = toadd->points[i];
      newPair.first += toadd->toaddx, newPair.second += toadd->toaddy;
      ans += cur->get(len - newPair.first, weight - newPair.second);
    }
    for (int i = 0; i < ((int)(toadd->points).size()); i++) {
      pair<int, int> newPair = toadd->points[i];
      newPair.first += toadd->toaddx, newPair.second += toadd->toaddy;
      cur->add(newPair.first, newPair.second);
    }
  }
  infos[v] = cur;
  return ans;
}
int main() {
  srand(rdtsc());
  while (scanf("%d%d%d", &n, &len, &weight) >= 1) {
    es = cs = vector<vector<int> >(n);
    pr[0] = -1;
    for (int i = 1; i < n; i++) {
      int w;
      scanf("%d%d", &pr[i], &w);
      --pr[i];
      es[pr[i]].push_back(i);
      cs[pr[i]].push_back(w);
    }
    long long cnt = dfs(0);
    printf(
        "%lld"
        "\n",
        cnt);
  }
  return 0;
}