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:36777216")
using namespace std;
struct segment_tree {
  int l, r, sum;
  int mid() { return l + r >> 1; }
} tree[100005 << 2];
struct edge {
  int next, v, c;
} e[100005 << 1];
int first[100005], dist[100005], size[100005];
int n, m, x, y, z, K, cnt, tot_size, heavy, mx, id, W;
long long ans;
char c;
bool del[100005];
vector<pair<int, int> > sub[100005], all;
void init_tree(int l, int r, int x) {
  tree[x].l = l, tree[x].r = r, tree[x].sum = 0;
  if (l == r) return;
  int mid = tree[x].mid();
  init_tree(l, mid, (x << 1)), init_tree(mid + 1, r, ((x << 1) + 1));
}
void add(int pos, int num, int x) {
  if (tree[x].l == tree[x].r) {
    tree[x].sum += num;
    return;
  }
  int mid = tree[x].mid();
  if (pos <= mid)
    add(pos, num, (x << 1));
  else
    add(pos, num, ((x << 1) + 1));
  tree[x].sum = tree[(x << 1)].sum + tree[((x << 1) + 1)].sum;
}
int query(int l, int r, int x) {
  if (l > r) return 0;
  if (l <= tree[x].l && r >= tree[x].r) return tree[x].sum;
  int mid = tree[x].mid(), res = 0;
  if (l <= mid) res += query(l, r, (x << 1));
  if (r > mid) res += query(l, r, ((x << 1) + 1));
  return res;
}
void addedge(int u, int v, int c) {
  e[++cnt].next = first[u], first[u] = cnt, e[cnt].v = v, e[cnt].c = c;
  e[++cnt].next = first[v], first[v] = cnt, e[cnt].v = u, e[cnt].c = c;
}
void dfs_size(int x, int pre) {
  size[x] = 1;
  for (int i = first[x]; i != -1; i = e[i].next)
    if (e[i].v != pre && !del[e[i].v])
      dfs_size(e[i].v, x), size[x] += size[e[i].v];
}
void dp(int x, int pre) {
  int tmp = 0;
  for (int i = first[x]; i != -1; i = e[i].next)
    if (e[i].v != pre && !del[e[i].v])
      dp(e[i].v, x), tmp = max(tmp, size[e[i].v]);
  tmp = max(tmp, tot_size - size[x]);
  if (tmp < mx) mx = tmp, heavy = x;
}
void dfs_get_heavy(int x) {
  heavy = -1, mx = 0x7fffffff;
  dfs_size(x, 0), tot_size = size[x];
  dp(x, 0);
}
void dfs_get_dist(int x, int pre, int dd, int len) {
  sub[id].push_back(make_pair(dd, len)), all.push_back(make_pair(dd, len));
  for (int i = first[x]; i != -1; i = e[i].next)
    if (e[i].v != pre && !del[e[i].v])
      dfs_get_dist(e[i].v, x, dd + e[i].c, len + 1);
}
void dfs(int X) {
  dfs_get_heavy(X);
  X = heavy;
  del[X] = true;
  if (tot_size == 1) return;
  id = 0, all.clear();
  for (int i = first[X]; i != -1; i = e[i].next)
    if (!del[e[i].v]) sub[++id].clear(), dfs_get_dist(e[i].v, 0, e[i].c, 1);
  for (int i = 1; i <= id; i++) {
    sort(sub[i].begin(), sub[i].end());
    for (int head = 0, tt = sub[i].size(); head < tt; head++) {
      add(sub[i][head].second, 1, 1);
    }
    for (int head = 0, tt = sub[i].size(), tail = sub[i].size() - 1; head < tt;
         head++) {
      add(sub[i][head].second, -1, 1);
      while (tail > head && sub[i][tail].first + sub[i][head].first > W)
        add(sub[i][tail].second, -1, 1), tail--;
      if (head == tail) break;
      ans -= query(0, K - sub[i][head].second, 1);
    }
  }
  sort(all.begin(), all.end());
  for (int head = 0, tt = all.size(); head < tt; head++) {
    add(all[head].second, 1, 1);
    if (all[head].first <= W && all[head].second <= K) ans++;
  }
  for (int head = 0, tt = all.size(), tail = all.size() - 1; head < tt;
       head++) {
    add(all[head].second, -1, 1);
    while (tail > head && all[tail].first + all[head].first > W)
      add(all[tail].second, -1, 1), tail--;
    if (head == tail) break;
    ans += query(0, K - all[head].second, 1);
  }
  for (int i = first[X]; i != -1; i = e[i].next)
    if (!del[e[i].v]) dfs(e[i].v);
}
int main() {
  while (scanf("%d%d%d", &n, &K, &W) == 3) {
    init_tree(1, n, 1);
    memset(first, -1, sizeof(first));
    memset(del, 0, sizeof(del));
    ans = 0, cnt = -1;
    for (int i = 1; i < n; i++) scanf("%d%d", &x, &y), addedge(i + 1, x, y);
    dfs(1);
    printf("%I64d\n", ans);
  }
}