str = gets.chomp;
list = str.split(" ")
hash = {}
list.each do |s|
    hash[s] = 0
end
list.each do |s|
    hash[s] += 1
end
h = hash.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }
print h[0][0]
print " "
l = hash.sort {|(k1, v1), (k2, v2)| k2.size <=> k1.size }
puts l[0][0]
