using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public int b { get; set; }
}
public class rmq
{
    private readonly int INTMAX = int.MaxValue;
    private int[] dat;
    private static int size;

    public rmq(int n)
    {
        size = 1;
        while (size < n) size *= 2;
        dat = Enumerable.Repeat(INTMAX, 2 * size - 1).ToArray();
    }

    public void update(int i, int a)
    {
        i += size - 1;
        dat[i] = a;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = Min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    private int query(int a, int b, int k, int L, int r)
    {
        if (r <= a || b <= L) return INTMAX;
        if (a <= L && r <= b) return dat[k];
        else
        {
            int vL = query(a, b, k * 2 + 1, L, (L + r) / 2);
            int vr = query(a, b, k * 2 + 2, (L + r) / 2, r);
            return Min(vL, vr);
        }
    }

    public int query(int a, int b) => query(a, b, 0, 0, size);

}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            ps[i] = new P { x = int.Parse(line[0]), y = int.Parse(line[1]), b = int.Parse(line[2]) };
        }
        ps = ps.OrderBy(x => x.b).ToArray();
        getAns(n, d, ps);
    }
    static void getAns(int n, int d, P[] ps)
    {
        var res = 0L;
        var rminx = new rmq(n);
        var rmaxx = new rmq(n);
        var rminy = new rmq(n);
        var rmaxy = new rmq(n);

        var ps2 = new int[n];
        for (int i = 0; i < n; i++)
        {
            ps2[i] = ps[i].b;
            rminx.update(i, ps[i].x);
            rmaxx.update(i, -ps[i].x);
            rminy.update(i, ps[i].y);
            rmaxy.update(i, -ps[i].y);
        }
        var pre = -1;
        var pretr = -1;
        for (int i = 0; i < n - 1; i++)
        {
            var t = ps2[i];
            if (t != pre)
            {
                var tmax = t + d;
                var tr = UpperBound(ps2, tmax);
                if (tr != pretr && tr - i >= 2)
                {
                    var xmin = rminx.query(i, tr);
                    var xmax = -rmaxx.query(i, tr);
                    var ymin = rminy.query(i, tr);
                    var ymax = -rmaxy.query(i, tr);
                    res = Max(res, (long)(xmax - xmin) * (ymax - ymin));
                }
                pretr = tr;
            }
            pre = ps2[i];
        }
        Console.WriteLine(res);


    }
    static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) <= 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    static int UpperBound<T>(T[] arr, T value)
    {
        return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}



Measured memory_bytes: 52080