#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 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; } ll dot(const pll &a, const pll &b) { return a.X * b.X + a.Y * b.Y; } int sign(const ll &a) { return a == 0 ? 0 : a > 0 ? 1 : -1; } int ori(const pll &a, const pll &b, const pll &c) { return sign(cross(b - a, c - a)); } 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); vector segs = {{A.X, 0}, {B.X, 0}}; for (int j = 0; j < n; ++j) { if (i == j) continue; for (int b = 0; b < 4; ++b) { pll C = poly[j][b], D = poly[j][(b + 1) % 4]; int sc = ori(A, B, C), sd = ori(A, B, D); if (sc != sd && min(sc, sd) < 0) { segs.pb(pll(C.X, sign(sc - sd))); } if (!sc && !sd && i < j && sign(dot(B - A, D - C)) > 0) { segs.pb(pll(C.X, 1)); segs.pb(pll(D.X, -1)); } } } if (sgn == 1) sort(ALL(segs)); else sort(ALL(segs), greater<>()); for (auto &s : segs) s.X = clamp(s.X, min(A.X, B.X), max(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)); } 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"; }