import Control.Monad
import qualified Data.Map as M

main = do
 n <- read <$> getLine :: IO Int
 aList <- replicateM n (read <$> getLine) :: IO [Int]
 let l = M.fromList $ zip [0..] $ scanl max 0 aList
 let r = M.fromList $ zip [0..] $ scanr max 0 aList
 mapM_ print $ [ max (l M.! i) (r M.! (i+1)) | i <- [0..(n-1)] ]