#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; int main(){ int n, m, x; cin >> n >> m >> x; vector c(n); vector> lst(5, vector(n)); for (int i=0; i> c[i]; c[i]--; lst[c[i]][i] += 1; } vector> bonus(5, vector(n)); for (int i=0; i> a >> b >> y; a--; b--; bonus[b][a] += y; } for (int i=0; i<5; i++){ reverse(lst[i].begin(), lst[i].end()); } ll ans = n * x; vector qr(n); for (int i=0; i ar = convolution_ll(lst[j], bonus[j]); for (int i=0; i