import Control.Applicative ((<$>)) import qualified Data.ByteString.Char8 as SC import Data.List (sortBy) import Data.Maybe (fromJust) data Color = White | Black deriving (Enum, Show) type Block = Int unsafeReadInt :: SC.ByteString -> Int unsafeReadInt = fst . fromJust . SC.readInt maxHeight :: [Block] -> [Block] -> Int maxHeight ws0 bs0 = max candw candb where ws1 = sortBy (flip compare) ws0 bs1 = sortBy (flip compare) bs0 candw = mh 0 maxBound White ws1 bs1 candb = mh 0 maxBound Black ws1 bs1 mh :: Int -> Int -> Color -> [Block] -> [Block] -> Int mh h _ White [] _ = h mh h _ Black _ [] = h mh h prev White (w : ws) bs | w < prev = mh (h + 1) w Black ws bs | otherwise = mh h prev White ws bs mh h prev Black ws (b : bs) | b < prev = mh (h + 1) b White ws bs | otherwise = mh h prev Black ws bs main :: IO () main = do _ <- SC.getLine ws <- fmap unsafeReadInt . SC.words <$> SC.getLine _ <- SC.getLine bs <- fmap unsafeReadInt . SC.words <$> SC.getLine print $ maxHeight ws bs