input = gets.chomp.split.sort
longest ,frequent = "",""
frequent_num = 0
(input.size).times do |i|
  longest = input[i] if longest.size < input[i].size
  if frequent_num < input.select{|x| x==input[i]}.size
    frequent_num = input.select{|x| x==input[i]}.size
    frequent = input[i]
  end
end
puts frequent + " " + longest