Problem: On the way home, Karen decided to stop by the supermarket to buy some groceries.

<image>

She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars.

The supermarket sells n goods. The i-th good can be bought for ci dollars. Of course, each good can only be bought once.

Lately, the supermarket has been trying to increase its business. Karen, being a loyal customer, was given n coupons. If Karen purchases the i-th good, she can use the i-th coupon to decrease its price by di. Of course, a coupon cannot be used without buying the corresponding good.

There is, however, a constraint with the coupons. For all i ≥ 2, in order to use the i-th coupon, Karen must also use the xi-th coupon (which may mean using even more coupons to satisfy the requirement for that coupon).

Karen wants to know the following. What is the maximum number of goods she can buy, without exceeding her budget b?

Input

The first line of input contains two integers n and b (1 ≤ n ≤ 5000, 1 ≤ b ≤ 109), the number of goods in the store and the amount of money Karen has, respectively.

The next n lines describe the items. Specifically:

  * The i-th line among these starts with two integers, ci and di (1 ≤ di < ci ≤ 109), the price of the i-th good and the discount when using the coupon for the i-th good, respectively. 
  * If i ≥ 2, this is followed by another integer, xi (1 ≤ xi < i), denoting that the xi-th coupon must also be used before this coupon can be used. 

Output

Output a single integer on a line by itself, the number of different goods Karen can buy, without exceeding her budget.

Examples

Input

6 16
10 9
10 5 1
12 2 1
20 18 3
10 2 3
2 1 5


Output

4


Input

5 10
3 1
3 1 1
3 1 2
3 1 3
3 1 4


Output

5

Note

In the first test case, Karen can purchase the following 4 items:

  * Use the first coupon to buy the first item for 10 - 9 = 1 dollar. 
  * Use the third coupon to buy the third item for 12 - 2 = 10 dollars. 
  * Use the fourth coupon to buy the fourth item for 20 - 18 = 2 dollars. 
  * Buy the sixth item for 2 dollars. 



The total cost of these goods is 15, which falls within her budget. Note, for example, that she cannot use the coupon on the sixth item, because then she should have also used the fifth coupon to buy the fifth item, which she did not do here.

In the second test case, Karen has enough money to use all the coupons and purchase everything.

Solution (in JAVA):

Solution:
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;


public class Main {

    public static int[] combine(int[] c1, int[] c2, int b, int lNodes, int rNodes) {
        if (lNodes < rNodes)
            return combine(c2, c1, b, rNodes, lNodes);

        int[] result = new int[lNodes + rNodes + 1];
        Arrays.fill(result, -1);

        for (int k = 0; k < lNodes + rNodes + 1; ++k) {
            for (int r = 0; r <= Math.min(k, rNodes); r++) {
                if (c2[r] < 0)
                    continue;

                if (lNodes < k - r || c1[k - r] < 0)
                    continue;

                int val = c1[k - r] + c2[r];
                if (val > b)
                    continue;

                if (result[k] == -1 || val < result[k]) {
                    result[k] = val;
                }
            }
        }
        return result;
    }


    public static Pair solve(int idx,
                             ArrayList<ArrayList<Integer>> children,
                             int[] c,
                             int[] d, int b) {

        int[] yes = new int[2];
        int[] no = new int[2];

        Arrays.fill(yes, -1);
        Arrays.fill(no, -1);
        no[0] = 0;
        if (c[idx] <= b)
            no[1] = c[idx];

        yes[0] = -1;

        if (c[idx] - d[idx] <= b)
            yes[1] = c[idx] - d[idx];

        int nodes = 1;

        for (int child: children.get(idx)) {
            Pair solution = solve(child, children, c, d, b);
            solution.with[0] = 0;

            int size = Math.max(solution.with.length, solution.without.length);
            int[] min = new int[size];

            for (int i = 0; i < size; ++i) {
                int l = -1;
                if (i < solution.without.length)
                    l = solution.without[i];

                int r = -1;
                if (i < solution.with.length)
                    r = solution.with[i];

                if (r >= 0 && l >= 0)
                    min[i] = Math.min(l, r);
                else
                    min[i] = Math.max(l,r );

            }

            yes = combine(yes, min, b, nodes, solution.nodes);
            //System.out.println("no: " + str(no) + " without: " + str(solution.without));

            no = combine(no, solution.without, b, nodes, solution.nodes);

            nodes += solution.nodes;

            //System.out.println(str(min));
            //System.out.println(str(no));
        }

        //System.out.println(idx + " " + str(yes) + " " + str(no));
        return new Pair(yes, no, nodes);
    }

    public static String str(int[] a) {
        StringBuilder s = new StringBuilder();
        s.append("[");
        for (int i = 0; i < a.length; ++i) {
            if (i > 0)
                s.append(",");
            s.append(a[i]);
        }
        s.append("]");
        return s.toString();
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int b = scan.nextInt();

        int[] c = new int[n];
        int[] d = new int[n];

        ArrayList<ArrayList<Integer>> children = new ArrayList<>(n);

        for (int i = 0; i < n; ++i) {
            c[i] = scan.nextInt();
            d[i] = scan.nextInt();
            children.add(new ArrayList<>());

            if (i > 0) {
                int dep = scan.nextInt();
                children.get(dep - 1).add(i);
            }
        }

        Pair solutions = solve(0, children, c, d, b);

        int max = 0;

        for (int i = 0; i < solutions.without.length; ++i)
            if (solutions.without[i] >= 0 && i > max)
                max = i;

        for (int i = 0; i < solutions.with.length; ++i)
            if (solutions.with[i] >= 0 && i > max)
                max = i;

        System.out.println(max);
    }
}

class Pair {
    int[] with;
    int[] without;
    int nodes;

    Pair(int[] with, int[] without, int nodes) {
        this.with = with;
        this.without = without;
        this.nodes = nodes;
    }
}