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 MAXN = 100000 + 100;
struct edge {
  int next, to, w;
} e[2 * MAXN];
int p[MAXN], l;
void init() {
  memset(p, -1, sizeof(p));
  l = 0;
}
void ins(int a, int b, int c) {
  e[l].next = p[a];
  e[l].to = b;
  e[l].w = c;
  p[a] = l;
  l++;
}
struct Point {
  int dis, dep;
  Point() {}
  Point(int _dep, int _dis) : dis(_dis), dep(_dep) {}
};
bool operator<(const Point &x, const Point &y) {
  if (x.dis == y.dis) return x.dep < y.dep;
  return x.dis < y.dis;
}
int n, L, W;
bool done[MAXN];
int s[MAXN], f[MAXN];
int dis[MAXN], dep[MAXN];
int root, size;
vector<Point> v;
long long ans = 0;
int c[MAXN];
int lowbit(int x) { return x & (-x); }
void add(int x, int a) {
  x++;
  for (int i = x; i <= n; i += lowbit(i)) c[i] += a;
}
int get(int x) {
  x++;
  if (x > n) x = n;
  int ret = 0;
  for (int i = x; i > 0; i -= lowbit(i)) ret += c[i];
  return ret;
}
void getroot(int x, int fa) {
  s[x] = 1;
  f[x] = 0;
  for (int i = p[x]; i != -1; i = e[i].next) {
    int b = e[i].to;
    if (b != fa && !done[b]) {
      getroot(b, x);
      f[x] = max(f[x], s[b]);
      s[x] += s[b];
    }
  }
  f[x] = max(f[x], size - s[x]);
  if (f[x] < f[root]) root = x;
}
void getdep(int x, int fa) {
  v.push_back(Point(dep[x], dis[x]));
  s[x] = 1;
  for (int i = p[x]; i != -1; i = e[i].next) {
    int b = e[i].to;
    if (b != fa && !done[b]) {
      dep[b] = dep[x] + 1;
      dis[b] = dis[x] + e[i].w;
      getdep(b, x);
      s[x] += s[b];
    }
  }
}
long long calc(int x, int depp, int diss) {
  long long ret = 0;
  dep[x] = depp;
  dis[x] = diss;
  v.clear();
  getdep(x, 0);
  sort(v.begin(), v.end());
  for (int i = 0; i <= v.size() - 1; i++) add(v[i].dep, 1);
  for (int l = 0, r = v.size() - 1; l <= r;) {
    if (v[l].dis + v[r].dis <= W) {
      add(v[l].dep, -1);
      ret += get(L - v[l].dep);
      l++;
    } else {
      add(v[r].dep, -1);
      r--;
    }
  }
  return ret;
}
void work(int x) {
  ans += calc(x, 0, 0);
  done[x] = true;
  for (int i = p[x]; i != -1; i = e[i].next) {
    int b = e[i].to;
    if (!done[b]) {
      ans -= calc(b, 1, e[i].w);
      root = 0;
      f[root] = size = s[b];
      getroot(b, 0);
      work(root);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  init();
  cin >> n >> L >> W;
  int a, b;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a >> b;
    ins(a, i + 1, b);
    ins(i + 1, a, b);
  }
  root = 0;
  f[root] = size = n;
  getroot(1, 0);
  work(root);
  cout << ans << endl;
  return 0;
}