import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- replicateM n $ readLn :: IO [Int]
  let ls = V.fromList $ scanl1 max as
      rs = V.fromList $  scanr1 max as

  print $ (rs V.! 1)
  forM_ [2..n-1] $ \i -> do
    print $ max (ls V.! (i-2)) (rs V.! i)
  print $ (ls V.! (n-2))
