let f (xl, xu, yl, yu) (x, y, a) =
  match a with
  | 1 -> (max xl x, xu, yl, yu)
  | 2 -> (xl, min xu x, yl, yu)
  | 3 -> (xl, xu, max yl y, yu)
  | _ -> (xl, xu, yl, min yu y)
let () =
  let xl, xu, yl, yu =
    Scanf.scanf "%d %d %d" (fun w h n ->
      Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun x y a -> x, y, a))
    |> Array.fold_left f (0, w, 0, h)) in
  max 0 (xu-xl)* max 0 (yu-yl) |> Printf.printf "%d\n"
    
