while (line = gets.to_i) != 0 do
  array = []
  line.times do |i|
    array << gets.to_i
  end
  array.sort!
  sum = 0
  (1..array.size - 2).each do |i|
    sum += array[i]
  end
  puts sum / (array.size - 2)
end
