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 N = 2e6 + 100;
struct node {
  int nt, to;
  long long w;
} a[N << 1];
struct data {
  int len;
  long long w;
} B[N], H[N];
long long s[N], ans = 0, dp[N];
int sz[N], head[N], dep[N], f[N], g[N], vis[N], n, l, val, b = 0, h = 0,
                                                           cnt = 0;
void read(int &x) {
  char ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar()) 2333;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch ^ 48);
}
void read(long long &x) {
  char ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar()) 2333;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch ^ 48);
}
bool comp(data xx, data yy) { return xx.w < yy.w; }
int lwt(int x) { return x & (-x); }
void add(int x, int y, long long w) {
  a[++cnt].to = y, a[cnt].w = w, a[cnt].nt = head[x], head[x] = cnt;
  a[++cnt].to = x, a[cnt].w = w, a[cnt].nt = head[y], head[y] = cnt;
}
void UPD(int x, int z) {
  for (; x <= (n + 2); x += lwt(x)) s[x] += z;
}
long long Get_sum(int x) {
  long long res = 0;
  if (x <= 0) return 0;
  for (; x; x -= lwt(x)) res += s[x];
  return res;
}
int Get(int u, int fa) {
  sz[u] = 1;
  f[u] = fa;
  g[u] = u;
  for (int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if (to == fa || vis[to]) continue;
    Get(to, u);
    sz[u] += sz[to];
  }
  int pos = -1;
  for (int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if (to == fa || vis[to]) continue;
    if (sz[to] * 2 >= sz[u]) pos = g[to];
  }
  if (pos == -1) return u;
  while (sz[f[pos]] * 2 <= sz[u]) pos = f[pos];
  return g[u] = pos;
}
void find(int u, int fa) {
  for (int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if (to == fa || vis[to]) continue;
    dep[to] = dep[u] + 1, dp[to] = dp[u] + a[i].w;
    H[++h].w = dp[to], H[h].len = dep[to];
    B[++b].w = dp[to], B[b].len = dep[to];
    find(to, u);
  }
}
void js() {
  sort(H + 1, H + 1 + h, comp);
  for (int i = 1; i <= h; ++i) UPD(H[i].len, 1);
  int lt = h;
  for (int i = 1; i <= h; ++i) {
    int flg = 0;
    while (lt - 1 >= 0 && H[lt].w + H[i].w > val) {
      UPD(H[lt].len, -1), lt--;
    }
    if (lt <= i) {
      if (lt == i) UPD(H[i].len, -1);
      break;
    } else
      UPD(H[i].len, -1);
    ans += Get_sum(l - H[i].len);
  }
}
void sj() {
  sort(B + 1, B + 1 + b, comp);
  for (int i = 1; i <= b; ++i) UPD(B[i].len, 1);
  int lt = b;
  for (int i = 1; i <= b; ++i) {
    int flg = 0;
    while (lt - 1 >= 0 && B[lt].w + B[i].w > val) {
      UPD(B[lt].len, -1), lt--;
    }
    if (lt <= i) {
      if (lt == i) UPD(B[i].len, -1);
      break;
    } else
      UPD(B[i].len, -1);
    ans -= Get_sum(l - B[i].len);
  }
}
void dfs(int u, int fa) {
  int be = Get(u, fa);
  h = 1, H[1].len = 1, H[1].w = 0;
  for (int i = head[be]; i; i = a[i].nt) {
    if (vis[a[i].to])
      continue;
    else {
      b = 1, B[1].len = 2, B[1].w = a[i].w;
      H[++h].len = 2, H[h].w = a[i].w;
      dep[a[i].to] = 2, dp[a[i].to] = a[i].w;
      find(a[i].to, be);
      sj();
    }
  }
  js();
  vis[be] = 1;
  for (int i = head[be]; i; i = a[i].nt) {
    if (vis[a[i].to]) continue;
    dfs(a[i].to, be);
  }
}
int main() {
  read(n), read(l), read(val);
  l += 2;
  for (int i = 2; i <= n; ++i) {
    int x;
    long long w;
    read(x), read(w);
    add(x, i, w);
  }
  vis[0] = 1, dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}