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 N = 1e5 + 5, oo = 2e9 + 10;
int n, c, l, f[N], sub[N];
bool flag, mark[N];
long long ans;
vector<pair<long long, int> > adj[N], all[N], cur[N];
int query(int m) {
  m++;
  int res = 0;
  while (m) res += f[m], m -= m & -m;
  return res;
}
void update(int m, int c) {
  m++;
  while (m < N) f[m] += c, m += m & -m;
}
void dfs(int v, int par, int l, long long w,
         vector<pair<long long, int> > &cur) {
  cur.push_back(pair<long long, int>(w, l));
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (!mark[adj[v][i].first] && adj[v][i].first != par)
      dfs(adj[v][i].first, v, l + 1, w + adj[v][i].second, cur);
}
long long cal(vector<pair<long long, int> > &v) {
  long long res = 0;
  sort(v.begin(), v.end());
  int n = v.size(), pt = 0;
  for (int i = n - 1; i >= 0; i--) {
    int a = v[i].first, b = v[i].second;
    while (pt < n && a + v[pt].first <= c) {
      update(v[pt].second, 1);
      pt++;
    }
    if (b <= l) {
      res += query(l - b);
      if (2 * a <= c && 2 * b <= l) res--;
    }
  }
  for (int i = 0; i < pt; i++) update(v[i].second, -1);
  return res / 2;
}
void solve(int v, int par, int n) {
  sub[v] = 1;
  for (int i = 0; i < (int)adj[v].size() && !flag; i++) {
    int u = adj[v][i].first;
    if (u != par && !mark[u]) {
      solve(u, v, n);
      sub[v] += sub[u];
    }
  }
  if (flag) return;
  long long res = 0;
  if (2 * sub[v] >= n) {
    mark[v] = true;
    for (int i = 0; i < (int)adj[v].size(); i++) {
      int u = adj[v][i].first;
      if (!mark[u]) {
        dfs(adj[v][i].first, v, 1, adj[v][i].second, cur[v]);
        res -= cal(cur[v]);
        copy(cur[v].begin(), cur[v].end(), back_inserter(all[v]));
        vector<pair<long long, int> >().swap(cur[v]);
        solve(u, v, u == par ? n - sub[v] : sub[u]);
        flag = false;
      }
    }
    all[v].push_back(pair<long long, int>(0, 0));
    res += cal(all[v]);
    ans += res;
    vector<pair<long long, int> >().swap(all[v]);
    flag = true;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> l >> c;
  for (int i = 1; i < n; i++) {
    int par, w;
    cin >> par >> w;
    par--;
    adj[par].push_back(pair<long long, int>(i, w));
    adj[i].push_back(pair<long long, int>(par, w));
  }
  solve(0, -1, n);
  cout << ans << '\n';
  return 0;
}