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 double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
using namespace std;
struct EDGE {
  int v, next, w;
} edge[305555];
int head[111111], e;
int n, d1, d2, vis[111111], root, num;
long long ans;
void init() {
  memset(vis, 0, sizeof(vis));
  memset(head, -1, sizeof(head));
  e = 0;
  ans = 0;
}
void add(int u, int v, int w) {
  edge[e].v = v;
  edge[e].w = w;
  edge[e].next = head[u];
  head[u] = e++;
}
int mx[111111], size[111111], mi, dis[111111], dd[111111];
void dfssize(int u, int fa) {
  size[u] = 1;
  mx[u] = 0;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v != fa && !vis[v]) {
      dfssize(v, u);
      size[u] += size[v];
      if (size[v] > mx[u]) mx[u] = size[v];
    }
  }
}
void dfsroot(int r, int u, int fa) {
  if (size[r] - size[u] > mx[u]) mx[u] = size[r] - size[u];
  if (mx[u] < mi) mi = mx[u], root = u;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v != fa && !vis[v]) dfsroot(r, v, u);
  }
}
void dfsdis(int u, int dz, int d, int fa) {
  dis[num] = d;
  dd[num++] = dz;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v != fa && !vis[v]) dfsdis(v, dz + 1, d + edge[i].w, u);
  }
}
pair<int, int> p[305555];
struct query {
  int l, r, ask;
  int t;
  query() {}
  bool operator<(const query &gg) const {
    if (ask != gg.ask) return ask < gg.ask;
    return t < gg.t;
  }
};
const int maxn = 100010;
struct bit {
  long long a[maxn * 2];
  int n;
  bit() {}
  void init(int _n) {
    n = _n;
    for (int i = 0; i < n + 5; i++) a[i] = 0;
  }
  long long quer(int x) {
    long long s = 0;
    for (int i = x; i; i -= i & (-i)) {
      s += a[i];
    }
    return s;
  }
  void add(int q, long long e) {
    int i;
    for (i = q; i <= n; i += i & (-i)) {
      a[i] += e;
    }
  }
} b;
long long calc(int u, int z, int d) {
  long long ret = 0;
  num = 0;
  dfsdis(u, z, d, 0);
  int i, j, k;
  for (i = 0; i < num; i++) {
    p[i] = make_pair(dd[i], dis[i]);
  }
  sort(p, p + num);
  i = 0, j = num - 1;
  vector<query> q;
  for (i = 0; i < num; i++) {
    query tmp;
    tmp.t = 0;
    tmp.l = tmp.r = i + 1;
    tmp.ask = p[i].second;
    q.push_back(tmp);
  }
  i = 0, j = num - 1;
  while (i < j) {
    while (p[i].first + p[j].first > d1 && i < j) j--;
    query tmp;
    tmp.t = 1;
    tmp.ask = d2 - p[i].second;
    tmp.l = i + 2;
    tmp.r = j + 1;
    q.push_back(tmp);
    i++;
  }
  b.init(num + 5);
  sort(q.begin(), q.end());
  for (i = 0; i < (int)((q).size()); i++) {
    if (q[i].t == 0) {
      b.add(q[i].l, 1);
    } else {
      ret += b.quer(q[i].r) - b.quer(q[i].l - 1);
    }
  }
  return ret;
}
void dfs(int u) {
  mi = n;
  dfssize(u, 0);
  dfsroot(u, u, 0);
  ans += calc(root, 0, 0);
  vis[root] = 1;
  for (int i = head[root]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (!vis[v]) {
      ans -= calc(v, 1, edge[i].w);
      dfs(v);
    }
  }
}
int main() {
  while (scanf("%d%d%d", &n, &d1, &d2) != EOF) {
    init();
    int u, v, w;
    for (int i = 2; i <= n; i++) {
      scanf("%d%d", &u, &w);
      add(u, i, w);
      add(i, u, w);
    }
    dfs(1);
    cout << ans << endl;
  }
  return 0;
}