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 = 110000;
vector<pair<int, int> > adj[maxn];
bool mark[maxn];
int n, len, w, sub[maxn], h[maxn], d[maxn], fen[maxn * 10];
long long ans;
vector<int> ver, vs;
void inline rem(int i) {
  for (int x = i + 1; x < (1ll << 20); x += (-x) & x) fen[x]--;
}
void inline add(int i) {
  for (int x = i + 1; x < (1ll << 20); x += (-x) & x) fen[x]++;
}
long long inline get(int i, long long sum = 0) {
  for (int x = i + 1; x > 0; x -= (-x) & x) sum += fen[x];
  return sum;
}
void dfss(int root, int par) {
  sub[root] = 1;
  for (auto x : adj[root])
    if (!mark[x.first] and x.first != par) {
      dfss(x.first, root);
      sub[root] += sub[x.first];
    }
}
void dfs(int root, int par) {
  vs.push_back(root);
  ver.push_back(root);
  for (auto e : adj[root]) {
    int x = e.first;
    int wg = e.second;
    if (mark[x] or x == par) continue;
    h[x] = h[root] + 1;
    d[x] = d[root] + wg;
    dfs(x, root);
  }
}
bool cmp(int i, int j) { return d[i] < d[j]; }
long long solve(vector<int> &v) {
  int it = v.size() - 1;
  for (auto x : v) add(h[x]);
  long long ret = 0;
  for (auto x : v) {
    while (it >= 0 and d[v[it]] + d[x] > w) {
      rem(h[v[it]]);
      it--;
    }
    ret += get(len - h[x]);
  }
  while (it >= 0) {
    rem(h[v[it]]);
    it--;
  }
  return ret;
}
void cen(int v, int par) {
  int med = v;
  dfss(v, -1);
  int k = sub[v] / 2;
  int dad = par;
  while (1) {
    bool found = 0;
    for (auto e : adj[med]) {
      if (!mark[e.first] and e.first != dad and sub[e.first] > k) {
        found = 1;
        dad = med;
        med = e.first;
        break;
      }
    }
    if (!found) break;
  }
  mark[med] = 1;
  for (auto e : adj[med]) {
    int x = e.first;
    int wg = e.second;
    if (mark[x]) continue;
    d[x] = wg;
    h[x] = 1;
    dfs(x, med);
    sort(vs.begin(), vs.end(), cmp);
    ans -= solve(vs);
    vs.clear();
  }
  d[med] = 0;
  h[med] = 0;
  ver.push_back(med);
  ans--;
  sort(ver.begin(), ver.end(), cmp);
  ans += solve(ver);
  ver.clear();
  for (auto e : adj[med])
    if (!mark[e.first]) cen(e.first, med);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> len >> w;
  for (int i = 1; i < n; i++) {
    int p, w;
    cin >> p >> w;
    p--;
    adj[p].push_back(make_pair(i, w));
    adj[i].push_back(make_pair(p, w));
  }
  cen(0, -1);
  cout << ans / 2;
}