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 long long N = 100010, M = 1000010, INF = 0x3f3f3f3f;
inline long long max(long long x, long long y) { return x > y ? x : y; }
inline long long min(long long x, long long y) { return x < y ? x : y; }
inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; }
long long head[N], ver[M], edge[M], Next[M], tot;
long long n, L, W, rt, ans, c[N], d[N], vis[N], size[N];
vector<pair<long long, long long> > v;
void add(long long x, long long y) {
  for (++x; x < N; x += x & -x) c[x] += y;
}
long long ask(long long x) {
  long long res = 0;
  x = max(x, 0) + 1;
  for (; x; x -= x & -x) res += c[x];
  return res;
}
void add(long long x, long long y, long long z) {
  ver[++tot] = y, edge[tot] = z, Next[tot] = head[x], head[x] = tot;
}
void get_size(long long x, long long fa) {
  size[x] = 1;
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i];
    if (y == fa || vis[y]) continue;
    get_size(y, x);
    size[x] += size[y];
  }
}
void get_rt(long long x, long long fa, long long sum) {
  size[x] = 1;
  long long flag = 1;
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i];
    if (y == fa || vis[y]) continue;
    get_rt(y, x, sum);
    size[x] += size[y];
    if (size[y] > sum / 2) flag = 0;
  }
  if (flag && sum - size[x] <= sum / 2) rt = x;
}
void get_dis(long long x, long long fa, long long val, long long dis) {
  v.push_back(make_pair(val, dis));
  if (val >= W || dis >= L) return;
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i], z = edge[i];
    if (y == fa || vis[y]) continue;
    get_dis(y, x, val + z, dis + 1);
  }
}
void calc(long long x) {
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i], z = edge[i];
    if (vis[y]) continue;
    v.clear();
    get_dis(y, x, z, 1);
    sort(v.begin(), v.end());
    for (pair<long long, long long> z : v) add(z.second, 1);
    for (long long l = 0, r = v.size() - 1; l < (long long)v.size(); l++) {
      add(v[l].second, -1);
      while (l < r && v[l].first + v[r].first > W) add(v[r--].second, -1);
      if (l >= r) break;
      ans -= ask(L - v[l].second);
    }
  }
  v.clear();
  get_dis(x, 0, 0, 0);
  sort(v.begin(), v.end());
  for (pair<long long, long long> z : v) add(z.second, 1);
  for (long long l = 0, r = v.size() - 1; l < (long long)v.size(); l++) {
    add(v[l].second, -1);
    while (l < r && v[l].first + v[r].first > W) add(v[r--].second, -1);
    if (l >= r) break;
    ans += ask(L - v[l].second);
  }
}
void solve(long long x) {
  vis[x] = 1;
  calc(x);
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i];
    if (vis[y]) continue;
    get_size(y, x);
    get_rt(y, x, size[y]);
    solve(rt);
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &L, &W);
  for (long long i = 1; i < n; i++) {
    long long p, w;
    scanf("%lld%lld", &p, &w);
    add(i + 1, p, w), add(p, i + 1, w);
  }
  get_size(1, 0);
  get_rt(1, 0, n);
  solve(rt);
  printf("%lld\n", ans);
  return 0;
}