Problem:
English Sentence

Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.

The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces.

Input

A text is given in a line. You can assume the following conditions:

The number of letters in the text is less than or equal to 1000.

The number of letters in a word is less than or equal to 32.

There is only one word which is arise most frequently in given text.

There is only one word which has the maximum number of letters in given text.

Output

The two words separated by a space.

Sample Input

Thank you for your mail and your lectures

Output for the Sample Input

your lectures

Solution in Ruby (judge verdict: Accepted)

class StrSet
  attr_reader :str, :len, :num
  def initialize(s = "")
    @str = s
    @len = s.length()
    @num = 1
  end
  
  def check_len(s)
    if (@len < s.length())
      @str = s
      @len = s.length()
    end
  end
  def check_num(s, n)
    if (@num < n)
      @str = s
      @num = n
    end
  end
  def count
    @num += 1
  end
end

max = StrSet.new()
requency = StrSet.new()
str_ary = []

gets().split().each() do |word|
  max.check_len(word)
  
  a_length = str_ary.length()
  str_ary.each() do |set|
    if (set.str == word)
      set.count()
      break
    end
    a_length -= 1
  end
  if (a_length == 0)
    str_ary << StrSet.new(word)
  end
end

requency = StrSet.new()
str_ary.each() do |set|
  requency.check_num(set.str, set.num)
end

puts("#{requency.str} #{max.str}")