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;
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 400010;
int n, w, front[N], cnt, rt, siz[N], vis[N], tot, f[N];
struct node {
  int to, nxt, w;
} e[N];
void Add(int u, int v, int w) {
  e[++cnt] = (node){v, front[u], w};
  front[u] = cnt;
}
void getroot(int u, int ff) {
  siz[u] = 1;
  f[u] = 0;
  for (int i = front[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (vis[v] || v == ff) continue;
    getroot(v, u);
    siz[u] += siz[v];
    f[u] = max(f[u], siz[v]);
  }
  f[u] = max(f[u], tot - siz[u]);
  if (f[u] < f[rt]) rt = u;
}
long long ans;
int dis[N], dep[N];
struct thing {
  int dis, dep;
  bool operator<(const thing &b) const { return dis < b.dis; }
} p[N];
void getdis(int u, int ff) {
  p[++cnt] = (thing){dis[u], dep[u]};
  for (int i = front[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == ff || vis[v]) continue;
    dep[v] = dep[u] + 1;
    dis[v] = dis[u] + e[i].w;
    getdis(v, u);
  }
}
int c[N], L;
int lowbit(int x) { return x & (-x); }
void Add(int x, int d) {
  while (x <= n + 1) {
    c[x] += d;
    x += lowbit(x);
  }
}
int query(int x) {
  if (x <= 0) return 0;
  int ret = 0;
  while (x) {
    ret += c[x];
    x -= lowbit(x);
  }
  return ret;
}
long long calc(int u, int ds, int dp) {
  dis[u] = ds;
  dep[u] = dp;
  cnt = 0;
  getdis(u, u);
  sort(p + 1, p + cnt + 1);
  for (int i = 1; i <= cnt; i++) Add(p[i].dep + 1, 1);
  int l = 1, r = cnt;
  long long ret = 0;
  while (l < r) {
    if (p[l].dis + p[r].dis <= w) {
      Add(p[l].dep + 1, -1);
      ret += query(L - p[l].dep + 1);
      l++;
    } else {
      Add(p[r].dep + 1, -1);
      r--;
    }
  }
  Add(p[l].dep + 1, -1);
  return ret;
}
void solve(int u) {
  ans += calc(u, 0, 0);
  vis[u] = 1;
  for (int i = front[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (vis[v]) continue;
    ans -= calc(v, e[i].w, 1);
    rt = 0;
    tot = siz[v];
    getroot(v, v);
    solve(rt);
  }
}
int main() {
  n = gi();
  L = gi();
  w = gi();
  for (int i = 2; i <= n; i++) {
    int fa = gi(), v = gi();
    Add(fa, i, v);
    Add(i, fa, v);
  }
  tot = f[0] = n;
  getroot(1, 0);
  solve(rt);
  printf("%lld\n", ans);
  return 0;
}