words = gets.chomp.split

word_counts = Hash.new(0)
max = ''
words.each do |word|
  word_counts[word] += 1

  max = word if (max.length < word.length)
end
word_counts = word_counts.sort.reverse!
puts "#{word_counts[0][0]} #{max}"