object Main extends App {
  val src = io.Source.stdin.getLines.next.split(" ").toList

  val mostFreqNum =
    (for { word <- src } yield src.count(_ == word)).max + 1

  val srcIndexed = src.zipWithIndex

  val mostFreq = srcIndexed(mostFreqNum)._1

  val longest = ("" /: src)((a, b) => if (a.length > b.length) a else b)

  println(s"$mostFreq $longest")
}