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 = 5e5;
const int maxm = 1e4 + 10;
const int INF = 0x3f3f3f3f;
struct edge {
  int v, nxt, w;
} edges[maxn << 1];
int head[maxn], edgenum, sz[maxn], root, mxr, cnt, k, w, n;
bool vis[maxn];
int ts[maxn];
struct node {
  int w, d;
  node(int w = 0, int d = 0) : w(w), d(d) {}
  bool operator<(const struct node& rhs) const {
    return this->w == rhs.w ? this->d < rhs.d : this->w < rhs.w;
  }
} a[maxn];
void init() {
  memset(head, -1, sizeof(head));
  memset(vis, 0, sizeof(vis));
  memset(ts, 0, sizeof(ts));
  edgenum = 0;
}
void add(int u, int v, int w) {
  edges[edgenum].v = v;
  edges[edgenum].w = w;
  edges[edgenum].nxt = head[u];
  head[u] = edgenum++;
}
void modify(int idx, int v) {
  while (idx <= n && idx) {
    ts[idx] += v;
    idx += ((idx) & (-(idx)));
  }
}
int query(int idx) {
  int ans = 0;
  while (idx) {
    ans += ts[idx];
    idx -= ((idx) & (-(idx)));
  }
  return ans;
}
void getroot(int u, int fa, int sum) {
  sz[u] = 1;
  int ma = 0;
  for (int i = head[u]; ~i; i = edges[i].nxt) {
    int v = edges[i].v;
    if (v == fa || vis[v]) continue;
    getroot(v, u, sum);
    if (ma < sz[v]) ma = sz[v];
    sz[u] += sz[v];
  }
  if (fa) ma = max(ma, sum - sz[u]);
  if (mxr > ma) mxr = ma, root = u;
}
void dfs(int u, int fa, int w, int d) {
  a[cnt++] = node(w, d);
  sz[u] = 1;
  for (int i = head[u]; ~i; i = edges[i].nxt) {
    int v = edges[i].v;
    if (v == fa || vis[v]) continue;
    dfs(v, u, w + edges[i].w, d + 1);
    sz[u] += sz[v];
  }
}
long long cal(int l, int r) {
  if (l >= r) return 0;
  int p = l, q = r;
  long long ans = 0;
  sort(a + l, a + r + 1);
  for (int i = l; i <= r; i++) modify(a[i].d, 1);
  for (int p = l, q = r; p <= q; p++) {
    while (p < q && a[p].w + a[q].w > w) {
      modify(a[q].d, -1);
      q--;
    }
    modify(a[p].d, -1);
    if (p >= q) break;
    ans += query(max(0, k - a[p].d));
  }
  return ans;
}
long long ans = 0;
void divide(int u, int sum) {
  if (sum == 1) return;
  mxr = INF;
  getroot(u, 0, sum);
  vis[root] = 1;
  cnt = 0;
  int pre = 0;
  for (int i = head[root]; ~i; i = edges[i].nxt) {
    int v = edges[i].v;
    if (vis[v]) continue;
    dfs(v, root, edges[i].w, 1);
    ans -= cal(pre, cnt - 1);
    pre = cnt;
  }
  a[cnt++] = node(0, 0);
  ans += cal(0, cnt - 1);
  for (int i = head[root]; ~i; i = edges[i].nxt) {
    if (vis[edges[i].v]) continue;
    divide(edges[i].v, sz[edges[i].v]);
  }
}
int main() {
  while (scanf("%d%d%d", &n, &k, &w) == 3) {
    int a, b;
    init();
    for (int i = 2; i <= n; i++) {
      scanf("%d%d", &a, &b);
      add(i, a, b);
      add(a, i, b);
    }
    ans = 0;
    divide(1, n);
    printf("%I64d\n", ans);
  }
  return 0;
}