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 N = 1e5 + 50;
int to[N << 1], las[N << 1], fir[N], ds[N << 1], cnt;
inline void add_edge(int u, int v, int a) {
  to[++cnt] = v;
  las[cnt] = fir[u];
  fir[u] = cnt;
  ds[cnt] = a;
  to[++cnt] = u;
  las[cnt] = fir[v];
  fir[v] = cnt;
  ds[cnt] = a;
}
inline int max(int u, int v) { return u > v ? u : v; }
inline int min(int u, int v) { return u < v ? u : v; }
int n, m, k, x, y;
int f[N], dis[N], dep[N], siz[N], vis[N];
int Cnt, rot, sum;
long long ans;
struct node {
  int dis, dep;
} sth[N];
struct Tree {
  int f[N];
  void insert(int u) {
    if (u == 0) return;
    for (int i = u; i <= n + 1; i += i & -i) f[i]++;
  }
  void erase(int u) {
    if (u == 0) return;
    for (int i = u; i <= n + 1; i += i & -i) f[i]--;
  }
  int Ans(int u) {
    if (u <= 0) return 0;
    int ret = 0;
    for (int i = u; i; i &= i - 1) ret += f[i];
    return ret;
  }
} s;
bool mmp(const node &u, const node &v) { return u.dis < v.dis; }
void grot(int u, int v) {
  siz[u] = 1;
  f[u] = 0;
  for (int i = fir[u]; i; i = las[i])
    if (to[i] != v && !vis[to[i]]) {
      grot(to[i], u);
      siz[u] += siz[to[i]];
      f[u] = max(f[u], siz[to[i]]);
    }
  f[u] = max(f[u], sum - siz[u]);
  if (f[u] < f[rot]) rot = u;
}
void gsth(int u, int v) {
  sth[++Cnt] = (node){dis[u], dep[u]};
  for (int i = fir[u]; i; i = las[i])
    if (to[i] != v && !vis[to[i]]) {
      dis[to[i]] = dis[u] + ds[i];
      dep[to[i]] = dep[u] + 1;
      gsth(to[i], u);
    }
}
long long calc(int u, int Dis, int Dep) {
  Cnt = 0;
  dis[u] = Dis;
  dep[u] = Dep;
  gsth(u, 0);
  sort(sth + 1, sth + Cnt + 1, mmp);
  for (int i = 1; i <= Cnt; i++) s.insert(sth[i].dep + 1);
  int l = 1, r = Cnt;
  long long res = 0;
  while (l < r) {
    if (sth[l].dis + sth[r].dis <= k) {
      s.erase(sth[l].dep + 1);
      res += s.Ans(m - sth[l].dep + 1);
      l++;
    } else {
      s.erase(sth[r].dep + 1);
      r--;
    }
  }
  s.erase(sth[l].dep + 1);
  return res;
}
void solve(int u) {
  ans += calc(u, 0, 0);
  vis[u] = 1;
  for (int i = fir[u]; i; i = las[i])
    if (!vis[to[i]]) {
      ans -= calc(to[i], ds[i], 1);
      rot = 0;
      sum = siz[to[i]];
      grot(to[i], 0);
      solve(rot);
    }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &x, &y);
    add_edge(x, i, y);
  }
  f[0] = sum = n;
  grot(1, 0);
  solve(rot);
  printf("%I64d\n", ans);
}