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 MX = 100009;
const int inf = 100000009;
int centroidMarked[MX] = {};
int subsz[MX];
vector<int> tree[MX];
vector<int> cost[MX];
int parent[MX];
int level[MX];
int pa[17][MX];
int dist[17][MX];
vector<pair<int, int>> v[MX];
pair<int, int> av[MX];
vector<int> cenTree[MX];
long long bit[MX];
int L, W;
long long ANS = 0;
int dd = 0;
long long query(int k, int s) {
  if (k <= 0) return 0;
  k = min(k, s);
  long long sum = 0;
  for (; k > 0; k -= k & -k) sum += bit[k];
  return sum;
}
void update_bit(int k, int s) {
  k++;
  for (; k <= s; k += k & -k) bit[k]++;
}
void dfs(int cur, int prev) {
  subsz[cur] = 1;
  for (int i = 0; i < tree[cur].size(); i++) {
    int v = tree[cur][i];
    if (v != prev && !centroidMarked[v]) {
      dfs(v, cur);
      subsz[cur] += subsz[v];
    }
  }
}
long long calc_pair(int root, int ln, int w, int ind = 0) {
  int k;
  if (ind == 0)
    k = v[root].size() + 1;
  else
    k = dd + 1;
  for (int i = 0; i <= k + 9; i++) bit[i] = 0;
  long long p = 0;
  for (int i = k - 2, j = 0; i >= 0; i--) {
    if (ind == 0) {
      while (j < k - 1 && v[root][i].first + v[root][j].first <= w)
        update_bit(v[root][j++].second, k);
      int tmp = query(ln - v[root][i].second + 1, k);
      p += tmp;
      if (2 * v[root][i].first <= w && 2 * v[root][i].second <= ln) p--;
    } else {
      while (j < k - 1 && av[i].first + av[j].first <= w) {
        update_bit(av[j++].second, k);
      }
      int tmp = query(ln - av[i].second + 1, k);
      p += tmp;
      if (2 * av[i].first <= w && 2 * av[i].second <= ln) p--;
    }
  }
  return p;
}
int getCentroid(int cur, int prev, int sz) {
  bool isC = true;
  int hvChild = 0;
  for (int i = 0; i < tree[cur].size(); i++) {
    int v = tree[cur][i];
    if (v != prev && !centroidMarked[v] && subsz[v] > sz) {
      hvChild = v;
      isC = false;
      break;
    }
  }
  if (isC && subsz[cur] >= sz) return cur;
  return getCentroid(hvChild, cur, sz);
}
void precalc(int cur, int prev, int weight, int dist) {
  av[dd++] = make_pair(weight, dist);
  for (int i = 0; i < tree[cur].size(); i++) {
    if (!centroidMarked[tree[cur][i]] && tree[cur][i] != prev) {
      precalc(tree[cur][i], cur, weight + cost[cur][i], dist + 1);
    }
  }
}
int getCentroid(int src) {
  dfs(src, -1);
  int c = getCentroid(src, -1, subsz[src] / 2);
  centroidMarked[c] = 1;
  for (int i = 0; i < tree[c].size(); i++) {
    if (!centroidMarked[tree[c][i]]) {
      dd = 0;
      precalc(tree[c][i], c, 0, 0);
      sort(av, av + dd);
      ANS -= calc_pair(tree[c][i], L - 2, W - 2 * cost[c][i], 1);
    }
  }
  return c;
}
int build(int root) {
  int cent = getCentroid(root);
  for (int i = 0; i < tree[cent].size(); i++) {
    int v = tree[cent][i];
    if (!centroidMarked[v]) {
      int csub = build(v);
      parent[csub] = cent;
      cenTree[cent].push_back(csub);
    }
  }
  return cent;
}
void setPar(int cur, int prev, int lv, int cst) {
  pa[0][cur] = prev;
  dist[0][cur] = cst;
  level[cur] = lv;
  for (int i = 0; i < tree[cur].size(); i++)
    if (tree[cur][i] != prev) setPar(tree[cur][i], cur, lv + 1, cost[cur][i]);
}
void initLCA(int n) {
  for (int i = 1; i < 17; i++) {
    for (int j = 1; j <= n; j++) {
      if (pa[i - 1][j] != -1) {
        pa[i][j] = pa[i - 1][pa[i - 1][j]];
      }
    }
  }
  for (int i = 1; i < 17; i++) {
    for (int j = 1; j <= n; j++) {
      if (pa[i - 1][j] != -1) {
        dist[i][j] = dist[i - 1][pa[i - 1][j]] + dist[i - 1][j];
      }
    }
  }
}
int findLCA(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  int diff = level[u] - level[v];
  for (int i = 0; i < 17; i++)
    if ((diff >> i) & 1) u = pa[i][u];
  if (u == v) return u;
  for (int i = 16; i >= 0; i--) {
    if (pa[i][u] != pa[i][v]) {
      u = pa[i][u];
      v = pa[i][v];
    }
  }
  return pa[0][u];
}
int dst(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  int diff = level[u] - level[v];
  int sum = 0;
  for (int i = 16; i >= 0; i--) {
    if ((diff >> i) & 1) {
      sum += dist[i][u];
      u = pa[i][u];
    }
  }
  return sum;
}
int getDist(int u, int v) {
  int lca = findLCA(u, v);
  return dst(u, lca) + dst(v, lca);
}
int getLen(int u, int v) {
  int lca = findLCA(u, v);
  return level[u] + level[v] - 2 * level[lca];
}
void process(int n) {
  for (int i = 1; i <= n; i++) {
    int tu = i;
    int ltu = i;
    while (tu != -1) {
      int ln = getLen(i, tu);
      int dst = getDist(i, tu);
      v[tu].emplace_back(dst, ln);
      ltu = tu;
      tu = parent[tu];
    }
  }
  for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
}
void solve(int root) {
  ANS += calc_pair(root, L, W, 0);
  for (int i = 0; i < cenTree[root].size(); i++) solve(cenTree[root][i]);
}
int main() {
  int n;
  cin >> n >> L >> W;
  memset(parent, -1, sizeof(parent));
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    tree[a].push_back(i + 1);
    tree[i + 1].push_back(a);
    cost[a].push_back(b);
    cost[i + 1].push_back(b);
  }
  setPar(1, -1, 1, 0);
  int f = build(1);
  initLCA(n);
  process(n);
  solve(f);
  cout << ANS / 2 << endl;
  return 0;
}