import Data.Bool
import Data.List
main = do
    [w,h,_] <- map read . words <$> getLine
    xyas <- tuplify . map read . words <$> getContents
    print $ sum [solve x y xyas | y <- [1..h], x <- [1..w]]

solve _ _ [] = 1
solve u v ((x,y,1):as) = bool (solve u v as) 0 $ u <= x
solve u v ((x,y,2):as) = bool (solve u v as) 0 $ x < u
solve u v ((x,y,3):as) = bool (solve u v as) 0 $ v <= y
solve u v ((x,y,4):as) = bool (solve u v as) 0 $ y < v

tuplify [] = []
tuplify (x:y:z:xs) = (x,y,z):tuplify xs
