import sys input = sys.stdin.readline MOD = 998244353 INV2 = pow(2, MOD - 2, MOD) n, m = map(int, input().split()) X1 = []; X2 = []; Xst = set([]) Y1 = []; Y2 = []; Yst = set([]) for s, y, w in (map(int, input().split()) for _ in [0] * n): d = m - w x1, y1 = (s - d) - y, (s - d) + y x2, y2 = (s + d) - y, (s + d) + y X1.append(x1); X2.append(x2); Xst.add(x1); Xst.add(x2) Y1.append(y1); Y2.append(y2); Yst.add(y1); Yst.add(y2) X = sorted(Xst); Y = sorted(Yst) idX = {}; idY = {} for i, (s, y) in enumerate(zip(X, Y)): idX[s] = idY[y] = i w, h = len(idX), len(idY) dp = [[0] * h for _ in [0] * w] for x1, y1, x2, y2 in zip(X1, Y1, X2, Y2): dp[idX[x1]][idY[y1]] += 1 dp[idX[x1]][idY[y2]] -= 1 dp[idX[x2]][idY[y1]] -= 1 dp[idX[x2]][idY[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)