loop do
  judge_num = gets.chomp.to_i
  if judge_num == 0
    break
  end
  max_val = 0
  min_val = 1001
  sum = 0
  judge_num.times do |i|
    value = gets.chomp.to_i
    if value > max_val
      max_val = value
    end
    if value < min_val
      min_val = value
    end
    sum += value
  end
  sum -= (min_val + max_val)
  puts (sum / (judge_num - 2)).floor
end
