text = STDIN.gets.chomp!
words = text.split(' ')
counts = {}
longest_word = ""
words.each do |word|
  if word.length > longest_word.length then
    longest_word = word
  end
  if counts.has_key?(word) then
    counts[word]+=1
  else
    counts[word]=0
  end
end

max_count=0
most_frequent_word=""
counts.keys.each do |key|
  if max_count < counts[key] then
    most_frequent_word = key
    max_count = counts[key]
  end
end

puts "#{most_frequent_word} #{longest_word}"