import scala.io.StdIn.readLine
import scala.collection.immutable.HashMap

object Main {

  def main(args:Array[String]) = {
    val r = readLine.split(" ")
    var (w1,max,w2,freq) = ("",0,"",0)
    val freqs = r.foldLeft(HashMap[String,(Int,Int)]()) { (x,y) =>
      if(x.contains(y)) x.updated(y,(x(y)._1+1,x(y)._2)) else x ++ HashMap[String,(Int,Int)]( y -> (0,y.length) )
    }

    for(s <- freqs) {
      if(max < s._2._2) { max = s._2._2;w1 = s._1 }
      if(freq < s._2._1) { freq = s._2._1;w2 = s._1 }
    }

    println(w2 + " " + w1)
  }
}