
import Data.List
import Control.Monad
import Data.Maybe

maxNum :: [Int] -> Int
maxNum = foldr1 (\x acc -> if x > acc then x else acc)

sndMaxNum :: [Int] -> Int
sndMaxNum ints =
  let
    big = maximum ints
    idx = fromMaybe 0 $ elemIndex big ints
  in maximum $ take idx ints ++ drop (idx+1) ints

hoge :: [Int] -> Int -> Int
hoge ints idx = maxNum $ take idx ints ++ drop (idx+1) ints

foo :: [Int] -> [Int]
foo ints = [ hoge ints i | i <- [0..(length ints - 1)] ]

bar :: [Int] -> Int -> [Int]
bar ints big = do
  idx <- [0..(length ints - 1)]
  if (ints!!idx) /= big then return big else return $ hoge ints idx

baz :: [Int] -> Int -> Int -> [Int]
baz ints big sndBig = [ if (ints!!i) == big then sndBig else big | i <- [0..(length ints - 1)] ]

printList :: [Int] -> IO ()
printList ints = mapM_ putStrLn $ lines $ intercalate "\n" $ map show ints

main = do
  n <- read <$> getLine :: IO Int
  ints <- replicateM n (read <$> getLine) :: IO [Int]
  printList $ baz ints (maximum ints) (sndMaxNum ints)
