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 = 100010;
vector<int> G[N];
int lowbit(int x) { return x & (-x); }
int L, n, o, k;
long long C[N], ans;
long long sum(int x) {
  long long ret = 0;
  while (x > 0) {
    ret += C[x];
    x -= lowbit(x);
  }
  return ret;
}
void add(int x, int d) {
  if (x == 0) {
    C[0] += d;
    return;
  }
  while (x <= o) {
    C[x] += d;
    x += lowbit(x);
  }
}
struct edge {
  int u, v, w;
  edge(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}
} e[N << 1];
struct node {
  int d, c;
  bool operator<(const node x) const { return d == x.d ? c < x.c : d < x.d; }
} a[N];
int dic[N], dis[N], son[N], mxs[N], root, cntd;
bool vis[N];
void dfs1(int x, int p = 0) {
  son[x] = 1;
  mxs[x] = 0;
  for (int j = 0; j < G[x].size(); j++) {
    int i = G[x][j];
    if (e[i].v != p && vis[e[i].v] == 0) {
      dfs1(e[i].v, x);
      son[x] += son[e[i].v];
      mxs[x] = max(mxs[x], son[e[i].v]);
    }
  }
  mxs[x] = max(mxs[x], n - son[x]);
  if (mxs[root] > mxs[x]) root = x;
}
void dfs2(int x, int p = 0) {
  son[x] = 1;
  a[cntd].d = dis[x];
  a[cntd++].c = dic[x];
  for (int j = 0; j < G[x].size(); j++) {
    int i = G[x][j];
    if (e[i].v != p && vis[e[i].v] == 0) {
      dis[e[i].v] = dis[x] + e[i].w;
      dic[e[i].v] = dic[x] + 1;
      dfs2(e[i].v, x);
      son[x] += son[e[i].v];
    }
  }
}
long long cal(int x, int w = 0, int wc = 0) {
  long long ret = 0;
  cntd = 0;
  dis[x] = w;
  dic[x] = wc;
  dfs2(x);
  sort(a, a + cntd);
  int l = 0, r = cntd - 1;
  for (int i = 1; i < cntd; i++) add(a[i].c, 1);
  while (l < r) {
    while (a[l].d + a[r].d > k && l < r) {
      add(a[r].c, -1);
      --r;
    }
    if (r <= l) break;
    if (L - a[l].c >= 0) ret += sum(L - a[l].c);
    ++l;
    add(a[l].c, -1);
  }
  return ret;
}
void solve(int x) {
  ans += cal(x);
  vis[x] = 1;
  for (int j = 0; j < G[x].size(); j++) {
    int i = G[x][j];
    if (!vis[e[i].v]) {
      ans -= cal(e[i].v, e[i].w, 1);
      mxs[0] = n = son[e[i].v];
      dfs1(e[i].v, root = 0);
      solve(root);
    }
  }
}
void init() {
  ans = 0;
  for (int i = 1; i <= n; i++) G[i].clear();
  memset(vis, 0, sizeof(vis));
}
int main() {
  while (scanf("%d%d%d", &n, &L, &k) != EOF) {
    o = n;
    init();
    int cnt = 0;
    for (int i = 1; i < n; i++) {
      int u = i + 1, v, w;
      scanf("%d%d", &v, &w);
      e[cnt] = edge(u, v, w);
      G[u].push_back(cnt++);
      e[cnt] = edge(v, u, w);
      G[v].push_back(cnt++);
    }
    mxs[0] = n + 1;
    root = 0;
    dfs1(1);
    solve(root);
    cout << ans << endl;
  }
  return 0;
}