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>
const int oo = 2139063143;
const int N = 2010000;
const int mod = 1000000007;
using namespace std;
inline void sc(int &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
int n, suml, sumw;
struct EDGE {
  int v, w, nx;
} lb[N << 1];
int tot = 1, top[N];
void add(int u, int v, int w) {
  lb[++tot].v = v, lb[tot].w = w, lb[tot].nx = top[u], top[u] = tot;
}
int siz[N], masiz[N], bs[N];
long long dep[N];
bool vis[N];
int q[N], head, tail;
void dfs(int u) {
  q[++tail] = u;
  siz[u] = vis[u] = 1, masiz[u] = 0;
  vis[u] = 1;
  for (int kb = top[u]; kb != -1; kb = lb[kb].nx) {
    int v = lb[kb].v, w = lb[kb].w;
    if (vis[v]) continue;
    dep[v] = dep[u] + w, bs[v] = bs[u] + 1;
    dfs(v);
    siz[u] += siz[v];
    masiz[u] = max(masiz[u], siz[v]);
  }
  vis[u] = 0;
}
int bit[N];
void add(int w, int d) {
  if (w > suml) return;
  for (; w < N; w += w & -w) bit[w] += d;
}
int sum(int w) {
  if (w > suml || w <= 0) return 0;
  int ans = 0;
  for (; w; w -= w & -w) ans += bit[w];
  return ans;
}
bool ly(int A, int B) { return dep[A] < dep[B]; }
bool sta[N];
long long calc(int l, int r) {
  long long ans = 0;
  sort(q + l, q + r + 1, ly);
  for (int i = l; i <= r; i++) add(bs[q[i]], 1), sta[i] = 1;
  for (int i = l, j = r; i <= j; i++) {
    sta[i] = 0, add(bs[q[i]], -1);
    while (i < j && dep[q[i]] + dep[q[j]] > sumw)
      sta[j] = 0, add(bs[q[j--]], -1);
    if (i == j) break;
    ans += sum(suml - bs[q[i]]);
  }
  for (int i = l; i <= r; i++)
    if (sta[i]) add(q[i], -1), sta[i] = 0;
  return ans;
}
long long ans = 0;
void work(int u) {
  head = 1, tail = 0;
  dfs(u);
  int t = siz[u], mi = masiz[u];
  for (int i = 1; i <= tail; i++) {
    int v = q[i];
    int mm = max(masiz[v], t - siz[v]);
    if (mm < mi) mi = mm, u = v;
  }
  vis[u] = 1;
  head = 1, tail = 0;
  for (int kb = top[u]; kb != -1; kb = lb[kb].nx) {
    int v = lb[kb].v, w = lb[kb].w;
    if (vis[v]) continue;
    dep[v] = w, bs[v] = 1;
    dfs(v);
    ans -= calc(head, tail);
    head = tail + 1;
  }
  ans += calc(1, tail);
  for (int i = 1; i <= tail; i++)
    if (bs[q[i]] <= suml && dep[q[i]] <= sumw) ++ans;
  for (int kb = top[u]; kb != -1; kb = lb[kb].nx) {
    int v = lb[kb].v;
    if (vis[v]) continue;
    work(v);
  }
}
int main() {
  memset(top, -1, sizeof(top));
  sc(n), sc(suml), sc(sumw);
  for (int i = 2; i <= n; i++) {
    int p, w;
    sc(p), sc(w);
    add(i, p, w), add(p, i, w);
  }
  work(1);
  printf("%lld\n", ans);
  return 0;
}