import Data.List

modeW :: String -> String
modeW ss =
    let dist = (map (\ks -> (head ks, length ks)) . group . sort . words) ss
        maxn = (maximum . map snd) dist
    in concat $ map fst $ filter ((== maxn) . snd) dist

longestW :: String -> String
longestW ss = (snd . maximum . reverse . sort . map (\s -> (length s, s)) . nub . words) ss

main :: IO ()
main = interact $ (++ "\n") . unwords . (\ss -> [modeW ss, longestW ss])