import Data.List (foldl')
import qualified Data.Map.Strict as Map

type WordCount = Map.Map String Int

main = input >>= return . solve >>= output

input :: IO [String]
input = words `fmap` getLine

output :: (String,String) -> IO ()
output (s1,s2) = putStrLn $ unwords [s1,s2]

solve :: [String] -> (String, String)
solve ws = wc `seq` (mostFrequent wc, longest wc)
    where
    wc = wordCount ws

wordCount :: [String] -> WordCount
wordCount = foldl' countUp Map.empty
    where
    countUp wc w = Map.insertWith (+) w 1 wc

mostFrequent :: WordCount -> String
mostFrequent wc = maxCount `seq` head [w|(w,c)<-Map.assocs wc, c == maxCount]
    where
    maxCount = maximum $ Map.elems wc

longest :: WordCount -> String
longest wc = maxLength `seq` head [w|w<-Map.keys wc, length w == maxLength]
    where
    maxLength = maximum $ map length $ Map.keys wc