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 inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = (int)1e9 + 7;
const int N = 5e5 + 100;
int n, len, w;
int tree[N];
int root, sz[N], mxr;
int vis[N];
int head[N], to[N * 2], nt[N * 2], ct[N * 2];
void add(int x, int v) {
  for (int i = x; i <= n && i; i += i & (-i)) tree[i] += v;
}
int query(int x) {
  int ret = 0;
  for (int i = x; i; i -= i & (-i)) ret += tree[i];
  return ret;
}
void getW(int o, int u, int num) {
  sz[u] = 1;
  int mx = 0;
  for (int i = head[u]; ~i; i = nt[i]) {
    int v = to[i];
    if (vis[v] || v == o) continue;
    getW(u, v, num);
    sz[u] += sz[v];
    mx = max(mx, sz[v]);
  }
  if (o) mx = max(mx, num - sz[u]);
  if (mx < mxr) mxr = mx, root = u;
}
struct Node {
  int first, second;
  bool operator<(const Node& x) const {
    if (first == x.first) return second < x.second;
    return first < x.first;
  }
} p[N];
long long cal(int l, int r) {
  if (l >= r) return 0;
  sort(p + l, p + r + 1);
  long long ans = 0;
  for (int i = l; i <= r; i++) add(p[i].second, 1);
  for (int L = l, R = r; L <= R; L++) {
    while (L < R && p[L].first + p[R].first > w) {
      add(p[R].second, -1);
      R--;
    }
    add(p[L].second, -1);
    if (L >= R) break;
    ans += query(max(0, len - p[L].second));
  }
  return ans;
}
int sum = 0;
void Dfs(int o, int u, int deep, int w) {
  sz[u] = 1;
  ++sum;
  p[sum].first = w;
  p[sum].second = deep;
  for (int i = head[u]; ~i; i = nt[i]) {
    int v = to[i];
    if (v == o || vis[v]) continue;
    Dfs(u, v, deep + 1, w + ct[i]);
    sz[u] += sz[v];
  }
}
long long ans = 0;
void GG(int id, int num) {
  if (num == 1) {
    return;
  }
  mxr = inf;
  getW(0, id, num);
  vis[root] = 1;
  int ls = 1;
  sum = 0;
  for (int i = head[root]; ~i; i = nt[i]) {
    int v = to[i];
    if (vis[v]) continue;
    Dfs(0, to[i], 1, ct[i]);
    ans -= cal(ls, sum);
    ls = sum + 1;
  }
  sum++;
  p[sum].first = p[sum].second = 0;
  ans += cal(1, sum);
  for (int i = head[root]; ~i; i = nt[i]) {
    int v = to[i];
    if (vis[v]) continue;
    GG(v, sz[v]);
  }
}
int tot = 0;
void add(int u, int v, int w) {
  to[tot] = v;
  ct[tot] = w;
  nt[tot] = head[u];
  head[u] = tot++;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d%d", &n, &len, &w);
  int u, v, val;
  for (int i = 2; i <= n; i++) {
    u = i;
    scanf("%d%d", &v, &val);
    add(u, v, val);
    add(v, u, val);
  }
  GG(1, n);
  printf("%I64d\n", ans);
  return 0;
}