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;
int n, L, W;
int cnt;
bool vis[100005];
long long ans;
struct Node {
  int to, cost;
};
vector<Node> G[100005];
int root, sum, son[100005], Max[100005];
struct node {
  int dep, len;
  bool operator<(const node &a) const {
    return (len == a.len) ? (dep < a.dep) : (len < a.len);
  }
};
vector<node> E[100005], mp;
void Getans(int x, int fa) {
  son[x] = 1, Max[x] = 0;
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].to;
    if (y == fa || vis[y]) continue;
    Getans(y, x);
    son[x] += son[y];
    Max[x] = max(Max[x], son[y]);
  }
  Max[x] = max(Max[x], sum - son[x]);
  if (Max[x] < Max[root]) root = x;
}
void dfs(int x, int fa, int dep, int len) {
  E[cnt].push_back((node){dep, len});
  son[x] = 1;
  mp.push_back((node){dep, len});
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].to, cost = G[x][i].cost;
    if (vis[y] || y == fa) continue;
    dfs(y, x, dep + 1, len + cost);
    son[x] += son[y];
  }
}
int Stk[100005];
void Add(int l, int x, int mx) {
  for (int i = l; i <= mx; i += i & (-i)) Stk[i] += x;
}
int query(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= i & (-i)) res += Stk[i];
  return res;
}
long long calc(vector<node> &E) {
  long long res = 0;
  int mx = 0;
  for (int i = 0; i < (int)E.size(); i++) mx = max(mx, E[i].dep);
  for (int i = (1), i_end_ = (mx); i <= i_end_; i++) Stk[i] = 0;
  for (int i = 0; i < (int)E.size(); i++) Add(E[i].dep, 1, mx);
  for (int i = 0, j = (int)E.size() - 1; i < (int)E.size(); i++) {
    while (i < j && E[i].len + E[j].len > W) {
      Add(E[j].dep, -1, mx);
      j--;
    }
    if (i >= j) break;
    Add(E[i].dep, -1, mx);
    res += query(min(mx, L - E[i].dep));
  }
  return res;
}
void solve(int x) {
  vis[x] = 1, cnt = 0;
  if (sum == 1) return;
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].to, cost = G[x][i].cost;
    if (vis[y]) continue;
    dfs(y, x, 1, cost);
    sort(E[cnt].begin(), E[cnt].end());
    cnt++;
  }
  sort(mp.begin(), mp.end());
  ans += calc(mp);
  for (int i = (0), i_end_ = (cnt - 1); i <= i_end_; i++) {
    for (int j = 0; j < (int)E[i].size(); j++) {
      if (E[i][j].len <= W && E[i][j].dep <= L) ans++;
    }
    ans -= calc(E[i]);
  }
  mp.clear();
  for (int i = (0), i_end_ = (cnt - 1); i <= i_end_; i++) E[i].clear();
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].to;
    if (vis[y]) continue;
    root = 0;
    sum = son[y];
    Getans(y, x);
    solve(root);
  }
}
int main() {
  scanf("%d%d%d", &n, &L, &W);
  for (int i = (1), i_end_ = (n); i <= i_end_; i++) G[i].clear();
  for (int i = (2), i_end_ = (n); i <= i_end_; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[i].push_back((Node){a, b});
    G[a].push_back((Node){i, b});
  }
  memset(vis, 0, sizeof(vis));
  for (int i = (0), i_end_ = (n); i <= i_end_; i++) E[i].clear();
  mp.clear();
  ans = 0;
  root = 0;
  sum = n;
  Max[root] = 0x3f3f3f3f;
  Getans(1, 0);
  solve(root);
  printf("%lld\n", ans);
  return 0;
}