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;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long tot;
int n, sum, cnt, l, w, rt;
int size[100005], last[100005], f[100005];
int dep[100005], dis[100005];
int t[100005];
bool vis[100005];
vector<pair<int, int> > q;
vector<int> rec;
struct edge {
  int to, next, v;
} e[200005];
void add(int x, int val) {
  for (int i = x; i <= n; i += i & -i) t[i] += val;
}
int query(int x) {
  if (x <= 0) return 0;
  int ans = 0;
  for (int i = x; i; i -= i & -i) ans += t[i];
  return ans;
}
void insert(int u, int v, int w) {
  e[++cnt] = (edge){v, last[u], w};
  last[u] = cnt;
  e[++cnt] = (edge){u, last[v], w};
  last[v] = cnt;
}
void getrt(int x, int fa) {
  f[x] = 0;
  size[x] = 1;
  for (int i = last[x]; i; i = e[i].next)
    if (e[i].to != fa && !vis[e[i].to]) {
      getrt(e[i].to, x);
      size[x] += size[e[i].to];
      f[x] = max(f[x], size[e[i].to]);
    }
  f[x] = max(f[x], sum - size[x]);
  if (f[x] < f[rt]) rt = x;
}
void getdp(int x, int fa) {
  q.push_back(make_pair(dis[x], dep[x]));
  for (int i = last[x]; i; i = e[i].next)
    if (e[i].to != fa && !vis[e[i].to]) {
      dep[e[i].to] = dep[x] + 1;
      dis[e[i].to] = dis[x] + e[i].v;
      getdp(e[i].to, x);
    }
}
long long cal() {
  int now = 0;
  long long ans = 0;
  sort(q.begin(), q.end());
  for (int i = (int)q.size() - 1; i >= 0; i--) {
    while (now < q.size() && q[now].first + q[i].first <= w) {
      add(q[now].second, 1);
      rec.push_back(q[now].second);
      now++;
    }
    if (q[i].first * 2 <= w && q[i].second * 2 <= l) ans--;
    ans += query(l - q[i].second);
  }
  return ans / 2;
}
void ini() {
  q.clear();
  for (int i = 0; i < rec.size(); i++) add(rec[i], -1);
  rec.clear();
}
void solve(int x) {
  vis[x] = 1;
  for (int i = last[x]; i; i = e[i].next)
    if (!vis[e[i].to]) {
      dep[e[i].to] = 1;
      dis[e[i].to] = e[i].v;
      getdp(e[i].to, x);
    }
  for (int i = 0; i < q.size(); i++)
    if (q[i].first <= w && q[i].second <= l) tot++;
  tot += cal();
  ini();
  for (int i = last[x]; i; i = e[i].next)
    if (!vis[e[i].to]) {
      dep[e[i].to] = 1;
      dis[e[i].to] = e[i].v;
      getdp(e[i].to, x);
      tot -= cal();
      ini();
    }
  for (int i = last[x]; i; i = e[i].next)
    if (!vis[e[i].to]) {
      sum = size[e[i].to];
      rt = 0;
      getrt(e[i].to, 0);
      solve(rt);
    }
}
int main() {
  n = read();
  l = read();
  w = read();
  for (int i = 2; i <= n; i++) {
    int p = read(), w = read();
    insert(p, i, w);
  }
  rt = 0;
  f[0] = 1000000000;
  sum = n;
  getrt(1, 0);
  solve(rt);
  cout << tot << endl;
  return 0;
}