
class WordCount
  def sentence(array)
    result = array.each_with_object(Hash.new(0)) { |w, h| h[w] += 1 }
    [
      result.max_by { |_, v| v },
      result.max_by { |k, _| k.length }
    ].map { |a| a[0].to_s }
  end
end

mode, max_length = WordCount.new.sentence(STDIN.gets.split)
printf "%s %s\n", mode, max_length