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

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

foo :: [Int] -> (Int,Int) -> (Int,Int)
foo [] tup = tup
foo (n:ns) (big,sndBig)
  | n > big = foo ns (n,sndBig)
  | n > sndBig = foo ns (big,n)
  | otherwise = foo ns (big,sndBig)

bar :: [Int] -> Int -> Int -> [Int]
bar ints big sndBig = map (\n -> if n == big then sndBig else big) ints

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]
  let (i,j) = foo ints (0,0)
  printList $ bar ints i j
