import Control.Monad
import Data.List
main = do
    n <- readLn
    a <- replicateM n readLn
    let ml = take n (scanl (max) 0 a)
    let mr = drop 1 (scanr (max) 0 a)
    let m = zipWith (max) ml mr
    forM_ m print
