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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int w[(200000 + 10)];
int n, L, W;
int fst[(200000 + 10)], vv[(200000 + 10)], nxt[(200000 + 10)],
    cost[(200000 + 10)], e;
void init() {
  for (int i = 1; i <= n; ++i) fst[i] = -1;
  e = 0;
}
void add(int u, int v, int w) {
  vv[e] = v, nxt[e] = fst[u], cost[e] = w, fst[u] = e++;
}
struct TA {
  int g[(200000 + 10)];
  int n;
  void init(int nn) {
    n = nn + 1;
    for (int i = 0; i <= n; ++i) g[i] = 0;
  }
  int lowbit(int x) { return x & (-x); }
  void add(int x, int v) {
    ++x;
    while (x <= n) {
      g[x] += v;
      x += lowbit(x);
    }
  }
  int query(int x) {
    ++x;
    x = min(x, n);
    int s = 0;
    while (x > 0) {
      s += g[x];
      x -= lowbit(x);
    }
    return s;
  }
} ta;
struct node {
  int w, l;
  node() {}
  node(int ww, int ll) { w = ww, l = ll; }
  bool operator<(const node &ot) const {
    return w < ot.w || (w == ot.w && l < ot.l);
  }
} all[(200000 + 10)], cur[(200000 + 10)];
int sz[(200000 + 10)], tot, root, mx;
bool vis[(200000 + 10)];
int t1, t2;
void dfss(int u, int p) {
  sz[u] = 1;
  for (int i = fst[u]; ~i; i = nxt[i]) {
    int v = vv[i];
    if (v == p || vis[v]) continue;
    dfss(v, u);
    sz[u] += sz[v];
  }
}
void dfsr(int u, int p) {
  int mu = 0;
  for (int i = fst[u]; ~i; i = nxt[i]) {
    int v = vv[i];
    if (v == p || vis[v]) continue;
    dfsr(v, u);
    mu = max(mu, sz[v]);
  }
  mu = max(mu, tot - sz[u]);
  if (root == -1 || mx > mu) {
    root = u, mx = mu;
  }
}
void find_root(int &u) {
  dfss(u, -1);
  root = -1, tot = sz[u];
  dfsr(u, -1);
  u = root;
}
void dfs(int u, int p, int ll, int ww) {
  cur[t2++] = node(ww, ll);
  all[t1++] = node(ww, ll);
  for (int i = fst[u]; ~i; i = nxt[i]) {
    int v = vv[i];
    if (v == p || vis[v]) continue;
    dfs(v, u, ll + 1, ww + cost[i]);
  }
}
long long cal(node *cur, int n) {
  sort(cur, cur + n);
  long long ans = 0;
  ta.init(n);
  for (int i = 0; i < n; ++i) ta.add(cur[i].l, 1);
  int j = n - 1;
  for (int i = 0; i < n; ++i) {
    while (j > i && cur[i].w + cur[j].w > W) {
      ta.add(cur[j].l, -1);
      --j;
    }
    ta.add(cur[i].l, -1);
    ans += max(0, ta.query(L - cur[i].l));
  }
  return ans;
}
long long ans;
void solve(int u) {
  find_root(u);
  vis[u] = 1;
  t1 = 0;
  for (int i = fst[u]; ~i; i = nxt[i]) {
    int v = vv[i];
    if (vis[v]) continue;
    t2 = 0;
    dfs(v, u, 1, cost[i]);
    ans -= cal(cur, t2);
  }
  all[t1++] = node(0, 0);
  ans += cal(all, t1);
  for (int i = fst[u]; ~i; i = nxt[i]) {
    int v = vv[i];
    if (vis[v]) continue;
    solve(v);
  }
}
int main() {
  scanf("%d%d%d", &n, &L, &W);
  int u, v, w;
  init();
  for (int i = 2; i <= n; ++i) {
    scanf("%d%d", &u, &w);
    add(u, i, w);
    add(i, u, w);
  }
  ans = 0;
  for (int i = 0; i <= n; ++i) vis[i] = 0;
  solve(1);
  printf("%I64d\n", ans);
}