Go: /*
	Problem A: ICPC 得点集計ソフトウェア
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1147&lang=jp
*/

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// 標準入力を取得するScannerのインスタンスを作成
var sc = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込み文字列として返す
func readLine() string {
	if sc.Scan() {
		return sc.Text()
	}
	return ""
}

func average() (avg int) {
	// 審判の人数を取得する
	n, _ := strconv.Atoi(readLine())

	// 得点
	score := make([]int, 0, n)

	// 得点を読み込む
	for n > 0 {
		line, _ := strconv.Atoi(readLine())
		score = append(score, line)
		n--
	}

	if len(score) == 0 {
		return 0
	}

	// ソート
	sort.Ints(score)
	// 先頭を削除
	score = append(score[:0], score[1:]...)
	// 末尾を削除
	score = score[:len(score)-1]

	// 合計
	for i := 0; i < len(score); i++ {
		avg += score[i]
	}

	// 平均
	avg = avg / len(score)
	return avg
}

func main() {
	// 改行区切りから単語(スペース)区切りで読み込むように変更する
	sc.Split(bufio.ScanWords)
	for {
		avg := average()
		if avg != 0 {
			fmt.Println(avg)
		} else {
			break
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main(void){
    for(int n, sum = 0, ma, mi; cin >> n, n; cout << sum / (n - 2) << endl, sum = 0){
        rep(i, n){
            int s; cin >> s;
            if(!i) mi = s;
            else if(i == 1) ma = max(mi, s), mi = min(mi, s); 
            else if(s < mi) sum += mi, mi = s;
            else if(s > ma) sum += ma, ma = s;
            else sum += s;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
bool test = true;
int num;
while(test)
{
int ans = 0;
cin >> num;
if(num != 0)
{
int a[num];
for(int i = 0;i<num;i++)
{
 cin >> a[i];
}
sort(a, a + num);
for(int i=1; i<num-1;i++)
{
ans += a[i];
}
cout << ans << endl;
}
else
{
return 0;
}
}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    REP(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int sum = 0;
    FOR(i,1,n-1)sum+=a[i];
    cout<<sum/(n-2)<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int main(){
	int n, s[100], k;
	double l, g, sum;
	double ans;
	while(1){
		cin >> n;
		if(!n) break;
		g = -1;
		l = 1001;
		sum = 0;
		for(k=0;k<n;k++){
			cin >> s[k];
			sum += s[k];
			if(g < s[k]) g = s[k];
			if(l > s[k]) l = s[k];
			//cout << g << " " << l << " " << sum << endl;
		}
		ans = (sum - l - g)/((double)n-2);
		printf("%.0f\n", ans);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int a[100];
	int b,sum=0,point;
	while(1){
		cin >> b;
		if(b==0) break;
		for(int i=0;i<b;i++){
			cin >> a[i];
			
		}
		sort(a,a+b);
		for(int j=1;j<b-1;j++){
			sum+=a[j];
		}
		point=sum/(b-2);
		cout << point << endl;
		sum=0;
		
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int solve(vector<int> s){
    sort(s.begin(),s.end());
    int al = 0;
    for(int i=1;i<s.size()-1;i++){
        al += s[i];
    }
    return al / (s.size()-2);
}
int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> s(n);
        for(int i=0;i<n;i++) cin >> s[i];
        cout << solve(s) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; ++i){
		int m, j = 0;
		while(cin >> m,m){
			a[j] = m;
			j++;
		}
		sort(a,a+j+1);
		int sum = 0;
		for (int k = 1; k < j; ++k){
			sum += a[k];
		}
		cout << (sum / j-1) << endl;
	}
	return 0;
}

C++: #include <cstdio>

int main()
{
int n;
vector<int> s;
scanf("%d", &n);
s.resize(n);
for(int i = 0; i < n; ++i)
scanf("%d", &s[i]);
sort(s.begin(), s.end());
int sum = 0;
for(int i = 1; i < n - 1; ++i)
sum += s[i];
printf("%d\n", sum / (n - 2));
return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(void){
	int n,i,s,b,w,ans;
	while(true){
		scanf("%d",&n);
		if(n==0){break;}
		ans = 0;
		b = -1;
		w = 1001;
		for(i=0; i<n; i++){
			 cin >> s;
			 b = max(s,b);
			 w = min(s,w);
			 ans += s;
		}
		ans -= b;
		ans -= w;
		cout << (ans/(n-2)) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int n, tmp;
    int ans = 0;
    while(cin >> n && n) {
        vector<int> in;
        for(int i=0; i<n; ++i) {
            cin >> tmp;
            in.push_back(tmp);
        }
        sort(in.begin(), in.end());
        for(int i=1; i<n-1; ++i) ans += in[i];
        cout << ans/(n-2) << endl;
    }
}

C++: #include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  ll N;
  ll s[1100];
  ll sum=0;
  ll t=1;
  while(N){
  cin >>N;
  for(ll i = 0; i < N; ++i){
      cin >> s[i];
  }
  sort(s,s+N);
  for(ll i = 1; i < N-1; ++i){
    sum+=s[i];
  }
  cout<<sum/(N-2)<<endl;
  cin>>N;
}
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){

  while(true){
    int n;
    cin >> n;

    if(n==0) break;

    int sum=0, a=INF, b=-1; //a:min, b:max

    rep(i,n){
      int s;
      scanf("%d",&s);
      sum += s;
      a=min(a,s);
      b=max(b,s);
    }
    sum=(sum-a-b)/(n-2);

    cout << sum << endl;

  }

}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

void remove_minmax(vector<int> &data){
  int max = 0;
  int min = 1000000;
  int min_i = 0;
  int max_i = 0;
  int count = 0;
  vector<int>::iterator it = data.begin();
  while (it != data.end()){
    if (*it < min){
      min = *it;
      min_i = count;
    }
    if (*it > max){
      max = *it;
      max_i = count;
    }
    ++count;
    ++it;
  }
  data[max_i] = 0;
  data[min_i] = 0;
}

int main(void){
  int n;
  while (cin >> n){
    if (n == 0){
      return 0;
    }
    
    vector<int> data;
    
    for (int i=0; i<n; ++i){
      int num;
      cin >> num;
      data.push_back(num);
    }
    remove_minmax(data);

    int total = floor((double)accumulate(data.begin(), data.end(), 0)/(n-2));
    cout << total << endl;
  }
  return 0;
}