input = gets.split(" ")
n = input.length()
words = Hash.new(0)
frequent = input[0]
frequency = 1
longest = input[0]
for i in 0..(n-1)
  words[input[i]] += 1
  if words[input[i]] > frequency
    frequent = input[i]
    frequency = words[input[i]]
  end
  if input[i].size > longest.size
    longest = input[i]
  end
end
print "#{frequent}", " ", "#{longest}", "\n"