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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 1e5 + 50;
const int M = 11;
const long long MOD = 1e6 + 3;
const int INF = 0x3f3f3f3f;
struct node {
  int e, next, w;
} edge[N << 1];
int tot, rt, mx, cnt, n, L, W;
int first[N], vis[N], sz[N];
pair<int, int> dis[N];
long long ans, C[N];
void init(int n) {
  tot = 0;
  ans = 0;
  for (int i = 0; i <= n; i++) {
    vis[i] = 0;
    first[i] = -1;
  }
}
void add(int u, int v, int w) {
  edge[tot] = (node){v, first[u], w};
  first[u] = tot++;
  edge[tot] = (node){u, first[v], w};
  first[v] = tot++;
}
void dfs1(int u, int fa) {
  int maxv = 1;
  sz[u] = 1;
  for (int i = first[u]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    if (v == fa || vis[v]) continue;
    dfs1(v, u);
    sz[u] += sz[v];
    maxv = max(maxv, sz[v]);
  }
  maxv = max(maxv, sz[0] - sz[u]);
  if (maxv < mx) mx = maxv, rt = u;
}
void dfs2(int u, int fa, int depth, int d) {
  dis[cnt++] = make_pair(d, depth);
  sz[u] = 1;
  for (int i = first[u]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    if (v == fa || vis[v]) continue;
    dfs2(v, u, depth + 1, d + edge[i].w);
    sz[u] += sz[v];
  }
}
int lowbit(int x) { return x & -x; }
int up;
void update(int x, int v) {
  while (x <= up) {
    C[x] += v;
    x += lowbit(x);
  }
}
long long query(int x) {
  x = min(x, up);
  long long ret = 0;
  while (x > 0) {
    ret += C[x];
    x -= lowbit(x);
  }
  return ret;
}
long long solve(int u, int depth, int d) {
  long long num = 0;
  cnt = 0;
  up = 0;
  dfs2(u, -1, depth, d);
  sort(dis, dis + cnt);
  for (int i = 0; i < cnt; i++) up = max(up, dis[i].second);
  for (int i = 0; i <= up; i++) C[i] = 0;
  for (int i = 1; i < cnt; i++) update(dis[i].second, 1);
  int l = 0, r = cnt - 1;
  while (l < r) {
    while (l < r && dis[r].first + dis[l].first > W)
      update(dis[r].second, -1), r--;
    num += query(L - dis[l].second);
    l++;
    update(dis[l].second, -1);
  }
  return num;
}
void dfs(int u, int num) {
  sz[0] = num;
  mx = INF;
  dfs1(u, -1);
  vis[rt] = 1;
  ans += solve(rt, 1, 0);
  for (int i = first[rt]; i != -1; i = edge[i].next) {
    int v = edge[i].e;
    if (vis[v]) continue;
    ans -= solve(v, 2, edge[i].w);
    dfs(v, sz[v]);
  }
}
int u, v, w;
int main() {
  scanf("%d%d%d", &n, &L, &W);
  L += 2;
  init(n);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &u, &w);
    add(i, u, w);
  }
  dfs(1, n);
  printf("%I64d", ans);
  return 0;
}