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 inf = 0x3f3f3f3f;
const int N = 100005;
using namespace std;
vector<pair<int, int> > g[N];
int sz[N], f[N], sum;
bool vis[N];
int root, L, W;
void getroot(int x, int fa) {
  sz[x] = 1;
  f[x] = 0;
  for (int i = 0; i < g[x].size(); ++i) {
    int u = g[x][i].first;
    if (u != fa && !vis[u]) {
      getroot(u, x);
      if (sz[u] > f[x]) f[x] = sz[u];
      sz[x] += sz[u];
    }
  }
  if (sum - sz[x] > f[x]) f[x] = sum - sz[x];
  if (root == -1 || f[x] < f[root]) root = x;
}
vector<pair<int, int> > v;
vector<int> ww;
long long ans = 0;
void gt(int x, int fa, int d, int w) {
  v.push_back(make_pair(d, w));
  ww.push_back(w);
  for (int i = 0; i < g[x].size(); ++i) {
    int u = g[x][i].first;
    if (u != fa && !vis[u]) gt(u, x, d + 1, w + g[x][i].second);
  }
}
int s[N], nn;
void add(int x, int d) {
  for (; x <= nn; x += x & (-x)) s[x] += d;
}
int gtsum(int x) {
  int res = 0;
  for (; x > 0; x -= x & (-x)) res += s[x];
  return res;
}
int low(int x) { return lower_bound(ww.begin(), ww.end(), x) - ww.begin(); }
long long calc(int x, int d, int w) {
  v.clear();
  ww.clear();
  gt(x, -1, d, w);
  sort(v.begin(), v.end());
  sort(ww.begin(), ww.end());
  ww.erase(unique(ww.begin(), ww.end()), ww.end());
  nn = ww.size();
  int j = v.size() - 1;
  long long res = 0;
  for (int i = 0; i < v.size(); ++i) add(low(v[i].second) + 1, 1);
  for (int i = 0; i < v.size() && i <= j; ++i) {
    add(low(v[i].second) + 1, -1);
    while (i < j && v[j].first + v[i].first > L)
      add(low(v[j--].second) + 1, -1);
    if (i >= j) break;
    int t = W - v[i].second;
    res += (long long)gtsum(low(t + 1));
  }
  return res;
}
void dfs(int x) {
  ans += calc(x, 0, 0);
  vis[x] = true;
  for (int i = 0; i < g[x].size(); ++i) {
    int u = g[x][i].first;
    if (!vis[u]) {
      ans -= calc(u, 1, g[x][i].second);
      root = -1;
      sum = sz[u];
      getroot(u, -1);
      dfs(root);
    }
  }
}
int main() {
  int n, i, u, w;
  scanf("%d%d%d", &n, &L, &W);
  for (i = 0; i < n - 1; ++i) {
    scanf("%d%d", &u, &w);
    --u;
    g[i + 1].push_back(make_pair(u, w));
    g[u].push_back(make_pair(i + 1, w));
  }
  root = -1;
  sum = n;
  getroot(0, -1);
  dfs(root);
  printf("%I64d", ans);
  return 0;
}