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 N = 1e5 + 5;
int n, l, w, x, y, t[N], dp[N];
vector<pair<int, int> > g[N];
bool o;
long long ans;
bool used[N];
vector<pair<int, int> > q;
int getcenter(int v, int size, int pr = -1) {
  for (auto it : g[v]) {
    int to = it.first;
    if (!used[to] && to != pr && dp[to] > size / 2) {
      return getcenter(to, size, v);
    }
  }
  return v;
}
int calc(int v, int pr = -1) {
  dp[v] = 1;
  for (auto it : g[v]) {
    int to = it.first;
    if (!used[to] && to != pr) {
      dp[v] += calc(to, v);
    }
  }
  return dp[v];
}
void dfs(int v, int curw, int curl, int pr = -1) {
  q.push_back(make_pair(curw, curl));
  for (auto it : g[v]) {
    int to = it.first, len = it.second;
    if (!used[to] && to != pr) {
      dfs(to, curw + len, curl + 1, v);
    }
  }
}
inline void update(int pos, int val) {
  for (int i = pos + 1; i < N; i += i & -i) {
    t[i] += val;
  }
}
inline int get(int pos) {
  int cur = 0;
  for (int i = pos + 1; i >= 1; i -= i & -i) {
    cur += t[i];
  }
  return cur;
}
inline long long solve() {
  sort(q.begin(), q.end());
  for (auto it : q) {
    update(it.second, 1);
  }
  long long sum = 0;
  for (int i = 0, j = (int)q.size() - 1; i < q.size(); i++) {
    while (j >= i && q[j].first + q[i].first > w) {
      update(q[j].second, -1);
      j--;
    }
    if (j < i) {
      break;
    }
    update(q[i].second, -1);
    sum += get(l - q[i].second);
  }
  return sum;
}
void build(int v) {
  int center = getcenter(v, calc(v));
  q.clear();
  dfs(center, 0, 0);
  ans += solve();
  for (auto it : g[center]) {
    int to = it.first;
    if (!used[to]) {
      int len = it.second;
      q.clear();
      dfs(to, len, 1, center);
      ans -= solve();
    }
  }
  used[center] = true;
  for (auto it : g[center]) {
    int to = it.first;
    if (!used[to]) {
      build(to);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &l, &w);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &x, &y);
    g[i].push_back(make_pair(x, y));
    g[x].push_back(make_pair(i, y));
  }
  build(1);
  printf("%lld", ans);
}