import sys input = sys.stdin.readline MOD = 998244353 INV2 = pow(2, MOD - 2, MOD) n, m = map(int, input().split()) enemies = [[x - y, x + y, m - h] for x, y, h in [map(int, input().split()) for _ in [0] * n]] X1 = [x - d for x, _, d in enemies] X2 = [x + d for x, _, d in enemies] Y1 = [y - d for _, y, d in enemies] Y2 = [y + d for _, y, d in enemies] Xst = set(X1) | set(X2) Yst = set(Y1) | set(Y2) X, Y = sorted(Xst), sorted(Yst) Xid = { x : i for i, x in enumerate(X) } Yid = { y : i for i, y in enumerate(Y) } w, h = len(Xid), len(Yid) dp = [[0] * h for _ in [0] * w] for x1, y1, x2, y2 in zip(X1, Y1, X2, Y2): dp[Xid[x1]][Yid[y1]] += 1 dp[Xid[x1]][Yid[y2]] -= 1 dp[Xid[x2]][Yid[y1]] -= 1 dp[Xid[x2]][Yid[y2]] += 1 for i in range(w): for j in range(1, h): dp[i][j] += dp[i][j - 1] for i in range(1, w): for j in range(h): dp[i][j] += dp[i - 1][j] area = [0] * (n + 1) for i in range(w - 1): for j in range(h - 1): area[dp[i][j]] += ((X[i + 1] - X[i]) % MOD) * ((Y[j + 1] - Y[j]) % MOD) % MOD for s in area[1:]: ans = s % MOD * INV2 % MOD print(ans)