#!/bin/ruby n = gets.strip.to_i types = gets.strip types = types.split(' ').map(&:to_i) # your code goes here type_data_hash = {} types.each do |val| unless type_data_hash.include?("#{val}") type_data_hash["#{val}"] = 0 end end types.each do |val| type_data_hash["#{val}"] += 1 end #p type_data_hash max_hash = type_data_hash.select {|k,v| v == type_data_hash.values.max } #p max_hash final_answer = 0 iteration = 0 max_hash.each do |key, value| if iteration == 0 final_answer = key.to_i iteration += 1 end if key.to_i < final_answer final_answer = key.to_i end end print final_answer