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 M = 100000 + 10;
int n, L, W, tot, head[M];
struct name {
  int id, v, nx;
} to[M << 1];
void add(int x, int y, int v) {
  to[++tot] = (name){y, v, head[x]};
  head[x] = tot;
}
int rt, all, sz[M], mx[M];
struct node {
  int l, w;
  bool operator<(const node &_) const {
    if (w == _.w) return l < _.l;
    return w < _.w;
  }
};
vector<node> a[M], c;
int cnt;
long long ans;
bool mk[M];
void getrt(int x, int fa) {
  sz[x] = 1, mx[x] = 0;
  for (int i = head[x]; i; i = to[i].nx) {
    int y = to[i].id;
    if (y == fa || mk[y]) continue;
    getrt(y, x);
    sz[x] += sz[y];
    mx[x] = max(mx[x], sz[y]);
  }
  mx[x] = max(mx[x], all - sz[x]);
  if (mx[x] < mx[rt]) rt = x;
}
void dfs(int x, int fa, int len, int val) {
  a[cnt].push_back((node){len, val});
  sz[x] = 1;
  c.push_back((node){len, val});
  for (int i = head[x]; i; i = to[i].nx) {
    int y = to[i].id, w = to[i].v;
    if (mk[y] || y == fa) continue;
    dfs(y, x, len + 1, val + w);
    sz[x] += sz[y];
  }
}
int s[M];
void Add(int l, int x, int maxx) {
  for (int i = l; i <= maxx; i += i & (-i)) s[i] += x;
}
int ask(int x) {
  int ret = 0;
  for (int i = x; i > 0; i -= i & (-i)) ret += s[i];
  return ret;
}
long long cal(vector<node> &a) {
  long long ret = 0;
  int maxx = 0;
  for (int i = 0; i < a.size(); i++) maxx = max(maxx, a[i].l);
  for (int i = 1; i <= maxx; i++) s[i] = 0;
  for (int i = 0; i < a.size(); i++) Add(a[i].l, 1, maxx);
  for (int i = 0, j = a.size() - 1; i < a.size(); i++) {
    while (i < j && a[i].w + a[j].w > W) {
      Add(a[j].l, -1, maxx);
      j--;
    }
    if (i >= j) break;
    Add(a[i].l, -1, maxx);
    ret += ask(min(maxx, L - a[i].l));
  }
  return ret;
}
void solve(int x) {
  mk[x] = 1, cnt = 0;
  for (int i = head[x]; i; i = to[i].nx) {
    int y = to[i].id, val = to[i].v;
    if (mk[y]) continue;
    dfs(y, x, 1, val);
    sort(a[cnt].begin(), a[cnt].end());
    cnt++;
  }
  sort(c.begin(), c.end());
  ans += cal(c);
  for (int i = (0), _en = (cnt - 1); i <= _en; i++) {
    for (int j = (0), _en = (a[i].size() - 1); j <= _en; j++)
      if (a[i][j].w <= W && a[i][j].l <= L) ans++;
    ans -= cal(a[i]);
  }
  c.clear();
  for (int i = (0), _en = (cnt - 1); i <= _en; i++) a[i].clear();
  for (int i = head[x]; i; i = to[i].nx) {
    int y = to[i].id;
    if (mk[y]) continue;
    rt = 0;
    all = sz[y];
    getrt(y, x);
    solve(rt);
  }
}
int main() {
  scanf("%d%d%d", &n, &L, &W);
  for (int i = (2), _en = (n); i <= _en; i++) {
    int y, v;
    scanf("%d%d", &y, &v);
    add(i, y, v);
    add(y, i, v);
  }
  all = n, mx[rt] = 0x3f3f3f3f;
  getrt(1, 0);
  solve(rt);
  printf("%I64d\n", ans);
  return 0;
}