using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var H = input[0]; var W = input[1]; var K = (long)input[2]; var sum = 0L; var treasure = new Dictionary<(int, int), long>(); for (int i = 0; i < K; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); temp[0]--; temp[1]--; treasure.Add((temp[0], temp[1]), temp[2]); } var dic = new Dictionary<(int, int), int>(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int x = i; x < H; x++) { for (int y = j - (H - i) < 0 ? 0 : j - (H - i); y < (j + (H - i) > W - 1 ? W : j + (H - i)); y++) { if ((x + y >= i + j) && (x - y >= i - j)) { if (dic.ContainsKey((x, y))) dic[(x, y)]++; else dic.Add((x, y), 1); } } } } } foreach (var item in treasure) { if (dic.ContainsKey(item.Key)) sum += dic[item.Key] * item.Value; } Console.WriteLine(sum % 998244353); } }