import Data.List  -- sortBy, group
import Data.Ord   -- comparing

mode ls = fst . head $ svls
  where vls = map valLen . group . sort $ ls     -- list of value-length pairs
        valLen ls = (head ls, length ls)
        svls = sortBy (flip $ comparing snd) vls -- sorted vls

maxLen ls = head . sortBy (flip $ comparing length) $ ls

main = do
  s <- getLine
  let ls = words s
      ml = [mode ls,  maxLen ls]
  putStrLn . unwords $ ml