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 inf = ((1 << 30) - 1);
const long long linf = ((1ll << 62) - 1);
const char *fin = "input.txt";
const char *fout = "output.txt";
const int cc = 2000;
struct coolset {
  vector<pair<int, int> > a, b;
  vector<vector<int> > rmq;
  vector<pair<int, int> > _;
  int counter;
  inline coolset() : counter(0) {}
  inline void build(int i, int l, int r) {
    if (l == r) {
      rmq[i].resize(1);
      rmq[i][0] = a[l].second;
      return;
    }
    build(i * 2, l, (l + r) / 2);
    build(i * 2 + 1, (l + r) / 2 + 1, r);
    rmq[i].resize(((int)(rmq[i * 2]).size()) + ((int)(rmq[i * 2 + 1]).size()));
    merge((rmq[i * 2]).begin(), (rmq[i * 2]).end(), (rmq[i * 2 + 1]).begin(),
          (rmq[i * 2 + 1]).end(), rmq[i].begin());
  }
  inline void rebuild() {
    counter = 0;
    _.resize(((int)(a).size()) + ((int)(b).size()));
    sort((b).begin(), (b).end());
    merge((a).begin(), (a).end(), (b).begin(), (b).end(), _.begin());
    swap(a, _), _.clear(), b.clear();
    rmq.clear(), rmq.resize(((int)(a).size()) * 4 + 10);
    build(1, 0, ((int)(a).size()) - 1);
  }
  inline void insert(const pair<int, int> &pt) {
    b.push_back(pt);
    if ((++counter) >= cc) rebuild();
  }
  inline int getLocalValue(int i, int t) {
    return upper_bound((rmq[i]).begin(), (rmq[i]).end(), t) - rmq[i].begin();
  }
  inline int getValue(int i, int ll, int rr, int l, int r, int t) {
    if (ll > r || rr < l) return 0;
    if (l <= ll && rr <= r) return getLocalValue(i, t);
    return getValue(i * 2, ll, (ll + rr) / 2, l, r, t) +
           getValue(i * 2 + 1, (ll + rr) / 2 + 1, rr, l, r, t);
  }
  inline int getValue(int x2, int y2) {
    if ((++counter) >= cc) rebuild();
    int r =
        upper_bound((a).begin(), (a).end(), make_pair(x2, inf)) - a.begin() - 1;
    int res = (r >= 0 ? getValue(1, 0, ((int)(a).size()) - 1, 0, r, y2) : 0);
    for (__typeof((b).begin()) i = (b).begin(); i != (b).end(); ++i)
      if (i->first <= x2 && i->second <= y2) ++res;
    return res;
  }
  inline int size() { return ((int)(a).size()) + ((int)(b).size()); }
  inline void clear() {
    a.clear(), b.clear(), rmq.clear();
    counter = 0;
  }
};
const int cmax = 100500;
int n, maxL, maxW;
vector<int> g[cmax];
int p[cmax], w[cmax];
struct state {
  int addL, addW;
  coolset st;
  state() : addL(0), addW(0) {}
  inline void insert(const pair<int, int> &pt) {
    st.insert(make_pair(pt.first - addL, pt.second - addW));
  }
  inline int getValue(int mL, int mW) {
    return st.getValue(mL - addL, mW - addW);
  }
  inline int size() { return st.size(); }
};
state states[cmax];
long long result = 0;
state *dfs(int v) {
  state *res = &states[v];
  res->insert(make_pair(0, 0));
  for (int i = 0; i < ((int)(g[v]).size()); i++) {
    int to = g[v][i];
    state *down = dfs(to);
    ++down->addL, down->addW += w[to];
    if (down->size() > res->size()) swap(down, res);
    for (__typeof((down->st.a).begin()) i = (down->st.a).begin();
         i != (down->st.a).end(); ++i) {
      int curL = i->first + down->addL, curW = i->second + down->addW;
      int mL = maxL - curL, mW = maxW - curW;
      result += res->getValue(mL, mW);
    }
    for (__typeof((down->st.b).begin()) i = (down->st.b).begin();
         i != (down->st.b).end(); ++i) {
      int curL = i->first + down->addL, curW = i->second + down->addW;
      int mL = maxL - curL, mW = maxW - curW;
      result += res->getValue(mL, mW);
    }
    for (__typeof((down->st.a).begin()) i = (down->st.a).begin();
         i != (down->st.a).end(); ++i) {
      int curL = i->first + down->addL, curW = i->second + down->addW;
      res->insert(make_pair(curL, curW));
    }
    for (__typeof((down->st.b).begin()) i = (down->st.b).begin();
         i != (down->st.b).end(); ++i) {
      int curL = i->first + down->addL, curW = i->second + down->addW;
      res->insert(make_pair(curL, curW));
    }
  }
  return res;
}
int main() {
  assert(scanf("%d%d%d", &n, &maxL, &maxW));
  for (int i = 1; i < n; i++) {
    assert(scanf("%d%d", &p[i], &w[i])), --p[i];
    g[p[i]].push_back(i);
  }
  dfs(0);
  cout << result << '\n';
  return 0;
}