strings = gets.split(" ")
hash = Hash.new(0)
longest_size = strings.max_by{ |(elm1)| elm1.length}
strings.each {|e| hash[e] += 1}
freq_num = hash.max_by{|_,len_i| len_i }[0]

puts "#{freq_num} #{longest_size}"

