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;
int n, L, m, head[1000005], cnt, root, sz[1000005], sum, mx;
long long t[1000005], ans;
struct edge {
  int to, next, cost;
} e[1000005 << 1];
struct dist {
  int len, dis;
  bool operator<(const dist &p) const { return dis < p.dis; }
} dis[1000005], q[1000005];
bool vis[1000005];
inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * w;
}
int lowbit(int x) { return x & (-x); }
void add(int x, int y) {
  if (x == 0) return;
  for (int i = x; i <= n + 1; i += lowbit(i)) t[i] += y;
}
long long query(int x) {
  if (x <= 0) return 0;
  long long res = 0;
  for (int i = x; i; i -= lowbit(i)) res += t[i];
  return res;
}
inline void add(int u, int v, int w) {
  e[++cnt] = (edge){v, head[u], w};
  head[u] = cnt;
}
void fdrt(int u, int fa) {
  sz[u] = 1;
  int num = 0;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa || vis[v]) continue;
    fdrt(v, u);
    sz[u] += sz[v];
    num = max(num, sz[v]);
  }
  num = max(num, sum - sz[u]);
  if (mx > num) mx = num, root = u;
}
void gtds(int u, int fa) {
  q[++cnt] = dis[u];
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa || vis[v]) continue;
    dis[v].len = dis[u].len + 1;
    dis[v].dis = dis[u].dis + e[i].cost;
    gtds(v, u);
  }
}
long long calc(int u, int len, int d) {
  cnt = 0;
  dis[u].len = len, dis[u].dis = d;
  gtds(u, 0);
  sort(q + 1, q + cnt + 1);
  for (int i = 1; i <= cnt; i++) add(q[i].len + 1, 1);
  int l = 1, r = cnt;
  long long res = 0;
  while (l < r) {
    if (q[l].dis + q[r].dis <= m) {
      add(q[l].len + 1, -1);
      res += query(L - q[l].len + 1);
      l++;
    } else
      add(q[r].len + 1, -1), r--;
  }
  add(q[l].len + 1, -1);
  return res;
}
void solve(int u) {
  ans += calc(u, 0, 0);
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (vis[v]) continue;
    ans -= calc(v, 1, e[i].cost);
    sum = mx = sz[v];
    fdrt(v, 0);
    solve(root);
  }
}
int main() {
  n = read();
  L = read();
  m = read();
  for (int i = 2; i <= n; i++) {
    int u = read(), w = read();
    add(u, i, w);
    add(i, u, w);
  }
  sum = mx = n;
  fdrt(1, 0);
  solve(root);
  printf("%I64d\n", ans);
  return 0;
}