words=gets.chomp.split(" ")
length=(0..words.size-1).map{|i| words[i].size}
count=(0..words.size-1).map{|i| words[0..i].count(words[i])}
puts [words[count.index(count.max)],words[length.index(length.max)]].join(" ")
