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>
#pragma GCC optimize(3)
namespace orz {
inline void read(int &x) { scanf("%d", &x); }
inline void read(unsigned int &x) { scanf("%u", &x); }
inline void read(long long &x) { scanf("%I64d", &x); }
inline void read(unsigned long long &x) { scanf("%I64u", &x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  read(tmp);
  x = tmp;
}
inline void read(char &x) { x = getchar(); }
inline void read(char *x) { scanf("%s", x); }
template <class T>
inline void read(T *a, int n) {
  for (int i = (0); i < (n); ++i) read(a[i]);
}
template <class T1, class T2>
inline void read(T1 &a, T2 &b) {
  read(a);
  read(b);
}
template <class T1, class T2, class T3>
inline void read(T1 &a, T2 &b, T3 &c) {
  read(a);
  read(b);
  read(c);
}
template <class T1, class T2, class T3, class T4>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d) {
  read(a);
  read(b);
  read(c);
  read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d, T5 &e) {
  read(a);
  read(b);
  read(c);
  read(d);
  read(e);
}
inline void write(int x) { printf("%d", x); }
inline void write(unsigned int x) { printf("%u", x); }
inline void write(long long x) { printf("%I64d", x); }
inline void write(unsigned long long x) { printf("%I64u", x); }
inline void write(double x) { printf("%.10lf", x); }
inline void write(long double x) { printf("%.10lf", (double)x); }
inline void write(char x) { putchar(x); }
inline void write(char *x) { printf("%s", x); }
template <class T>
inline void writes(T x) {
  write(x);
  putchar(' ');
}
template <class T1, class T2>
inline void writes(T1 a, T2 b) {
  writes(a);
  writes(b);
}
template <class T1, class T2, class T3>
inline void writes(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
}
template <class T1, class T2, class T3, class T4>
inline void writes(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writes(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
}
template <class T1, class T2>
inline void writesln(T1 a, T2 b) {
  writes(a);
  writes(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writesln(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writesln(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writesln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
  putchar('\n');
}
template <class T1, class T2>
inline void writeln(T1 a, T2 b) {
  write(a);
  write(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writeln(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writeln(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writeln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
  putchar('\n');
}
template <class T1, class T2>
inline void write(T1 a, T2 b) {
  write(a);
  write(b);
}
template <class T1, class T2, class T3>
inline void write(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
}
template <class T1, class T2, class T3, class T4>
inline void write(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void write(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
}
template <class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <class T>
inline void writeln(T *a, int n) {
  for (int i = (0); i < (n); ++i) write(a[i]);
  putchar('\n');
}
template <class T>
inline void writesln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writes(a[i]);
  putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writeln(a[i]);
}
}  // namespace orz
using namespace orz;
int n, mdep, mdis, siz[100007];
std::set<std::pair<int, int> > adj[100007];
std::pair<int, int> point[100007];
int pn = 0;
int mdd, mx;
int tree[100007], ddis[100007], ddep[100007];
int BIT_SIZE;
inline void inc(int x) {
  ++x;
  for (; x < BIT_SIZE; x += ((x) & (-(x)))) ++tree[x];
}
inline int get(int x) {
  ++x;
  if (x >= BIT_SIZE) x = BIT_SIZE - 1;
  long long ans = 0;
  for (; x; x -= ((x) & (-(x)))) ans += tree[x];
  return ans;
}
inline long long sweep() {
  std::sort(point, point + pn);
  int asdf = 0;
  for (int i = (0); i < (pn); ++i)
    if (point[i].second > asdf) asdf = point[i].second;
  BIT_SIZE = asdf + 3;
  memset(tree, 0, sizeof(int) * BIT_SIZE);
  int j = 0;
  long long ans = 0;
  for (int i = (pn - 1); i >= (0); --i) {
    for (; j < pn && point[i].first + point[j].first <= mdis; ++j)
      inc(point[j].second);
    if (point[i].second <= mdep) ans += (long long)get(mdep - point[i].second);
  }
  pn = 0;
  return ans;
}
inline void sfs(int x, int p) {
  point[pn++] = std::pair<int, int>(ddis[x], ddep[x]);
  for (__typeof(adj[x].begin()) it = adj[x].begin(); it != adj[x].end(); ++it)
    if (it->first != p) sfs(it->first, x);
}
inline void efs(int x, int p, int dis, int dep) {
  point[pn++] = std::pair<int, int>(dis, dep);
  ddis[x] = dis;
  ddep[x] = dep;
  siz[x] = 1;
  for (__typeof(adj[x].begin()) it = adj[x].begin(); it != adj[x].end(); ++it)
    if (it->first != p) {
      efs(it->first, x, dis + it->second, dep + 1);
      siz[x] += siz[it->first];
    }
}
inline void dfs(int x, int p, int n) {
  siz[x] = 1;
  int cn = 0;
  for (__typeof(adj[x].begin()) it = adj[x].begin(); it != adj[x].end(); ++it)
    if (it->first != p) {
      dfs(it->first, x, n);
      siz[x] += siz[it->first];
      if (siz[it->first] > cn) cn = siz[it->first];
    }
  int tmp = std::max(cn, n - cn);
  if (tmp <= mdd) {
    mdd = tmp;
    mx = x;
  }
}
inline long long go(int x, int n) {
  mdd = 0x1f1f1f1f;
  dfs(x, 0, n);
  x = mx;
  efs(x, 0, 0, 0);
  long long ans = sweep();
  for (__typeof(adj[x].begin()) it = adj[x].begin(); it != adj[x].end(); ++it) {
    adj[it->first].erase(std::pair<int, int>(x, it->second));
    sfs(it->first, x);
    ans -= sweep();
    ans += go(it->first, siz[it->first]);
  }
  return ans;
}
int main() {
  read(n, mdep, mdis);
  for (int i = (2); i <= (n); ++i) {
    int t, w;
    read(t, w);
    adj[i].insert(std::pair<int, int>(t, w));
    adj[t].insert(std::pair<int, int>(i, w));
  }
  writeln((go(1, n) - (long long)n) / 2LL);
  return 0;
}