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 = 100100;
struct Edge {
  int next, to, w;
  Edge() {}
  Edge(int next, int to, int w) : next(next), to(to), w(w) {}
};
Edge edge[N << 1];
int head[N], countedge;
void addedge(const int& s, const int& t, const int& w) {
  edge[countedge] = Edge(head[s], t, w);
  head[s] = countedge++;
  edge[countedge] = Edge(head[t], s, w);
  head[t] = countedge++;
}
struct BIT {
  vector<int> t;
  int sz;
  BIT() {}
  BIT(int sz) : sz(sz) { t = vector<int>(sz, 0); }
  void update(int x, int val) {
    if (x < 0)
      return;
    else if (0 == x) {
      t[0] += val;
      return;
    }
    for (int i = x; i < sz; i += ((i) & -(i))) {
      t[i] += val;
    }
  }
  int query(int x) {
    if (x < 0) return 0;
    if (x >= sz) x = sz - 1;
    int ret = t[0];
    for (int i = x; i; i -= ((i) & -(i))) {
      ret += t[i];
    }
    return ret;
  }
};
struct Solve {
  int n, L, W;
  int sz[N];
  bool vis[N];
  void predfs(int u, int fa) {
    sz[u] = 1;
    for (int tmp = head[u]; tmp != -1; tmp = edge[tmp].next) {
      int v = edge[tmp].to;
      if (v == fa || vis[v]) continue;
      predfs(v, u);
      sz[u] += sz[v];
    }
  }
  int root;
  int mx[N], mi;
  void dfsroot(int u, int fa, int r) {
    mx[u] = sz[r] - sz[u];
    for (int tmp = head[u]; tmp != -1; tmp = edge[tmp].next) {
      int v = edge[tmp].to;
      if (v == fa || vis[v]) continue;
      dfsroot(v, u, r);
      mx[u] = max(mx[u], sz[v]);
    }
    if (mx[u] < mi) {
      mi = mx[u];
      root = u;
    }
  }
  vector<pair<int, int> > a, b;
  void cal(int u, int fa, pair<int, int> pre) {
    a.push_back(pre);
    b.push_back(pre);
    for (int tmp = head[u]; tmp != -1; tmp = edge[tmp].next) {
      int v = edge[tmp].to;
      if (v == fa || vis[v]) continue;
      cal(v, u, make_pair(pre.first + edge[tmp].w, pre.second + 1));
    }
  }
  long long ans;
  long long f(vector<pair<int, int> >& v) {
    sort(v.begin(), v.end());
    int l = -1, r = (int)v.size() - 1;
    long long ans = 0;
    BIT tree = BIT(v.size());
    while (r > 0) {
      if (l == r) {
        tree.update(v[l].second, -1);
        l--;
      }
      while (l + 1 < r && v[l + 1].first + v[r].first <= W) {
        l++;
        tree.update(v[l].second, 1);
      }
      ans += tree.query(L - v[r].second);
      r--;
    }
    return ans;
  }
  void dfs(int u) {
    a.clear();
    a.push_back(make_pair(0, 0));
    for (int tmp = head[u]; tmp != -1; tmp = edge[tmp].next) {
      int v = edge[tmp].to;
      if (vis[v]) continue;
      b.clear();
      cal(v, u, make_pair(edge[tmp].w, 1));
      ans -= f(b);
    }
    ans += f(a);
  }
  void gao(int u) {
    mi = n;
    root = u;
    predfs(u, 0);
    dfsroot(u, 0, u);
    vis[root] = true;
    dfs(root);
    for (int tmp = head[root]; tmp != -1; tmp = edge[tmp].next) {
      int v = edge[tmp].to;
      if (vis[v]) continue;
      gao(v);
    }
  }
  void solve() {
    scanf("%d%d%d", &n, &L, &W);
    memset(head, -1, sizeof(head));
    countedge = 0;
    for (int i = 1; i < n; i++) {
      int p, w;
      scanf("%d%d", &p, &w);
      addedge(i + 1, p, w);
    }
    memset(vis, 0, sizeof(vis));
    ans = 0;
    gao(1);
    cout << ans << endl;
  }
} s;
int main() {
  s.solve();
  return 0;
}