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++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

string target;
int ts;
struct Group1 {
	int a, b;
	bool operator < (const Group1 &g) const {
		// if (a == g.a) return b > g.b;
		return a < g.a;
	}
}; 
struct Group2 {
	int a, b;
	bool operator < (const Group2 &g) const {
		// if (b == g.b) return a > g.a;
		return b > g.b;
	}
};

signed main(void)
{
	int N;
	while (1) {
		cin >> N;
		if (N == 0) break;
		vector<int> v(N);
		rep(i, N) {
			cin >> v[i];
		}
		sort(ALL(v));
		int sum = 0;
		REP(i, 1, v.size() - 1) {
			sum += v[i];
		}
		cout << sum/(N-2) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<numeric>
#include<map>
#include<math.h>

using namespace::std;

int main(void)
{
  int n;
  vector<int> s;

  while(cin >> n && n != 0)
    {
      int tempS;
      s.clear();

      for(int i = 0; i < n; i++)
	{
	  cin >> tempS;
	  s.push_back(tempS);
	}

      sort( s.begin() , s.end() );
      int ans=0;
      for(int i = 1; i < n-1; i++)
	{
	  ans+=s[i]; 
	}
      cout << ans/( n - 2 ) << endl;
    }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(void){
  while(true){
    long n;
    cin >> n;
    if(n == 0){
      break;
    }
    vector<long> S;
    for(int i = 0; i < n;++i){
      long s;
      cin >> s;
      S.push_back(s);
    }
      long mx = *max_element(S.begin(), S.end());
      long mn = *min_element(S.begin(), S.end());
      long sum = accumulate(S.begin(), S.end(), 0);
      cout << (sum - mx - mn) / (n - 2)  << endl;
  }
 return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    vector<int> input(n);
    for(int i = 0; i < n; i++){ cin >> input[i]; }
    sort(input.begin(), input.end());
    
    int ans = 0;
    for(int i = 1; i < n - 1; i++){ ans += input[i]; }
    ans /= (n - 2);
    cout << ans << endl;
  }


  return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;

int main()
{
  int n,s,i,sum;
  multiset<int> ms;
  multiset<int>::iterator it,ite;
  while(cin>>n,n){
    ms.clear();
    for(i=0;i<n;i++){
      cin>>s;
      ms.insert(s);
    }
    sum=0;
    ite=ms.end();
    ite--;
    it=ms.begin();
    for(it++;it!=ite;it++)sum+=*it;
    cout<<sum/(n-2)<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 2e18;
const double PI = acos(-1);

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	while (N != 0)
	{

		int mav = 0;
		int miv = 1000;
		int sum = 0;
		REP(i, N)
		{
			int a;
			cin >> a;
			sum += a;
			mav = max(mav, a);
			miv = min(miv, a);
		}
		cout << (sum - mav - miv) / (N - 2) << endl;
		cin >> N;
	}
	return 0;
}

C++: // includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  while(1) {
    int n;
    cin >> n;
    if(!n) break;
    vector<int> v(n);
    for(auto &e: v) cin >> e;
    sort(begin(v), end(v));
    ll sum = 0;
    for(int i = 1; i < n - 1; i++) sum += v[i];
    cout << sum / (n - 2) << "\n";
  }
  return 0;
}