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 GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 100 * 1000 + 10;
vector<int> E[MAX];
int fr[MAX], to[MAX], weight[MAX];
int siz[MAX], max_subtree[MAX], dont[MAX];
int dfs_in[MAX], dfs_out[MAX], dfs_time;
int n, max_l, max_w;
long long ans = 0;
vector<int> vertices;
int rev[MAX], path_len[MAX];
long long path_weight[MAX];
vector<int> ST[MAX << 2][2];
int IDX[MAX][20];
int dfs_cnt(int u, int p) {
  siz[u] = 1;
  max_subtree[u] = 0;
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    int t = dfs_cnt(v, u);
    siz[u] += t;
    max_subtree[u] = max(max_subtree[u], t);
  }
  return siz[u];
}
void get_root(int u, int p, int V, int& root) {
  max_subtree[u] = max(max_subtree[u], V - siz[u]);
  if (root == -1 || max_subtree[u] < max_subtree[root]) root = u;
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    get_root(v, u, V, root);
  }
}
void merge(vector<int>& A, vector<int>& B, vector<int>& C) {
  int i = 0, j = 0;
  while (i < ((int)A.size()) && j < ((int)B.size())) {
    if (path_len[A[i]] < path_len[B[j]])
      C.push_back(A[i++]);
    else
      C.push_back(B[j++]);
  }
  while (i < ((int)A.size())) C.push_back(A[i++]);
  while (j < ((int)B.size())) C.push_back(B[j++]);
}
void build(int node, int s, int e, int depth) {
  for (int i = 0; i < (2); i++) ST[node][i].clear();
  ST[node][1].resize(e - s + 1);
  if (s == e) {
    int u = vertices[s];
    ST[node][0].push_back(u);
    IDX[u][depth] = 0;
    return;
  }
  int m = (s + e) >> 1, left = node << 1, right = left | 1;
  build(left, s, m, depth + 1);
  build(right, m + 1, e, depth + 1);
  merge(ST[left][0], ST[right][0], ST[node][0]);
  for (int i = 0; i < (e - s + 1); i++) {
    int u = ST[node][0][i];
    IDX[u][depth] = i;
  }
}
inline void update(int p, int v, vector<int>& BIT) {
  for (++p; p <= ((int)BIT.size()); p += ((p) & (-(p)))) BIT[p - 1] += v;
}
inline int get(int p, vector<int>& BIT) {
  int ret = 0;
  for (++p; p; p ^= ((p) & (-(p)))) ret += BIT[p - 1];
  return ret;
}
void update(int node, int s, int e, int pos, int depth) {
  update(IDX[vertices[pos]][depth], 1, ST[node][1]);
  if (s == e) return;
  int m = (s + e) >> 1, left = node << 1, right = left | 1;
  if (pos <= m)
    update(left, s, m, pos, depth + 1);
  else
    update(right, m + 1, e, pos, depth + 1);
}
int query(int node, int s, int e, int pos, int len) {
  if (e <= pos) {
    int p = lower_bound(ST[node][0].begin(), ST[node][0].end(), len + 1,
                        [](const int& a, const int& target) {
                          return path_len[a] < target;
                        }) -
            ST[node][0].begin();
    return get(p - 1, ST[node][1]);
  }
  int m = (s + e) >> 1, left = node << 1, right = left | 1;
  if (pos <= m)
    return query(left, s, m, pos, len);
  else
    return query(left, s, m, pos, len) + query(right, m + 1, e, pos, len);
  ;
}
void explore(int u, int p, int len, long long w) {
  vertices.push_back(u);
  path_len[u] = len;
  path_weight[u] = w;
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    explore(v, u, len + 1, w + weight[e]);
  }
}
void compute(int u, int p) {
  auto idx =
      lower_bound(vertices.begin(), vertices.end(), max_w - path_weight[u] + 1,
                  [](const int& a, const long long& target) {
                    return path_weight[a] < target;
                  }) -
      vertices.begin();
  if (idx) {
    --idx;
    int tmp = query(1, 0, ((int)vertices.size()) - 1, idx, max_l - path_len[u]);
    ans += tmp;
  }
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    compute(v, u);
  }
}
void insert(int u, int p) {
  update(1, 0, ((int)vertices.size()) - 1, rev[u], 0);
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    insert(v, u);
  }
}
void divide_conquer(int u, int p) {
  dont[p] = 1;
  int V = dfs_cnt(u, p), root = -1;
  if (V == 1) return;
  get_root(u, p, V, root);
  assert(root != -1);
  u = root;
  vertices.clear();
  vertices.push_back(u);
  path_weight[u] = path_len[u] = 0;
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    explore(v, u, 1, weight[e]);
  }
  sort(vertices.begin(), vertices.end(), [](const int& a, const int& b) {
    return tie(path_weight[a], path_len[a]) < tie(path_weight[b], path_len[b]);
  });
  for (int i = 0; i < (((int)vertices.size())); i++) rev[vertices[i]] = i;
  build(1, 0, ((int)vertices.size()) - 1, 0);
  update(1, 0, ((int)vertices.size()) - 1, rev[u], 0);
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    compute(v, u);
    insert(v, u);
  }
  for (int e : E[u]) {
    int v = fr[e] + to[e] - u;
    if (v == p || dont[v]) continue;
    divide_conquer(v, u);
  }
}
int main() {
  scanf("%d %d %d", &n, &max_l, &max_w);
  for (int e = 0; e < (n - 1); e++) {
    to[e] = e + 2;
    scanf("%d %d", fr + e, weight + e);
    E[fr[e]].push_back(e);
    E[to[e]].push_back(e);
  }
  vertices.reserve(n);
  divide_conquer(1, 0);
  cout << ans << endl;
  return 0;
}