日本情報オリンピック 第5回本選 第2問 Reloaded

module Main (main) where

import Control.Monad (liftM)
import Data.List (group)
import System.Environment (getArgs)

execute :: Int -> String -> String
execute n = flip (!!) n . iterate execute'
  where
    execute' :: String -> String
    execute' = concatMap (\xss@(x:_) -> show (length xss) ++ [x]) . group

main = do
    (inputFile:_) <- getArgs
    (l1:l2:_) <- liftM lines $ readFile inputFile
    writeFile "output.txt" $ execute (read l1) l2