import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Monad

solve :: VU.Vector Int -> Int -> IO ()
solve xs n = forM_ [0..n-1] $ \i -> do
    if (i == l)
        then print $ max lm rm
        else print m
    where
        l = VU.last $ VU.elemIndices m xs 
        (vl,vr) = VU.splitAt (l+1) xs
        
        lm = VU.maximum $ VU.init vl 
        rm = if VU.null vr then lm else VU.maximum vr
        m = VU.maximum xs

main = do
    n <- readLn :: IO Int
    xs <- VU.replicateM n (fst . fromJust . B.readInt <$> B.getLine)
    solve xs n