l = gets.split
ln = {:mx => 0, :wd => ""}
lm = {:mx => 0, :wd => ""}
l.each{|w|
  if lm[:mx] < l.count(w)
    lm[:mx] = l.count(w)
    lm[:wd] = w
  end
  if ln[:mx] < w.length
    ln[:mx] = w.length
    ln[:wd] = w
  end
}
puts "#{lm[:wd]} #{ln[:wd]}"