import Control.Applicative
import Control.Monad
import Data.List

main = do
  n <- (read::String -> Int) <$> getLine
  arr <- forM [1..n] (\i -> (read::String -> Int) <$> getLine)
  let sorted = reverse . sort $ arr
  forM_ arr (\x -> if x == sorted !! 0 then print (sorted !! 1) else print (sorted !! 0))
