import Control.Applicative
import Data.List

main = do
  word <- words <$> getLine
  putStrLn $ unwords . (modeWord word :) . (longestWode word :) $ []

modeWord :: [String] -> String
modeWord = fst . foldl1 (\x y -> if snd x > snd y then x else y) . fmap (\x -> (head x, length x)) . group . sort

longestWode :: [String] -> String
longestWode = fst . foldl1 (\x y -> if snd x > snd y then x else y) . fmap (\x -> (x, length x)) . nub . sort