#include<stdio.h>
int main(void)
{
	int n,s;
	int i,j,sum,max,min,ave;

	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		sum=0;
		min=1001;
		max=-1;
		for(i=0;i<n;i++)	{
			scanf("%d",&s);
			sum+=s;
			if(max<s)	max=s;
			if(min>s)	min=s;
		}
		ave=(sum-max-min)/(n-2);
		printf("%d\n",ave);
	}

	return 0;
}
