import qualified Data.List as L
import Control.Monad
main = do
  n <- read <$>  getLine :: IO Int
  as <- fmap read . lines <$> getContents :: IO [Int]
  let as' = L.sort as
      m1 = as' !! (n - 1)
      m2 = as' !! (n - 2)
  forM_ as $ \a ->
    print $ if a < m1 then m1 else m2
