#include #define REP(i, x, n) for(int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F first #define S second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; int main() { // ios_base::sync_with_stdio(false); int N, B; cin >> N >> B; vector> p1, p2; rep(i, N) { int x, y, p; cin >> x >> y >> p; p1.push_back(mp(mp(x, y), p)); p2.push_back(mp(mp(y, x), p)); } sort(all(p1)); sort(all(p2)); int ans = 0; rep(i, N) REP(j, i, N) { int l = p1[i].F.F - 1; int r = p1[j].F.F + 1; int b = 0; vector> vp; rep(k, N) { if(p2[k].F.S <= l || r <= p2[k].F.S) continue; int tmp = p2[k].F.F; while(k < N && tmp == p2[k].F.F) { if(l < p2[k].F.S && p2[k].F.S < r) { vp.push_back(p2[k]); b += p2[k].S; } k++; } if(b > B) { while(1) { tmp = vp.front().F.F; while(vp.size() && tmp == vp.front().F.F) { b -= vp.front().S; vp.erase(vp.begin()); } if(b <= B) break; } } ans = max(ans, (int)vp.size()); k--; } } cout << ans << endl; return 0; }