#!/bin/ruby n = gets.strip.to_i types = gets.strip types = types.split(' ').map(&:to_i) # your code goes here id_freq = {} types.each do |x| if !id_freq.include? x id_freq[x] = 1 else id_freq[x] += 1 end end highest_freq = 0 common_id = 0 id_freq.each do |key, value| if value == highest_freq if key < common_id common_id = key end end if value > highest_freq highest_freq = value common_id = key end end p common_id