import Control.Monad
import Data.List

main = do
 n <- read <$> getLine :: IO Int
 aList' <- replicateM n (read <$> getLine) :: IO [Int]
 let aList = groupBy (\x y -> (snd x) == (snd y)) $ sortOn (\x -> (snd x) * (-1)) $ zip [1..] aList'
 let maxIdxs = map fst (head aList)
 let maxVal  = snd (head (head aList))
 let nextMaxVal = if (length aList) == 1 then maxVal else snd (head (aList !! 1))
 mapM_ print $ map (\x -> if x `elem` maxIdxs then nextMaxVal else maxVal) [1..n]