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 = 100010;
struct ha {
  int v, w;
};
struct node {
  int dis, dep;
} s[N];
int n, m, k, dis[N], vis[N], sum, size[N], dep[N], f[N], rt, cnt, c[N];
long long ans;
vector<ha> q[N];
void add(int x, int y) {
  if (!x) return;
  while (x <= n + 1) {
    c[x] += y;
    x += x & -x;
  }
}
int Sum(int x) {
  if (x <= 0) return 0;
  int res = 0;
  while (x) {
    res += c[x];
    x -= x & -x;
  }
  return res;
}
bool cmp(node a, node b) { return a.dis < b.dis; }
void getroot(int u, int fa) {
  size[u] = 1;
  f[u] = 0;
  for (int i = 0; i < q[u].size(); i++) {
    int v = q[u][i].v;
    if (vis[v] || v == fa) continue;
    getroot(v, u);
    size[u] += size[v];
    f[u] = max(f[u], size[v]);
  }
  f[u] = max(f[u], sum - size[u]);
  if (f[u] < f[rt]) rt = u;
}
void dfs(int u, int fa) {
  s[++cnt] = (node){dis[u], dep[u]};
  for (int i = 0; i < q[u].size(); i++) {
    int v = q[u][i].v, w = q[u][i].w;
    if (v == fa || vis[v]) continue;
    dis[v] = dis[u] + w;
    dep[v] = dep[u] + 1;
    dfs(v, u);
  }
}
long long calc(int u, int Dis, int Dep) {
  cnt = 0;
  dis[u] = Dis;
  dep[u] = Dep;
  dfs(u, 0);
  sort(s + 1, s + cnt + 1, cmp);
  for (int i = 1; i <= cnt; i++) add(s[i].dep + 1, 1);
  int l = 1, r = cnt;
  long long res = 0;
  while (l < r) {
    if (s[l].dis + s[r].dis <= k) {
      add(s[l].dep + 1, -1);
      res += Sum(m - s[l].dep + 1);
      l++;
    } else {
      add(s[r].dep + 1, -1);
      r--;
    }
  }
  add(s[l].dep + 1, -1);
  return res;
}
void solve(int u) {
  ans += calc(u, 0, 0);
  vis[u] = 1;
  for (int i = 0; i < q[u].size(); i++) {
    int v = q[u][i].v;
    if (vis[v]) continue;
    ans -= calc(v, q[u][i].w, 1);
    rt = 0;
    sum = size[v];
    getroot(v, 0);
    solve(rt);
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i < n; i++) {
    int p, w;
    cin >> p >> w;
    q[i + 1].push_back((ha){p, w});
    q[p].push_back((ha){i + 1, w});
  }
  f[rt] = sum = n;
  getroot(1, 0);
  solve(rt);
  cout << ans;
  return 0;
}