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;
struct Edge {
  int Data, Weight;
};
struct Node {
  int Depth, Cost, Color;
};
struct Event {
  int Time, Value, Type;
};
bool operator<(Event A, Event B) {
  return (A.Time == B.Time) ? (A.Type < B.Type) : (A.Time < B.Time);
}
int Get() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int X = 0;
  while (c >= '0' && c <= '9') {
    X = X * 10 + c - 48;
    c = getchar();
  }
  return X;
}
const int inf = 1000000000;
int Total;
vector<Edge> G[100000];
bool Visited[100000];
Node T[100000];
Event E[200000];
int Data[100000], Sum[100001];
int Find(int X, int N) {
  int Left = -1, Right = N - 1;
  while (Left < Right) {
    int Mid = (Left + Right + 1) / 2;
    if (X >= Data[Mid])
      Left = Mid;
    else
      Right = Mid - 1;
  }
  return Left;
}
void Add(int X, int N) {
  while (X <= N) {
    Sum[X]++;
    X += X & -X;
  }
}
int GetSum(int X) {
  int Ans = 0;
  while (X) {
    Ans += Sum[X];
    X ^= X & -X;
  }
  return Ans;
}
int FindCenter(int Start) {
  static int Queue[100000], Parent[100000];
  int Front = 0, Rear = 1;
  Queue[0] = Start;
  Parent[Start] = -1;
  while (Front < Rear) {
    int V = Queue[Front++];
    for (int i = 0; i < G[V].size(); i++) {
      int U = G[V][i].Data;
      if (Visited[U] || U == Parent[V]) continue;
      Parent[U] = V;
      Queue[Rear++] = U;
    }
  }
  static int Size[100000];
  int Min = inf, Best;
  for (int i = Rear - 1; i >= 0; i--) {
    int V = Queue[i], Max = 0;
    Size[V] = 1;
    for (int j = 0; j < G[V].size(); j++) {
      int U = G[V][j].Data;
      if (Visited[U] || U == Parent[V]) continue;
      Size[V] += Size[U];
      Max = max(Max, Size[U]);
    }
    Max = max(Max, Rear - Size[V]);
    if (Max < Min) {
      Min = Max;
      Best = V;
    }
  }
  return Best;
}
void DFS(int X, int Last, int Depth, int Cost, int Color) {
  T[Total++] = (Node){Depth, Cost, Color};
  for (int i = 0; i < G[X].size(); i++) {
    int Y = G[X][i].Data;
    if (Visited[Y] || Y == Last) continue;
    DFS(Y, X, Depth + 1, Cost + G[X][i].Weight, Color);
  }
}
long long Solve(int Root, int MaxLen, int MaxDist) {
  Root = FindCenter(Root);
  int Counter = Total = 1;
  T[0] = (Node){0, 0, 0};
  for (int i = 0; i < G[Root].size(); i++) {
    int V = G[Root][i].Data;
    if (Visited[V]) continue;
    DFS(V, Root, 1, G[Root][i].Weight, Counter++);
  }
  long long Ans = 0;
  for (int i = 0, j = 0; i < Total; i = j) {
    while (j < Total && T[i].Color == T[j].Color) j++;
    int CountEvent = 0, CountValue = 0;
    for (int k = i; k < j; k++) {
      E[CountEvent++] = (Event){T[k].Depth, T[k].Cost, 0};
      E[CountEvent++] = (Event){MaxLen - T[k].Depth, MaxDist - T[k].Cost, 1};
      Data[CountValue++] = T[k].Cost;
    }
    sort(E, E + CountEvent);
    sort(Data, Data + CountValue);
    for (int k = 0; k <= CountValue; k++) Sum[k] = 0;
    for (int k = 0; k < CountEvent; k++)
      if (!E[k].Type)
        Add(Find(E[k].Value, CountValue) + 1, CountValue);
      else
        Ans -= GetSum(Find(E[k].Value, CountValue) + 1);
  }
  int CountEvent = 0, CountValue = 0;
  for (int i = 0; i < Total; i++) {
    E[CountEvent++] = (Event){T[i].Depth, T[i].Cost, 0};
    E[CountEvent++] = (Event){MaxLen - T[i].Depth, MaxDist - T[i].Cost, 1};
    Data[CountValue++] = T[i].Cost;
  }
  sort(E, E + CountEvent);
  sort(Data, Data + CountValue);
  for (int i = 0; i <= CountValue; i++) Sum[i] = 0;
  for (int i = 0; i < CountEvent; i++)
    if (!E[i].Type)
      Add(Find(E[i].Value, CountValue) + 1, CountValue);
    else
      Ans += GetSum(Find(E[i].Value, CountValue) + 1);
  Ans /= 2;
  Visited[Root] = true;
  for (int i = 0; i < G[Root].size(); i++)
    if (!Visited[G[Root][i].Data])
      Ans += Solve(G[Root][i].Data, MaxLen, MaxDist);
  return Ans;
}
int main() {
  int N = Get(), MaxLen = Get(), MaxDist = Get();
  for (int i = 1; i < N; i++) {
    int X = Get() - 1, W = Get();
    G[i].push_back((Edge){X, W});
    G[X].push_back((Edge){i, W});
  }
  memset(Visited, 0, sizeof(Visited));
  cout << Solve(0, MaxLen, MaxDist) << endl;
  return 0;
}