#include <stdio.h>

int solve(int n){
  int i, s, total, min, max;
  scanf("%d", &s);
  min = s;
  max = s;
  total = s;
  for(i = 1; i < n; i++){
    scanf("%d", &s);
    if(s < min) min = s;
    if(s > max) max = s;
    total += s;
  }

  total -= min;
  total -= max;

  return total / (n - 2);
}

int main(void){
  int n;
  while(1){
    scanf("%d", &n);
    if(n == 0) return 0;
    else printf("%d\n", solve(n));
  }
}
