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 = 100005;
const int MAXE = 200005;
struct Edge {
  int v, c, n;
  Edge() {}
  Edge(int var, int cost, int next) : v(var), c(cost), n(next) {}
};
struct Node {
  int w, d;
  Node() {}
  Node(int w, int d) : w(w), d(d) {}
  bool operator<(const Node& a) const { return w < a.w; }
};
Edge E[MAXE];
int H[MAXN], cntE;
int Q[MAXN], head, tail;
bool vis[MAXN];
int siz[MAXN];
int dis[MAXN];
int dep[MAXN];
int pre[MAXN];
Node node[MAXN];
int T[MAXN], maxdis;
long long ans;
int n, w, l;
void clear() {
  ans = 0;
  cntE = 0;
  memset(H, -1, sizeof H);
  memset(vis, 0, sizeof vis);
}
void addedge(int u, int v, int c) {
  E[cntE] = Edge(v, c, H[u]);
  H[u] = cntE++;
}
void add(int x, int v) {
  for (int i = x; i <= maxdis; i += i & -i) T[i] += v;
}
int sum(int x, int res = 0) {
  for (int i = x; i > 0; i -= i & -i) res += T[i];
  return res;
}
int get_root(int s) {
  head = tail = 0;
  pre[s] = 0;
  Q[tail++] = s;
  while (head != tail) {
    int u = Q[head++];
    for (int i = H[u]; ~i; i = E[i].n) {
      int v = E[i].v;
      if (v != pre[u] && !vis[v]) {
        pre[v] = u;
        Q[tail++] = v;
      }
    }
  }
  int tot_size = tail;
  int root = s, max_size = tail;
  while (tail) {
    int u = Q[--tail];
    int cnt = 0;
    siz[u] = 1;
    for (int i = H[u]; ~i; i = E[i].n) {
      int v = E[i].v;
      if (v != pre[u] && !vis[v]) {
        siz[u] += siz[v];
        cnt = max(siz[v], cnt);
      }
    }
    cnt = max(cnt, tot_size - siz[u]);
    if (cnt < max_size) {
      max_size = cnt;
      root = u;
    }
  }
  return root;
}
long long get_ans(int s, int init_dis, int init_dep, bool isroot) {
  head = tail = 0;
  int top = 0;
  pre[s] = 0;
  Q[tail++] = s;
  dis[s] = init_dis;
  dep[s] = init_dep;
  while (head != tail) {
    int u = Q[head++];
    if (!isroot || u != s) node[top++] = Node(dis[u], dep[u]);
    for (int i = H[u]; ~i; i = E[i].n) {
      int v = E[i].v;
      if (v != pre[u] && !vis[v]) {
        pre[v] = u;
        dis[v] = dis[u] + E[i].c;
        dep[v] = dep[u] + 1;
        Q[tail++] = v;
      }
    }
  }
  sort(node, node + top);
  long long res = 0;
  int j = top - 1;
  maxdis = 0;
  for (int i = (0); i < (top); ++i)
    if (node[i].d > maxdis) maxdis = node[i].d;
  for (int i = (1); i <= (maxdis); ++i) T[i] = 0;
  for (int i = (0); i < (top); ++i) add(node[i].d, 1);
  if (isroot)
    for (int i = (0); i < (top); ++i)
      if (node[i].w <= w && node[i].d <= l) ++ans;
  for (int i = (0); i < (top); ++i) {
    while (i < j && node[i].w + node[j].w > w) {
      add(node[j].d, -1);
      --j;
    }
    if (j <= i) break;
    add(node[i].d, -1);
    res += sum(min(maxdis, l - node[i].d));
  }
  return res;
}
void divide(int u) {
  int root = get_root(u);
  vis[root] = 1;
  ans += get_ans(root, 0, 0, true);
  for (int i = H[root]; ~i; i = E[i].n) {
    int v = E[i].v;
    if (!vis[v]) ans -= get_ans(v, E[i].c, 1, false);
  }
  for (int i = H[root]; ~i; i = E[i].n)
    if (!vis[E[i].v]) divide(E[i].v);
}
void solve() {
  int x, d;
  clear();
  for (int i = (2); i <= (n); ++i) {
    scanf("%d%d", &x, &d);
    addedge(x, i, d);
    addedge(i, x, d);
  }
  divide(1);
  printf("%I64d\n", ans);
}
int main() {
  scanf("%d%d%d", &n, &l, &w);
  solve();
  return 0;
}