import Data.List

main = do
  s <- fmap (group . sort . words) getLine
  putStr $ snd $ last $ sort $ zip (map length s) (map head s)
  putStr " "
  putStrLn $ snd $ last $ sort $ zip (map (length . head) s) (map head s)
