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>
#pragma comment(linker, "/STACK:10000000000")
#pragma GCC optimize("O3")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007LL;
const long long INF2 = 1000000007LL * 1000000007LL;
const long double EPS = 1e-4 / 2;
const int SIZE = 601000;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
struct node {
  int sum;
  int l, r;
  node() {
    sum = 0;
    l = 0;
    r = 0;
  }
  void clear() {
    sum = 0;
    l = 0;
    r = 0;
  }
} nodes[SIZE];
int curNode = 0;
int newNode() {
  ++curNode;
  nodes[curNode].clear();
  return curNode;
}
struct segment_tree {
  int t;
  int n;
  segment_tree(int n_) {
    n = n_;
    curNode = 0;
    nodes[0].clear();
    t = newNode();
  }
  void join(int v, int l, int r) { nodes[v].sum = nodes[l].sum + nodes[r].sum; }
  void modify(int v, int vl, int vr, int ind, int val) {
    if (ind < vl || vr < ind) {
      return;
    }
    if (ind <= vl && vr <= ind) {
      nodes[v].sum += val;
      return;
    }
    int vm = (vl + vr) / 2;
    if (!nodes[v].l) nodes[v].l = newNode();
    if (!nodes[v].r) nodes[v].r = newNode();
    modify(nodes[v].l, vl, vm, ind, val);
    modify(nodes[v].r, vm + 1, vr, ind, val);
    join(v, nodes[v].l, nodes[v].r);
  }
  void modify(int ind, int val) { modify(t, 0, n - 1, ind, val); }
  int query(int v, int vl, int vr, int l, int r) {
    if (r < vl || vr < l) {
      return 0;
    }
    if (l <= vl && vr <= r) {
      return nodes[v].sum;
    }
    int vm = (vl + vr) / 2;
    if (!nodes[v].l) nodes[v].l = newNode();
    if (!nodes[v].r) nodes[v].r = newNode();
    int ql = query(nodes[v].l, vl, vm, l, r);
    int qr = query(nodes[v].r, vm + 1, vr, l, r);
    return ql + qr;
  }
  int query(int l, int r) {
    return query(t, 0, n - 1, max(l, 0), min(n - 1, r));
  }
  int get() {
    if (t == 0) return 0;
    return nodes[t].sum;
  }
};
long long ans;
int W, L, n;
struct ev {
  bool tp;
  int w, l;
  ev() {}
  ev(int tp, int w, int l) : tp(tp), w(w), l(l) {}
  bool operator<(const ev& b) const {
    if (w != b.w) return w < b.w;
    if (tp != b.tp) return tp < b.tp;
    return l < b.l;
  }
};
long long scanline(vector<pair<int, int> >& v) {
  long long res = 0;
  segment_tree sgt(n + 10);
  vector<ev> events;
  for (auto& i : v) {
    res -= (2 * i.first <= W && 2 * i.second <= L);
    sgt.modify(i.second, 1);
    events.push_back({1, i.first, i.second});
    events.push_back({0, W - i.first + 1, i.second});
  }
  sort(begin(events), end(events));
  for (auto& i : events) {
    if (i.tp == 0) {
      sgt.modify(i.l, -1);
      continue;
    }
    int dist = L - i.l;
    if (dist < 0) dist = 0;
    res += sgt.query(0, dist);
  }
  return res / 2;
}
vector<pair<int, int> > g[SIZE];
int sizes[SIZE], deleted[SIZE];
int init_size(int v, int p = -1) {
  sizes[v] = 1;
  for (auto& i : g[v]) {
    if (deleted[i.first] || i.first == p) continue;
    sizes[v] += init_size(i.first, v);
  }
  return sizes[v];
}
int centroid(int v, int n, int p = -1) {
  for (auto& i : g[v])
    if (i.first != p && !deleted[i.first] && sizes[i.first] > (n >> 1))
      return centroid(i.first, n, v);
  return v;
}
void add(int v, int dist_w, int dist_l, vector<pair<int, int> >& vec,
         int p = -1) {
  vec.push_back({dist_w, dist_l});
  for (auto& i : g[v]) {
    if (deleted[i.first] || i.first == p) continue;
    add(i.first, dist_w + i.second, dist_l + 1, vec, v);
  }
}
void decomposition(int v) {
  int sz = init_size(v);
  if (sz == 1) return;
  int c = centroid(v, sz);
  sizes[c] = 0;
  deleted[c] = 1;
  vector<pair<int, int> > vall;
  for (auto& i : g[c]) {
    if (deleted[i.first]) continue;
    vector<pair<int, int> > v;
    add(i.first, i.second, 1, v);
    for (auto& i : v) {
      vall.push_back(i);
      if (i.first <= W && i.second <= L) ++ans;
    }
    ans -= scanline(v);
  }
  ans += scanline(vall);
  for (auto& i : g[c])
    if (!deleted[i.first]) decomposition(i.first);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> L >> W;
  for (int i = 1; i < n; ++i) {
    int v, w;
    cin >> v >> w;
    --v;
    g[i].push_back({v, w});
    g[v].push_back({i, w});
  }
  decomposition(0);
  cout << ans;
  return 0;
}