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;
void trace_() { cerr << "\n"; }
template <typename T1, typename... T2>
void trace_(T1 t1, T2... t2) {
  cerr << ' ' << t1;
  trace_(t2...);
}
const long long mxN = 1e5 + 5;
long long n, l, k;
vector<long long> g[mxN], w[mxN];
long long pa[mxN], sz[mxN];
bitset<mxN> del;
struct BIT {
  long long b[mxN];
  long long qry(long long i) {
    if (i <= 0) return 0;
    long long res = 0;
    for (; i > 0; i -= (i & -i)) res += b[i];
    return res;
  }
  void upd(long long i, long long v) {
    for (; i <= l; i += (i & -i)) b[i] += v;
  }
} bit;
long long ans = 0;
void get_sz(long long u, long long p) {
  sz[u] = 1;
  for (long long v : g[u]) {
    if (v == p or del[v]) continue;
    get_sz(v, u);
    sz[u] += sz[v];
  }
}
long long get_centroid(long long u, long long n, long long p) {
  for (long long v : g[u]) {
    if (v != p and !del[v] and sz[v] * 2 > n) return get_centroid(v, n, u);
  }
  return u;
}
vector<pair<long long, long long> > dat;
void dfs(long long u, long long p, long long sum, long long dep) {
  dat.emplace_back(sum, dep);
  if (sum <= k and dep <= l and dep > 1) ans++;
  for (long long i = 0; i < (long long)(g[u].size()); i++) {
    long long v = g[u][i], ww = w[u][i];
    if (v == p or del[v]) continue;
    dfs(v, u, sum + ww, dep + 1);
  }
}
inline long long cal(vector<pair<long long, long long> > &v) {
  vector<long long> Undo;
  sort(v.begin(), v.end());
  if ((long long)(v.size()) == 1) return 0;
  long long loli = -1, j = -1;
  for (long long i = (long long)(v.size()) - 2; i >= 0; i--) {
    if (v[i].first + v[i + 1].first <= k) {
      loli = i;
      j = i + 1;
      break;
    }
  }
  long long res = 0;
  for (long long i = loli; i >= 0; i--) {
    while (j < (long long)(v.size()) and v[i].first + v[j].first <= k) {
      bit.upd(v[j].second, 1);
      Undo.emplace_back(v[j].second);
      j++;
    }
    res += bit.qry(l - v[i].second);
    bit.upd(v[i].second, 1);
    Undo.emplace_back(v[i].second);
  }
  for (long long i : Undo) bit.upd(i, -1);
  return res;
}
long long build(long long u) {
  get_sz(u, -1);
  long long centroid = get_centroid(u, sz[u], -1);
  del[centroid] = 1;
  vector<pair<long long, long long> > tot;
  long long sub = 0;
  cerr << "["
       << "centroid"
       << "] :",
      trace_(centroid);
  ;
  for (long long i = 0; i < (long long)(g[centroid].size()); i++) {
    long long v = g[centroid][i], ww = w[centroid][i];
    if (del[v]) continue;
    dfs(v, -1, ww, 1);
    sub += cal(dat);
    tot.insert(tot.end(), dat.begin(), dat.end());
    dat.clear();
  }
  ans = ans + cal(tot) - sub;
  for (long long v : g[centroid]) {
    if (del[v]) continue;
    pa[build(v)] = centroid;
  }
  return centroid;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> l >> k;
  for (long long i = 2; i <= n; i++) {
    long long p, ww;
    cin >> p >> ww;
    if (ww <= k) ans++;
    g[p].push_back(i);
    g[i].push_back(p);
    w[p].push_back(ww);
    w[i].push_back(ww);
  }
  build(1);
  cout << ans << '\n';
}