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;
inline int read() {
  int x = 0;
  bool op = false;
  char c = getchar();
  while (!isdigit(c)) op |= (c == '-'), c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 100010;
const int INF = 1e9;
int n, L, W, tot, rt;
long long ans;
int cnt, Siz;
int head[N], nxt[N << 1], edge[N << 1], to[N << 1], dis[N], maxi[N], siz[N],
    len[N], tree[N];
bool vis[N];
void addedge(int u, int v, int w) {
  to[++tot] = v;
  edge[tot] = w;
  nxt[tot] = head[u];
  head[u] = tot;
  return;
}
struct Node {
  int dis, len;
  Node(int dis = 0, int len = 0) : dis(dis), len(len) {}
  bool operator<(const Node &tmp) const { return dis < tmp.dis; }
} d[N];
void find(int u, int fa) {
  siz[u] = 1;
  maxi[u] = 0;
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == fa || vis[to[i]]) continue;
    find(to[i], u);
    maxi[u] = max(maxi[u], siz[to[i]]);
    siz[u] += siz[to[i]];
  }
  maxi[u] = max(maxi[u], Siz - siz[u]);
  if (maxi[u] < maxi[rt]) rt = u;
  return;
}
void getdis(int u, int fa, int dist, int Len) {
  if (dist > W || Len > L) return;
  d[++cnt] = Node(dist, Len);
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == fa || vis[to[i]]) continue;
    getdis(to[i], u, dist + edge[i], Len + 1);
  }
  return;
}
int lowbit(int x) { return x & -x; }
void update(int x, int val) {
  while (x <= n + 1) {
    tree[x] += val;
    x += lowbit(x);
  }
  return;
}
int query(int x) {
  int res = 0;
  while (x > 0) {
    res += tree[x];
    x -= lowbit(x);
  }
  return res;
}
long long calc(int u, int dist, int Len) {
  cnt = 0;
  getdis(u, 0, dist, Len);
  sort(d + 1, d + 1 + cnt);
  int l = 1, r = cnt;
  long long res = 0;
  memset(tree, 0, sizeof(tree));
  for (int i = 2; i <= cnt; i++) update(d[i].len + 1, 1);
  while (l < r) {
    while (l < r && d[l].dis + d[r].dis > W) update(d[r--].len + 1, -1);
    res += r - l - (query(n + 1) - query(min(n + 1, L - d[l].len + 1)));
    update(d[++l].len + 1, -1);
  }
  return res;
}
void dfz(int u) {
  vis[u] = true;
  ans += calc(u, 0, 0);
  for (int i = head[u]; i; i = nxt[i]) {
    if (vis[to[i]]) continue;
    ans -= calc(to[i], edge[i], 1);
    Siz = siz[to[i]];
    rt = 0;
    maxi[0] = INF;
    find(to[i], 0);
    dfz(rt);
  }
  return;
}
signed main() {
  n = read();
  L = read();
  W = read();
  for (int i = 1; i < n; i++) {
    int p = read(), w = read();
    addedge(i + 1, p, w);
    addedge(p, i + 1, w);
  }
  maxi[0] = INF;
  rt = 0;
  Siz = n;
  find(1, 0);
  dfz(rt);
  printf("%lld", ans);
  return 0;
}