#include<stdio.h>

int getnumber(num){
	int x, sum, MAX, MIN, i;
	scanf("%d",&x);
	MAX = x;
	MIN = x;
	sum = x;
	for(i=1; i<num; i++){
		scanf("%d",&x);
		if(MAX <= x)
			MAX = x;
		else if(x <= MIN)
			MIN = x;
		sum += x;
	}
	return (sum -MAX -MIN)/(num-2);
}

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