use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let v: Vec = s.split_whitespace().flat_map(str::parse).collect(); let mut a = 0; for n in v[3..].chunks(3) { a += n[2] * (1..=v[1]) .map(|w| 0.max(n[0] - (n[1] - w).abs())) .sum::(); a %= 998244353; } println!("{a}") }