# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p,  last, cnt, sum, ans, d[2000][2000], a[600000], b[60000];
string str, ss;
bool f[202000];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost1, cost2; };
vector<Edge>vec[200000];
vector<LL>v;
map<LL, LL>ma;
multiset<LL>st;
struct query {
	LL x, y, d;
};
query q[2000000];
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
map<LL, int> zip;
LL unzip[300000];
int compress(vector<LL> &x) {
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for (int i = 0; i < x.size(); i++) {
		zip[x[i]] = i;
		unzip[i] = x[i];
	}
	return x.size();
}	
struct pos {
	LL max_x = 0, max_y = 0, min_x = INF, min_y = INF;
	pos operator+=(pos p) {
		this->max_x = max(this->max_x, p.max_x);
		this->min_x = min(this->min_x, p.min_x);
		this->max_y = max(this->max_y, p.max_y);
		this->min_y = min(this->min_y, p.min_y);
		return *this;
	}
	pos operator+(pos &p) {
		pos th = *this;
		th.max_x = max(this->max_x, p.max_x);
		th.min_x = min(this->min_x, p.min_x);
		th.max_y = max(this->max_y, p.max_y);
		th.min_y = min(this->min_y, p.min_y);
		return th;
	}
	pos operator+=(Pll& p) {
		this->max_x = max(this->max_x, p.first);
		this->min_x = min(this->min_x, p.first);
		this->max_y = max(this->max_y, p.second);
		this->min_y = min(this->min_y, p.second);
		return *this;
	}
};
pos pos_plus(pos p1, pos p2) {
	pos th;
	th.max_x = max(p1.max_x, p2.max_x);
	th.min_x = min(p1.min_x, p2.min_x);
	th.max_y = max(p1.max_y, p2.max_y);
	th.min_y = min(p1.min_y, p2.min_y);
	return th;
}
struct Seg {
	LL n;

	vector<pos>node;
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
	}
	void update(LL i, Pll p) {
		i = i + n - 1;
		node[i] += p;
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] += node[i * 2 + 1];
			node[i] += node[i * 2 + 2];
		}
	}
	pos find(LL i, LL a, LL b, LL l, LL r) {
		if (b < l || r < a)return pos();
		if (l <= a && b <= r)return node[i];
		return pos_plus(find(i * 2 + 1, a, (a + b) / 2, l, r), find(i * 2 + 2, (a + b + 1) / 2, b, l, r));
	}
};

Seg seg(210000);

int main() {
	cin >> n >> m;

	rep(i, n) {
		LL x, y, z;
		cin >> x >> y >> z;
		q[i] = query{ x,y,z };
		v.push_back(z);
	}
	compress(v);
	rep(i, n) {
		seg.update(zip[q[i].d],Pll(q[i].x,q[i].y));
	}
	LL cur = 0;
	for (auto i = zip.begin(); i != zip.end(); i++,cnt++) {
		while (i->first - unzip[cur] > m &&cur != zip.size() - 1) {
			cur++;
			if (cur == zip.size() - 1)
				break;
		}
		pos ANS= seg.find(0, 0, seg.n - 1,cur ,cnt );
		ans = max(ans, (ANS.max_x - ANS.min_x)*(ANS.max_y-ANS.min_y));
	}
	cout << ans<< endl;
	return 0;
}



Measured memory_bytes: 44156