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