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 = 1e5 + 10;
vector<pair<int, int> > v[maxn], fn[maxn], vec;
vector<int> tdo[maxn];
bool mark[maxn];
int MX, n, _L, _W, SZ[maxn];
long long ANS;
void add(int ln, int W) {
  pair<int, int> P = {W, -1};
  ++ln;
  while (ln < MX) {
    int ind = lower_bound(fn[ln].begin(), fn[ln].end(), P) - fn[ln].begin();
    while (ind < int((fn[ln]).size())) {
      fn[ln][ind].second++;
      ind += (ind & -ind);
    }
    ln += (ln & -ln);
  }
}
int ask(int ln, int W) {
  if (ln < 0 || W < 0) return 0;
  ++ln;
  int ans = 0;
  pair<int, int> P = {W, 2e9};
  ln = min(ln, MX - 1);
  while (ln > 0) {
    int ind = upper_bound(fn[ln].begin(), fn[ln].end(), P) - fn[ln].begin() - 1;
    while (ind > 0) {
      ans += fn[ln][ind].second;
      ind -= (ind & -ind);
    }
    ln -= (ln & -ln);
  }
  return ans;
}
void build() {
  for (int i = 0; i < MX; i++) fn[i].clear(), fn[i].push_back({-2, -2});
  for (pair<int, int> p : vec) {
    int ind = p.first + 1;
    while (ind < MX) {
      fn[ind].push_back({p.second, 0});
      ind += (ind & -ind);
    }
  }
  for (int i = 0; i < MX; i++) {
    sort(fn[i].begin(), fn[i].end());
  }
}
void dfsS(int u, int par = -1) {
  SZ[u] = 1;
  for (pair<int, int> p : v[u]) {
    int y = p.first;
    if (!mark[y] && y != par) {
      dfsS(y, u);
      SZ[u] += SZ[y];
    }
  }
}
int dfsC(int u, int ss, int par = -1) {
  for (pair<int, int> p : v[u]) {
    int y = p.first;
    if (!mark[y] && y != par && SZ[y] >= ss) return dfsC(y, ss, u);
  }
  return u;
}
void dfsP(int u, int W = 0, int ln = 0, int par = -1) {
  MX = max(MX, ln + 5);
  vec.push_back({ln, W});
  for (pair<int, int> p : v[u]) {
    int y = p.first;
    if (!mark[y] && y != par) dfsP(y, W + p.second, ln + 1, u);
  }
}
void dfsadd(int u, int W, int ln, int par) {
  add(ln, W);
  for (pair<int, int> p : v[u]) {
    int y = p.first;
    if (!mark[y] && y != par) dfsadd(y, W + p.second, ln + 1, u);
  }
}
void dfsask(int u, int W, int ln, int par) {
  ANS += ask(_L - ln, _W - W);
  for (pair<int, int> p : v[u]) {
    int y = p.first;
    if (!mark[y] && y != par) dfsask(y, W + p.second, ln + 1, u);
  }
}
void solve(int u) {
  dfsS(u);
  u = dfsC(u, SZ[u] / 2);
  vec.clear();
  MX = 0;
  dfsP(u);
  build();
  add(0, 0);
  mark[u] = 1;
  for (pair<int, int> p : v[u]) {
    if (!mark[p.first]) {
      dfsask(p.first, p.second, 1, u);
      dfsadd(p.first, p.second, 1, u);
    }
  }
  for (pair<int, int> p : v[u]) {
    if (!mark[p.first]) solve(p.first);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> _L >> _W;
  for (int i = 2; i <= n; i++) {
    int p, w;
    cin >> p >> w;
    v[p].push_back({i, w});
    v[i].push_back({p, w});
  }
  solve(1);
  cout << ANS << endl;
  return 0;
}