--2006年本選2問目より
module Main (main) where
import System
import Control.Monad.State
main = do
(filePath:_) <- getArgs
contents <- readFile filePath
let (x:y:_) = lines contents
in writeFile "output.txt" $ last (evalState (sequence (replicate ((read x) + 1) execute)) y)
execute :: State String String
execute = do
str <- get
put (convert str)
return str
convert :: String -> String
convert [] = []
convert x = let ss = convert' x
in concatMap (\x@(y:ys) -> (show (length x)) ++ [y]) ss
where
convert' :: String -> [String]
convert' [] = []
convert' yss@(y:ys) = let (f, s) = span (== y) yss
in f:convert' s