array = gets.chomp.split(" ")
hash = {}
array.each do |str|
    if hash.has_key?(str)
        hash[str] += 1
        else
        hash[str] = 1
    end
end
ml_w = ""
ml_l = 0
mc_w = ""
mc_c = 0
hash.each do |key, val|
    if key.length > ml_l
        ml_l = key.length
        ml_w = key
    end
    if val > mc_c
        mc_c = val
        mc_w = key
    end
end
puts mc_w + " " + ml_w