simulate :: [Int] -> [Int] -> IO ()
simulate _ [] = return ()
simulate (x:xs) (0:ys) = print x >> simulate xs ys
simulate xs (y:ys) = simulate (y:xs) ys

main :: IO ()
main  = getContents
    >>= return . map read . lines
    >>= simulate []