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 mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = (long long)INF * INF;
int n, len, W;
vector<pair<int, int> > adj[100100];
int subtree[100100];
int h[100100];
int wh[100100];
bool mark[100100];
vector<pair<int, int> > comp[100100];
int fen[100100];
void fenadd(int i, int x) {
  for (i++; i < 100100; i += i & -i) fen[i] += x;
}
int fensum(int i) {
  int res = 0;
  for (i++; i > 0; i -= i & -i) res += fen[i];
  return res;
}
void dfs(int v, int par, vector<pair<int, int> > &data, bool flag) {
  if (flag) data.push_back(make_pair(wh[v], h[v]));
  subtree[v] = 1;
  for (pair<int, int> p : adj[v]) {
    int u = p.first;
    if (mark[u] || u == par) continue;
    h[u] = h[v] + 1;
    wh[u] = wh[v] + p.second;
    dfs(u, v, data, flag);
    subtree[v] += subtree[u];
  }
}
int findcen(int v, int par, int S) {
  for (pair<int, int> p : adj[v]) {
    int u = p.first;
    if (mark[u] || u == par) continue;
    if (subtree[u] > S / 2) return findcen(u, v, S);
  }
  return v;
}
long long getpairs(const vector<pair<int, int> > &comp) {
  long long res = 0;
  for (pair<int, int> p : comp) {
    fenadd(p.second, 1);
  }
  int l = comp.size() - 1;
  for (int r = (0); r < ((int)comp.size()); r++) {
    while (l >= 0 && comp[l].first > W - comp[r].first) {
      fenadd(comp[l].second, -1);
      l--;
    }
    if (len >= comp[r].second) res += fensum(len - comp[r].second);
  }
  while (l >= 0) {
    fenadd(comp[l].second, -1);
    l--;
  }
  return res;
}
long long solve(int r) {
  dfs(r, -1, comp[r], false);
  int cen = findcen(r, -1, subtree[r]);
  long long res = 0;
  h[cen] = 0;
  wh[cen] = 0;
  mark[cen] = true;
  vector<pair<int, int> > allcomps;
  long long cnt = 0;
  for (pair<int, int> p : adj[cen]) {
    int u = p.first;
    if (mark[u]) continue;
    comp[u].clear();
    wh[u] = p.second;
    h[u] = 1;
    dfs(u, -1, comp[u], true);
    sort((comp[u]).begin(), (comp[u]).end());
    res -= getpairs(comp[u]);
    for (pair<int, int> p : comp[u]) {
      if (p.first <= W && p.second <= len) cnt++;
      allcomps.push_back(p);
    }
  }
  sort((allcomps).begin(), (allcomps).end());
  res += getpairs(allcomps);
  res /= 2;
  res += cnt;
  for (pair<int, int> p : adj[cen]) {
    int u = p.first;
    if (mark[u]) continue;
    res += solve(u);
  }
  return res;
}
int32_t main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> len >> W;
  for (int i = (2); i < (n + 1); i++) {
    int p, w;
    cin >> p >> w;
    adj[i].push_back(make_pair(p, w));
    adj[p].push_back(make_pair(i, w));
  }
  cout << solve(1) << '\n';
  return 0;
}