h = Hash.new
f = Hash.new
while s = gets do
  h.default = 0
  f.default = 0
  s.split.each{|i|
    h[i] = h[i] + 1
    f[i] = i.length
  }
  puts "#{h.max{|a, b| a[1] <=> b[1]}.shift} #{f.max{|a, b| a[1] <=> b[1]}.shift}"
end