n,b = map(int,input().split()) xyp = [] sx = set() sy = set() for _ in range(n): x,y,p = map(int,input().split()) xyp.append((x,y,p)) sx.add(x) sy.add(y) *sx, = sorted(sx) *sy, = sorted(sy) zx = {si:i for i,si in enumerate(sx)} zy = {si:i for i,si in enumerate(sy)} lx = len(sx) ly = len(sy) cnt = [[0]*ly for _ in range(lx)] pts = [[0]*ly for _ in range(lx)] for x,y,p in xyp: cnt[zx[x]][zy[y]] += 1 pts[zx[x]][zy[y]] += p for i in range(lx): for j in range(1,ly): cnt[i][j] += cnt[i][j-1] pts[i][j] += pts[i][j-1] for j in range(ly): for i in range(1,lx): cnt[i][j] += cnt[i-1][j] pts[i][j] += pts[i-1][j] def get_sum(a,h1,h2,w1,w2): #閉長方形 [h1からh2]*[w1からw2] の和 if h1 and w1: return a[h2][w2] - a[h1-1][w2] - a[h2][w1-1] + a[h1-1][w1-1] elif h1: return a[h2][w2] - a[h1-1][w2] elif w1: return a[h2][w2] - a[h2][w1-1] else: return a[h2][w2] ans = 0 for x0 in range(lx): for y0 in range(ly): y1 = ly-1 for x1 in range(x0,lx): while y0 <= y1 and get_sum(pts,x0,x1,y0,y1) > b: y1 -= 1 if y0 > y1: break ans = max(ans,get_sum(cnt,x0,x1,y0,y1)) print(ans)