while true do
  person_count = gets.to_i
  break if person_count == 0

  scores = Array.new(person_count, 0)
  total_score = 0

  person_count.times do |i|
    scores[i] = gets.to_i
    total_score += scores[i]
  end

  total_score -= scores.min
  total_score -= scores.max

  p total_score / (person_count-2)
end