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;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, l, w;
  cin >> n >> l >> w;
  int64_t ans = 0;
  vector<int> uu(n - 1), vv(n - 1), ww(n - 1);
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    cin >> uu[i] >> ww[i];
    uu[i] -= 1;
    vv[i] = i + 1;
    g[uu[i]].push_back(i);
    g[vv[i]].push_back(i);
  }
  const int m = l + 1;
  vector<int> tree(m * 2);
  [[maybe_unused]] auto modify = [&](int pos, int d) {
    if (pos < 0 || pos >= m) return;
    pos += m;
    tree[pos] += d;
    for (pos /= 2; pos > 0; pos /= 2)
      tree[pos] = tree[pos * 2] + tree[pos * 2 + 1];
  };
  [[maybe_unused]] auto query = [&](int l, int r) {
    if (r < l) return 0;
    int ans = 0;
    for (l += m, r += m; l <= r; l = (l + 1) / 2, r = (r - 1) / 2) {
      if (l % 2 != 0) ans += tree[l];
      if (r % 2 == 0) ans += tree[r];
    }
    return ans;
  };
  vector<bool> centroid(n);
  vector<int> sz(n), h(n);
  function<void(int, int)> get_sz = [&](int v, int prev) {
    sz[v] = 1;
    if (prev != -1)
      h[v] = h[prev] + 1;
    else
      h[v] = 0;
    for (auto e : g[v]) {
      int to = uu[e] == v ? vv[e] : uu[e];
      if (to != prev && !centroid[to]) {
        get_sz(to, v);
        sz[v] += sz[to];
      }
    }
  };
  function<int(int, int, int)> find_centroid = [&](int v, int prev, int total) {
    for (auto e : g[v]) {
      int to = uu[e] == v ? vv[e] : uu[e];
      if (to != prev && !centroid[to] && sz[to] > total / 2)
        return find_centroid(to, v, total);
    }
    return v;
  };
  vector<int> cw(n), ch(n);
  function<void(int, int, vector<int>&)> fill_subtree =
      [&](int v, int prev, vector<int>& subtree) {
        subtree.push_back(v);
        for (auto e : g[v]) {
          int to = uu[e] == v ? vv[e] : uu[e];
          if (to != prev && !centroid[to]) {
            ch[to] = ch[v] + 1;
            cw[to] = cw[v] + ww[e];
            fill_subtree(to, v, subtree);
          }
        }
      };
  function<void(int)> decomposition_slow = [&](int v) {
    get_sz(v, -1);
    int c = find_centroid(v, -1, sz[v]);
    centroid[c] = true;
    get_sz(c, -1);
    cw[c] = 0;
    ch[c] = 0;
    vector<vector<int>> subtrees;
    for (auto e : g[c]) {
      int to = uu[e] == c ? vv[e] : uu[e];
      if (!centroid[to]) {
        subtrees.emplace_back();
        ch[to] = 1;
        cw[to] = ww[e];
        fill_subtree(to, -1, subtrees.back());
      }
    }
    vector<int> all_ch;
    for (const auto& st : subtrees)
      for (auto x : st) all_ch.push_back(x);
    for (auto x : all_ch)
      if (ch[x] <= l && cw[x] <= w) ans += 1;
    int64_t cur = 0;
    for (const auto& st : subtrees)
      for (auto x : st) {
        auto pred = [&](int i) {
          return ch[i] + ch[x] <= l && cw[i] + cw[x] <= w;
        };
        int cnt1 = count_if(all_ch.begin(), all_ch.end(), pred);
        int cnt2 = count_if(st.begin(), st.end(), pred);
        cur += cnt1 - cnt2;
      }
    ans += cur / 2;
    for (auto e : g[c]) {
      int to = uu[e] == c ? vv[e] : uu[e];
      if (!centroid[to]) decomposition_slow(to);
    }
  };
  function<void(int)> decomposition = [&](int v) {
    get_sz(v, -1);
    int c = find_centroid(v, -1, sz[v]);
    centroid[c] = true;
    get_sz(c, -1);
    cw[c] = 0;
    ch[c] = 0;
    vector<vector<int>> subtrees;
    for (auto e : g[c]) {
      int to = uu[e] == c ? vv[e] : uu[e];
      if (!centroid[to]) {
        subtrees.emplace_back();
        ch[to] = 1;
        cw[to] = ww[e];
        fill_subtree(to, -1, subtrees.back());
      }
    }
    auto process = [&](const vector<int>& z) {
      int64_t cur = 0;
      vector<int> idx(z.size());
      iota(idx.begin(), idx.end(), 0);
      sort(idx.begin(), idx.end(),
           [&](int i, int j) { return tie(cw[z[i]], i) < tie(cw[z[j]], j); });
      for (auto i : idx) {
        modify(ch[z[i]], 1);
      }
      int last = (int)idx.size() - 1;
      for (auto i : idx) {
        while (last >= 0 && cw[z[idx[last]]] + cw[z[i]] > w) {
          modify(ch[z[idx[last]]], -1);
          last -= 1;
        }
        auto q = query(0, l - ch[z[i]]);
        cur += q;
      }
      while (last >= 0) {
        modify(ch[z[idx[last]]], -1);
        last -= 1;
      }
      return cur;
    };
    vector<int> all_ch;
    for (const auto& st : subtrees)
      for (auto x : st) all_ch.push_back(x);
    for (auto x : all_ch)
      if (ch[x] <= l && cw[x] <= w) ans += 1;
    int64_t cur = process(all_ch);
    for (const auto& st : subtrees) cur -= process(st);
    ans += cur / 2;
    for (auto e : g[c]) {
      int to = uu[e] == c ? vv[e] : uu[e];
      if (!centroid[to]) decomposition(to);
    }
  };
  decomposition(0);
  cout << ans << '\n';
}