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 = 100000;
int head[MAXN], L;
struct Edge {
  int to, next, len;
} edge[MAXN * 2 - 2];
int K, M;
int siz[MAXN];
bool solved[MAXN];
int getSize(int u, int fu) {
  int ret = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fu || solved[v]) continue;
    ret += getSize(v, u);
  }
  return ret;
}
pair<int, int> getCenter(int u, int fu, int size) {
  pair<int, int> ret = make_pair(MAXN, -1);
  int maxs = 0;
  siz[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fu || solved[v]) continue;
    pair<int, int> tmp = getCenter(v, u, size);
    siz[u] += siz[v];
    maxs = max(maxs, siz[v]);
    ret = min(ret, tmp);
  }
  return min(ret, make_pair(max(size - siz[u], maxs), u));
}
pair<int, int> path[MAXN], tot[MAXN];
int nums;
void getPath(int u, int fu, int now, int len) {
  path[nums++] = make_pair(len, now);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fu || solved[v]) continue;
    getPath(v, u, now + 1, len + edge[i].len);
  }
}
int tree[MAXN + 1];
void update(int x, int v) {
  for (; x < MAXN; x += x & -x) tree[x] += v;
}
int query(int x) {
  int ret = 0;
  for (; x > 0; x -= x & -x) ret += tree[x];
  return ret;
}
long long solve(pair<int, int> a[], int n) {
  if (!n) return 0;
  sort(a, a + n);
  long long ret = 0;
  for (int i = 0; i < n; ++i) update(a[i].second, 1);
  for (int i = 0, j = n - 1; i < n; ++i) {
    update(a[i].second, -1);
    while (i < j && a[i].first + a[j].first > M) update(a[j--].second, -1);
    if (i == j) break;
    ret += query(K - a[i].second);
  }
  return ret;
}
long long solve(int u) {
  int size = getSize(u, -1);
  u = getCenter(u, -1, size).second;
  solved[u] = 1;
  long long ret = 0;
  int n = 0;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (solved[v]) continue;
    nums = 0;
    getPath(v, u, 1, edge[i].len);
    for (int i = 0; i < nums; ++i) tot[n++] = path[i];
    ret -= solve(path, nums);
  }
  ret += solve(tot, n);
  for (int i = 0; i < n; ++i)
    if (tot[i].first <= M && tot[i].second <= K) ++ret;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (solved[v]) continue;
    ret += solve(v);
  }
  return ret;
}
void init(int n) {
  L = 0;
  memset(head, -1, 4 * n);
  memset(solved, 0, n);
}
void add_edge(int u, int v, int len) {
  edge[L].to = v;
  edge[L].len = len;
  edge[L].next = head[u];
  head[u] = L++;
}
int main() {
  int n;
  scanf("%d%d%d", &n, &K, &M);
  init(n);
  for (int i = 1; i < n; ++i) {
    int u, len;
    scanf("%d%d", &u, &len);
    add_edge(u - 1, i, len);
    add_edge(i, u - 1, len);
  }
  printf("%I64d\n", solve(0));
  return 0;
}