Ls = gets.chomp.split.map(&:to_i) counts = Ls.uniq.map{|item| [item, Ls.count(item)]}.to_h values = counts.values if values.count(values.max) == 1 puts counts.key(values.max) else puts counts.select { |k,value| value == values.max }.keys.max end