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 = 1e5 + 2;
long long inline in() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * flag;
}
int n, llim, wlim;
long long ans;
int head[MAXN], nume;
struct Adj {
  int nex, to, w;
} adj[MAXN << 1];
void addedge(int from, int to, int w) {
  adj[++nume] = (Adj){head[from], to, w};
  head[from] = nume;
}
void link(int u, int v, int w) {
  addedge(u, v, w);
  addedge(v, u, w);
}
long long val[MAXN];
int lowbit(int x) { return x & (-x); }
void add(int x, int v) {
  for (int i = x; i <= llim + 1; i += lowbit(i)) val[i] += v;
}
long long query(int x) {
  int ret = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) ret += val[i];
  return ret;
}
bool vis[MAXN];
int siz[MAXN], cen;
void getcen(int u, int fa, int tot) {
  siz[u] = 1;
  int mx = 0;
  for (int i = head[u]; i; i = adj[i].nex) {
    int v = adj[i].to;
    if (v == fa || vis[v]) continue;
    getcen(v, u, tot);
    siz[u] += siz[v];
    mx = max(mx, siz[v]);
  }
  mx = max(mx, tot - siz[u]);
  if (mx <= (tot + 1) / 2) cen = u;
}
int top;
pair<int, int> rec[MAXN];
void calc(int u, int fa, int dis, int sum) {
  if (dis <= llim && sum <= wlim) rec[++top] = make_pair(sum, dis);
  siz[u] = 1;
  for (int i = head[u]; i; i = adj[i].nex) {
    int v = adj[i].to, w = adj[i].w;
    if (v == fa || vis[v]) continue;
    calc(v, u, dis + 1, sum + w);
    siz[u] += siz[v];
  }
}
long long getans(int u, int fa, int dis, int sum) {
  long long ret = 0;
  top = 0;
  calc(u, fa, dis, sum);
  sort(rec + 1, rec + top + 1);
  int l = 1, r = top;
  for (int i = 1; i <= top; ++i) add(rec[i].second + 1, 1);
  for (; l <= top && r >= 1; ++l) {
    while (rec[l].first + rec[r].first > wlim && r >= 1)
      add(rec[r].second + 1, -1), --r;
    if (!r) break;
    ret += query(llim + 2 - rec[l].second - 1);
    if (rec[l].first * 2 <= wlim && rec[l].second * 2 <= llim) ret--;
  }
  for (int i = 1; i <= r; ++i) add(rec[i].second + 1, -1);
  return ret >> 1;
}
void solve(int u, int tot) {
  cen = 0;
  getcen(u, 0, tot);
  vis[cen] = true;
  ans += getans(cen, 0, 0, 0);
  for (int i = head[cen]; i; i = adj[i].nex) {
    int v = adj[i].to, w = adj[i].w;
    if (vis[v]) continue;
    ans -= getans(v, cen, 1, w);
  }
  top = 0;
  for (int i = head[cen]; i; i = adj[i].nex) {
    int v = adj[i].to;
    if (vis[v]) continue;
    solve(v, siz[v]);
  }
}
int main() {
  n = in();
  llim = in();
  wlim = in();
  for (int i = 2; i <= n; ++i) {
    int v = in(), w = in();
    link(i, v, w);
  }
  solve(1, n);
  printf("%lld\n", ans);
  return 0;
}