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 N = 1e5 + 7;
bool del[N];
long long ans;
int n, l, w, root, size, sz[N], f[N], dp[N], d[N], L[N], MAXD, c[N];
struct Edge {
  int v, w;
};
struct Node {
  int val, d;
  bool operator<(const Node &r) const {
    return val < r.val || (val == r.val && d < r.d);
  }
};
vector<Node> dep;
vector<Edge> adj[N];
inline int lowbit(int x) { return x & -x; }
inline void modify(int x) {
  for (; x <= MAXD; x += lowbit(x)) ++c[x];
}
inline int query(int x) {
  if (x > MAXD) x = MAXD;
  int res = 0;
  for (; x > 0; x -= lowbit(x)) res += c[x];
  return res;
}
inline void addedge(int u, int v, int w) {
  adj[u].push_back({v, w});
  adj[v].push_back({u, w});
}
void getroot(int u, int p) {
  sz[u] = 1;
  f[u] = 0;
  for (auto e : adj[u]) {
    int v = e.v;
    if (del[v] || v == p) continue;
    getroot(v, u);
    sz[u] += sz[v];
    f[u] = max(f[u], sz[v]);
  }
  f[u] = max(f[u], size - sz[u]);
  if (f[u] < f[root]) root = u;
}
void getdeep(int u, int p) {
  sz[u] = 1;
  dep.push_back({d[u], dp[u]});
  for (auto e : adj[u]) {
    int v = e.v;
    if (del[v] || v == p) continue;
    d[v] = d[u] + e.w;
    dp[v] = dp[u] + 1;
    getdeep(v, u);
    sz[u] += sz[v];
  }
}
long long cal(int u, int inid, int iniv) {
  int m = 0;
  long long res = 0;
  dp[u] = inid;
  d[u] = iniv;
  dep.clear();
  getdeep(u, 0);
  MAXD = 0;
  sort(dep.begin(), dep.end());
  for (auto v : dep) MAXD = max(MAXD, v.d);
  for (int i = 0; i <= MAXD; ++i) c[i] = 0;
  int cur = 0;
  for (int i = (int)dep.size() - 1; i >= 0; --i) {
    if (dep[i].d == 0) continue;
    for (int &j = cur; j < (int)dep.size() && dep[j].val <= w - dep[i].val; ++j)
      if (dep[j].d) modify(dep[j].d);
    if (l - dep[i].d > 0) res += query(l - dep[i].d);
  }
  for (auto v : dep)
    if (v.d && v.d + v.d <= l && v.val + v.val <= w) --res;
  res /= 2;
  if (inid == 0)
    for (auto v : dep)
      if (v.d && v.d <= l && v.val <= w) ++res;
  return res;
}
void solve(int u) {
  del[u] = true;
  ans += cal(u, 0, 0);
  for (Edge e : adj[u]) {
    int v = e.v;
    if (del[v]) continue;
    ans -= cal(v, 1, e.w);
    f[root = 0] = size = sz[v];
    getroot(v, 0);
    solve(root);
  }
}
int main() {
  scanf("%d%d%d", &n, &l, &w);
  for (int u = 2; u <= n; ++u) {
    int v, w;
    scanf("%d%d", &v, &w);
    addedge(u, v, w);
  }
  f[root = 0] = size = n;
  getroot(1, 0);
  solve(root);
  printf("%I64d\n", ans);
  return 0;
}