n = gets.chomp.to_i l_s = gets.chomp.split.map &:to_i extracts = {} max_key = 0 max_value = 0 l_s.group_by{|i|i}.each{|key, value| if value.size >= max_value max_value = value.size extracts[key] = value.size end } max_num = 0 max_level = 0 extracts.each {|level, num| if num >= max_num and level > max_level max_num = num max_level = level end } p max_level