import Control.Monad

mup n [] = []
mup n s = (s!!0!!n):(mup n (drop 1 s))

ac::[Int]->[Int]->[Int]->[Int]->[Int]->[(Int,Int)]
ac [] [] [] p q = [(t,s)|t<-[minimum p..maximum p],s<-[minimum q..maximum q]]
ac x y a p q= case (head a) of 1 -> ac (drop 1 x) (drop 1 y) (drop 1 a) (filter (>=(head x)) p) q
                               2 -> ac (drop 1 x) (drop 1 y) (drop 1 a) (filter (<=(head x)) p) q
                               3 -> ac (drop 1 x) (drop 1 y) (drop 1 a) p (filter (>=(head y)) q)
                               4 -> ac (drop 1 x) (drop 1 y) (drop 1 a) p (filter (<=(head y)) p)
main=do
 [w,h,n]<-map read.words<$>getLine
 s<-replicateM n $map read.words<$>getLine
 let xs = mup 0 s
 let ys = mup 1 s
 let ap = mup 2 s
 let ws = [0..w]
 let hs = [0..h]
 print$length$ac xs ys ap ws hs
 