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 maxn = 101000;
struct Weight {
  int w, d;
  bool operator<(const Weight &e) const {
    return (w == e.w) ? (d < e.d) : (w < e.w);
  }
} dis[maxn];
struct Depth {
  int w;
  int to, next;
} edge[maxn * 2];
int maxv[maxn], size[maxn], head[maxn];
bool vis[maxn];
long long ans;
int root, num, tot, n, lLimit, wLimit, N;
int s[maxn];
inline int Lowbit(int x) { return x & (-x); }
void update(int i, int x) {
  while (i <= n) s[i] += x, i += Lowbit(i);
}
int sum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += s[x];
    x -= Lowbit(x);
  }
  return sum;
}
void init() {
  ans = tot = 0;
  memset(head, -1, sizeof(head));
  memset(vis, false, sizeof(vis));
}
void AddEdge(int u, int to, int w) {
  edge[tot].to = to;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void DfsSize(int u, int par) {
  size[u] = 1;
  maxv[u] = 0;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v != par && vis[v] == 0) {
      DfsSize(v, u);
      size[u] += size[v];
      if (size[v] > maxv[u]) maxv[u] = size[v];
    }
  }
}
void DfsRoot(int r, int u, int par) {
  if (size[r] - size[u] > maxv[u]) maxv[u] = size[r] - size[u];
  if (maxv[u] < N) N = maxv[u], root = u;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v != par && !vis[v]) DfsRoot(r, v, u);
  }
}
void DfsDis(int u, int _w, int _d, int par) {
  dis[num].w = _w;
  dis[num++].d = _d;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v != par && !vis[v]) DfsDis(v, _w + edge[i].w, _d + 1, u);
  }
}
long long calc(int u, int _w, int _d) {
  long long ret = 0;
  num = 0;
  DfsDis(u, _w, _d, 0);
  sort(dis, dis + num);
  int i = 0, j = num - 1;
  while (j > 0) {
    while (dis[i].w + dis[j].w <= wLimit && i < j) {
      update(dis[i].d + 1, 1);
      ++i;
    }
    if (i > j) {
      update(dis[j].d + 1, -1);
    }
    ret += sum(lLimit - dis[j].d + 1);
    --j;
  }
  if (i) update(dis[0].d + 1, -1);
  return ret;
}
void dfs(int u) {
  N = n;
  DfsSize(u, 0);
  DfsRoot(u, u, 0);
  ans += calc(root, 0, 0);
  vis[root] = true;
  for (int i = head[root]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (vis[v] == 0) {
      ans -= calc(v, edge[i].w, 1);
      dfs(v);
    }
  }
}
int main() {
  int toIn, wIn;
  scanf("%d%d%d", &n, &lLimit, &wLimit);
  init();
  for (int i = 2; i <= n; ++i) {
    scanf("%d%d", &toIn, &wIn);
    AddEdge(toIn, i, wIn);
    AddEdge(i, toIn, wIn);
  }
  dfs(1);
  printf("%I64d\n", ans);
  return 0;
}