#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
pair<ll,pair<ll,ll>> p[ohara];
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------


struct SegmentTree{
    int siz;
    vector<ll> node;
    SegmentTree(int n,ll init){
        siz=1;
        while(siz<n)siz<<=1;
        node.assign(2*siz,init);
    }
 
    void update(int k,ll x){
        k+=siz-1;
        node[k]=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }
 
    ll query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=siz;
        if(r<=a||b<=l)return LINF;
        if(a<=l&&r<=b)return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};


struct SegmentTree2{
    int siz;
    vector<ll> node;
    SegmentTree2(int n,ll init){
        siz=1;
        while(siz<n)siz<<=1;
        node.assign(2*siz,init);
    }
 
    void update(int k,ll x){
        k+=siz-1;
        node[k]=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=max(node[2*k+1],node[2*k+2]);
        }
    }
 
    ll query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=siz;
        if(r<=a||b<=l)return -LINF;
        if(a<=l&&r<=b)return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>d;
    rep(i,n){
        cin>>x>>y>>b;
        p[i]=m_p(b,m_p(x,y));
    }
    SegmentTree xmi(ohara,LINF);
    SegmentTree ymi(ohara,LINF);
    SegmentTree2 xma(ohara,-LINF);
    SegmentTree2 yma(ohara,-LINF);
    sort(p,p+n);
    rep(i,n){
        xmi.update(i,p[i].se.fi);
        xma.update(i,p[i].se.fi);
        ymi.update(i,p[i].se.se);
        yma.update(i,p[i].se.se);
    }
    rep(i,n){
        //cout<<p[i].fi<<" "<<p[i].se.fi<<" "<<p[i].se.se<<"\n";
        ll lle=-1,rri=-1;
        ll le=0,ri=n-1,mid;
        while(ri-le>1){
            mid=(le+ri)/2;
            if(p[mid].fi<=p[i].fi-d)le=mid;
            else ri=mid;
        }
        rrep(j,max(le-5,0LL),min(n,ri+6)){
            if(p[j].fi<p[i].fi-d)continue;
            lle=j;
            break;
        }
        //if(lle==-1)lle=n-1;
        /*
        le=0,ri=n-1,mid;
        while(ri-le>1){
            mid=(le+ri)/2;
            if(p[mid].fi<=p[i].fi+d)le=mid;
            else ri=mid;
        }
        rrrep(j,min(ri+5,n-1),max(0LL,le-5)){
            if(p[j].fi>p[i].fi+d)continue;
            rri=j;
            break;
        }
        */
        //if(rri==-1)rri=0;
        ll xxmi,xxma,yymi,yyma;
        xxmi=xmi.query(lle,i+1);
        xxma=xma.query(lle,i+1);
        yymi=ymi.query(lle,i+1);
        yyma=yma.query(lle,i+1);
        //cout<<xxma<<" "<<xxmi<<" "<<yyma<<" "<<yymi<<"\n";
        cnt=(xxma-xxmi)*(yyma-yymi);
        ans=max(ans,cnt);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 73156