import Data.List

elsemax :: [Integer] -> [Integer]
elsemax [] = []
elsemax [a] = [a]
elsemax as = map (\x -> if x == bs!!0 then bs!!1 else bs!!0) as
    where bs = reverse $ sort as

main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getContents :: IO [Integer]
  mapM (putStrLn . show) $ elsemax as
