freq = Hash.new(0)
longest_size = -1
longest_word = ""

words = gets.chomp.split(" ")
words.each{|word|
    freq[word] += 1
    if word.size > longest_size
        longest_word = word
        longest_size= word.size
    end
}

puts freq.to_a.sort_by{|item| -item[1]}.first[0]
puts longest_word