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