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 int maxn = 100010;
struct edge {
  int to, next, v;
} e[maxn << 2];
struct path {
  int l, w;
} g[maxn << 2];
int n, num, cnt, mnl, root, x, y, w, l, va, maxl;
long long ans;
long long f[maxn];
int sz[maxn], head[maxn], mx[maxn], dis[maxn], dep[maxn];
bool vis[maxn];
bool cmp(path a, path b) { return a.w < b.w; }
void addedge(int x, int y, int va) {
  num++;
  e[num].to = y;
  e[num].next = head[x];
  e[num].v = va;
  head[x] = num;
}
void dfs1(int k, int pre) {
  int u;
  sz[k] = 1;
  mx[k] = 0;
  for (int j = head[k]; j; j = e[j].next) {
    u = e[j].to;
    if (vis[u] || u == pre) continue;
    dfs1(u, k);
    sz[k] += sz[u];
    mx[k] = max(mx[k], sz[u]);
  }
}
void dfs2(int k, int pre, int sum) {
  int u;
  mx[k] = max(mx[k], sum - sz[k]);
  if (mx[k] < mnl) mnl = mx[k], root = k;
  for (int j = head[k]; j; j = e[j].next) {
    u = e[j].to;
    if (vis[u] || u == pre) continue;
    dfs2(u, k, sum);
  }
}
void dfs3(int k, int pre) {
  int u;
  for (int j = head[k]; j; j = e[j].next) {
    u = e[j].to;
    if (vis[u] || u == pre) continue;
    dep[u] = dep[k] + 1;
    dis[u] = dis[k] + e[j].v;
    g[++cnt].l = dep[u];
    g[cnt].w = dis[u];
    dfs3(u, k);
  }
}
int lowbit(int c) { return c & -c; }
void add(int z, long long v) {
  for (; z <= maxl; z += lowbit(z)) f[z] += v;
}
long long query(int z) {
  long long sum = 0;
  for (; z; z -= lowbit(z)) sum += f[z];
  return sum;
}
long long calc(int x, int tag, int dist, int deep) {
  long long res = 0;
  int t;
  cnt = maxl = 0;
  dep[x] = deep;
  dis[x] = dist;
  if (tag == -1) {
    g[++cnt].l = dep[x];
    g[cnt].w = dis[x];
  }
  dfs3(x, 0);
  sort(g + 1, g + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) maxl = max(maxl, g[i].l);
  for (int i = 0; i <= maxl; i++) f[i] = 0;
  for (int i = 1; i <= cnt; i++) add(g[i].l, 1);
  t = cnt;
  if (tag == 1)
    for (int i = 1; i <= cnt; i++)
      if (g[i].l <= l && g[i].w <= w) ans++;
  for (int i = 1; i <= cnt; i++) {
    if (g[i].w > w) break;
    if (g[i].l > l) continue;
    while (t > i && g[t].w + g[i].w > w) {
      add(g[t].l, -1);
      t--;
    }
    if (t <= i) break;
    add(g[i].l, -1);
    res += query(min(maxl, l - g[i].l));
  }
  return res;
}
void solve(int x) {
  root = 0;
  mnl = n + 1;
  dfs1(x, 0);
  dfs2(x, 0, sz[x]);
  vis[root] = true;
  ans += calc(root, 1, 0, 0);
  for (int j = head[root]; j; j = e[j].next)
    if (!vis[e[j].to]) ans -= calc(e[j].to, -1, e[j].v, 1);
  for (int j = head[root]; j; j = e[j].next)
    if (!vis[e[j].to]) solve(e[j].to);
}
int main() {
  scanf("%d%d%d", &n, &l, &w);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &x, &va);
    y = i;
    addedge(x, y, va);
    addedge(y, x, va);
  }
  ans = 0;
  solve(1);
  printf("%I64d\n", ans);
  return 0;
}