Problem:
天体観測
ある晴れた夜の帰り道、空を見上げるとそこには無数の星。強く輝く星々、かすかに見える星々、いろ
いろな明るさの星々が夜空を彩っています。
あなたはふと思いました。この星空に自分の星座があったらどんなに素敵だろうと。そこであなたはひとつの基準を決め、部屋の窓から見える星々を適当につなげて自分の星座を作ることにしました。その基準とは、「どの２つの星を選んでも、それらの明るさの差がある定数
d
以下になるような星のグループを作り、その中で一番大きいものを自分の星座にしよう！」というものです。例えば、図のような窓から見える夜空を考えてみましょう（外側の長方形は窓枠です）。
この夜空には、明るさがそれぞれ 1，12, 2，4，1，8, 3，5，4 の９つの星がありますが、
d
= 2 とすると例えば以下のような３つの星座 A, B, C ができます。
大きさが 12 の星座 A
大きさが 10 の星座 B
大きさが 16 の星座 C
星座の大きさを次のように決めることにしました。ある星座の星をすべて含むような、窓枠に平行な辺からなる長方形のうち、面積が最も小さいものを選びます。この長方形の面積をその星座の大きさとします。例えば、上の夜空では星座 A, B, Cの大きさはそれぞれ12, 10, 16になるので、星座Cが最も大きい星座となります。
N
個の星の位置と明るさ、および整数
d
が与えられたとき、一番大きい星座の面積を求めるプログラムを作成してください。星の位置は窓枠の左下隅を原点とした座標で与えられ、軸は図のような向きとします。星座を構成する星が１つの場合や、星々が軸に平行な直線上にある場合は、その星座の面積は 0 となることに注意してください。
入力
入力は以下の形式で与えられる。
N
d
x
1
y
1
b
1
x
2
y
2
b
2
:
x
N
y
N
b
N
1 行目に星の数
N
(1 ≤
N
≤ 200000) と整数
d
(0 ≤
d
≤ 10
9
) が与えられる。続く
N
行に、
i
番目の星の座標を表す整数
x
i
(0 ≤
x
i
≤ 2000000) と
y
i
(0 ≤
y
i
≤ 2000000)、明るさを表す整数
b
i
(0 ≤
b
i
≤ 10
9
) が与えられる。入力される星の座標はすべて異なる。
出力
一番大きい星座の面積を１行に出力する。
入出力例
入力例
9 2
1 1 1
1 5 12
2 3 2
3 2 4
4 4 1
5 1 3
5 3 8
6 5 5
7 2 4
出力例
16

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
struct Star {
    int x, y, b;
    bool operator<(const Star& other) const {
        return b < other.b;
    }
};
int main() {
    int n, d; cin >> n >> d;
    vector<Star> star(n);
    rep(i, n)cin >> star[i].x >> star[i].y >> star[i].b;
    sort(star.begin(), star.end());
    multiset<ll> x, y;
    int left = 0, right = 0;
    x.insert(star[0].x);
    y.insert(star[0].y);
    ll ans = 0;
    while (left < n) {
        while (right + 1 < n && star[right + 1].b - star[left].b <= d) {
            right++;
            x.insert(star[right].x);
            y.insert(star[right].y);
            //printf("l: %d r: %d\n", left, right);
        }
        chmax(ans, (*prev(x.end()) - *x.begin()) * (*prev(y.end()) - *y.begin()));
        if (right == n - 1)break;
        right++;
        x.insert(star[right].x);
        y.insert(star[right].y);
        while (left < n && star[right].b - star[left].b > d) {
            x.erase(x.find(star[left].x));
            y.erase(y.find(star[left].y));
            left++;
            //printf("l: %d r: %d\n", left, right);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 170
memory_kb: 24436
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<ll, int>;

int main() {
    using star = tuple<int, ll, ll>;
    int N, d;
    cin >> N >> d;
    vector<star> v(N);
    for(int i=0; i<N; ++i) {
        int b;
        ll x, y;
        cin >> x >> y >> b;
        v[i] = make_tuple(b, x, y);
    }
    sort(v.begin(), v.end());

    ll res = 0;
    priority_queue<P> ma_x, ma_y;
    priority_queue<P, vector<P>, greater<P>> mi_x, mi_y;
    int l = 0, r = 0;
    while(true) {
        while(r < N && get<0>(v[r]) - get<0>(v[l]) <= d) {
            ma_x.push(P{get<1>(v[r]), r});
            ma_y.push(P{get<2>(v[r]), r});
            mi_x.push(P{get<1>(v[r]), r});
            mi_y.push(P{get<2>(v[r]), r});
            r++;
        }
        while(!ma_x.empty() && ma_x.top().second < l) {
            ma_x.pop();
        }
        while(!ma_y.empty() && ma_y.top().second < l) {
            ma_y.pop();
        }
        while(!mi_x.empty() && mi_x.top().second < l) {
            mi_x.pop();
        }
        while(!mi_y.empty() && mi_y.top().second < l) {
            mi_y.pop();
        }
        res = max(res, (ma_x.top().first - mi_x.top().first) * (ma_y.top().first - mi_y.top().first));

        if(r == N) {
            break;
        }
        l++;
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 24084
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}


template <class S, auto op, auto e> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
        size = bit_ceil(_n);
        log = countr_zero(size);
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    static int bit_ceil(int x) {
        return 1 << (32 - __builtin_clz(x - 1));
    }

    static int countr_zero(int x) {
        return __builtin_ctz(x);
    }
};

using S=pair<int,int>;
S op(S a, S b){
    return S{min(a.fi,b.fi),max(a.se,b.se)};
}
S e(){
    return S{(int)2e9, (int)-2e9};
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N,D;
    cin>>N>>D;
    vector<array<int,3>> A(N);
    rep(i,N)rep(j,3)cin>>A[i][(j+1)%3];
    sort(all(A));

    segtree<S,op,e> segy(N),segx(N);
    rep(i,N) segy.set(i, {A[i][1], A[i][1]});
    rep(i,N) segx.set(i, {A[i][2], A[i][2]});

    long ans=0;
    rep(l,N){
        int r=lower_bound(all(A), array<int,3>{A[l][0]+D+1,-1,-1})-A.begin();
        S sy=segy.prod(l,r);
        S sx=segx.prod(l,r);
        chmax(ans, 1l*(sy.se-sy.fi)*(sx.se-sx.fi));
    }
    cout<<ans<<"\n";


}
accuracy: 1
time_ms: 60
memory_kb: 15480
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i=0;i<N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

class segtree{
    public:
    int size=1;
    vector<ll>data;

    segtree(int N){
        while(size<=N)size*=2;
        data.assign(size*2,0);
    }
    void update(int v,ll x){
        int n = v + size;
        data[n]=x;
        while(n>=2){
            n/=2;
            data[n] = max(data[2*n],data[2*n+1]);
        }
        return;
    }
    ll imax(int l,int r,int a,int b,int u){
        if(r<=a||b<=l)return 0;
        if(l<=a&&b<=r)return data[u];
        int m = (a+b)/2;
        ll L = imax(l,r,a,m,u*2);
        ll R = imax(l,r,m,b,u*2+1);
        return max(L,R);
    }
    ll Max(int l,int r){return imax(l,r,0,size,1);}
};

class segtree2{
    public:
    int size=1;
    vector<ll>data;

    segtree2(int N){
        while(size<=N)size*=2;
        data.assign(size*2,998244353);
    }
    void update(int v,ll x){
        int n = v + size;
        data[n]=x;
        while(n>=2){
            n/=2;
            data[n] = min(data[2*n],data[2*n+1]);
        }
        return;
    }
    ll imin(int l,int r,int a,int b,int u){
        if(r<=a||b<=l)return 998244353;
        if(a>=l&&r>=b)return data[u];
        int m = (a+b)/2;
        ll L = imin(l,r,a,m,u*2);
        ll R = imin(l,r,m,b,u*2+1);
        return min(L,R);
    }
    ll Min(int l,int r){return imin(l,r,0,size,1);}
};

int main(){
    ll N,d;cin>>N>>d;
    vector<pair<ll,pair<ll,ll>>>star(N);
    rep(i,N)cin>>star[i].se.fi>>star[i].se.se>>star[i].fi;
    sort(all(star));
    segtree xM(N),yM(N);
    segtree2 xm(N),ym(N);
    rep(i,N){
        xM.update(i,star[i].se.fi);
        xm.update(i,star[i].se.fi);
        yM.update(i,star[i].se.se);
        ym.update(i,star[i].se.se);
    }
    ll ans = 0;
    rep(i,N){
        ll tar = star[i].fi+d;
        int idx = lower_bound(all(star),make_pair(tar+1,make_pair(-1LL,-1LL)))-star.begin();
        ll x = xM.Max(i,idx)-xm.Min(i,idx);
        ll y = yM.Max(i,idx)-ym.Min(i,idx);
        // cout<<xM.Max(i,idx)<<xm.Min(i,idx)<<yM.Max(i,idx)<<ym.Min(i,idx)<<endl;
        ans = max(ans,x*y);
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 220
memory_kb: 24116
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s ; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl
#define SZ(a) (int)a.size()
using LL = long long; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>;
const LL LINF = 1e18;
struct nd {
	long long x1, y1, x2, y2;

	nd(LL x1 = LINF, LL x2 = -LINF, LL y1 = LINF, LL y2 = -LINF) :x1(x1), x2(x2), y1(y1), y2(y2) {} // ! e
};
struct SegmentTreeFastAry {
	nd merge(nd& l, nd& r) {
		nd ret;
		ret.x1 = min(l.x1, r.x1);
		ret.x2 = max(l.x2, r.x2);
		ret.y1 = min(l.y1, r.y1);
		ret.y2 = max(l.y2, r.y2);
		return ret;
	}
	void updatepoint(nd& node,nd& nx) { // point update 
		node = merge(node, nx);
	}
	// -- setting -- // 
	int ARY_SIZE; nd node[1 << 20]; // 131072
	void init(int n) { ARY_SIZE = 1; while (ARY_SIZE < n) ARY_SIZE <<= 1; }
	SegmentTreeFastAry(int n) : ARY_SIZE(1) { init(n); }
	inline void update(int i, nd& val) {
		i += ARY_SIZE; updatepoint(node[i], val);
		while (i > 1) { i >>= 1;	node[i] = merge(node[i << 1], node[(i << 1) + 1]); }
	}
	inline nd query(int l, int r) {
		if (l >= r) return nd(); nd vl = nd(), vr = nd();
		for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
			if (l & 1) vl = merge(vl, node[l++]); if (r & 1) vr = merge(node[--r], vr);
		}	return merge(vl, vr);
	}
	nd operator[](int i) { return node[i + ARY_SIZE]; }
	//	void debugShow() { for (int i = ARY_SIZE; i < ARY_SIZE << 1; ++i) cerr << node[i].v << " "; cerr << "\n"; }
};

// submit前にnodesizeを変えること
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, D;
	cin >> N >> D;
	V<int>x(N), y(N), b(N * 3);

	FOR(i, 0, N) {
		cin >> x[i] >> y[i] >> b[i];
		b[i + N] = b[i] - D;
		b[i + 2 * N] = b[i] + D;
	}
	V<int>bc = b;
	SORT(bc); UNIQ(bc);
	V<int>bindex(3 * N);
	FOR(i, 0, 3*N) {
		bindex[i] = lower_bound(ALL(bc), b[i]) - bc.begin();
	}

	SegmentTreeFastAry seg(SZ(bc));
	FOR(i, 0, N) {
		nd renew(x[i], x[i], y[i], y[i]);
		seg.update(bindex[i] , renew);
	}
	LL ans = 0;
	FOR(i, 0, N) {
		{
			nd getnd = seg.query(bindex[i + N], bindex[i] + 1);
			LL square = (getnd.x2 - getnd.x1)*(getnd.y2 - getnd.y1);
			ans = max(ans, square);
		}
		{
			nd getnd = seg.query(bindex[i], bindex[i + 2 * N] + 1);
			LL square = (getnd.x2 - getnd.x1)*(getnd.y2 - getnd.y1);
			ans = max(ans, square);
		}
	}
	cout << ans << endl;

	return 0;
}
accuracy: 0.5151515151515151
time_ms: 270
memory_kb: 44388
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int N, d;
  cin >> N >> d;
  vector<array<int, 3>> p(N);
  for(int i = 0; i < N; i++) {
    cin >> p[i][0] >> p[i][1] >> p[i][2];
  }
  sort(p.begin(), p.end(), [](auto x, auto y){ return x[2] < y[2]; });
  long long ans = 0;
  multiset<int> X, Y;
  for(int i = 0, j = 0; j < N; j++) {
    while(i < j && p[j][2]-p[i][2] > d) {
      X.erase(X.find(p[i][0]));
      Y.erase(Y.find(p[i][1]));
      i++;
    }
    X.insert(p[j][0]);
    Y.insert(p[j][1]);
    long long xmin = *X.begin();
    long long xmax = *X.rbegin();
    long long ymin = *Y.begin();
    long long ymax = *Y.rbegin();
    ans = max(ans, (xmax-xmin)*(ymax-ymin));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 24020
final_rank: 17

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n, -inf);
    Min.resize(2 * n, inf);
  }
  void update(int idx, int val, bool isMax) {
    idx += n - 1;
    if (isMax)
      Max[idx] = val;
    else
      Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      if (isMax)
        Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
      else
        Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  int get(int a, int b, bool isMax, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return isMax ? -inf : inf;
    if (a <= l && r <= b)
      return isMax ? Max[k] : Min[k];
    int vl = get(a, b, isMax, k * 2 + 1, l, (l + r) / 2);
    int vr = get(a, b, isMax, k * 2 + 2, (l + r) / 2, r);
    return isMax ? max(vl, vr) : min(vl, vr);
  }
};

int X[200020], Y[200020];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  for (int i = 0; i < N; ++i) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.push_back(pii(b, i));
  }
  sort(hoge.begin(), hoge.end());
  for (int i = 0; i < N; ++i) {
    x_seg.update(i, X[hoge[i].second], false);
    x_seg.update(i, X[hoge[i].second], true);
    y_seg.update(i, Y[hoge[i].second], false);
    y_seg.update(i, Y[hoge[i].second], true);
  }
  ll ans = -inf;
  for (int i = 0; i < N; ++i) {
    int b = hoge[i].first;
    int idx = upper_bound(hoge.begin(), hoge.end(), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get(i, idx, false);
    int max_x = x_seg.get(i, idx, true);
    int min_y = y_seg.get(i, idx, false);
    int max_y = y_seg.get(i, idx, true);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 14444
final_rank: 12

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n, -inf);
    Min.resize(2 * n, inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};

int X[200020], Y[200020];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  hoge.reserve(N);
  for (int i = 0; i < N; ++i) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.push_back(pii(b, i));
  }
  sort(hoge.begin(), hoge.end());
  for (int i = 0; i < N; ++i) {
    x_seg.min_update(i, X[hoge[i].second]);
    x_seg.max_update(i, X[hoge[i].second]);
    y_seg.min_update(i, Y[hoge[i].second]);
    y_seg.max_update(i, Y[hoge[i].second]);
  }
  ll ans = -inf;
  int prev_idx = -1, min_x, max_x, min_y, max_y;
  for (int i = 0; i < N; ++i) {
    int b = hoge[i].first;
    int idx = upper_bound(hoge.begin(), hoge.end(), pii(b + d, inf)) - hoge.begin();
    if (idx != prev_idx) {
      min_x = x_seg.get_min(i, idx);
      max_x = x_seg.get_max(i, idx);
      min_y = y_seg.get_min(i, idx);
      max_y = y_seg.get_max(i, idx);
      prev_idx = idx;
    }
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 14184
final_rank: 3

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; ++i) {
      Max[i] = -inf;
      Min[i] = inf;
    }
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    if (i > 0 && hoge[i].fst == hoge[i - 1].fst)
      continue;
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 170
memory_kb: 14436
final_rank: 4

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; ++i) {
      Max[i] = -inf;
      Min[i] = inf;
    }
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14440
final_rank: 6

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Max), -inf);
    fill(all(Min), inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
const int MAXN = 200020;
int X[MAXN], Y[MAXN];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14452
final_rank: 10

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
  }
  void min_update(int idx, int val) {
    idx += n;
    Min[idx] = val;
    while (idx > 1) {
      idx >>= 1;
      Min[idx] = min(Min[idx << 1], Min[(idx << 1) | 1]);
    }
  }
  void max_update(int idx, int val) {
    idx += n;
    Max[idx] = val;
    while (idx > 1) {
      idx >>= 1;
      Max[idx] = max(Max[idx << 1], Max[(idx << 1) | 1]);
    }
  }
  int get_min(int a, int b) {
    int res = inf;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1)
        chmin(res, Min[a++]);
      if (b & 1)
        chmin(res, Min[--b]);
    }
    return res;
  }
  int get_max(int a, int b) {
    int res = -inf;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1)
        chmax(res, Max[a++]);
      if (b & 1)
        chmax(res, Max[--b]);
    }
    return res;
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 14396
final_rank: 2

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Max), -inf);
    fill(all(Min), inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    int idx = hoge[i].scd;
    x_seg.min_update(i, X[idx]);
    x_seg.max_update(i, X[idx]);
    y_seg.min_update(i, Y[idx]);
    y_seg.max_update(i, Y[idx]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14408
final_rank: 5

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Min), inf);
    fill(all(Max), -inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14440
final_rank: 6

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Min), inf);
    fill(all(Max), -inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14440
final_rank: 6

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Max), -inf);
    fill(all(Min), inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14452
final_rank: 10

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    fill(all(Max),-inf);
    fill(all(Min),inf);
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  vector<int> minx(N),maxx(N),miny(N),maxy(N);
  rep(i, N) {
    minx[hoge[i].scd]=X[hoge[i].scd];
    maxx[hoge[i].scd]=X[hoge[i].scd];
    miny[hoge[i].scd]=Y[hoge[i].scd];
    maxy[hoge[i].scd]=Y[hoge[i].scd];
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 17356
final_rank: 13

code_snippet: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai                                                               \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define rep1(i, x) for (int i = 1; i <= (int)(x); ++i)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename T> T &max(T &a, T &b) {
  if (a >= b)
    return a;
  return b;
}
template <typename T> T &min(T &a, T &b) {
  if (a < b)
    return a;
  return b;
}
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T> T rev(T a) {
  reverse(all(a));
  return a;
}
template <typename T> vector<T> &sort(vector<T> &a) {
  sort(all(a));
  return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
struct SegTree {
  int n;
  vector<int> Max;
  vector<int> Min;
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    Max.resize(2 * n);
    Min.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; ++i) {
      Max[i] = -inf;
      Min[i] = inf;
    }
  }
  void min_update(int idx, int val) {
    idx += n - 1;
    Min[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
    }
  }
  void max_update(int idx, int val) {
    idx += n - 1;
    Max[idx] = val;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
    }
  }
  int get_min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return inf;
    if (a <= l && r <= b)
      return Min[k];
    int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return Max[k];
    int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
int X[200020], Y[200020];
signed main() {
  omajinai;
  omajinai;
  int N, d;
  cin >> N >> d;
  SegTree x_seg, y_seg;
  x_seg.init(N), y_seg.init(N);
  vpii hoge;
  rep(i, N) {
    int x, y, b;
    cin >> x >> y >> b;
    X[i] = x, Y[i] = y;
    hoge.PB(pii(b, i));
  }
  sort(all(hoge));
  rep(i, N) {
    x_seg.min_update(i, X[hoge[i].scd]);
    x_seg.max_update(i, X[hoge[i].scd]);
    y_seg.min_update(i, Y[hoge[i].scd]);
    y_seg.max_update(i, Y[hoge[i].scd]);
  }
  ll ans = -inf;
  rep(i, N) {
    int b = hoge[i].fst;
    int idx = upper_bound(all(hoge), pii(b + d, inf)) - hoge.begin();
    int min_x = x_seg.get_min(i, idx);
    int max_x = x_seg.get_max(i, idx);
    int min_y = y_seg.get_min(i, idx);
    int max_y = y_seg.get_max(i, idx);
    ans = max(ans, 1ll * (max_x - min_x) * (max_y - min_y));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 14440
final_rank: 6