import Control.Monad
import Data.List

solve as i max | i >= max = []
               | otherwise = maximum (take i as ++ drop (i+1) as) :solve as (i+1) max

main = do
    n <- readLn :: IO Int
    an <- map read <$> replicateM n getLine :: IO [Int]
    mapM_ print (solve an 0 n)
    