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 Mx = 1 << 17;
int n, L, W;
long long R, Fen[Mx << 2];
vector<int> V1, VA;
struct node {
  vector<pair<int, int> > N;
  bool ctred = false;
  int sz, dw, dl;
} G[Mx];
int DFS1(int v, int u = -1) {
  G[v].sz = true;
  for (pair<int, int> e : G[v].N)
    if (!G[e.second].ctred && e.second != u) G[v].sz += DFS1(e.second, v);
  return G[v].sz;
}
void DFS2(int v, int u = -1, int w = 0) {
  if (u != -1) {
    G[v].dw = G[u].dw + w;
    G[v].dl = G[u].dl + 1;
  }
  V1.push_back(v);
  VA.push_back(v);
  for (pair<int, int> e : G[v].N) {
    if (!G[e.second].ctred && e.second != u) DFS2(e.second, v, e.first);
  }
}
bool wCompare(int u, int v) { return G[u].dw < G[v].dw; }
void add(int id, int d = +1) {
  for (id++; id < Mx; id += id & -id) Fen[id] += d;
}
void rmv(int id) { add(id, -1); }
int get(int id) {
  if (id < 0) return 0;
  int s = 0;
  for (id++; id; id -= id & -id) s += Fen[id];
  return s;
}
long long sweepLine(vector<int>& V) {
  long long A = 0;
  sort(V.begin(), V.end(), wCompare);
  for (int x : V) add(G[x].dl);
  int e = V.size() - 1;
  for (int i = 0; i < V.size(); i++) {
    for (; e >= 0 && G[V[i]].dw + G[V[e]].dw > W; e--) rmv(G[V[e]].dl);
    A += get(L - G[V[i]].dl);
  }
  for (; e >= 0; e--) rmv(G[V[e]].dl);
  V.resize(0);
  return A;
}
void centroid(int r = 1) {
  DFS1(r);
  int v = r, t = 1;
  bool ctr = false;
  while (!ctr) {
    ctr = true;
    for (pair<int, int> e : G[v].N) {
      int u = e.second;
      if (u != t && !G[u].ctred && 2 * G[u].sz > G[r].sz) {
        ctr = false;
        t = v;
        v = u;
        break;
      }
    }
  }
  G[v].ctred = true;
  G[v].dw = G[v].dl = 0;
  VA.push_back(v);
  for (pair<int, int> u : G[v].N)
    if (!G[u.second].ctred) {
      DFS2(u.second, v, u.first);
      R -= sweepLine(V1);
    }
  R += sweepLine(VA);
  for (pair<int, int> u : G[v].N)
    if (!G[u.second].ctred) centroid(u.second);
}
int main() {
  cin >> n >> L >> W;
  for (int i = 1; i < n; i++) {
    int p, w;
    cin >> p >> w;
    G[p].N.push_back({w, i + 1});
    G[i + 1].N.push_back({w, p});
  }
  centroid();
  cout << (R - n) / 2;
}