#include using namespace std; struct Point { int x; int y; int p; }; int score[410][410], cnt[410][410]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, b; cin >> n >> b; vector ps(n); vector vx(n), vy(n); for (int i = 0; i < n; i++) { cin >> ps[i].x >> ps[i].y >> ps[i].p; vx[i] = ps[i].x; vy[i] = ps[i].y; } sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); vx.erase(unique(vx.begin(), vx.end()), vx.end()); vy.erase(unique(vy.begin(), vy.end()), vy.end()); map X, Y; for (int i = 0; i < vx.size(); i++) X[vx[i]] = i; for (int i = 0; i < vy.size(); i++) Y[vy[i]] = i; for (int i = 0; i < n; i++) { score[X[ps[i].x] + 1][Y[ps[i].y] + 1] += ps[i].p; cnt[X[ps[i].x] + 1][Y[ps[i].y] + 1]++; } for (int i = 1; i <= 400; i++) { for (int j = 0; j <= 400; j++) { score[i][j] += score[i - 1][j]; cnt[i][j] += cnt[i - 1][j]; } } for (int i = 0; i <= 400; i++) { for (int j = 1; j <= 400; j++) { score[i][j] += score[i][j - 1]; cnt[i][j] += cnt[i][j - 1]; } } int ans = 0; for (int x1 = 0; x1 < n; x1++) { for (int x2 = x1; x2 < n; x2++) { for (int y1 = 0, y2 = 0; y2 < n; y2++) { while (y1 <= y2) { int tmp_score = score[x2 + 1][y2 + 1] - score[x2 + 1][y1] - score[x1][y2 + 1] + score[x1][y1]; int tmp_cnt = cnt[x2 + 1][y2 + 1] - cnt[x2 + 1][y1] - cnt[x1][y2 + 1] + cnt[x1][y1]; if (tmp_score <= b) { ans = max(ans, tmp_cnt); break; } y1++; } } } } cout << ans << endl; return 0; }