#include<stdio.h>

int mx, mn, n, as, t, i, s;
int main() {
  while(1) {
    scanf("%d", &n);
    if(n == 0) break;
    mx = 0;
    mn = 1000;
    t = 0;
    for(i = 0; i < n; i++) {
      scanf("%d", &s);
      t += s;
      if(s < mn) mn = s;
      if(mx < s) mx = s;
    }
    as = (t - mn - mx) / (n - 2);
    printf("%d\n", as);
  }
  return 0;
}