-- C Exception handling

import Control.Monad
import Data.List

main :: IO()
main = do
  l <- getLine
  let n = read l :: Int
  a_orig <- replicateM n getLine
  let a_list = map read a_orig :: [Int]

  let biggest: second: _ = sortBy (\x y -> compare y x)  a_list

  forM_ a_list $ \i -> do
    if i == biggest then
      putStrLn(show second)
      else
      putStrLn(show biggest)

