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>
const int N = 1e5 + 7;
using namespace std;
int n, l, w, t[N], dp[N], d[N], a[N], level[N];
vector<pair<int, int> > g[N];
long long ans;
void dfs(int v, int pr = -1) {
  dp[v] = 1;
  for (auto to : g[v])
    if (to.first != pr) {
      dfs(to.first, v);
      dp[v] += dp[to.first];
    }
}
int find_center(int v) {
  for (auto to : g[v])
    if (level[to.first] == -1 && dp[to.first] * 2 > dp[v]) {
      dp[v] -= dp[to.first];
      dp[to.first] += dp[v];
      return find_center(to.first);
    }
  return v;
}
void dfs2(int v, int pr, vector<int> &p) {
  p.push_back(v);
  for (auto to : g[v])
    if (level[to.first] == -1 && to.first != pr) {
      d[to.first] = d[v] + 1;
      a[to.first] = a[v] + to.second;
      dfs2(to.first, v, p);
    }
}
void upd(int pos, int val) {
  for (; pos <= n; pos |= (pos + 1)) t[pos] += val;
}
int get(int pos) {
  int result = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) result += t[pos];
  return result;
}
bool cmp(pair<int, pair<int, int> > x, pair<int, pair<int, int> > y) {
  if (x.second.second != y.second.second)
    return x.second.second < y.second.second;
  return x.first < y.first;
}
long long cntAns(vector<int> p) {
  vector<pair<int, pair<int, int> > > v;
  for (int i : p) {
    v.push_back(make_pair(1, make_pair(d[i], a[i])));
    v.push_back(make_pair(2, make_pair(l - d[i], w - a[i])));
  }
  sort(v.begin(), v.end(), &cmp);
  long long result = 0;
  for (int i = 0; i < v.size(); ++i)
    if (v[i].first == 1) {
      upd(v[i].second.first, 1);
    } else {
      result += get(v[i].second.first);
    }
  for (int i = 0; i < (int)v.size(); ++i)
    if (v[i].first == 1) upd(v[i].second.first, -1);
  return result;
}
void build(int v, int depth) {
  v = find_center(v);
  level[v] = depth;
  vector<int> p;
  d[v] = 0;
  a[v] = 0;
  p.push_back(v);
  for (auto to : g[v])
    if (level[to.first] == -1) {
      d[to.first] = d[v] + 1;
      a[to.first] = a[v] + to.second;
      dfs2(to.first, v, p);
    }
  ans += cntAns(p);
  for (auto to : g[v])
    if (level[to.first] == -1) {
      p.clear();
      dfs2(to.first, v, p);
      ans -= cntAns(p);
    }
  ans--;
  for (auto to : g[v])
    if (level[to.first] == -1) build(to.first, depth + 1);
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> l >> w;
  for (int i = 1; i < n; ++i) {
    int pi, wi;
    cin >> pi >> wi;
    g[i + 1].push_back(make_pair(pi, wi));
    g[pi].push_back(make_pair(i + 1, wi));
  }
  for (int i = 1; i <= n; ++i) level[i] = -1;
  dfs(1);
  build(1, 0);
  cout << ans / 2 << endl;
  exit(0);
}