#include using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; #define X first #define Y second #define SZ(a) ((int)a.size()) #define ALL(v) v.begin(), v.end() #define pb push_back const int MOD = 998244353; const int TWO = (MOD + 1) / 2; pll operator+(const pll &a, const pll &b) { return pll(a.X + b.X, a.Y + b.Y); } pll perp(const pll &a) { return pll(-a.Y, a.X); } ll cross(const pll &a, const pll &b) { return a.X * b.Y - a.Y * b.X; } pll arr[1505]; int health[1505]; __int128 sum[1505]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> arr[i].X >> arr[i].Y >> health[i]; auto [x, y] = arr[i]; arr[i] = pll(x + y, x - y); } vector> poly(n); auto itvsgn = [&](int l, int r) { return l < r ? 1 : -1; }; auto solve = [&]() { for (int i = 0; i < n; ++i) for (int a = 0; a < 4; a += 2) { pll A = poly[i][a], B = poly[i][(a + 1) % 4]; assert(A.Y == B.Y); int sgn = itvsgn(A.X, B.X); if (A.X > B.X) swap(A, B); vector segs = {{A.X, 0}, {B.X, 0}}; for (int j = 0; j < n; ++j) { if (i == j) continue; auto [yl, yr] = minmax(poly[j][0].Y, poly[j][2].Y); auto [xl, xr] = minmax(poly[j][0].X, poly[j][2].X); if (A.Y == yl) { if (sgn == 1 && i < j) { segs.pb(pll(xl, 1)); segs.pb(pll(xr, -1)); } } else if (A.Y == yr) { if (sgn == -1 && i < j) { segs.pb(pll(xl, 1)); segs.pb(pll(xr, -1)); } } else if (clamp(A.Y, yl, yr) == A.Y) { segs.pb(pll(xl, 1)); segs.pb(pll(xr, -1)); } } sort(ALL(segs)); for (auto &s : segs) s.X = clamp(s.X, A.X, B.X); int cnt = segs[0].second + 1; for (int j = 1; j < SZ(segs); ++j) { if (cnt > 0) { sum[cnt] += cross(pll(segs[j - 1].X, A.Y), pll(segs[j].X, A.Y)) * sgn; } cnt += segs[j].Y; } } }; for (int i = 0; i < n; ++i) { health[i] = m - health[i]; poly[i].pb(arr[i] + pll(-health[i], -health[i])); poly[i].pb(arr[i] + pll(health[i], -health[i])); poly[i].pb(arr[i] + pll(health[i], health[i])); poly[i].pb(arr[i] + pll(-health[i], health[i])); } solve(); for (int i = 0; i < n; ++i) { for (auto &p : poly[i]) p = perp(p); rotate(poly[i].begin(), poly[i].begin() + 1, poly[i].end()); } solve(); for (int i = 1; i <= n; ++i) cout << (ll)((sum[i] - sum[i + 1]) % MOD) * TWO % MOD * TWO % MOD << "\n"; }