import Control.Monad
import Data.List

main = do
    n <- readLn
    a <- replicateM n (readLn :: IO Int)
    let b = sort a
    let lb = last b
        llb = last (init b)
    mapM_ print $ map (\x -> if x == lb then llb else lb) a
