#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ long long N,M; cin>>N>>M; vector x(N),y(N),h(N); rep(i,N){ cin>>x[i]>>y[i]>>h[i]; long long t = x[i]; long long s = y[i]; x[i] = t+s; y[i] = t-s; } vector> a,b,c,d; vector> tx,ty; rep(i,N){ if(h[i]>M)continue; long long rem = M - h[i]; a.emplace_back(-rem,x[i]); b.emplace_back(rem,x[i]); c.emplace_back(-rem,y[i]); d.emplace_back(rem,y[i]); tx.emplace_back(-rem,x[i]); tx.emplace_back(rem,x[i]); ty.emplace_back(-rem,y[i]); ty.emplace_back(rem,y[i]); } sort(tx.begin(),tx.end(),[&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } }); sort(ty.begin(),ty.end(),[&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } }); { vector> t; rep(i,tx.size()){ if(t.size()==0 || t.back()!=tx[i])t.push_back(tx[i]); } tx = t; } { vector> t; rep(i,ty.size()){ if(t.size()==0 || t.back()!=ty[i])t.push_back(ty[i]); } ty = t; } vector imos(tx.size()+1,vector(ty.size()+1)); rep(i,a.size()){ int aa = distance(tx.begin(),lower_bound(tx.begin(),tx.end(),a[i], [&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } })); int bb = distance(tx.begin(),lower_bound(tx.begin(),tx.end(),b[i], [&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } })); int cc = distance(ty.begin(),lower_bound(ty.begin(),ty.end(),c[i], [&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } })); int dd = distance(ty.begin(),lower_bound(ty.begin(),ty.end(),d[i], [&](pair x,pair y){ long long A = x.first-y.first; long long B = y.second-x.second; if(A*B<=0)return A0){ return A*A < B*B * 2LL; } else{ return A*A > B*B * 2LL; } })); imos[aa][cc]++; imos[aa][dd]--; imos[bb][cc]--; imos[bb][dd]++; } rep(i,tx.size()){ rep(j,ty.size()+1)imos[i+1][j] += imos[i][j]; } rep(i,tx.size()+1){ rep(j,ty.size())imos[i][j+1] += imos[i][j]; } vector ans(N+1); rep(i,tx.size()-1){ rep(j,ty.size()-1){ int num = imos[i][j]; if(num==0)continue; /* cout<