#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; using ii = pair; map compX, compY, extX, extY; map point; vvi board, boardp; // all inclusive i64 pointsum(int i0, int i1, int j0, int j1) { i0++; i1++; j0++; j1++; return board[i1][j1] - board[i1][j0 - 1] - board[i0 - 1][j1] + board[i0 - 1][j0 - 1]; } i64 pointnum(int i0, int i1, int j0, int j1) { i0++; i1++; j0++; j1++; return boardp[i1][j1] - boardp[i1][j0 - 1] - boardp[i0 - 1][j1] + boardp[i0 - 1][j0 - 1]; } int main() { int n, b; cin >> n >> b; for (int i = 0; i < n; i++) { i64 x, y, p; cin >> x >> y >> p; compX[x] = compY[y] = 0; point[ii(x, y)] = p; } int k = 0; for (auto& p: compX) { p.second = k++; extX[p.second] = p.first; } k = 0; for (auto& p: compY) { p.second = k++; extY[p.second] = p.first; } int X = compX.size(), Y = compY.size(); board = vvi(X + 1, vi(Y + 1)); boardp = vvi(X + 1, vi(Y + 1)); for (int i = 0; i < X; i++) { for (int j = 0; j < Y; j++) { board[i + 1][j + 1] = point[ii(extX[i], extY[j])]; boardp[i + 1][j + 1] = point[ii(extX[i], extY[j])] > 0; } } for (int i = 0; i <= X; i++) { for (int j = 0; j < Y; j++) { board[i][j + 1] += board[i][j]; boardp[i][j + 1] += boardp[i][j]; } } for (int j = 0; j <= Y; j++) { for (int i = 0; i < X; i++) { board[i + 1][j] += board[i][j]; boardp[i + 1][j] += boardp[i][j]; } } i64 ans = 0; for (int i = 0; i < X; i++) { for (int j = i; j < X; j++) { i64 sum = 0; int l = 0, r = 0; while (1) { if (sum <= b) { sum += pointsum(i, j, r, r); if (sum <= b) { ans = max(ans, pointnum(i, j, l, r)); } r++; if (r == Y) { break; } } if (sum > b) { sum -= pointsum(i, j, l, l); l++; } } } } cout << ans << endl; }