{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B
import Data.IORef
import Data.Array.IO

main :: IO ()
main = do
    [w, h, n] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    as <- replicateM n $ map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [[Int]]
    t <- newArray ((1, 1), (w, h)) 0 :: IO (IOArray (Int, Int) Int)
    forM_ as $ \[x, y, a] ->
        if  | a == 1 -> forM_ [1..x] $ \xx -> forM_ [1..h] $ \yy -> writeArray t (xx, yy) 1
            | a == 2 -> forM_ [x+1..w] $ \xx -> forM_ [1..h] $ \yy -> writeArray t (xx, yy) 1
            | a == 3 -> forM_ [1..w] $ \xx -> forM_ [1..y] $ \yy -> writeArray t (xx, yy) 1
            | a == 4 -> forM_ [1..w] $ \xx -> forM_ [y+1..h] $ \yy -> writeArray t (xx, yy) 1
    s <- newIORef (0 :: Int)
    forM_ [1..w] $ \x ->
        forM_ [1..h] $ \y -> do
            color <- readArray t (x, y)
            when (color == 0) $ modifyIORef s (+ 1)
    print =<< readIORef s
