hist = {}
max = ""

while line = gets do
  words = line.chomp.split(" ")
  words.each do |w|
    if hist.include? w
      hist[w] += 1
    else
      hist[w] = 1
    end

    max = w if max.length < w.length
  end
end
hist = hist.sort{|(k1 ,v1), (k2, v2)| v2 <=> v1}
puts "#{hist.to_a[0][0]} #{max}"