import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=putStrLn.unwords.map show.solve.tail.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve as=[n,r]where
  n=maximum as
  r=maximumBy(\a b->compare(f a)(f b))$filter(n>)as
  f=min=<<(n-)