words = input().split(' ')

print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1]))
words = input().split()

print((max(words, key=words.count), max(words, key=len)))
words = input().split(" ")
print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1]))

words = input().split()
print((max(words, key=words.count), max(words, key=len)))

-words = input().split(" ") -print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1])) +words = input().split() +print((max(words, key=words.count), max(words, key=len)))