dict = File.readlines().collect(&:strip)
i = 0
res = dict.collect(&:reverse).sort.select do |z| 
  i += 1  while z > dict[i] and i < dict.length-1
  z == dict[i] and z < z.reverse
end
puts 
res.take(5).each {|z| puts }