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;
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
const int N = 320000;
int n, L, W;
long long Ans;
struct Vertice_Divide_and_Conquer {
 private:
  vector<int> E[N], F[N];
  vector<pair<int, int> > Dis[N << 1];
  int rt, fa[N], vis[N], A[N], al, size[N], sub[N], dep[N], gs[N], Cnt, t[N];

 public:
  void add(int x, int y, int z) {
    E[x].push_back(y);
    E[y].push_back(x);
    F[x].push_back(z);
    F[y].push_back(z);
  }
  void Dfs(int w, int Fa, int R, int dis, int lth, int par, int TT) {
    Dis[R].push_back(make_pair(lth, dis));
    Dis[par].push_back(make_pair(lth, dis));
    for (int i = 0; i < E[w].size(); i++)
      if (!vis[E[w][i]] && E[w][i] != Fa) {
        if (par)
          Dfs(E[w][i], w, R, dis + 1, lth + F[w][i], par, F[w][i]);
        else
          ++Cnt, Dfs(E[w][i], w, R, dis + 1, lth + F[w][i], Cnt, TT);
      }
  }
  void Subsize(int x, int Fa) {
    A[++al] = x;
    size[x] = sub[x] = 1;
    for (int i = 0; i < E[x].size(); i++)
      if (!vis[E[x][i]] && E[x][i] != Fa) {
        Subsize(E[x][i], x);
        size[x] += size[E[x][i]];
        sub[x] = max(sub[x], size[E[x][i]]);
      }
  }
  int Get_Center(int x, int Fa) {
    al = 0;
    Subsize(x, Fa);
    for (int i = 1; i <= al; i++) sub[A[i]] = max(sub[A[i]], al - size[A[i]]);
    int ans = 0;
    for (int i = 1; i <= al; i++)
      if (sub[A[i]] <= (al + 1) / 2) return A[i];
  }
  void T_add(int x, int c) {
    x++;
    if (x < 0) return;
    for (int i = x; i <= n + 10; i += i & (-i)) t[i] += c;
  }
  int T_ask(int x) {
    x++;
    if (x < 0) return 0;
    int ans = 0;
    for (int i = x; i; i -= i & (-i)) ans += t[i];
    return ans;
  }
  void SORT(int x, int ty) {
    long long aa = 0;
    int Last = Dis[x].size() - 1;
    sort(Dis[x].begin(), Dis[x].end());
    for (int i = 0; i < Dis[x].size(); i++) T_add(Dis[x][i].second, 1);
    for (int i = 0; i < Dis[x].size(); i++)
      if (Dis[x][i].first <= W) {
        while (Last >= 0 && Dis[x][Last].first + Dis[x][i].first > W)
          T_add(Dis[x][Last].second, -1), Last--;
        aa += (long long)ty * (long long)T_ask(L - Dis[x][i].second);
        if (Dis[x][i].first * 2 <= W && Dis[x][i].second * 2 <= L) aa -= ty;
      }
    while (Last >= 0) T_add(Dis[x][Last].second, -1), Last--;
    Ans += aa / 2;
  }
  void dfs(int rt, int Fa) {
    vis[rt] = 1;
    int CCnt = Cnt;
    Dfs(rt, Fa, rt, 0, 0, 0, 0);
    fa[rt] = Fa;
    SORT(rt, 1);
    for (int i = CCnt + 1; i <= Cnt; i++) SORT(i, -1);
    for (int i = 0; i < E[rt].size(); i++)
      if (!vis[E[rt][i]] && E[rt][i] != Fa) dfs(Get_Center(E[rt][i], rt), rt);
  }
  void build() {
    Cnt = n + 1;
    rt = Get_Center(1, 0);
    dfs(rt, 0);
  }
} VDC;
int m, x, y;
int main() {
  scanf("%d%d%d", &n, &L, &W);
  for (int i = 1; i <= n - 1; i++) scanf("%d%d", &x, &y), VDC.add(x, i + 1, y);
  VDC.build();
  printf("%lld\n", Ans);
}