import Data.List

-- most frequently
freq :: [String] -> [String] -> [Int]
freq xs ws = map (\x -> length $ filter (\w -> w == x) ws) xs

mfreq :: [Int] -> Maybe Int
mfreq ls =
    findIndex (\l -> l == max) ls where
      max = maximum ls

ansf :: [String] -> Maybe Int
ansf ws = mfreq $ freq (nub ws) ws

-- the maximum number of letters
mmaxi :: [Int] -> Maybe Int
mmaxi ls =
    findIndex (\l -> l == max) ls where
      max = maximum ls

bnsf :: [String] -> Maybe Int
bnsf ws = mmaxi $ map length ws

main = do
    input <- getLine
    let ws = words input
    let ans = (ansf ws) >>= (\x -> return $ ws !! x)
    let bns = (bnsf ws) >>= (\x -> return $ ws !! x)
    case (ans, bns) of
      (Just x, Just y) -> putStrLn $ x ++ " " ++ y
      _ -> return ()