import Control.Applicative ((<$>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.List (foldl', unfoldr) getL :: (ByteString -> [Int]) -> IO [Int] getL f = f <$> B.getLine readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int]) readIL f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') main :: IO () main = do B.getLine xs <- getL $ readIL B.readInt putStr $ unlines $ map show $ solve $ reverse xs solve :: [Int] -> [Int] solve (0:xs) = solve xs solve [] = [0, 0] solve [x] = [0, x] solve [x, y] = [1, y, x] solve [x, y, z] = [2, z, y, x] solve (x:y:z:w:rs) = zs where zs = solve (y:z+x:w:rs)