count = Hash.new(0)

sentence = gets

words = sentence.split(/ /)

words.each do |word|
    count[word] += 1
end

#??????????????????????????????????????????
max = 0
many_word = ""
count.each{|key, value|
  if value > max
    max = value
    many_word = key
  end
}

#?????????????????°????????????????????????
max = 0
longest_word = ""
count.each_key{|key|
  if key.length > max
    max = key.length
    longest_word = key
  end
}

puts "#{many_word} #{longest_word}"
