/*
 * 0302.cc: Star Watching
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

const int INF = 1 << 30;

/* typedef */

typedef long long ll;

template <typename T, const int BUFSIZE>
struct Treap {
  struct Node {
    T key, minkey, maxkey;
    int fix, size, cnt;
    Node *left, *right;

    void print(int k) {
      printf("%d: key=%lld, minkey=%lld, maxkey=%lld, fix=%d, size=%d\n",
	     k, key, minkey, maxkey, fix, size);
    }
    void print() { print(0); }
  };
  typedef Node *node;

  node root, nullnode, buf;
  Node buf0[BUFSIZE], buf1;

  const T TINF;
  
  Treap(T tinf): TINF(tinf) {
    nullnode = &buf1;
    nullnode->left = nullnode->right = nullnode;
    nullnode->key = nullnode->minkey = TINF;
    nullnode->maxkey = 0;
    nullnode->fix = nullnode->size = nullnode->cnt = 0;
    clear();
    srand(time(NULL));
  }

  void clear() { buf = buf0; root = nullnode; }
  
  int size() { return root->size; }

  void update(node& t) {
    t->size = 1 + t->left->size + t->right->size;
    t->minkey = t->maxkey = t->key;
    if (t->minkey > t->left->minkey) t->minkey = t->left->minkey;
    if (t->minkey > t->right->minkey) t->minkey = t->right->minkey;
    if (t->maxkey < t->left->maxkey) t->maxkey = t->left->maxkey;
    if (t->maxkey < t->right->maxkey) t->maxkey = t->right->maxkey;
  }

  node gen_node(T x) {
    node t = buf++;
    t->left = t->right = nullnode;
    t->key = t->minkey = t->maxkey = x;
    t->fix = rand();
    t->size = t->cnt = 1;
    return t;
  }
  
  void rot_l(node& k1) {
    node k2 = k1->right;
    k1->right = k2->left;
    k2->left = k1;
    update(k1);
    update(k2);
    k1 = k2;
  }

  void rot_r(node& k1) {
    node k2 = k1->left;
    k1->left = k2->right;
    k2->right = k1;
    update(k1);
    update(k2);
    k1 = k2;
  }

  void insert(node& t, T x) {
    if (t == nullnode)
      t = gen_node(x);
    else {
      if (t->key == x) {
	t->cnt++;
	return;
      }
      if (x < t->key) {
	insert(t->left, x);
	update(t);
	if (t->left->fix > t->fix) rot_r(t);
      }
      else {
	insert(t->right, x);
	update(t);
	if (t->right->fix > t->fix) rot_l(t);
      }
    }
  }
  void insert(T x) { insert(root, x); }

  void remove_node(node& t) {
    if (t == nullnode) return;
    if (t->left == nullnode || t->right == nullnode) {
      if (t->left == nullnode)
	t = t->right;
      else
	t = t->left;
    }
    else {
      if (t->left->fix < t->right->fix) {
	rot_l(t);
	remove_node(t->left);
	update(t);
      }
      else {
	rot_r(t);
	remove_node(t->right);
	update(t);
      }
    }
  }

  void remove(node& t, T x) {
    if (t != nullnode) {
      if (t->key == x) {
	if (--t->cnt <= 0) remove_node(t);
      }
      else if (x < t->key) {
	remove(t->left, x);
	update(t);
      }
      else {
	remove(t->right, x);
	update(t);
      }
    }
  }
  void remove(T x) { remove(root, x); }

  void print(node t, int k, int indent) {
    if (t == nullnode) return;
    if (t != NULL) {
      for (int i = 0; i < indent; i++) cout << "  ";
      t->print(k + t->left->size);
      print(t->left, k, indent + 1);
      print(t->right, k + t->left->size + 1, indent + 1);
    }
  }
  void print() { print(root, 0, 0); }
};

struct Star {
  int x, y, b;
  Star() {}
  Star(int _x, int _y, int _b): x(_x), y(_y), b(_b) {}
  bool operator<(const Star &s) const { return b < s.b; }
  void print() { printf("(%d,%d):%d\n", x, y, b); }
};

/* global variables */

Treap<int,MAX_N> xtrp(INF), ytrp(INF);
Star sts[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, d;
  cin >> n >> d;

  for (int i = 0; i < n; i++)
    cin >> sts[i].x >> sts[i].y >> sts[i].b;
  sort(sts, sts + n);
  //for (int i = 0; i < n; i++) printf("%d: ", i), sts[i].print();
  
  ll maxar = 0;

  for (int i = 0, j = 0; j < n;) {
    int maxb = sts[i].b + d;
    while (j < n && sts[j].b <= maxb) {
      xtrp.insert(sts[j].x);
      ytrp.insert(sts[j].y);
      j++;
    }

    int minx = xtrp.root->minkey;
    int maxx = xtrp.root->maxkey;
    int miny = ytrp.root->minkey;
    int maxy = ytrp.root->maxkey;

    ll ar = (ll)(maxx - minx) * (maxy - miny);
    if (maxar < ar) maxar = ar;
    //printf("i=%d,j=%d: (%d-%d)*(%d-%d) ar=%d\n",
    //i, j, minx, maxx, miny, maxy, ar);

    for (int pb = sts[i].b; i < n && pb == sts[i].b; i++) {
      xtrp.remove(sts[i].x);
      ytrp.remove(sts[i].y);
    }
  }

  printf("%lld\n", maxar);
  return 0;
}

Measured memory_bytes: 19136