import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split; auto n = rd[0].to!size_t, b = rd[1].to!int; auto pi = iota(n).map!(_ => readln.split.map!(to!int)).array; auto xi = pi.map!("a[0]").array; auto hx = compressMap(xi); auto w = hx.length; auto yi = pi.map!("a[1]").array; auto hy = compressMap(yi); auto h = hy.length; auto cij = new int[][](h, w); auto qij = new int[][](h, w); foreach (p; pi) { cij[hy[p[1]]][hx[p[0]]] = 1; qij[hy[p[1]]][hx[p[0]]] = p[2]; } foreach (i; 0..h) foreach (j; 1..w) { cij[i][j] += cij[i][j - 1]; qij[i][j] += qij[i][j - 1]; } auto maxC = 0; foreach (i; 0..w) foreach (j; i..w) { auto ci = iota(h).map!(k => cij[k][j] - (i == 0 ? 0 : cij[k][i - 1])); auto qi = iota(h).map!(k => qij[k][j] - (i == 0 ? 0 : qij[k][i - 1])); auto k = 0, l = 0, sumC = 0, sumQ = 0; while (true) { ++l; if (l > h) break; sumC += ci[l - 1]; sumQ += qi[l - 1]; if (sumQ <= b) maxC = max(maxC, sumC); while (sumQ > b) { ++k; sumC -= ci[k - 1]; sumQ -= qi[k - 1]; } } } writeln(maxC); } int[int] compressMap(int[] pi) { pi = pi.sort().array.uniq().array; int[int] h; foreach (i, p; pi) h[p] = i.to!int; return h; }