let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let () = 
  let w, h, n = Scanf.scanf "%d %d %d\n" (fun w h n -> w, h, n) in
  tabulate n (fun _ -> Scanf.scanf "%d %d %d\n" (fun x y a -> x, y, a))
    |> List.fold_left (fun (x1, y1, x2, y2) (x, y, a) ->
        match a with
        | 1 -> (max x1 x, y1, x2, y2)
        | 2 -> (x1, y1, min x2 x, y2)
        | 3 -> (x1, max y1 y, x2, y2)
        | 4 -> (x1, y1, x2, min y2 y)) (0, 0, w, h)
    |> (fun (x1, y1, x2, y2) -> max 0 (x2 - x1) * max 0 (y2 - y1))
    |> Printf.printf "%d\n"

