import Text.Regex.PCRE
import Data.Array

main = do
  _ <- getLine
  _ <- getLine
  input <- getContents
  print . parseInput . lines $ input

parseInput :: [String] -> (Array (Int, Int) Int, Array (Int, Int) Int)
parseInput input = (used, avail)
  where
    assocList = map parseLine input
    xmax = maximum $ map (fst . fst) assocList
    ymax = maximum $ map (snd . fst) assocList
    avail = array ((0, 0), (xmax, ymax)) [ ((x, y), a)
                                         | ((x, y), (_, a)) <- assocList ]
    used  = array ((0, 0), (xmax, ymax)) [ ((x, y), u)
                                         | ((x, y), (u, _)) <- assocList ]

parseLine :: String -> ((Int, Int), (Int, Int))
parseLine l = ((read x, read y), (read used, read avail))
  where
    pat = ".+x(\\d+)-y(\\d+) +\\d+T +(\\d+)T +(\\d+)T +.*"
    [[_, x, y, used, avail]] = l =~ pat :: [[String]]

