#!/usr/local/gnu/bin/bash
read w h n
x0=0
x1=$w
y0=0
y1=$h
for i in `seq $n`
do
    read x y a
    case $a in
        1 ) ((x0<x)) && x0=$x;;
        2 ) ((x1>x)) && x1=$x;;
        3 ) ((y0<y)) && y0=$y;;
        4 ) ((y1>y)) && y1=$y;;
    esac
done
((x0<x1&&y0<y1)) && echo $(((x1-x0)*(y1-y0))) || echo 0
