main=do
 [xx,yy,n]<-map read.words<$>getLine
 s<-map(map read.words).lines<$>getContents
 print$f 0 0 xx yy s
f x y xx yy[]=(max(xx-x)0)*(max(yy-y)0)
f x y xx yy([a,b,c]:s)=f(max x(if c==1 then a else x))(min xx(if c==2 then a else xx))(max y(if c==3 then b else y))(min yy(if c==4 then b else yy))s
