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;
namespace my_useful_tools {
const int INF = 0x3f3f3f3f;
inline void pc(char c) { putchar(c); }
template <class T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline void W(T p) {
  if (p < 0) pc('-'), p = -p;
  if (p / 10 != 0) W(p / 10);
  pc('0' + p % 10);
}
template <class T>
inline void Wn(T p) {
  W(p), puts("");
}
template <class T>
inline void W(T a, T b) {
  W(a), pc(' '), W(b);
}
template <class T>
inline void Wn(T a, T b) {
  W(a), pc(' '), Wn(b);
}
template <class T>
inline void W(T a, T b, T c) {
  W(a), pc(' '), W(b), pc(' '), W(c);
}
inline char gchar() {
  char ret = getchar();
  for (; ret == '\n' || ret == '\r' || ret == ' '; ret = getchar())
    ;
  return ret;
}
template <class T>
inline void fr(T& ret) {
  char c = ' ';
  int flag = 1;
  for (c = getchar(); c != '-' && !('0' <= c && c <= '9'); c = getchar())
    ;
  if (c == '-')
    flag = -1, ret = 0;
  else
    ret = c - '0';
  for (c = getchar(); '0' <= c && c <= '9'; c = getchar())
    ret = ret * 10 + c - '0';
  ret = ret * flag;
}
inline int fr() {
  int x;
  fr(x);
  return x;
}
template <class T>
inline void fr(T& a, T& b) {
  fr(a), fr(b);
}
template <class T>
inline void fr(T& a, T& b, T& c) {
  fr(a), fr(b), fr(c);
}
template <class T>
inline T fast_pow(T base, T index, T mod = 2147483647, T ret = 1) {
  for (; index; index >>= 1, base = base * base % mod)
    if (index & 1) ret = ret * base % mod;
  return ret;
}
};  // namespace my_useful_tools
using namespace my_useful_tools;
const int maxn = 4e5 + 100, maxe = maxn << 1;
struct Edge {
  int edge, head[maxn], to[maxe], next[maxe];
  int wei[maxe];
  Edge() {
    edge = 0;
    memset(head, -1, sizeof head);
  }
  void addEdge(int u, int v, int w) {
    to[edge] = v, next[edge] = head[u];
    wei[edge] = w;
    head[u] = edge++;
    to[edge] = u, next[edge] = head[v];
    wei[edge] = w;
    head[v] = edge++;
  }
} e;
long long c[maxn];
int lim;
void modify(int p, int d) {
  for (; p <= lim; c[p] += d, p += p & -p)
    ;
}
long long get_sum(int p) {
  long long ret = 0;
  for (; p; ret += c[p], p -= p & -p)
    ;
  return ret;
}
int n, L, Wt;
long long ans;
bool vis[maxn];
int q[maxn], h, t;
int fa[maxn];
int d, Md;
int g[maxn], f[maxn];
int getD(int s) {
  h = 1, t = 0;
  fa[s] = 0, g[s] = f[s] = 0;
  q[++t] = s;
  int d = -1;
  while (h <= t) {
    int u = q[h++];
    for (int i = e.head[u]; i != -1; i = e.next[i]) {
      int v = e.to[i];
      if (vis[v] || v == fa[u]) continue;
      fa[v] = u;
      q[++t] = v;
      g[v] = f[v] = 0;
    }
  }
  for (int i = t; 1 <= i; --i) {
    int u = q[i], p = fa[u];
    f[p] += (++f[u]);
    g[p] = max(g[p], f[u]);
    g[u] = max(g[u], t - f[u]);
    if (d == -1 || g[u] < g[d]) d = u;
  }
  vis[d] = true;
  return d;
}
pair<int, int> a[maxn];
int dep[maxn], dis[maxn];
void calc(int p, int o) {
  h = 1, t = 0;
  q[++t] = p, fa[p] = -1;
  while (h <= t) {
    int u = q[h++];
    for (int i = e.head[u]; i != -1; i = e.next[i]) {
      int v = e.to[i], w = e.wei[i];
      if (vis[v] || v == fa[u]) continue;
      dep[v] = dep[u] + 1;
      dis[v] = dis[u] + w;
      fa[v] = u;
      q[++t] = v;
    }
  }
  lim = dep[q[t]] + 1;
  memset(c + 1, 0, sizeof(*c) * lim);
  for (int i = 1; i <= t; ++i) a[i] = make_pair(dis[q[i]], dep[q[i]]);
  sort(a + 1, a + t + 1);
  for (int i = t, j = 1; i; --i) {
    while (j <= t && a[j].first + a[i].first <= Wt)
      modify(a[j++].second + 1, 1);
    ans += o * get_sum(max(0, min(lim, L - a[i].second + 1)));
  }
}
void solve(int p) {
  dis[p] = dep[p] = 0;
  calc(p, 1);
  for (int i = e.head[p]; i != -1; i = e.next[i]) {
    int v = e.to[i];
    if (!vis[v]) calc(v, -1);
  }
  for (int i = e.head[p]; i != -1; i = e.next[i]) {
    int v = e.to[i];
    if (!vis[v]) {
      solve(getD(v));
    }
  }
}
int main() {
  fr(n, L, Wt);
  for (int i = 1; i < n; ++i) {
    int v, w;
    fr(v, w);
    e.addEdge(v, i + 1, w);
  }
  solve(getD(1));
  Wn((ans - n) >> 1);
  return 0;
}