x = gets
y = x.split()

strlength= y.map{|str| str.length }

numlength = strlength.max

maxlengthin = strlength.find_index{|k| k == numlength}

strcount = []
i = 0
while i < y.length
 numcount = y.count{|a| y[i] == a}
 strcount << numcount
 i += 1
end

nummax = strcount.max

maxstr = strcount.find_index{|n| n == nummax}

puts "#{y[maxstr]} #{y[maxlengthin]}"
