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 long long N = 1e5 + 10;
const double Pi = acos(-1);
inline long long read() {
  long long x = 0, f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  return x * f;
}
long long n, l, w, ans;
long long cnt, head[N], siz[N];
bool vis[N];
struct Edge {
  long long to, nxt, w;
} edge[N << 1];
inline void AddEdge(long long u, long long v, long long d) {
  edge[++cnt] = (Edge){v, head[u], d};
  head[u] = cnt;
  return;
}
long long root;
void FindRoot(long long u, long long fa, long long s) {
  bool flag = 1;
  siz[u] = 1;
  for (long long i = head[u], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    if (v == fa || vis[v]) continue;
    FindRoot(v, u, s);
    siz[u] += siz[v];
    if (siz[v] > s / 2) flag = 0;
  }
  if (flag && (s - siz[u]) <= s / 2) root = u;
  return;
}
void GetSize(long long u, long long fa) {
  siz[u] = 1;
  for (long long i = head[u], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    if (v == fa || vis[v]) continue;
    GetSize(v, u);
    siz[u] += siz[v];
  }
  return;
}
struct Node {
  long long len, dis;
} e[N];
bool cmp(Node a, Node b) {
  return a.dis != b.dis ? a.dis < b.dis : a.len < b.len;
}
long long tot;
long long deep[N], dis[N];
void GetDis(long long u, long long fa, long long d) {
  deep[u] = deep[fa] + 1, dis[u] = dis[fa] + d;
  if (deep[u] > l || dis[u] > w) return;
  e[++tot] = (Node){deep[u], dis[u]};
  for (long long i = head[u], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    if (v == fa || vis[v]) continue;
    GetDis(v, u, edge[i].w);
  }
  return;
}
struct BIT {
  long long c[N];
  inline void modify(long long p, long long v) {
    for (; p <= n; p += (p & (-p))) c[p] += v;
    return;
  }
  inline long long query(long long p) {
    long long res = 0;
    for (; p; p -= (p & (-p))) res += c[p];
    return res;
  }
} t;
void Solve(long long x, long long s) {
  if (vis[x] || s == 1) return;
  FindRoot(x, 0, s);
  vis[root] = 1;
  tot = 0;
  deep[0] = -1;
  GetDis(root, 0, 0);
  sort(e + 1, e + tot + 1, cmp);
  ans += tot - 1;
  long long p = 1;
  for (register long long i = 2; i <= tot; ++i) {
    while (e[p].dis + e[i].dis > w) {
      t.modify(e[p].len, -1);
      --p;
    }
    if (e[i].len < l) ans += t.query(l - e[i].len);
    if (p < i - 1) continue;
    ++p;
    t.modify(e[i].len, 1);
  }
  for (register long long i = 2; i <= p; ++i) t.modify(e[i].len, -1);
  for (long long i = head[root], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    if (vis[v]) continue;
    tot = 0;
    deep[0] = 0;
    GetDis(v, 0, edge[i].w);
    sort(e + 1, e + tot + 1, cmp);
    long long p = 0;
    for (register long long j = 1; j <= tot; ++j) {
      while (e[p].dis + e[j].dis > w) {
        t.modify(e[p].len, -1);
        --p;
      }
      if (e[j].len < l) ans -= t.query(l - e[j].len);
      if (p < j - 1) continue;
      ++p;
      t.modify(e[j].len, 1);
    }
    for (register long long j = 1; j <= p; ++j) t.modify(e[j].len, -1);
  }
  GetSize(root, 0);
  for (long long i = head[root], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    Solve(v, siz[v]);
  }
  return;
}
signed main() {
  deep[0] = -1;
  n = read(), l = read(), w = read();
  for (register long long i = 2; i <= n; ++i) {
    long long a = read(), b = read();
    AddEdge(i, a, b), AddEdge(a, i, b);
  }
  Solve(1, n);
  printf("%lld\n", ans);
  return 0;
}