import Control.Monad
import Control.Applicative
import Data.List

main = do
  xs <- map toInt . words <$> getContents
  mapM_ print $ switch [] [] xs

toInt :: String -> Int
toInt s = read s

switch :: [Int] -> [Int] -> [Int] -> [Int]
switch acc _ [] = reverse acc
switch acc (s:ss) (0:ts) = switch (s:acc) ss ts
switch acc ss (t:ts) = switch acc (t:ss) ts