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 long long N = 1e5 + 10, INF = 1e9 + 7;
int n, l, w, sz[N], fen[N];
long long ans;
vector<pair<int, int> > adj[N], dis[N], tmp;
bool vis[N];
void dfscen(int v, int par);
int centroid(int v);
void dfs(int v, int par, int wei, int len, int i);
void add(int x);
void remove(int x);
int sum(int x);
void solve(int v);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> l >> w;
  for (int v = 2; v <= n; v++) {
    int u, wei;
    cin >> u >> wei;
    adj[v].push_back({u, wei}), adj[u].push_back({v, wei});
  }
  solve(1);
  cout << ans << '\n';
  return 0;
}
void dfscen(int v, int par) {
  sz[v] = 1;
  for (auto p : adj[v])
    if (p.first != par && !vis[p.first])
      dfscen(p.first, v), sz[v] += sz[p.first];
}
int centroid(int v) {
  dfscen(v, 0);
  int C = sz[v] / 2, par = 0;
  while (1) {
    bool found = true;
    for (auto p : adj[v])
      if (!vis[p.first] && p.first != par && sz[p.first] > C) {
        found = false, par = v, v = p.first;
        break;
      }
    if (found) return v;
  }
}
void dfs(int v, int par, int wei, int len, int i) {
  dis[i].push_back({wei, len});
  for (auto p : adj[v])
    if (!vis[p.first] && p.first != par)
      dfs(p.first, v, wei + p.second, len + 1, i);
}
void add(int x) {
  for (int i = x; i < N - 5; i += (i & -i)) fen[i]++;
}
void remove(int x) {
  for (int i = x; i < N - 5; i += (i & -i)) fen[i]--;
}
int sum(int x) {
  int ret = 0;
  for (int i = x; i > 0; i -= (i & -i)) ret += fen[i];
  return ret;
}
void solve(int v) {
  v = centroid(v);
  vis[v] = true;
  int i = 0, k;
  long long a = 0;
  tmp.clear();
  for (auto p : adj[v])
    if (!vis[p.first]) {
      dis[i].clear();
      dfs(p.first, v, p.second, 1, i);
      sort(dis[i].begin(), dis[i].end());
      k = dis[i].size() - 1;
      for (auto j : dis[i]) add(j.second);
      for (auto j : dis[i]) {
        tmp.push_back(j);
        if (j.first <= w && j.second <= l) a += 2;
        while (k >= 0 && j.first + dis[i][k].first > w)
          remove(dis[i][k].second), k--;
        a -= sum(max(0, l - j.second));
      }
      while (k >= 0) remove(dis[i][k].second), k--;
      i++;
    }
  k = tmp.size() - 1;
  sort(tmp.begin(), tmp.end());
  for (auto j : tmp) add(j.second);
  for (auto j : tmp) {
    while (k >= 0 && j.first + tmp[k].first > w) remove(tmp[k].second), k--;
    a += sum(max(0, l - j.second));
  }
  while (k >= 0) remove(tmp[k].second), k--;
  ans += a / 2;
  for (auto p : adj[v])
    if (!vis[p.first]) solve(p.first);
}