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 = 100 * 1000 + 10;
long long ans, dis[maxn];
vector<pair<long long, int> > V[maxn], tmp;
int pos = 1, s, f, h[maxn], mx[maxn][2], z[maxn], X, mark[maxn], fen[maxn], W,
    L, ret, n, u, w;
vector<pair<int, int> > vec[maxn];
inline void add(int x, int v) {
  for (x++; x < maxn; x += x & -x) fen[x] += v;
}
inline int get(int x) {
  if (x <= 0) return 0;
  ret = 0;
  for (; x; x -= x & -x) ret += fen[x];
  return ret;
}
void calc(int x, int p) {
  mx[x][0] = mx[x][1] = -1;
  z[x] = 1;
  for (int i = 0; i < ((int(vec[x].size()))); i++) {
    if (mark[vec[x][i].first] == 0 && p != vec[x][i].first) {
      calc(vec[x][i].first, x);
      z[x] += z[vec[x][i].first];
      if (z[vec[x][i].first] > mx[x][0]) {
        mx[x][0] = z[vec[x][i].first];
        mx[x][1] = vec[x][i].first;
      }
    }
  }
}
int fcent(int x) {
  if (mx[x][0] <= X / 2) return x;
  return fcent(mx[x][1]);
}
void gdis(int x, int p, int limit) {
  tmp.push_back(make_pair(dis[x], h[x]));
  for (int i = 0; i < ((int(vec[x].size()))); i++) {
    if ((mark[vec[x][i].first] == 0 || mark[vec[x][i].first] > limit) &&
        p != vec[x][i].first) {
      h[vec[x][i].first] = h[x] + 1;
      dis[vec[x][i].first] = dis[x] + vec[x][i].second;
      gdis(vec[x][i].first, x, limit);
    }
  }
}
void solve(int x) {
  calc(x, -1);
  X = z[x];
  int C = fcent(x);
  mark[C] = pos++;
  for (int i = 0; i < ((int(vec[C].size()))); i++) {
    if (mark[vec[C][i].first] == 0) {
      solve(vec[C][i].first);
      dis[vec[C][i].first] = vec[C][i].second;
      h[vec[C][i].first] = 1;
      gdis(vec[C][i].first, -1, mark[C]);
      sort(tmp.begin(), tmp.end());
      s = f = 0;
      while (f < ((int(tmp.size())))) {
        while (s < f && tmp[s].first + tmp[f].first <= W)
          add(tmp[s++].second, 1);
        while (s > 0 && tmp[s - 1].first + tmp[f].first > W) {
          add(tmp[s - 1].second, -1);
          s--;
        }
        ans -= get(L - tmp[f].second + 1);
        f++;
      }
      while (s > 0) {
        add(tmp[s - 1].second, -1);
        s--;
      }
      for (int j = 0; j < ((int(tmp.size()))); j++) V[C].push_back(tmp[j]);
      tmp.clear();
    }
  }
  V[C].push_back(make_pair(0, 0));
  sort(V[C].begin(), V[C].end());
  s = f = 0;
  while (f < ((int(V[C].size())))) {
    while (s < f && V[C][s].first + V[C][f].first <= W)
      add(V[C][s++].second, 1);
    while (s > 0 && V[C][s - 1].first + V[C][f].first > W) {
      add(V[C][s - 1].second, -1);
      s--;
    }
    ans += get(L - V[C][f].second + 1);
    f++;
  }
  while (s > 0) {
    add(V[C][s - 1].second, -1);
    s--;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> L >> W;
  for (int i = 1; i < n; i++) {
    cin >> u >> w;
    u--;
    vec[u].push_back(make_pair(i, w));
    vec[i].push_back(make_pair(u, w));
  }
  solve(0);
  cout << ans;
  return 0;
}