h=maximum.map head.filter ((==1).last)
i=minimum.map head.filter ((==2).last)
j=maximum.map (!!1).filter ((==3).last)
k=minimum.map (!!1).filter ((==4).last)
f l [a,b,c]=do
 let q=if not (null (filter ((==1).last) l)) then h l else 0
     w=if not (null (filter ((==2).last) l)) then i l else a
     e=if not (null (filter ((==3).last) l)) then j l else 0
     r=if not (null (filter ((==4).last) l)) then k l else b
 let z=a*b-(q*b+(a-w)*b+e*a+(b-r)*a-(b-r+e)*(a-w+q))
 if z<0 then 0 else z
main=do
 l<-map(map read).map words.lines<$>getContents
 print$f (tail l) (head l)