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;
struct EDGE {
  int ent;
  int to[100005 * 2], nxt[100005 * 2], val[100005 * 2], head[100005];
  void Reset() {
    ent = 2;
    memset(head, 0, sizeof(head));
  }
  void Adde(int u, int v, int w) {
    to[ent] = v;
    val[ent] = w;
    nxt[ent] = head[u];
    head[u] = ent++;
    to[ent] = u;
    val[ent] = w;
    nxt[ent] = head[v];
    head[v] = ent++;
  }
} E;
struct BIT {
  int val[100005], N;
  int Lowbit(int x) { return x & -x; }
  void Reset(int n) { N = n + 1; }
  void Modify(int p, int x) {
    p++;
    for (; p <= N; p += Lowbit(p)) val[p] += x;
  }
  int Query(int p) {
    static int ans;
    ans = 0;
    p++;
    for (; p; p -= Lowbit(p)) ans += val[p];
    return ans;
  }
} DT;
int N, K, W;
long long ANS;
int size[100005];
bool vis[100005];
void getroot(int u, int dad, int num, int &root, int &rootnum) {
  int maxnum = 0;
  size[u] = 0;
  for (int i = E.head[u]; i; i = E.nxt[i]) {
    if (E.to[i] == dad || vis[E.to[i]]) continue;
    getroot(E.to[i], u, num, root, rootnum);
    size[u] += size[E.to[i]];
    maxnum = max(maxnum, size[E.to[i]]);
  }
  size[u]++;
  maxnum = max(maxnum, num - size[u]);
  if (maxnum < rootnum) root = u, rootnum = maxnum;
}
long long calu(int s, int len, int deep) {
  long long ret = 0;
  static pair<int, int> A[100005];
  static int dis[100005], dep[100005], reach[100005], rnt, ant;
  static queue<int> Q;
  ant = 0;
  rnt++;
  Q.push(s);
  dis[s] = len;
  reach[s] = rnt;
  dep[s] = deep;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    A[++ant] = make_pair(dis[u], dep[u]);
    for (int i = E.head[u]; i; i = E.nxt[i]) {
      int v = E.to[i];
      if (reach[v] == rnt || vis[v]) continue;
      dis[v] = dis[u] + E.val[i];
      dep[v] = dep[u] + 1;
      reach[v] = rnt;
      Q.push(v);
    }
  }
  sort(A + 1, A + ant + 1);
  for (int i = 1; i <= ant; i++) DT.Modify(A[i].second, 1);
  int l = 1, r = ant;
  while (l <= r) {
    if (A[l].first + A[r].first > K)
      DT.Modify(A[r].second, -1), r--;
    else
      DT.Modify(A[l].second, -1),
          ret += (W - A[l].second >= 0 ? DT.Query(W - A[l].second) : 0), l++;
  }
  return ret;
}
void divide(int u) {
  int root, rootnum = size[u];
  getroot(u, 0, size[u], root, rootnum);
  vis[root] = 1;
  ANS += calu(root, 0, 0);
  for (int i = E.head[root]; i; i = E.nxt[i])
    if (!vis[E.to[i]]) ANS -= calu(E.to[i], E.val[i], 1);
  for (int i = E.head[root]; i; i = E.nxt[i])
    if (!vis[E.to[i]]) divide(E.to[i]);
}
void read(int &x) {
  static int sign;
  static char ch;
  x = 0;
  sign = 1;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x = x * sign;
}
int main() {
  read(N);
  read(W);
  read(K);
  E.Reset();
  DT.Reset(N);
  ANS = 0;
  for (int i = 2, dad, w; i <= N; i++) read(dad), read(w), E.Adde(dad, i, w);
  size[1] = N;
  divide(1);
  cout << ANS << endl;
  return 0;
}