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 = 3e5 + 5;
const int INF = 0x3f3f3f3f;
struct node {
  int x, y;
  int op;
  bool operator<(const node &a) const {
    if (x != a.x) return x < a.x;
    if (y != a.y) return y < a.y;
    return op < a.op;
  }
  node(){};
  node(int _x, int _y, int _op) { x = _x, y = _y, op = _op; }
} a[maxn], tmp[maxn];
int cnt;
int n, L, W;
struct EDGE {
  int v, w, nxt;
} edge[maxn << 1];
int head[maxn];
int tot;
void add_edge(int u, int v, int w) {
  edge[tot].v = v;
  edge[tot].w = w;
  edge[tot].nxt = head[u];
  head[u] = tot++;
}
int sz[maxn], vis[maxn], mx[maxn];
int get_root(int u, int fa, int num) {
  int y = 0;
  mx[u] = 0;
  sz[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].nxt) {
    int v = edge[i].v;
    if (!vis[v] && v != fa) {
      int z = get_root(v, u, num);
      sz[u] += sz[v];
      mx[u] = max(mx[u], sz[v]);
      if (mx[y] > mx[z]) y = z;
    }
  }
  mx[u] = max(mx[u], num - sz[u]);
  return mx[u] < mx[y] ? u : y;
}
void dfs(int u, int fa, int len, int weight) {
  a[++cnt] = node(len, weight, 0);
  a[++cnt] = node(L - len, W - weight, 1);
  for (int i = head[u]; i != -1; i = edge[i].nxt) {
    int v = edge[i].v;
    if (!vis[v] && v != fa) {
      dfs(v, u, len + 1, weight + edge[i].w);
    }
  }
}
long long cdq(int l, int r) {
  if (l == r) return 0;
  int mid = (l + r) >> 1;
  long long ans = cdq(l, mid) + cdq(mid + 1, r);
  int p = l, q = mid + 1, res = 0;
  for (int i = l; i <= r; i++) {
    if ((p <= mid &&
         (a[p].y < a[q].y || (a[p].y == a[q].y && a[p].op <= a[q].op))) ||
        q > r) {
      res += a[p].op ^ 1;
      tmp[i] = a[p++];
    } else {
      ans += a[q].op * res;
      tmp[i] = a[q++];
    }
  }
  for (int i = l; i <= r; i++) {
    a[i] = tmp[i];
  }
  return ans;
}
long long Find(int u, int len, int weight) {
  long long res = 0;
  cnt = 0;
  dfs(u, -1, len, weight);
  sort(a + 1, a + cnt + 1);
  for (int i = 1; i <= cnt; i++) {
    if (2 * a[i].x <= L && 2 * a[i].y <= W) res += a[i].op ^ 1;
  }
  return (cdq(1, cnt) - res) / 2;
}
long long solve(int u, int num) {
  int root = get_root(u, -1, num);
  long long res = Find(root, 0, 0);
  vis[root] = 1;
  for (int i = head[root]; i != -1; i = edge[i].nxt) {
    int v = edge[i].v, w = edge[i].w;
    if (!vis[v]) {
      res -= Find(v, 1, w);
      res += solve(v, sz[v] > sz[root] ? num - sz[root] : sz[v]);
    }
  }
  return res;
}
int main() {
  mx[0] = INF;
  memset(head, -1, sizeof(head));
  tot = 0;
  scanf("%d%d%d", &n, &L, &W);
  for (int i = 2; i <= n; i++) {
    int u, w;
    scanf("%d%d", &u, &w);
    add_edge(i, u, w);
    add_edge(u, i, w);
  }
  printf("%lld\n", solve(1, n));
  return 0;
}