import scala.collection.mutable._

import io.StdIn.readLine

object Main extends App {
  val map:Map[String,Int] = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val l = s.map(_.length).max
  val maxL = s.find(_.length == l).get

  map.foreach(println)
  println(maxF + " " + maxL)
}
