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 NMax = 110000;
int N, L, W, del[NMax], size[NMax], maxnode[NMax];
vector<pair<int, int> > G[NMax], whole, sub[NMax];
vector<int> subtree;
void DFS(int a, int fa) {
  size[a] = 1;
  maxnode[a] = 0;
  subtree.push_back(a);
  for (vector<pair<int, int> >::iterator e = G[a].begin(); e != G[a].end(); ++e)
    if (!del[e->second] && e->second != fa) {
      DFS(e->second, a);
      maxnode[a] = max(maxnode[a], size[e->second]);
      size[a] += size[e->second];
    }
}
void DFS(int a, int bigroot, int h, int p, int fa) {
  whole.push_back(make_pair(p, h));
  sub[bigroot].push_back(make_pair(p, h));
  for (vector<pair<int, int> >::iterator e = G[a].begin(); e != G[a].end(); ++e)
    if (!del[e->second] && fa != e->second) {
      DFS(e->second, bigroot, h + 1, p + e->first, a);
    }
}
long long F[NMax];
int deep;
inline void insert(int a) {
  a++;
  for (int i = a; i <= deep + 10; i += i & -i) F[i]++;
}
long long get(int a) {
  a++;
  a = min(a, deep + 10);
  long long ret = 0;
  for (int i = a; i > 0; i -= i & -i) ret += F[i];
  return ret;
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int maxt;
long long calc(vector<pair<int, int> > a) {
  sort(a.begin(), a.end());
  deep = 0;
  for (int i = 0; i < a.size(); i++) deep = max(deep, a[i].second);
  for (int i = 0; i <= deep + 10; i++) F[i] = 0;
  long long ret = 0;
  int p = 0;
  for (int i = (int)a.size() - 1; i >= 0; i--) {
    while (p < a.size() && a[i].first + a[p].first <= W)
      insert(a[p].second), p++;
    if (L >= a[i].second) ret += get(L - a[i].second);
  }
  return ret;
}
long long ret1;
int cnt = 0;
void go(int a, int h) {
  subtree.clear();
  cnt++;
  DFS(a, -1);
  int minn = -1, Min = 100000000;
  for (int i = 0; i < (int)subtree.size(); i++) {
    maxnode[subtree[i]] = max(maxnode[subtree[i]], size[a] - size[subtree[i]]);
    if (maxnode[subtree[i]] < Min) {
      Min = maxnode[subtree[i]];
      minn = subtree[i];
    }
  }
  a = minn;
  whole.clear();
  whole.push_back(make_pair(0, 0));
  del[a] = 1;
  for (vector<pair<int, int> >::iterator e = G[a].begin(); e != G[a].end(); ++e)
    if (!del[e->second]) {
      sub[e->second].clear();
      DFS(e->second, e->second, 1, e->first, a);
      ret1 -= calc(sub[e->second]);
    }
  ret1 += calc(whole);
  ret1 -= 1;
  for (vector<pair<int, int> >::iterator e = G[a].begin(); e != G[a].end(); ++e)
    if (!del[e->second]) go(e->second, h + 1);
}
int main() {
  scanf("%d%d%d", &N, &L, &W);
  for (int i = 1; i < N; i++) {
    int second, first;
    scanf("%d%d", &second, &first);
    G[i + 1].push_back(make_pair(first, second));
    G[second].push_back(make_pair(first, i + 1));
  }
  go(1, 0);
  printf("%lld\n", ret1 / 2);
  return 0;
}