words = STDIN.gets.split(/ /).sort!
maxlength = 0
maxappearance = 0
num = 0
temp = ""
out = Array.new
for i in 0.. words.length-1
  if maxlength < words[i].length
    maxlength = words[i].length
    out[1] = words[i]
  end
  if temp == words[i]
    num += 1
    temp = words[i]
  else
    num = 0
    temp = words[i]
  end
  if maxappearance < num
    maxappearance = num
    out[0] = words[i]
  end
end
puts out*" "