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

Solution:
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
  if (x < y) x = y;
}
vector<int> t_parent;
vector<int> t_ord;
vector<int> t_left, t_right;
void tree_eulertour(const vector<vector<int> > &g, int root) {
  int n = g.size();
  t_parent.assign(n, -1);
  t_ord.clear();
  t_left.assign(n, -1);
  t_right.assign(n, -1);
  vector<int> stk;
  stk.push_back(root);
  while (!stk.empty()) {
    int i = stk.back();
    stk.pop_back();
    if (i < 0) {
      i = -i - 1;
      t_right[i] = t_ord.size();
      continue;
    }
    t_left[i] = t_ord.size();
    t_ord.push_back(i);
    stk.push_back(-(i + 1));
    for (int j = (int)g[i].size() - 1; j >= 0; j--) {
      int c = g[i][j];
      if (t_parent[c] == -1 && c != root) {
        t_parent[c] = i;
        stk.push_back(c);
      }
    }
  }
}
int main() {
  int n;
  int B;
  while (~scanf("%d%d", &n, &B)) {
    vector<int> cs(n), ds(n);
    vector<vector<int> > g(n);
    for (int(i) = 0; (i) < (int)(n); ++(i)) {
      int c;
      int d;
      scanf("%d%d", &c, &d);
      cs[i] = c, ds[i] = d;
      if (i != 0) {
        int p;
        scanf("%d", &p), --p;
        g[p].push_back(i);
      }
    }
    tree_eulertour(g, 0);
    function<pair<vector<int>, vector<int> >(int, int)> rec =
        [&](int i, int j) -> pair<vector<int>, vector<int> > {
      if (j == g[i].size()) {
        vector<int> v = {INF, cs[i] - ds[i]};
        vector<int> w = {0, INF};
        return make_pair(v, w);
      }
      int c = g[i][j];
      vector<int> A0, A1, B0, B1;
      tie(A0, A1) = rec(c, 0);
      tie(B0, B1) = rec(i, j + 1);
      vector<int> res0(A0.size() + B0.size() - 1, INF);
      vector<int> res1(res0.size(), INF);
      for (int(k) = 0; (k) < (int)((int)res0.size()); ++(k)) {
        int aL = max(0, k - ((int)B0.size() - 1));
        int aR = min((int)A0.size() - 1, k);
        int x0 = INF;
        for (int(a) = (int)(aL); (a) <= (int)(aR); ++(a)) {
          int b = k - a;
          amin(x0, min(A0[a], A1[a]) + B0[b]);
        }
        amin(res0[k], x0);
      }
      if (j == 0) {
        vector<int> sorted(t_right[i] - t_left[i]);
        for (int(k) = 0; (k) < (int)(sorted.size()); ++(k))
          sorted[k] = cs[t_ord[t_left[i] + k]];
        sort(sorted.begin(), sorted.end());
        int sum = 0;
        amin(res1[0], 0);
        for (int(k) = 0; (k) < (int)(sorted.size()); ++(k)) {
          sum += sorted[k];
          if (sum > INF) break;
          amin(res1[k + 1], sum);
        }
      }
      return make_pair(res0, res1);
    };
    vector<int> v, w;
    tie(v, w) = rec(0, 0);
    vector<int> A(v.size());
    for (int(i) = 0; (i) < (int)(v.size()); ++(i)) A[i] = min(v[i], w[i]);
    assert(A.size() == n + 1);
    int ans = 0;
    for (int(k) = 0; (k) < (int)(A.size()); ++(k))
      if (A[k] <= B) amax(ans, k);
    printf("%d\n", ans);
  }
  return 0;
}