open Batteries
let () =
  let w,h,n = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in
  let pair_l = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d %d %d " (fun a b c-> a,b,c)) in

  let x1 = let l = List.filter (fun (x,y,a) -> a=1) pair_l |> List.map (fun (x,y,a) -> x) in
           try List.max l with _ -> 0
  in
  let x2 = let l = List.filter (fun (x,y,a) -> a=2) pair_l |> List.map (fun (x,y,a) -> x) in
           try List.min l with _ -> w
  in
  let y1 = let l = List.filter (fun (x,y,a) -> a=3) pair_l |> List.map (fun (x,y,a) -> y) in
           try List.max l with _ -> 0
  in
  let y2 = let l = List.filter (fun (x,y,a) -> a=4) pair_l |> List.map (fun (x,y,a) -> y) in
           try List.min l with _ -> h
  in

  let x = x2 - x1 in
  let x = if x < 0 then 0 else x in
  let y = y2 - y1 in
  let y = if y < 0 then 0 else y in

  Printf.printf "%d\n" @@ x*y
