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 JAVA):

Solution:
import java.io.*;
import java.math.BigInteger;
import java.math.BigInteger.*;
import java.util.*;


import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;


public class Main {

    void run(){
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        try {
            if( oj ){
//                br = new BufferedReader(new FileReader("zanzibar.in"));
                br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
            else{
                br = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            }
        } catch ( Exception e) {
            MLE();
        }
        double tBeg = System.currentTimeMillis();
        solve();
//        if( !oj )out.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        out.flush();
    }

    StringTokenizer st;
    BufferedReader br;
    PrintWriter out;

    String next(){
        while( st==null || !st.hasMoreElements() ){
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                return null;
            }
        }
        return st.nextToken();
    }

    int nextInt(){ return Integer.parseInt(next()); }
    long nextLong(){ return Long.parseLong(next()); }

    void MLE(){
        int[][] arr = new int[1024*1024][];
        for( int i = 0; i < 1024*1024; ++i )
            arr[i] = new int[1024*1024];
    }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new Main().run();
    }
////////////////////////////////////////////////////////////////

    class Fenwick{
        int[] tree;

        Fenwick( int _n ){
            tree = new int[_n];
        }

        void add( int ind, int delta ){
            for( int i = ind; i < tree.length; i = i|(i+1) )
                tree[i] += delta;
        }

        int sumPref( int ind ){
            ind = min( ind, tree.length - 1 );
            int sum = 0;
            for( int i = ind; 0 <= i; i = (i&(i+1))-1 )
                sum += tree[i];
            return sum;
        }
    }

    void mySort( int[] a ){
        Integer[] b = new Integer[a.length];
        for( int i = 0; i < a.length; ++i ) b[i] = a[i];
        sort( b, new Comparator<Integer>() {
            @Override
            public int compare(Integer a, Integer b) {
                return weight[a] - weight[b];
            }
        } );
        for( int i = 0; i < a.length; ++i ) a[i] = b[i];
    }

    class Edge{
        int to, w;
        Edge rev;
        boolean isKilled;
        Edge( int _to, int _w ){
            to = _to;
            w  = _w;
            isKilled = false;
        }
    }

    int n, L, W;
    ArrayList<Edge>[] gr;
    long ans = 0;
    int[] depth, weight, cnt, color;

    int szComp;
    int[] comp;
    void dfs( int v, int p, int dep, int curW ){
        comp[szComp++] = v;
        cnt[v] = 1;
        depth[v] = dep;
        weight[v] = curW;
        for( Edge e : gr[v] ){
            if( e.isKilled || e.to==p )
                continue;
            dfs( e.to, v, dep+1, curW + e.w );
            cnt[v] += cnt[e.to];
        }
    }

    void paint( int v, int p, int col ){
        color[v] = col;
        for( Edge e : gr[v] ){
            if( e.isKilled || e.to==p )
                continue;
            paint(e.to, v, col);
        }
    }

    void fuckThis( int root ){
        szComp = 0; dfs(root,-1,0,0);
        {
            int cntAllVer = cnt[root];
            int pred = -1;
            while(true){
                boolean doSome = false;
                for( Edge e : gr[root] ){
                    if( e.isKilled || e.to == pred )
                        continue;
                    if( 2*cnt[e.to] > cntAllVer ){
                        pred = root;
                        root = e.to;
                        doSome = true;
                        break;
                    }
                }
                if( !doSome ) break;
            }
        }

        szComp = 0;  dfs(root,-1,0,0);
        int[] ord = copyOf( comp, szComp );
        mySort(ord);

        Fenwick f = new Fenwick( cnt[root] );
        int cntChildren = 0;
        Fenwick[] sub = new Fenwick[cnt[root]];

        for( Edge e : gr[root] )
            if( !e.isKilled  ){
                paint( e.to, root, cntChildren );
                sub[cntChildren] = new Fenwick(cnt[e.to]+1);
                //
                ++cntChildren;
            }



        int posR = ord.length - 1;
        for( int ver : ord ){
            if( ver == root ) continue;
            while( 0 <= posR && W < weight[ver] + weight[ord[posR]] ){
                int to = ord[posR];
                if( to != root ){
                    ans += f             .sumPref( L - depth[to] );
                    ans -= sub[color[to]].sumPref( L - depth[to] );
                }
                --posR;
            }
            f              .add(depth[ver], 1);
            sub[color[ver]].add(depth[ver], 1);
        }
        while( 0 <= posR ){
            int to = ord[posR];
            if( to != root ){
                ans += f             .sumPref( L - depth[to] );
                ans -= sub[color[to]].sumPref( L - depth[to] );
            }
            --posR;
        }
        for( int ver : ord ){
            if( ver == root ) continue;
            if( depth[ver] <= L && weight[ver] <= W )
                ans += 2;
        }


        for( Edge e : gr[root] ){
            if( !e.isKilled  ){
                e.isKilled = e.rev.isKilled = true;
                fuckThis( e.to );
            }
        }
    }

    void solve(){
        n = nextInt();
        L = nextInt();
        W = nextInt();
        gr = new ArrayList[n+1];
        for( int v = 1; v <= n; ++v )
            gr[v] = new ArrayList<>();
        for( int v = 2; v <= n; ++v ){
            int to = nextInt();
            int w  = nextInt();
            Edge
                    e0 = new Edge(to,w),
                    e1 = new Edge(v ,w);
            e0.rev = e1;
            e1.rev = e0;
            gr[v ].add(e0);
            gr[to].add(e1);
        }
        cnt    = new int[n+1];
        depth  = new int[n+1];
        weight = new int[n+1];
        color  = new int[n+1];
        comp   = new int[n+1];
        fuckThis(1);
        ans /= 2;
        out.println( ans );
    }

}