(* O(n) *)
Scanf.scanf " %d %d %d" @@ fun w h n ->
  let left = ref 0 in
  let right = ref w in
  let down = ref 0 in
  let up = ref h in
  for i = 1 to n do
    Scanf.scanf " %d %d %d" @@ fun x y -> function
    | 1 -> left := max !left x
    | 2 -> right := min !right x
    | 3 -> down := max !down y
    | 4 -> up := min !up y
    | _ -> assert false
  done;
  let w2 = max 0 @@ !right - !left in
  let h2 = max 0 @@ !up - !down in
  Printf.printf "%d\n" @@ w2 * h2