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 long long N = 1e5 + 5;
long long n, L, W, fi[N], tot = 0;
struct edge {
  long long to, nxt, w;
} e[N << 1];
void add(long long u, long long v, long long w) {
  e[++tot].to = v;
  e[tot].w = w;
  e[tot].nxt = fi[u];
  fi[u] = tot;
}
long long sz[N], G, mn, ans = 0;
bool vis[N];
void getG(long long u, long long fa, long long size) {
  sz[u] = 1;
  long long num = 0;
  for (long long i = fi[u]; i; i = e[i].nxt) {
    long long v = e[i].to;
    if (v == fa || vis[v]) continue;
    getG(v, u, size);
    sz[u] += sz[v];
    if (sz[v] > num) num = sz[v];
  }
  num = max(num, size - sz[u]);
  if (mn > num) {
    mn = num;
    G = u;
  }
}
long long dis[N], sum[N], num[N], tt = 0;
struct node {
  long long n, d;
} cnt[N];
void dfs(long long u, long long fa) {
  sum[u] = 1;
  for (long long i = fi[u]; i; i = e[i].nxt) {
    long long v = e[i].to;
    if (v == fa || vis[v]) continue;
    dis[v] = dis[u] + e[i].w;
    num[v] = num[u] + 1;
    dfs(v, u);
    sum[u] += sum[v];
  }
  cnt[++tt].d = dis[u];
  cnt[tt].n = num[u];
}
bool cmp(node a, node b) { return a.d < b.d; }
long long c[N];
long long lowbit(long long x) { return x & (-x); }
void update(long long i, long long x) {
  if (i <= 0) return;
  while (i <= n + 1) {
    c[i] += x;
    i += lowbit(i);
  }
}
long long getsum(long long i) {
  if (i <= 0) return 0;
  long long res = 0;
  while (i > 0) {
    res += c[i];
    i -= lowbit(i);
  }
  return res;
}
long long cal(long long u, long long w, long long nn) {
  long long res = 0;
  tt = 0;
  dis[u] = w;
  num[u] = nn;
  dfs(u, 0);
  sort(cnt + 1, cnt + 1 + tt, cmp);
  for (long long i = 1; i <= tt; i++) update(cnt[i].n + 1, 1);
  long long l = 1, r = tt;
  while (l < r) {
    if (cnt[l].d + cnt[r].d <= W) {
      update(cnt[l].n + 1, -1);
      res += getsum(L - cnt[l].n + 1);
      l++;
    } else {
      update(cnt[r].n + 1, -1);
      r--;
    }
  }
  update(cnt[l].n + 1, -1);
  return res;
}
void solve(long long u) {
  ans += cal(u, 0, 0);
  vis[u] = 1;
  for (long long i = fi[u]; i; i = e[i].nxt) {
    long long v = e[i].to;
    if (vis[v]) continue;
    ans -= cal(v, e[i].w, 1);
    mn = 1e5;
    getG(v, u, sum[v]);
    solve(G);
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &L, &W);
  long long u, v;
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &u, &v);
    add(u, i + 1, v);
    add(i + 1, u, v);
  }
  mn = 1e5;
  getG(1, 0, n);
  solve(G);
  printf("%lld", ans);
  return 0;
}