#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 segtree { ll n; vector dat; void init(ll n_) { n=1; while (n (2*n-1,0LL); } void update(ll k, ll a) { k+=n-1; dat[k]+=a; while(k>0) { k=(k-1)/2; dat[k]=dat[k*2+1]+dat[2*k+2]; } } ll query (ll a, ll b, ll k,ll l, ll r) { if(r<=a||b<=l) return 0; if(a<=l&&r<=b) return dat[k]; else { ll vl=query(a,b,k*2+1,l,(l+r)/2); ll vr=query(a,b,k*2+2,(l+r)/2,r); return vl+vr; } } }; int main() { ll H,W,K;cin>>H>>W>>K; vector>> note(H+W+10,vector> (0)); vector> memo(H,vector (W,0)); for(ll i=0;i>x>>y>>v; x--;y--; memo[x][y]+=v; } for(ll i=0;i=0;i--) { for(auto x:note[i]) { p.update(x.first,x.second); } for(auto x:note[i]) { ans+=p.query(x.first,H+W,0,0,p.n); ans%=mod; } } cout<