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 = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
struct eT {
  void setd(int _u, int _v, int _w, int _l) {
    u = _u, v = _v, w = _w, last = _l;
  }
  int u, v, w, last;
} edge[MAXN * 2];
class ftT {
 public:
  void clear(int n) {
    data.clear();
    size = n + 3;
    data.resize(size);
  }
  void upd(int p, int x) {
    for (; p < size; p += p & -p) data[p] += x;
  }
  int sum(int p) {
    int ans = 0;
    for (; p; p ^= p & -p) ans += data[p];
    return ans;
  }

 private:
  int size;
  vector<int> data;
} ft;
int n, ml, mw;
long long ans;
int ke, la[MAXN];
pair<int, int> aw;
int size[MAXN];
int tl;
vector<int> nw[MAXN], tw[MAXN];
bool vis[MAXN];
void init();
void input();
void work();
void dfs(int now, int fa, int nl, int nw);
int getw(int now, int fa, int as);
void divi(int now, int ns);
long long getnum(vector<int> nw[], int nl);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d%d", &n, &ml, &mw);
  int fa, nw;
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 2; i <= n; ++i) {
    scanf("%d%d", &fa, &nw);
    edge[ke].setd(fa, i, nw, la[fa]);
    la[fa] = ke++;
    edge[ke].setd(i, fa, nw, la[i]);
    la[i] = ke++;
  }
}
void work() {
  divi(1, n);
  printf("%I64d\n", ans);
}
void divi(int now, int ns) {
  if (ns == 1) return;
  aw = make_pair(INF, -1);
  getw(now, -1, ns);
  now = aw.second;
  long long na = 0;
  int nl = 0, rl;
  for (int i = la[now]; ~i; i = edge[i].last) {
    if (!vis[edge[i].v]) {
      tl = 0;
      dfs(edge[i].v, now, 1, edge[i].w);
      if (tl > nl) {
        for (int j = nl + 1; j <= tl; ++j) nw[j].clear();
        nl = tl;
      }
      for (int j = 1; j <= tl; ++j) {
        for (auto x : tw[j]) nw[j].push_back(x);
      }
      na -= getnum(tw, tl);
      for (int j = 1; j <= tl; ++j) tw[j].clear();
    }
  }
  na += getnum(nw, nl);
  na >>= 1;
  for (int i = 1; i <= nl; ++i) na += nw[i].size();
  for (int i = 1; i <= nl; ++i) nw[i].clear();
  ans += na;
  vis[now] = true;
  for (int i = la[now]; ~i; i = edge[i].last) {
    if (!vis[edge[i].v]) divi(edge[i].v, size[edge[i].v]);
  }
}
int getw(int now, int fa, int as) {
  int ns = 1, ms = 0, v, ret;
  for (int i = la[now]; ~i; i = edge[i].last) {
    v = edge[i].v;
    if (v ^ fa && !vis[v]) {
      ret = getw(v, now, as);
      ms = (((ms) > (ret)) ? (ms) : (ret));
      ns += ret;
    }
  }
  size[now] = ns;
  ms = (((ms) > (as - ns)) ? (ms) : (as - ns));
  aw = (((aw) < (make_pair(ms, now))) ? (aw) : (make_pair(ms, now)));
  return ns;
}
void dfs(int now, int fa, int nl, int nw) {
  if (nl > ml || nw > mw) return;
  tw[nl].push_back(nw);
  tl = (((tl) > (nl)) ? (tl) : (nl));
  for (int i = la[now]; ~i; i = edge[i].last) {
    if (edge[i].v ^ fa && !vis[edge[i].v]) {
      dfs(edge[i].v, now, nl + 1, nw + edge[i].w);
    }
  }
}
long long getnum(vector<int> nw[], int nl) {
  long long na = 0;
  map<int, int> mp;
  int kc = 0;
  for (int i = 1; i <= nl; ++i)
    for (auto x : nw[i]) mp[x] = 0;
  for (pair<const int, int> &x : mp) x.second = ++kc;
  mp.insert(make_pair(-INF, 0));
  mp.insert(make_pair(INF, -1));
  ft.clear(kc);
  int ri;
  for (int i = 1; i <= nl; ++i) {
    for (auto x : nw[i]) ft.upd(mp[x], 1);
    ri = ml - i;
    if (ri <= nl)
      for (auto x : nw[ri]) na += ft.sum((--mp.upper_bound(mw - x))->second);
  }
  ri = (((nl + 1) < (ml - nl)) ? (nl + 1) : (ml - nl));
  for (int i = 1; i < ri; ++i)
    for (auto x : nw[i]) na += ft.sum((--mp.upper_bound(mw - x))->second);
  return na;
}