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;
int W, L;
const int Maxn = 1e5 + 9;
vector<pair<int, int> > get_sort;
int fen[Maxn], mark[Maxn], sub[Maxn];
vector<pair<int, int> > al[Maxn];
int query(int v) {
  v++;
  if (v < 1) return 0;
  int ret = 0;
  for (v; v; v -= v & -v) ret += fen[v];
  return ret;
}
void update(int v, int x) {
  v++;
  for (v; v < Maxn; v += v & -v) fen[v] += x;
  return;
}
int dfs1(int v, int p = -1) {
  if (mark[v]) return 0;
  sub[v] = 1;
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first;
    if (u ^ p) sub[v] += dfs1(u, v);
  }
  return sub[v];
}
int find_cen(int v, int p, int n) {
  if (mark[v]) cout << "what the hell";
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first;
    if (u != p && !mark[u] && sub[u] > n / 2) return find_cen(u, v, n);
  }
  return v;
}
void dfs2(int v, int p, int depl = 0, int depw = 0) {
  if (mark[v]) return;
  get_sort.push_back(make_pair(depw, depl));
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first;
    if (u ^ p) dfs2(u, v, depl + 1, depw + al[v][i].second);
  }
  return;
}
long long get_cnt(int u, int v, int w, int l) {
  if (w < 0 || l < 0) return 0;
  long long ret = 0;
  get_sort.clear();
  dfs2(u, v);
  sort(get_sort.begin(), get_sort.end());
  int ed = get_sort.size() - 1;
  for (int i = 0; i < get_sort.size(); i++) update(get_sort[i].second, 1);
  for (int i = 0; i < get_sort.size(); i++) {
    int curl = get_sort[i].second, curw = get_sort[i].first;
    while (ed + 1 && get_sort[ed].first + curw > w) {
      update(get_sort[ed--].second, -1);
    }
    if (l >= curl) ret += query(l - curl);
    if (curl * 2 <= l && curw * 2 <= w) ret--;
  }
  while (ed + 1) update(get_sort[ed--].second, -1);
  return (ret) / 2;
}
long long rec(int v) {
  if (mark[v]) return 0;
  dfs1(v);
  v = find_cen(v, -1, sub[v]);
  long long ret = 0;
  ret = get_cnt(v, -1, W, L);
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first, w = al[v][i].second;
    ret -= get_cnt(u, v, W - 2 * w, L - 2);
  }
  mark[v] = 1;
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first;
    ret += rec(u);
  }
  return ret;
}
int main() {
  int n;
  scanf("%d%d%d", &n, &L, &W);
  for (int i = 0; i < n - 1; i++) {
    int v, w;
    scanf("%d%d", &v, &w);
    al[i + 1].push_back(make_pair(--v, w));
    al[v].push_back(make_pair(i + 1, w));
  }
  printf("%I64d\n", rec(0));
}