word_counts = Hash.new(0)
max = ""
words = gets.chomp.split(nil)
words.each do |word|
  word_counts[word] += 1

  max = word if (word.length > max.length)
end
ws = word_counts.sort{|a,b|a[1]<=>b[1]}.reverse!
puts "#{ws[0][0]} #{max}"