#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _MSC_VER #include #endif #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define REV(v) v.rbegin(), v.rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end()) #define MP make_pair #define MT make_tuple using namespace std; typedef long long ll; typedef long double ld; typedef pair P; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); int n, b; cin >> n >> b; vector x(n), y(n), p(n); vector> v(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; rep(i, n) v[i] = MT(x[i], y[i], p[i]); sort(ALL(v)); rep(i, n){ tie(x[i], y[i], p[i]) = v[i]; } int ans = 0; rep(i, n) rep(j, n){ int y1 = y[i], y2 = y[j]; if (y1 > y2) continue; int l = 0, r = 0; int sum = 0, cnt = 0; int lastl = -1, lastr = -1; while (1){ while (r < n && sum <= b){ if (sum <= b) ans = max(ans, cnt); lastr = r; while (r < n && x[lastr] == x[r]){ if (y1 <= y[r] && y[r] <= y2){ ++cnt; sum += p[r]; } ++r; } } if (sum <= b) ans = max(ans, cnt); if (l >= r) break; lastl = l; while (l < n && x[lastl] == x[l]){ if (y1 <= y[l] && y[l] <= y2){ --cnt; sum -= p[l]; } ++l; } if (sum <= b) ans = max(ans, cnt); } } cout << ans << endl; }