data = gets.chomp.split
longestString = ""
freq = {}

data.each do |elem|
  longestString = elem if longestString.size < elem.size
  if freq.key?(elem)
    freq[elem] += 1
  else
    freq[elem] = 1
  end
end

keys = freq.keys
values = freq.values

puts "#{keys[values.index(values.max)]} #{longestString}"

# あんまりきれいな書き方ではないけど，
# ” There is only one word which is arise most frequently in given text.”よりindexを使った