import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map read . words <$> getLine :: IO [Int]
cond t f c = if c then t else f
-- end of templete

f :: [Int] -> [Int] -> IO ()
f _ [] = return ()
f (t:s) (0:c) = print t >> f s c
f s (x:c) = f (x:s) c

main = do
    map readInt . lines <$> getContents >>= f []