{-# OPTIONS_GHC -Wall -Werror #-}

import Control.Monad (mapM_)

solve :: [Int] -> [Int]
solve = snd . foldl foldFunc ([], [])
  where foldFunc (x:xs, ys) 0 = (xs, ys ++ [x])
        foldFunc (xs, ys)   n = (n:xs, ys)

main :: IO ()
main = getContents >>= mapM_ (putStrLn . show) . solve . map read . words