class A def initialize n = gets.chomp.to_i l = gets.chomp.split(' ').map(&:to_i) cache = Hash.new(false) p l.group_by{|i| cache[i] || cache[i] = l.count(i)}.sort.reverse.to_h.first.last.uniq.sort.last end end A.new