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 Maxn = 100005;
int n, L, W;
vector<pair<int, int> > neigh[Maxn];
bool er[Maxn];
int siz[Maxn];
int N;
vector<int> BIT[Maxn];
vector<int> unBIT[Maxn];
long long res;
void Count(int v, int p) {
  siz[v] = 1;
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i].first;
    if (u == p || er[u]) continue;
    Count(u, v);
    siz[v] += siz[u];
  }
}
int getCentroid(int v, int p, int sz) {
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i].first;
    if (u == p || er[u]) continue;
    if (siz[u] > sz / 2) return getCentroid(u, v, sz);
  }
  return v;
}
void Create(int ind, int w) {
  ind++;
  for (int i = ind; i <= N; i += i & -i) unBIT[i].push_back(w);
}
void Add(int l, int w) {
  for (int i = l + 1; i <= N; i += i & -i) {
    int ind =
        lower_bound(unBIT[i].begin(), unBIT[i].end(), w) - unBIT[i].begin();
    for (int j = ind + 1; j < BIT[i].size(); j += j & -j) BIT[i][j]++;
  }
}
int Get(int l, int w) {
  if (l > L || w > W) return 0;
  l = min(N, L - l + 1);
  w = W - w;
  int res = 0;
  for (int i = l; i > 0; i -= i & -i) {
    int ind =
        upper_bound(unBIT[i].begin(), unBIT[i].end(), w) - unBIT[i].begin() - 1;
    for (int j = ind + 1; j > 0; j -= j & -j) res += BIT[i][j];
  }
  return res;
}
void createAll(int v, int p, int l, int w) {
  Create(l, w);
  for (int i = 0; i < neigh[v].size(); i++) {
    pair<int, int> u = neigh[v][i];
    if (u.first == p || er[u.first]) continue;
    createAll(u.first, v, l + 1, w + u.second);
  }
}
void addAll(int v, int p, int l, int w) {
  Add(l, w);
  for (int i = 0; i < neigh[v].size(); i++) {
    pair<int, int> u = neigh[v][i];
    if (u.first == p || er[u.first]) continue;
    addAll(u.first, v, l + 1, w + u.second);
  }
}
long long getAll(int v, int p, int l, int w) {
  long long res = Get(l, w);
  for (int i = 0; i < neigh[v].size(); i++) {
    pair<int, int> u = neigh[v][i];
    if (u.first == p || er[u.first]) continue;
    res += getAll(u.first, v, l + 1, w + u.second);
  }
  return res;
}
void Solve(int v) {
  Count(v, 0);
  int C = getCentroid(v, 0, siz[v]);
  N = siz[v];
  for (int i = 0; i <= N; i++) {
    unBIT[i].clear();
    BIT[i].clear();
  }
  createAll(C, 0, 0, 0);
  for (int i = 0; i <= N; i++) {
    sort(unBIT[i].begin(), unBIT[i].end());
    unBIT[i].erase(unique(unBIT[i].begin(), unBIT[i].end()), unBIT[i].end());
    BIT[i].resize(unBIT[i].size() + 1, 0);
  }
  Add(0, 0);
  for (int i = 0; i < neigh[C].size(); i++) {
    pair<int, int> u = neigh[C][i];
    if (er[u.first]) continue;
    res += getAll(u.first, C, 1, u.second);
    addAll(u.first, C, 1, u.second);
  }
  er[C] = true;
  for (int i = 0; i < neigh[C].size(); i++) {
    pair<int, int> u = neigh[C][i];
    if (er[u.first]) continue;
    Solve(u.first);
  }
}
int main() {
  scanf("%d %d %d", &n, &L, &W);
  for (int i = 2; i <= n; i++) {
    int p, w;
    scanf("%d %d", &p, &w);
    neigh[p].push_back(pair<int, int>(i, w));
    neigh[i].push_back(pair<int, int>(p, w));
  }
  Solve(1);
  printf("%I64d\n", res);
  return 0;
}