import java.io.*; import java.util.*; public class Main_yukicoder165_1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int b = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; int[] p = new int[n]; SortedSet tsx = new TreeSet(); SortedSet tsy = new TreeSet(); int m = 0; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); p[i] = sc.nextInt(); tsx.add(x[i]); tsy.add(y[i]); m++; } if (m == 0) { pr.println(0); pr.close(); sc.close(); return; } Map hmx = new HashMap<>(); Map hmy = new HashMap<>(); int ix = 1; for (int e : tsx) { hmx.put(e, ix++); } int iy = 1; for (int e : tsy) { hmy.put(e, iy++); } int cx = tsx.size(); int cy = tsy.size(); int[][] xy = new int[cx + 1][cy + 1]; int[][] xyc = new int[cx + 1][cy + 1]; for (int i = 0; i < n; i++) { xy[hmx.get(x[i])][hmy.get(y[i])] = p[i]; xyc[hmx.get(x[i])][hmy.get(y[i])] = 1; } for (int i = 1; i <= cy; i++) { for (int j = 1; j <= cx; j++) { xy[j][i] += xy[j - 1][i]; xyc[j][i] += xyc[j - 1][i]; } } for (int j = 1; j <= cx; j++) { for (int i = 1; i <= cy; i++) { xy[j][i] += xy[j][i - 1]; xyc[j][i] += xyc[j][i - 1]; } } // pr.printf("%d %d\n", cx, cy); int max = 0; for (int x1 = 0; x1 <= cx; x1++) { for (int y1 = 0; y1 <= cy; y1++) { int x2 = x1; for (int ny2 = y1; ny2 <= cy; ny2++) { int point = xy[x2][ny2] - xy[x2][y1] - xy[x1][ny2] + xy[x1][y1]; int l = x2 - 1; int r = cx + 1; while (r - l > 1) { int mid = l + (r - l) / 2; point = xy[mid][ny2] - xy[mid][y1] - xy[x1][ny2] + xy[x1][y1]; if (point > b) { // if (data[mid] > value) { r = mid; } else { l = mid; } } int cnt = xyc[r - 1][ny2] - xyc[r - 1][y1] - xyc[x1][ny2] + xyc[x1][y1]; max = Math.max(max, cnt); } } } pr.println(max); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }