import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val m = mutableMapOf<String, Int>()
    while (sc.hasNext()) {
        val n = sc.next()
        m[n] = m.getOrDefault(n, 0)+1
    }
    val l = m.toList()
    val ans1 = l.sortedBy { it.second }.last().first
    val ans2 = l.sortedBy { it.first.length }.last().first
    println("$ans1 $ans2")
}
