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>
#pragma GCC optimize("O2")
using namespace std;
const int Max = 5e5 + 10;
const int LOG = 20;
int n, l, w;
bool hide[Max];
vector<pair<int, int> > N[Max];
int H[Max], W[Max];
int sub[Max];
void pre(int v, int p) {
  sub[v] = 1;
  for (pair<int, int> u : N[v])
    if (u.first != p && !hide[u.first]) pre(u.first, v), sub[v] += sub[u.first];
}
inline int find_centroid(int v, int sz) {
  int p = v;
  bool no = true;
  while (no) {
    no = false;
    for (pair<int, int> u : N[v])
      if (!hide[u.first] && u.first != p && sub[u.first] * 2 > sz) {
        p = v, v = u.first, no = true;
        break;
      }
  }
  return (v);
}
vector<pair<int, int> > A;
long long ANS;
int bit[Max];
inline void upd(int i, int x) {
  i += 2;
  while (i <= n + 3) bit[i] += x, i += i & -i;
}
inline int get(int i) {
  i += 2;
  long long ans = 0;
  while (i >= 1) ans += bit[i], i -= i & -i;
  return ans;
}
void DFS(int v, int p) {
  A.push_back(make_pair(W[v], H[v]));
  for (pair<int, int> u : N[v])
    if (!hide[u.first] && u.first != p)
      W[u.first] = W[v] + u.second, H[u.first] = H[v] + 1, DFS(u.first, v);
}
inline long long Query() {
  long long ans = 0;
  sort(A.begin(), A.end());
  int ptr = A.size() - 1;
  for (int i = 0; i < A.size(); i++) {
    upd(A[i].second, 1);
    while (ptr >= 0 && A[ptr].first + A[i].first > w) ptr--;
    while (ptr >= 0 &&
           (i == A.size() - 1 || A[ptr].first + A[i + 1].first > w)) {
      if (l - A[ptr].second >= 0) ans += get(l - A[ptr].second);
      ptr--;
    }
  }
  for (int i = 0; i < A.size(); i++) upd(A[i].second, -1);
  A.clear();
  return ans;
}
void solve(int v) {
  pre(v, v);
  v = find_centroid(v, sub[v]);
  W[v] = 0;
  H[v] = 0;
  DFS(v, v);
  ANS += Query();
  for (pair<int, int> u : N[v])
    if (!hide[u.first])
      H[u.first] = 1, W[u.first] = u.second, DFS(u.first, v), ANS -= Query();
  hide[v] = true;
  for (pair<int, int> u : N[v])
    if (!hide[u.first]) solve(u.first);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d%d%d", &n, &l, &w);
  for (int i = 2; i <= n; i++) {
    int p, x;
    scanf("%d%d", &p, &x);
    N[i].push_back(make_pair(p, x));
    N[p].push_back(make_pair(i, x));
  }
  solve(1);
  cout << (ANS - n) / 2 << '\n';
}