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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1e5 + 10;
int len, num, n, l, w;
long long ans;
int head[maxn], sum[maxn << 2];
int m[maxn], Size[maxn], mi, Root, vis[maxn];
struct Node {
  int l;
  int w;
} dis[maxn];
struct Edge {
  int to;
  int next;
  int val;
} e[maxn << 1];
void add(int from, int to, int val) {
  e[len].to = to;
  e[len].val = val;
  e[len].next = head[from];
  head[from] = len++;
}
void up(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void build(int l, int r, int rt) {
  sum[rt] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
void update(int key, int add, int l, int r, int rt) {
  if (l == r) {
    sum[rt] += add;
    return;
  }
  int mid = (l + r) >> 1;
  if (key <= mid)
    update(key, add, l, mid, rt << 1);
  else
    update(key, add, mid + 1, r, rt << 1 | 1);
  up(rt);
}
int ask(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return sum[rt];
  int mid = (l + r) >> 1;
  int ans = 0;
  if (L <= mid) ans += ask(L, R, l, mid, rt << 1);
  if (R > mid) ans += ask(L, R, mid + 1, r, rt << 1 | 1);
  return ans;
}
void clear(int key, int l, int r, int rt) {
  sum[rt] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (key <= mid)
    clear(key, l, mid, rt << 1);
  else
    clear(key, mid + 1, r, rt << 1 | 1);
}
void gaosize(int x, int fa) {
  Size[x] = 1;
  m[x] = 0;
  for (int i = head[x]; i != -1; i = e[i].next) {
    int cc = e[i].to;
    if (cc == fa || vis[cc]) continue;
    gaosize(cc, x);
    Size[x] += Size[cc];
    if (Size[cc] > m[x]) m[x] = Size[cc];
  }
}
void gaoroot(int root, int x, int fa) {
  m[x] = max(m[x], Size[root] - Size[x]);
  if (mi > m[x]) {
    mi = m[x];
    Root = x;
  }
  for (int i = head[x]; i != -1; i = e[i].next) {
    int cc = e[i].to;
    if (vis[cc] || cc == fa) continue;
    gaoroot(root, cc, x);
  }
}
void gaodis(int x, int fa, Node val) {
  dis[num++] = val;
  for (int i = head[x]; i != -1; i = e[i].next) {
    int cc = e[i].to;
    if (vis[cc] || cc == fa) continue;
    Node t = val;
    t.l++;
    t.w += e[i].val;
    gaodis(cc, x, t);
  }
}
int cmp(const Node &a, const Node &b) { return a.w < b.w; }
long long calc(int x, Node val) {
  long long ret = 0;
  num = 0;
  gaodis(x, 0, val);
  sort(dis, dis + num, cmp);
  for (int i = 0; i < num; i++) {
    update(dis[i].l, 1, 0, n, 1);
  }
  int i = 0;
  int j = num - 1;
  while (i < j) {
    while (dis[i].w + dis[j].w > w && i < j) {
      update(dis[j].l, -1, 0, n, 1);
      j--;
    }
    update(dis[i].l, -1, 0, n, 1);
    if (l >= dis[i].l) ret += ask(0, min(n, l - dis[i].l), 0, n, 1);
    i++;
  }
  if (i == j) update(dis[i].l, -1, 0, n, 1);
  return ret;
}
void gao(int x) {
  mi = n;
  gaosize(x, 0);
  gaoroot(x, x, 0);
  Node t;
  t.l = 0;
  t.w = 0;
  ans += calc(Root, t);
  vis[Root] = 1;
  for (int i = head[Root]; i != -1; i = e[i].next) {
    int cc = e[i].to;
    if (vis[cc]) continue;
    Node t;
    t.l = 1;
    t.w = e[i].val;
    ans -= calc(cc, t);
    gao(cc);
  }
}
void init() {
  ans = 0;
  len = 0;
  memset(head, -1, sizeof(head));
  memset(vis, 0, sizeof(vis));
}
int main() {
  int a, b;
  cin >> n >> l >> w;
  init();
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    add(i + 1, a, b);
    add(a, i + 1, b);
  }
  gao(1);
  cout << ans << endl;
  return 0;
}