result = []
loop do
    input = gets.chomp!.to_i
    ary = []
    break unless input != 0

    input.times do
        ary << gets.chomp!.to_i
    end

    ary.sort_by!{|a, b| a<=>b}
    ary.delete_at(0)
    ary.delete_at(ary.length-1)

    sum = 0
    ary.each do |i|
        sum += i
    end

    result << sum / ary.length
end

result.each do |r|
    p r
end