import Control.Applicative ((<$>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr) import Data.Char (isSpace) main :: IO () main = getLine >> solve <$> (readil B.readInt <$> B.getLine) >>= mapM_ putStrLn solve :: [Int] -> [String] solve = f . reverse where f (0:rs) = f rs f [] = ["0", "0"] f [a] = ["0", show a] f [a, b] = ["1", show b ++ " " ++ show a] f [a, b, c] = ["2", show c ++ " " ++ show b ++ " " ++ show a] f (a:b:c:d:rs) = f (b:c+a:d:rs) readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')