while s = gets do
  h = Hash.new
  f = Hash.new
  s.chomp.split.each{|i|
    if h[i].nil? then
      h[i] = 0
      f[i] = 0
    end
    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