import Data.Sequence as SQ
import System.IO
import Control.Applicative
import Data.List

process :: SQ.Seq Int -> String -> SQ.Seq Int
process sq s = let 
        w = words s 
        n = SQ.length sq in case head w of
    "add" -> sq |> (read $! last w)
    "take" -> case n of
                        0 -> sq
                        _ -> (SQ.inits sq) `SQ.index` (n - 1)
    "mum!" -> let
                left = SQ.take (n `div` 2) sq
                right = SQ.drop (n `div` 2) sq
              in right><left

pp :: SQ.Seq Int -> String
pp sq = (show n) ++ "\n" ++ (intercalate " " [show (sq `index` i) | i <- [0..n-1]]) where
    n = SQ.length sq

main = do
    queries <- tail <$> lines <$> readFile "kenobi.in"
    writeFile "kenobi.out" $! pp $! foldl process SQ.empty queries
