#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 using P = pair; P op(P a,P b){ a.first += b.first; a.second += b.second; return a; } P e(){ return make_pair(0,0); } P mapping(mint a,P b){ b.first += a*b.second; return b; } mint composition(mint a,mint b){ return a+b; } mint id(){ return 0; } int main(){ int H,W,K; cin>>H>>W>>K; vector

t(300000,make_pair(0,1)); vector> seg(2, lazy_segtree(t)); int C = 100001; vector>> vs(C*2); rep(i,K){ int x,y,z; cin>>x>>y>>z; x--,y--; vs[x-y+C].emplace_back(x+y,z); } mint ans = 0; rep(i,C*2){ int tt = i-C; int L=max(tt,-tt),R = min(2*(W-1)+tt,2*(H-1)-tt); if(L<=R){ seg[L%2].apply(L/2,R/2+1,1); } rep(j,vs[i].size()){ int y = vs[i][j].first; mint vv = vs[i][j].second; mint s = 0; if(y%2==0){ s += seg[0].prod(0,y/2+1).first; s += seg[1].prod(0,y/2).first; } else{ s += seg[0].prod(0,y/2+1).first; s += seg[1].prod(0,y/2+1).first; } ans += vv * s; } } cout<