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 = 100000 + 10;
int n, l;
long long w;
vector<pair<int, int> > g[maxn];
long long ans;
int vis[maxn];
int siz[maxn];
int mx[maxn];
int c[maxn];
inline int lowbit(int x) { return x & -x; }
int SUM(int x) {
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
void ADD(int x, int add) {
  while (x <= l + 1) {
    c[x] += add;
    x += lowbit(x);
  }
}
void getsize(int cur, int fa) {
  siz[cur] = 1;
  mx[cur] = 0;
  for (int i = 0; i < g[cur].size(); ++i) {
    int v = g[cur][i].first;
    if (v != fa && !vis[v]) {
      getsize(v, cur);
      siz[cur] += siz[v];
      if (siz[v] > mx[cur]) {
        mx[cur] = siz[v];
      }
    }
  }
}
int root, mi;
void find(int rt, int cur, int fa) {
  mx[cur] = max(mx[cur], siz[rt] - siz[cur]);
  if (mx[cur] < mi) {
    mi = mx[cur];
    root = cur;
  }
  for (int i = 0; i < g[cur].size(); ++i) {
    int v = g[cur][i].first;
    if (v != fa && !vis[v]) {
      find(rt, v, cur);
    }
  }
}
struct node {
  long long d1;
  int d2;
  node(long long d1 = 0, int d2 = 0) : d1(d1), d2(d2) {}
};
bool cmp(node a, node b) { return a.d1 < b.d1; }
node dis[maxn];
int cnt;
void getdis(int cur, long long d1, int d2, int fa) {
  dis[cnt++] = node(d1, d2);
  for (int i = 0; i < g[cur].size(); ++i) {
    int v = g[cur][i].first;
    int w = g[cur][i].second;
    if (v != fa && !vis[v]) {
      getdis(v, d1 + w, d2 + 1, cur);
    }
  }
}
long long solve(int cur, long long d1, int d2) {
  long long ret = 0;
  cnt = 0;
  getdis(cur, d1, d2, 0);
  sort(dis, dis + cnt, cmp);
  int i = 0, j = cnt - 1;
  for (int i = 0; i < cnt; ++i) {
    ADD(dis[i].d2 + 1, 1);
  }
  while (i < j) {
    ADD(dis[i].d2 + 1, -1);
    while (i < j && dis[i].d1 + dis[j].d1 > w) {
      ADD(dis[j].d2 + 1, -1);
      --j;
    }
    if (l - dis[i].d2 >= 0) {
      int tmp = SUM(l - dis[i].d2 + 1);
      ret += tmp;
    }
    ++i;
  }
  if (SUM(dis[j].d2 + 1)) ADD(dis[j].d2 + 1, -1);
  return ret;
}
const int inf = 0x3f3f3f3f;
void dfs(int cur) {
  getsize(cur, 0);
  mi = inf;
  find(cur, cur, 0);
  ans += solve(root, 0, 0);
  vis[root] = 1;
  int tmproot = root;
  for (int i = 0; i < g[tmproot].size(); ++i) {
    int v = g[tmproot][i].first;
    int w = g[tmproot][i].second;
    if (!vis[v]) {
      ans -= solve(v, w, 1);
      dfs(v);
    }
  }
}
int main() {
  scanf("%d %d %lld", &n, &l, &w);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(make_pair(i + 1, y));
    g[i + 1].push_back(make_pair(x, y));
  }
  dfs(1);
  printf("%lld\n", ans);
  return 0;
}