#include using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i=b;i--) ll mod=998244353; struct LazySegmentTree { private: int n; vector node, lazy; public: LazySegmentTree(vector v) { int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1, 0); for(int i=0; i=0; i--) node[i] = node[i*2+1] + node[i*2+2]; } void eval(int k, int l, int r) { if(lazy[k] != 0) { node[k] += lazy[k]; if(r - l > 1) { lazy[2*k+1] += lazy[k] / 2; lazy[2*k+2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); node[k] = node[2*k+1] + node[2*k+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; int main() { ll H,W,K;cin>>H>>W>>K; LazySegmentTree p(vector (W+H,0)); vector>> note(H+W,vector> (0)); for(ll i=0;i>x>>y>>v; x--;y--; note[x-y+W-1].push_back(make_pair(x+y,v)); } ll ans=0; for(ll k=1-W;k<=H-1;k++) { pair x,y; if(-1*k>=0) { x=make_pair(0,-k); } else { x=make_pair(k,0); } if(k+W-1<=H-1) { y=make_pair(k+W-1,W-1); } else { y=make_pair(H-1,H-1-k); } p.add(x.first+x.second,y.first+y.second+1,1); if(x.first==0) { p.add(x.first+x.second,x.first+x.second+1,1); } if(k!=1-W&&y.second==W-1) { p.add(y.first+y.second,y.first+y.second+1,1); } for(auto t:note[k+W-1]) { ll now=p.getsum(0,t.first+1); ll count=(t.first-x.first-y.first)/2; now-=count; now/=2; ans+=now%mod*t.second; ans%=mod; } } if(ans<0) ans+=mod; cout<