splitEvery5 :: String -> [String] splitEvery5 = takeWhile (not . null) . map (take 5) . iterate (drop 5) main :: IO () main = interact $ unwords . (\(a, b) -> [show a, show b]) . foldr (\x (a, b) -> if x == "(^^*)" then (a + 1, b) else (a, b + 1) ) (0, 0) . splitEvery5 . init . init