h = Hash.new(0)
max_length = 0
max_str = ""
gets.chomp.split.each do |s|
    h[s] += 1
    if s.length > max_length
        max_length = s.length
        max_str = s
    end
end

print h.sort{|(k1, v1), (k2, v2)| v2 <=> v1}[0][0], " ", max_str, "\n"
