import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Data.Sequence         ((<|), (><), (|>))
import qualified Data.Sequence         as S

import           Data.Foldable         (toList)
import           Data.List             (foldl')

readi :: B.ByteString -> Int
readi bs | Just (n, _) <- B.readInt bs = n

splitElem :: Int -> S.Seq Int -> [S.Seq Int]
splitElem n s
    | Nothing <- midx = [s]
    | Just i <- midx =
        let (l, r) = S.splitAt i s
            (m S.:< r') = S.viewl r
         in [l, r', S.singleton m]
  where
    midx = S.elemIndexL n s

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- fmap readi . B.words <$> B.getLine
    is <- S.fromList . fmap readi . B.words <$> B.getLine

    let as = foldl' (\acc p -> concatMap (splitElem p) acc) [is] ps
    let as' = foldr (><) S.empty as
    putStrLn . unwords . fmap show $ toList as'

