object Main {
    def pack(l: List[String]): List[(Int, Int, String)] = {
        if (l.isEmpty) Nil
        else {
            val (x, y) = l.span(_ == l.head)
            (x.size, x.head.size, x.head) :: pack(y)
        }
    }

    def main(args: Array[String]) = {
        val in = io.StdIn.readLine.split(" ")
        val a = pack(in.toList.sorted)
        println(a.maxBy(_._1)._3 + " " + a.maxBy(_._2)._3)
    }
}