read X Y n;
for((;i++<n;))do
	read a b c;
	if [ $c = 1 ];then
		x=$[x<a?a:x]
	elif [ $c = 2 ];then
		X=$[X<a?X:a]
	elif [ $c = 3 ];then
		y=$[y<b?b:y]
	else
		Y=$[Y<b?Y:b]
	fi
done
echo $[(x<X?X-x:0)*(y<Y?Y-x:0)]
