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 long long N = 1e5 + 4;
long long n, maxL, maxW, res;
vector<pair<long long, long long> > adj[N];
long long numChild[N], total;
bool Disable[N];
void DFS_SubTree(long long par, long long u) {
  numChild[u] = 1;
  for (long long i = 0; i < (long long)adj[u].size(); ++i) {
    long long v = adj[u][i].second;
    if (v == par || Disable[v]) continue;
    DFS_SubTree(u, v);
    numChild[u] += numChild[v];
  }
}
long long Find_Centroid(long long par, long long u) {
  for (long long i = 0; i < (long long)adj[u].size(); ++i) {
    long long v = adj[u][i].second;
    if (v == par || Disable[v]) continue;
    if (numChild[v] > total / 2) return Find_Centroid(u, v);
  }
  return u;
}
long long wei[N], len[N];
vector<long long> lsNode;
void DFS_get_allNode(long long par, long long u) {
  lsNode.push_back(u);
  for (long long i = 0; i < (long long)adj[u].size(); ++i) {
    long long v = adj[u][i].second, uv = adj[u][i].first;
    if (v == par || Disable[v]) continue;
    wei[v] = wei[u] + uv;
    len[v] = len[u] + 1;
    DFS_get_allNode(u, v);
  }
}
vector<long long> BIT, rar;
void update_BIT(long long pos, long long val) {
  pos = lower_bound(rar.begin(), rar.end(), pos) - rar.begin() + 1;
  for (; pos < (long long)BIT.size(); pos += pos & (-pos)) BIT[pos] += val;
}
long long get_BIT(long long pos) {
  pos = upper_bound(rar.begin(), rar.end(), pos) - rar.begin();
  long long ans = 0;
  for (; pos > 0; pos -= pos & (-pos)) ans += BIT[pos];
  return ans;
}
long long Count_Pair(long long par, long long u, long long limL,
                     long long limW) {
  wei[u] = len[u] = 0;
  lsNode.clear();
  DFS_get_allNode(par, u);
  sort(lsNode.begin(), lsNode.end(),
       [](long long &a, long long &b) { return len[a] < len[b]; });
  rar.clear();
  for (long long node : lsNode) rar.push_back(wei[node]);
  sort(rar.begin(), rar.end());
  rar.resize(unique(rar.begin(), rar.end()) - rar.begin());
  BIT.clear();
  BIT.resize(rar.size() + 2);
  for (long long node : lsNode) update_BIT(wei[node], 1);
  long long r = (long long)lsNode.size() - 1, numPair = 0;
  for (long long l = 0; l < (long long)lsNode.size(); ++l) {
    while (r >= 0 && len[lsNode[l]] + len[lsNode[r]] > limL) {
      update_BIT(wei[lsNode[r]], -1);
      --r;
    }
    numPair += get_BIT(limW - wei[lsNode[l]]);
  }
  for (long long node : lsNode)
    if (2 * len[node] <= limL && 2 * wei[node] <= limW) numPair--;
  return numPair / 2;
}
void process(long long par, long long u) {
  res += Count_Pair(par, u, maxL, maxW);
  for (long long i = 0; i < (long long)adj[u].size(); ++i) {
    long long v = adj[u][i].second, uv = adj[u][i].first;
    if (v == par || Disable[v]) continue;
    res -= Count_Pair(u, v, maxL - 2, maxW - 2 * uv);
  }
}
void Centroid_Decompose(long long par, long long u) {
  DFS_SubTree(par, u);
  total = numChild[u];
  long long centroid = Find_Centroid(par, u);
  process(par, centroid);
  Disable[centroid] = true;
  for (long long i = 0; i < (long long)adj[centroid].size(); ++i) {
    long long v = adj[centroid][i].second;
    if (v == par || Disable[v]) continue;
    Centroid_Decompose(centroid, v);
  }
}
void sol() {
  Centroid_Decompose(0, 1);
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  cin >> n >> maxL >> maxW;
  long long u, w;
  for (long long v = 2; v <= n; ++v) {
    cin >> u >> w;
    adj[u].push_back(pair<long long, long long>(w, v));
    adj[v].push_back(pair<long long, long long>(w, u));
  }
  sol();
  return 0;
}