type Stack = [Int]
type Result = [Int]

main :: IO ()
main = do
  c <- getContents
  let is = map read $ lines c
      res = proc is
  mapM_ (putStrLn . show) res

proc :: Stack -> Result
proc = reverse . snd . foldl proc' ([], [])
  where proc' (s, res) 0 = let (i, s') = pop s in (s', i : res)
        proc' (s, res) i = (push s i, res)

push :: Stack -> Int -> Stack
push xs i = i : xs

pop :: Stack -> (Int, Stack)
pop (x:xs) = (x, xs)