import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List
import Data.Ord

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

solve :: [Int] -> [Int] -> [Int]
solve [] _ = []
solve (a:as) list@(s1:s2:ss) = res : solve as list
  where res = if a /= s1 then s1 else s2

main :: IO ()
main = do
  getLine
  as <- readIntLines
  let sorted = sortOn Down as
  mapM_ print $ solve as sorted