Bの問題

```count :: Int -> Int -> Int -> Int -> [Event] -> [Int]
count a b _ _ [] = [a, b]
count a b sa sb ((Dpt, A):es) | sa ==    = count (a+1) b sa sb es
| otherwise = count a b (sa-1) sb es
count a b sa sb ((Dpt, B):es) | sb ==    = count a (b+1) sa sb es
| otherwise = count a b sa (sb-1) es
count a b sa sb ((Arv, A):es) = count a b sa (sb+1) es
count a b sa sb ((Arv, B):es) = count a b (sa+1) sb es
```

```import Control.Monad
import Data.List
data Action = Arv | Dpt deriving (Eq, Ord, Show)
data Train = A | B deriving (Eq, Ord, Show)
type Event = (Action, Train)
-- make event list from instance
mkEvents :: (Int, [[(Int, Int)]], [[(Int, Int)]]) -> [Event]
mkEvents (t, as, bs) = map snd.sort \$ mkEpart t as A ++ mkEpart t bs B
where mkEpart t ts x = [(d, (Dpt, x)) | d <- dpts] ++ [(tournaround a, (Arv, x)) | a <- arvs]
where (dpts, arvs) = unzip.map ((x:y:zs) -> (x,y)) \$ ts
tournaround (h,m) = (h + div (m + t) 60, mod (m + t) 60)
-- main part
count :: Int -> Int -> Int -> Int -> [Event] -> [Int]
count a b _ _ [] = [a, b]
count a b sa sb ((Dpt, A):es) | sa ==    = count (a+1) b sa sb es
| otherwise = count a b (sa-1) sb es
count a b sa sb ((Dpt, B):es) | sb ==    = count a (b+1) sa sb es
| otherwise = count a b sa (sb-1) es
count a b sa sb ((Arv, A):es) = count a b sa (sb+1) es
count a b sa sb ((Arv, B):es) = count a b (sa+1) sb es
main = mapM_ putStrLn.zipWith output [1..].map (count    .mkEvents) =<< (`replicateM` getCase) =<< getInt
-- output and input function
toTime :: String -> (Int, Int)
toTime s = (read.take 2 \$ s, read.take 2.drop 3 \$ s)
getCase :: IO (Int, [[(Int, Int)]], [[(Int, Int)]])
getCase = do t <- getInt
[a,b] <- getInts
as <- replicateM a (liftM (map toTime.words) getLine)
bs <- replicateM b (liftM (map toTime.words) getLine)
return (t, as, bs)
output :: Show a => Int -> [a] -> String
output x xs = concat \$ "Case #" : show x : ": " : interleave (map show xs) " "
where interleave []     y = []
interleave [x]    y = [x]
interleave (x:xs) y = x:y:interleave xs y
getList :: Read a => IO [a]
getList = liftM (map read.words) getLine
getInts :: IO [Int]
getInts = getList
getInt :: IO Int