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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;

public class c3 implements Runnable {

	static long[][][] memo;
	static long[] cs, ds;
	static ArrayList<Integer>[] adjs;
	static int n;
	static long oo = 1000000000000000L;
	static int[] counts;
	
	public static void main(String[] args) {
		new Thread(null, new c3(), "c", 1L << 28).start();
	}
	public void run() {
		try {
			FastScanner in = new FastScanner(System.in);
			n = in.nextInt();
			long b = in.nextLong();
			memo = new long[2][n][];
			cs = new long[n];
			ds = new long[n];
			adjs = new ArrayList[n];
			for (int i = 0; i < n; i++)
				adjs[i] = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				cs[i] = in.nextLong();
				ds[i] = in.nextLong();
				if (i > 0) {
					int x = in.nextInt() - 1;
					adjs[x].add(i);
				}
			}
			counts = new int[n];
			getCount(0);
			long[] tmp = go(1, 0);
			int ans = 0;
			for (int i = 0; i < tmp.length; i++) {
				if (tmp[i] <= b) ans = i;
			}
			System.out.println(ans);
		} catch (Throwable t) {
			t.printStackTrace();
			System.exit(-1);
		}
	}
	
	static int getCount(int cur) {
		int ans = 1;
		for (int next : adjs[cur])
			ans += getCount(next);
		return counts[cur] = ans;
	}
	
	static long[] go(int coupon, int cur) {
		if (memo[coupon][cur] != null) return memo[coupon][cur];
		int m = counts[cur];
		long[] ans = new long[m + 1];
		Arrays.fill(ans, oo);
		ans[0] = 0;
		// buy it =)
		{
			long cost = cs[cur] - (ds[cur] * coupon);
			ArrayList<List> pq = new ArrayList<>(m + 1);
			pq.add(new List(new long[]{0}));
			for (int next : adjs[cur]) {
				long[] tmp = go(coupon, next);
				pq.add(new List(tmp));
			}
			Collections.sort(pq);
			List big = pq.get(pq.size() - 1);
			for (int i = 0; i < pq.size() - 1; i++)
				big = combine(pq.get(i), big);
			for (int i = 0; i < big.n; i++) {
				ans[i + 1] = big.arr[i] + cost;
			}
		}
		// don't buy
		{
			ArrayList<List> pq = new ArrayList<>(m + 1);
			pq.add(new List(new long[]{0}));
			for (int next : adjs[cur]) {
				long[] tmp = go(0, next);
				pq.add(new List(tmp));
			}
			Collections.sort(pq);
			List big = pq.get(pq.size() - 1);
			for (int i = 0; i < pq.size() - 1; i++)
				big = combine(pq.get(i), big);
			for (int i = 0; i < big.n; i++) {
				ans[i] = Math.min(ans[i], big.arr[i]);
			}
		}
		//System.out.printf("(%d, %d): %s\n", coupon, cur, Arrays.toString(ans));
		return memo[coupon][cur] = ans;
	}
	
	static List combine(List a, List b) {
		long[] res = new long[a.n + b.n - 1];
		Arrays.fill(res, oo);
		res[0] = 0;
		for (int i = 0; i < a.n; i++) {
			for (int j = 0; j < b.n; j++) {
				res[i + j] = Math.min(res[i + j], a.arr[i] + b.arr[j]);
			}
		}
		return new List(res);
	}
	
	static class List implements Comparable<List> {
		long[] arr;
		int n;
		public List(long[] arrr) {
			arr = arrr;
			n = arr.length;
		}
		public int compareTo(List l) {
			return Integer.compare(n, l.n);
		}
	}
	
	//@
	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;
		
	    public FastScanner(InputStream i) {
	        br = new BufferedReader(new InputStreamReader(i));
	        st = new StringTokenizer("");
	    }
				
	    public String next() throws IOException {
	        if(st.hasMoreTokens())
	            return st.nextToken();
	        else
	            st = new StringTokenizer(br.readLine());
	        return next();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    //#
	    public long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    public double nextDouble() throws IOException {
	        return Double.parseDouble(next());
	    }
	    //$
	}
	static class ArrayUtils {
		static Random rand = new Random();
		public static void sort(byte[] arr) {
			int n = arr.length;
			for (int i = 0; i < n; i++) {
				int x = rand.nextInt(n);
				byte tmp = arr[x];
				arr[x] = arr[i];
				arr[i] = tmp;
			}
			Arrays.sort(arr);
		}
		public static void sort(int[] arr) {
			int n = arr.length;
			for (int i = 0; i < n; i++) {
				int x = rand.nextInt(n);
				int tmp = arr[x];
				arr[x] = arr[i];
				arr[i] = tmp;
			}
			Arrays.sort(arr);
		}
		public static void sort(long[] arr) {
			int n = arr.length;
			for (int i = 0; i < n; i++) {
				int x = rand.nextInt(n);
				long tmp = arr[x];
				arr[x] = arr[i];
				arr[i] = tmp;
			}
			Arrays.sort(arr);
		}
		public static void sort(double[] arr) {
			int n = arr.length;
			for (int i = 0; i < n; i++) {
				int x = rand.nextInt(n);
				double tmp = arr[x];
				arr[x] = arr[i];
				arr[i] = tmp;
			}
			Arrays.sort(arr);
		}
	}
}