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 <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
T ext_gcd(T a, T b, T& first, T& second) {
  if (b == 0) {
    first = 1, second = 0;
    return a;
  }
  T d = ext_gcd(b, a % b, second, first);
  second -= first * (a / b);
  return d;
}
template <typename T>
T inverse(T a, T n) {
  T first, second;
  T t = ext_gcd(a, n, first, second);
  if (t != 1) return -1;
  return (first % n + n) % n;
}
template <typename T>
T Q_mul(T a, T b, T Mod) {
  T ret;
  for (ret = 0; b; b >>= 1, a = (a + a) % Mod)
    if (b & 1) ret = (ret + a) % Mod;
  return ret;
}
template <typename T>
T quick_pow_mod(T a, T b, T Mod) {
  T ret;
  for (ret = 1; b; b >>= 1, (a *= a) %= Mod)
    if (b & 1) (ret *= a) %= Mod;
  return ret;
}
template <typename T>
T quick_pow(T a, T b) {
  T ret;
  for (ret = 1; b; b >>= 1, a *= a)
    if (b & 1) ret *= a;
  return ret;
}
double combination(int n, int r) {
  if (r < n - r) return combination(n, n - r);
  double s = 1.0;
  for (int i = 1; i <= int(n - r); ++i) s *= (r + i), s /= i;
  return s;
}
template <typename T>
inline void read(T& v) {
  T ret = 0, sgnv = 1;
  char p;
  while (!isdigit(p = getchar()))
    if (p == '-') sgnv = -1;
  do ret = (ret << 3) + (ret << 1) + p - '0';
  while (isdigit(p = getchar()));
  v = sgnv * ret;
}
const int maxn = 1e5 + 5;
struct Edge {
  int v, w, next;
} edge[2 * maxn];
int head[maxn], sz[maxn], dp[maxn], tree[maxn], n, l, w, cnt, tot;
bool vis[maxn];
pair<pair<int, int>, int> p[maxn];
long long ans;
inline int lowbit(int first) { return first & -first; }
void init() { memset(tree + 1, 0, sizeof(int) * n); }
void update(int first, int d) {
  for (int i = first; i <= n; i += lowbit(i)) tree[i] += d;
}
int query(int first) {
  int s = 0;
  for (int i = first; i; i -= lowbit(i)) s += tree[i];
  return s;
}
inline void addedge(int u, int v, int w) {
  edge[cnt].v = v, edge[cnt].w = w, edge[cnt].next = head[u], head[u] = cnt++;
}
int getroot(int u, int fa, int n) {
  int v, root = -1, tmp;
  dp[u] = 0, sz[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].next) {
    if ((v = edge[i].v) == fa || vis[v]) continue;
    tmp = getroot(v, u, n), sz[u] += sz[v], dp[u] = max(dp[u], sz[v]);
    if (root == -1 || dp[tmp] < dp[root]) root = tmp;
  }
  dp[u] = max(dp[u], n - sz[u]);
  if (root == -1 || dp[u] < dp[root]) root = u;
  return root;
}
void dfs(int u, int fa, int first, int second) {
  ++first, p[tot++] = make_pair(make_pair(w - second, l - first), 1);
  for (int i = head[u]; ~i; i = edge[i].next)
    if (edge[i].v != fa && !vis[edge[i].v])
      dfs(edge[i].v, u, first, second + edge[i].w);
}
void daq(int u) {
  int v;
  vis[u] = true, p[tot++] = make_pair(make_pair(0, 1), 0);
  for (int i = head[u]; ~i; i = edge[i].next)
    if (!vis[v = edge[i].v]) {
      dfs(v, u, 1, edge[i].w);
      sort(p, p + tot);
      for (int j = 0; j < int(tot); ++j) {
        if (p[j].second) {
          if (p[j].first.second > 0) ans += query(p[j].first.second);
          p[j].second = 2, p[j].first.first = w - p[j].first.first,
          p[j].first.second = l - p[j].first.second;
        } else
          update(p[j].first.second, 1);
      }
      for (int j = 0; j < int(tot); ++j) {
        if (p[j].second == 0)
          update(p[j].first.second, -1);
        else if (p[j].second == 2)
          p[j].second = 0;
      }
    }
  tot = 0;
  for (int i = head[u]; ~i; i = edge[i].next)
    if (!vis[v = edge[i].v]) daq(getroot(v, u, sz[v]));
}
int main() {
  int u, v;
  read(n), read(l), read(w), l += 2, memset(head + 1, -1, sizeof(int) * n);
  for (int i = 1; i <= int(n - 1); ++i)
    read(u), read(v), addedge(u, i + 1, v), addedge(i + 1, u, v);
  daq(getroot(1, 0, n)), printf("%I64d", ans);
  return 0;
}