#line 2 "lib/prelude.hpp" #ifndef LOCAL #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #endif #include using namespace std; using ll = long long; #define rep2(i, m, n) for (auto i = (m); i < (n); i++) #define rep(i, n) rep2(i, 0, n) #define repr2(i, m, n) for (auto i = (n); i-- > (m);) #define repr(i, n) repr2(i, 0, n) #define all(x) begin(x), end(x) #line 2 "main.cpp" #include #include using mint = atcoder::modint998244353; vector add(vector a, const vector& b) { a.resize(max(a.size(), b.size())); rep(i, b.size()) a[i] += b[i]; return a; } vector sub(vector a, const vector& b) { a.resize(max(a.size(), b.size())); rep(i, b.size()) a[i] -= b[i]; return a; } vector mul(vector a, mint r) { rep(i, a.size()) a[i] *= r; return a; } vector conv(vector a, vector b, int deg = -1) { if (~deg) a.resize(min(a.size(), deg)), b.resize(min(b.size(), deg)); auto f = convolution(a, b); if (~deg) f.resize(deg); return f; } vector diff(vector a) { rep(i, a.size() - 1) a[i] = a[i + 1] * (i + 1); a.pop_back(); return a; } vector integr(vector a) { a.push_back(0); repr(i, a.size() - 1) a[i + 1] = a[i] / (i + 1); a[0] = 0; return a; } vector inv(vector f, int deg) { assert(f[0] != 0); vector g = {f[0].inv()}; for (int m = 1; m < deg; m *= 2) { auto h = conv(f, g, m * 2); fill(h.begin(), h.begin() + m, 0); auto hg = conv(h, g, m * 2); rep(i, m * 2) hg[i] = -hg[i]; g.insert(g.end(), hg.begin() + m, hg.end()); } g.resize(deg); return g; } vector log(vector a, int deg) { assert(a[0] == 1); vector a2 = a; return integr(conv(diff(move(a)), inv(move(a2), deg - 1), deg - 1)); } vector exp(vector h, int deg) { assert(h[0] == 0); int n = 1 << atcoder::internal::ceil_pow2(deg); h.resize(n); vector f = {1}, g = {1}; vector q(h.size() - 1); rep(i, q.size()) q[i] = h[i+1] * (i+1); for (int m = 1; m < n; m *= 2) { auto fgg = conv(conv(f, g, m), g, m); g.resize(m); rep(i, m) g[i] = g[i] * 2 - fgg[i]; auto fq = conv(f, {q.begin(), q.begin() + m - 1}); rep(i, fq.size()) fq[i] = -fq[i] + (i < f.size() - 1 ? f[i+1] * (i+1) : 0); auto w = conv(g, fq, m * 2 - 1); rep(i, m-1) w[i] += q[i]; w.push_back(0); repr(i, m * 2 - 1) w[i+1] = h[i+1] - w[i] / (i+1); w[0] = h[0]; auto fw = conv(f, w, m * 2); f.resize(m * 2); rep(i, m * 2) f[i] += fw[i]; } return f; } struct rational { vector numer, denom; }; rational sum(const vector& v) { int n = v.size(); vector t(n * 2); copy(all(v), t.begin() + n); repr2(i, 1, n) t[i] = {add(conv(t[i * 2].numer, t[i * 2 + 1].denom), conv(t[i * 2].denom, t[i * 2 + 1].numer)), conv(t[i * 2].denom, t[i * 2 + 1].denom)}; return t[1]; } mint fact[100001]; vector stirling2(int n) { vector a(n + 1), b(n + 1); rep(i, n + 1) { a[i] = mint(i).pow(n) / fact[i]; b[i] = mint(-1).pow(i) / fact[i]; } return conv(a, b, n + 1); } int n, m, a[100000], b[100000], c[100000]; int main() { fact[0] = 1; rep(i, size(fact) - 1) fact[i + 1] = fact[i] * (i + 1); scanf("%d%d", &n, &m); assert(1 <= n && n <= 100000); assert(1 <= m && m <= 100000); rep(i, n) { scanf("%d%d%d", a + i, b + i, c + i); assert(1 <= a[i] && a[i] < 998244353); assert(1 <= b[i] && b[i] < 998244353); assert(1 <= c[i] && c[i] < 998244353); } // sum_k k! S(M,k) [x^k] prod (a+bx)^c vector s = stirling2(m); // prod (a+bx)^c // = prod a^c exp(sum c log(1+rx)) // = prod a^c exp(sum c int r/(1+rx)) // = prod a^c exp(int sum c/(1/r+x)) vector terms(n); rep(i, n) terms[i] = {{c[i]}, {mint(a[i]) / b[i], 1}}; rational total = sum(terms); auto frac = conv(total.numer, inv(total.denom, m), m); mint coef = 1; rep(i, n) coef *= mint(a[i]).pow(c[i]); vector f = mul(exp(integr(frac), m + 1), coef); mint ans = 0; rep(k, m + 1) ans += fact[k] * s[k] * f[k]; printf("%d\n", ans.val()); }