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

WordCount.new.sentence(STDIN.gets.split)