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;
struct BIT {
  long long tree[2000005];
  inline void mem() {
    memset(tree, 0, sizeof(tree));
    return;
  }
  inline long long lowbit(long long x) { return x & (-x); }
  inline void add(long long pos, long long val) {
    pos++;
    while (pos <= 200000) tree[pos] += val, pos += lowbit(pos);
    return;
  }
  inline long long query(long long pos) {
    pos++;
    long long ans = 0;
    while (pos) ans += tree[pos], pos -= lowbit(pos);
    return ans;
  }
} bit;
long long n, maxl, maxw, u[2000005], v[2000005], w[2000005], first[2000005],
    nxt[2000005];
long long root, mn, sum, size[2000005], book[2000005];
long long ans;
inline void getroot(long long now, long long fa) {
  long long mx = 0;
  size[now] = 1;
  for (long long i = first[now]; i; i = nxt[i]) {
    if (v[i] == fa || book[v[i]] == 1) continue;
    getroot(v[i], now);
    size[now] += size[v[i]];
    mx = max(mx, size[v[i]]);
  }
  mx = max(mx, sum - size[now]);
  if (mx < mn) mn = mx, root = now;
  return;
}
struct node {
  long long l, w;
} c[2000005];
bool cmp(node a, node b) { return a.w < b.w; }
long long tot;
inline void get(long long now, long long fa, long long nowl, long long noww) {
  if (nowl > maxl || noww > maxw) return;
  tot++;
  c[tot].l = nowl, c[tot].w = noww;
  for (long long i = first[now]; i; i = nxt[i]) {
    if (v[i] == fa || book[v[i]] == 1) continue;
    get(v[i], now, nowl + 1, noww + w[i]);
  }
  return;
}
inline long long calc() {
  sort(c + 1, c + 1 + tot, cmp);
  long long j = 1, nowans = 0;
  for (long long i = tot; i >= 1; i--) {
    while (j > i) j--, bit.add(c[j].l, -1);
    while (c[i].w + c[j].w <= maxw && j < i) bit.add(c[j].l, 1), j++;
    nowans += bit.query(maxl - c[i].l);
  }
  for (long long i = 1; i < j; i++) bit.add(c[i].l, -1);
  return nowans;
}
inline void dfs(long long now) {
  book[now] = 1;
  tot = 0;
  get(now, 0, 0, 0);
  ans += calc();
  for (long long i = first[now]; i; i = nxt[i]) {
    if (book[v[i]] == 1) continue;
    tot = 0;
    get(v[i], now, 1, w[i]);
    ans -= calc();
  }
  for (long long i = first[now]; i; i = nxt[i]) {
    if (book[v[i]] == 1) continue;
    root = 0, mn = 1000000000, sum = size[v[i]];
    getroot(v[i], 0);
    sum = size[v[i]];
    getroot(root, 0);
    dfs(root);
  }
  return;
}
signed main() {
  cin >> n >> maxl >> maxw;
  for (long long i = 2; i <= n; i++) {
    long long nowfa = 0;
    scanf("%d%d", &nowfa, &w[i]);
    u[i] = i, v[i] = nowfa;
    nxt[i] = first[u[i]];
    first[u[i]] = i;
    u[i + n] = v[i], v[i + n] = u[i], w[i + n] = w[i];
    nxt[i + n] = first[u[i + n]], first[u[i + n]] = i + n;
  }
  bit.mem();
  root = 0, mn = 1000000000, sum = n;
  getroot(1, 0);
  dfs(1);
  cout << ans << endl;
  return 0;
}