#include<stdio.h>
#include<math.h>

int main(void){
	
	int n,i;
	int max,min;
	int readed,ans;
	double avg;
	
	while(1){
		
		scanf(" %d",&n);
		
		max = 0;
		min = 2000;
		
		if(n==0){
			break;
		}
		
		for(i = 0;i < n;i++){
			
			scanf(" %d",&readed);
			
			if(max < readed){
				max = readed;
			}
			
			if(min > readed){
				min = readed;
			}
			
			avg += readed;
		}
		
		avg -= max + min;
		
		avg /= n - 2;
		
		ans = (int)floor(avg);
		
		printf("%d\n",ans);
		
	}
	
	return(0);
	
}