#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { ll h, w, k, sum1 = 0, mod = 998244353; cin >> h >> w >> k; for (ll i = 0; i < k; i++){ ll x, y, v, dl, dr; cin >> x >> y >> v; dl = max(x - y, (ll) 0); dr = max(x - (w - y + 1), (ll) 0); sum1 += (x*x - (dl+1)*dl/2 - (dr+1)*dr/2)*v; sum1 %= mod; } cout << sum1 << endl; }