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 = 500000, Maxm = 1000, Mo = 7340033, oo = INT_MAX >> 1;
typedef int Arr[Maxn];
Arr use, t, s, vis, l, r;
int n, w, d, i;
long long ans;
vector<pair<int, int> > e[Maxn], a[Maxn];
vector<pair<int, int> > b(Maxn);
int ask(int k, int l, int r, int x, int y) {
  if (y < l || r < x) return 0;
  if (x <= l && r <= y) return t[k];
  int mid = (l + r) / 2;
  return ask(k * 2, l, mid, x, y) + ask(k * 2 + 1, mid + 1, r, x, y);
}
void ins(int k, int l, int r, int x, int key) {
  if (x < l || r < x) return;
  if (l == r) {
    t[k] += key;
    return;
  }
  int mid = (l + r) / 2;
  ins(k * 2, l, mid, x, key);
  ins(k * 2 + 1, mid + 1, r, x, key);
  t[k] = t[k * 2 + 1] + t[k * 2];
}
void calc(vector<pair<int, int> > &a, vector<pair<int, int> > &b) {
  int p = -1;
  for (int i = (int)a.size() - 1; i >= 0; i--) {
    while (p + 1 < b.size() && a[i].first + b[p + 1].first <= w)
      ins(1, 0, d, b[++p].second, 1);
    ans += ask(1, 0, d, 0, d - a[i].second);
  }
  for (int i = 0; i <= p; i++) ins(1, 0, d, b[i].second, -1);
}
pair<int, int> find(int u, int f, int sum) {
  s[u] = 1;
  int lar = 0;
  pair<int, int> ans = make_pair((oo), (0));
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].second;
    if (v == f || vis[v]) continue;
    pair<int, int> x = find(v, u, sum);
    s[u] += s[v];
    lar = max(lar, s[v]);
    ans = min(ans, x);
  }
  lar = max(lar, sum - s[u]);
  ans = min(ans, make_pair((lar), (u)));
  return ans;
}
void dfs(int u, int f, int x, int y, vector<pair<int, int> > &a) {
  a.push_back((make_pair((x), (y))));
  s[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].second, c = e[u][i].first;
    if (v == f || vis[v]) continue;
    dfs(v, u, x + c, y + 1, a);
    s[u] += s[v];
  }
}
void Merge(int x, int y) {
  b.clear();
  int px = 0, py = 0;
  int ctx = a[x].size(), cty = a[y].size();
  while (px != ctx && py != cty)
    if (a[x][px] < a[y][py])
      b.push_back((a[x][px++]));
    else
      b.push_back((a[y][py++]));
  if (px == ctx)
    while (py != cty) b.push_back((a[y][py++]));
  if (py == cty)
    while (px != ctx) b.push_back((a[x][px++]));
}
void dfs(int u, int f, int sum) {
  pair<int, int> pp = find(u, f, sum);
  u = pp.second;
  int m = 0, left, x = -1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].second, c = e[u][i].first;
    if (vis[v]) continue;
    a[++m].clear();
    dfs(v, u, c, 1, a[m]);
    sort(a[m].begin(), a[m].end());
  }
  a[++m].clear();
  a[left = m].push_back((make_pair((0), (0))));
  while (left > 1) {
    for (int i = 1; i <= m; i++)
      if (!use[i]) {
        if (x >= 0) {
          calc(a[x], a[i]);
          int ct = a[x].size() + a[i].size();
          Merge(x, i);
          a[x] = b;
          x = -1;
          use[i] = 1;
          left--;
        } else
          x = i;
      }
  }
  for (i = 1; i <= m; i++) use[i] = 0;
  vis[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].second;
    if (!vis[v] && s[v] > 1) dfs(v, u, s[v]);
  }
}
int main() {
  int tm1 = clock();
  ios::sync_with_stdio(0);
  cin >> n >> d >> w;
  for (i = 2; i <= n; i++) {
    int v, c;
    cin >> v >> c;
    e[i].push_back((make_pair((c), (v))));
    e[v].push_back((make_pair((c), (i))));
  }
  dfs(1, 0, n);
  cout << ans << endl;
}