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>
#pragma GCC target("sse2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int maxn = 1000500;
inline int g() {
  int x;
  cin >> x;
  return x;
}
inline long long gl() {
  long long x;
  cin >> x;
  return x;
}
inline char gc() {
  char x;
  cin >> x;
  return x;
}
inline string gs() {
  string s;
  cin >> s;
  return s;
}
template <typename T>
inline vector<T> gv(int len) {
  vector<T> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<int> gv(int len) {
  vector<int> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<pair<int, int>> gv_andPairCnt(int len) {
  vector<pair<int, int>> a(len);
  int i = 1;
  for (auto &it : a) {
    it.second = i;
    i++;
    cin >> it.first;
  }
  return a;
}
double power_log(double power, double val) { return log(val) / log(power); }
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it : v) os << it << ", ";
  os << "\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &v) {
  os << "deque:{";
  for (auto it : v) os << it << " ";
  os << "}\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "set:{";
  for (auto it : v) os << it << " ";
  os << "}";
  return os;
}
template <typename T, typename T2>
ostream &operator<<(ostream &os, const map<T, T2> &v) {
  os << "map:{\n";
  for (auto it : v) os << "    {" << it.first << " <> " << it.second << "}\n";
  os << "}\n";
  return os;
}
template <typename T, typename T2>
ostream &operator<<(ostream &os, const pair<T, T2> &v) {
  os << "{" << v.first << ", " << v.second << "}";
  return os;
}
template <typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
  vector<pair<T, H>> a(len);
  for (auto &it : a) {
    cin >> it.first >> it.second;
  }
  return a;
}
template <typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
  set<T> s;
  for (auto &it : vec) s.insert(it);
  return s;
}
const long long md = 1e9 + 7;
template <typename T>
class fenwick {
 public:
  vector<T> fenw;
  int n;
  fenwick(int _n) : n(_n) { fenw.resize(n); }
  void modify(int x, T v) {
    while (x < n) {
      fenw[x] += v;
      x |= (x + 1);
    }
  }
  T get(int x) {
    T v{};
    while (x >= 0) {
      v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};
vector<int> arr[maxn];
int n, mxm, price[maxn], sale[maxn];
pair<int, int> path[maxn];
using vii2 = pair<pair<int, bool>, int>;
vector<vii2> dp[maxn], tmp;
const int mx = 5001;
int tmp1[mx][2];
void umin(int &x, int val) {
  if (x == -1) {
    x = val;
  } else
    x = min(x, val);
}
void merge(vector<vii2> &l, vector<vii2> &r, int v, bool safe = false) {
  memset(tmp1, -1, sizeof(tmp1));
  for (auto &it : l) {
    for (auto &it2 : r) {
      if (it.first.second && it2.first.second) {
        if (it.second + it2.second - path[v].second > mxm) {
          continue;
        }
        umin(tmp1[it.first.first + it2.first.first - path[v].first][true],
             it.second + it2.second - path[v].second);
      } else {
        if (safe && it.first.second && !it2.first.second) {
          continue;
        }
        if (it.second + it2.second > mxm) {
          continue;
        }
        umin(tmp1[it.first.first + it2.first.first]
                 [it.first.second || it2.first.second],
             it.second + it2.second);
      }
    }
  }
  for (auto &it : l) {
    umin(tmp1[it.first.first][it.first.second], it.second);
  }
  for (auto &it : r) {
    umin(tmp1[it.first.first][it.first.second], it.second);
  }
  tmp.clear();
  for (int i = 0; i < (mx); ++i)
    for (int j = 0; j < (2); ++j) {
      if (tmp1[i][j] != -1) {
        tmp.push_back({{i, j}, tmp1[i][j]});
      }
    }
}
void rec1(int v, int cnt = 0, int fg = 0) {
  cnt += 1, fg += sale[v];
  if (fg > mxm) {
    cnt += n;
    fg = 0;
  }
  path[v] = make_pair(cnt, fg);
  for (auto &it : arr[v]) {
    rec1(it, cnt, fg);
  }
}
void calc(int v) {
  for (auto &it : arr[v]) {
    calc(it);
  }
  int pos = -1, sz = 0;
  for (auto &it : arr[v]) {
    if (dp[it].size() > sz) {
      pos = it;
      sz = dp[it].size();
    }
  }
  if (pos == -1) {
    dp[v].push_back({{1, 0}, price[v]});
    if (path[v].first <= n)
      dp[v].push_back({{path[v].first, 1}, path[v].second});
  } else {
    swap(dp[v], dp[pos]);
    for (auto &it : arr[v]) {
      if (pos == it) {
        continue;
      }
      merge(dp[v], dp[it], v);
      swap(dp[v], tmp);
    }
    dp[pos].push_back({{1, 0}, price[v]});
    if (path[v].first <= n)
      dp[pos].push_back({{path[v].first, 1}, path[v].second});
    merge(dp[v], dp[pos], v, true);
    swap(dp[v], tmp);
    for (auto &it : arr[v]) {
      dp[it].clear();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  n = g(), mxm = g();
  {
    price[1] = g(), sale[1] = g();
    sale[1] = price[1] - sale[1];
  }
  for (int i = 2; i <= n; i++) {
    price[i] = g(), sale[i] = g();
    sale[i] = price[i] - sale[i];
    int x = g();
    arr[x].push_back(i);
  }
  rec1(1);
  calc(1);
  int ans = 0;
  for (auto &it : dp[1]) {
    if (it.second <= mxm) ans = max(ans, it.first.first);
  }
  cout << ans;
}