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 = 100010;
int n, L, W;
long long bit[MAXN];
inline int lowbit(int x) { return x & -x; }
void add(int x, long long v) {
  for (; x <= n + 1; x += lowbit(x)) bit[x] += v;
}
long long query(int x) {
  if (x <= 0) return 0;
  int ret = 0;
  for (; x; x -= lowbit(x)) ret += bit[x];
  return ret;
}
struct edge {
  int to;
  long long w;
  int nxt;
} e[MAXN << 1];
int head[MAXN], cnt = 0;
void adde(int x, int y, int w) {
  e[++cnt] = (edge){y, w, head[x]}, head[x] = cnt;
}
void addedge(int x, int y, int w) {
  adde(x, y, w);
  adde(y, x, w);
}
int root, dp[MAXN], sum, size[MAXN], vis[MAXN];
void getRoot(int x, int prev) {
  size[x] = 1, dp[x] = 0;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == prev || vis[v]) continue;
    getRoot(v, x), size[x] += size[v];
    dp[x] = max(dp[x], size[v]);
  }
  dp[x] = max(dp[x], sum - size[x]);
  if (dp[x] < dp[root]) root = x;
}
struct Dnode {
  long long dis;
  int dep;
  bool operator<(const Dnode& k1) const { return dis < k1.dis; }
} D[MAXN];
int tot = 0;
void getD(int x, int prev, int dis, int dep) {
  D[++tot] = (Dnode){dis, dep};
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (vis[v] || v == prev) continue;
    getD(v, x, dis + e[i].w, dep + 1);
  }
}
long long calc(int x, int d1, int d2) {
  tot = 0, getD(x, 0, d1, d2);
  sort(D + 1, D + tot + 1);
  int l = 1, r = tot;
  for (int i = l; i <= r; i++) add(D[i].dep + 1, 1);
  long long ret = 0;
  while (l < r) {
    if (D[l].dis + D[r].dis <= W) {
      add(D[l].dep + 1, -1);
      ret += query(L - D[l].dep + 1);
      l++;
    } else
      add(D[r].dep + 1, -1), r--;
  }
  add(D[l].dep + 1, -1);
  return ret;
}
long long ans = 0;
void solve(int x) {
  vis[x] = 1, ans += calc(x, 0, 0);
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (vis[v]) continue;
    ans -= calc(v, e[i].w, 1);
    sum = size[v], dp[root = 0] = 0x3f3f3f3f;
    getRoot(v, x), solve(root);
  }
}
int main() {
  scanf("%d%d%d", &n, &L, &W);
  for (int i = 2; i <= n; i++) {
    int fa, w;
    scanf("%d%d", &fa, &w);
    addedge(fa, i, w);
  }
  dp[root = 0] = 0x3f3f3f3f, sum = n;
  getRoot(1, 0), solve(root);
  printf("%lld\n", ans);
  return 0;
}