(* O(n) *)
Scanf.scanf " %d %d %d" @@ fun w h n ->
  let l, r, b, t = ref 0, ref w, ref 0, ref h in
  for i = 1 to n do
    Scanf.scanf " %d %d %d" @@ fun x y -> function
    | 1 -> l := max !l x
    | 2 -> r := min !r x
    | 3 -> b := max !b y
    | _ -> t := min !t y
  done;
  max 0 (!r - !l) * max 0 (!t - !b) |> Printf.printf "%d\n"