Go: package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		n, _ := strconv.Atoi(sc.Text())
		if n == 0 {
			break
		}
		scores := make([]int, n, n)
		for i := 0; i < n; i++ {
			sc.Scan()
			scores[i], _ = strconv.Atoi(sc.Text())
		}
		sort.IntSlice(scores).Sort()
		var sum = 0
		for i := 1; i < len(scores)-1; i++ {
			sum += scores[i]
		}
		fmt.Println(sum / (n - 2))
	}
}

C++: #include <iostream>
using namespace std;
int N,S;
int set = 0;
int main(){
  while(set <= 20){
    //while(cin >> N && N >= 3 && N <= 100) {
    cin >> N;
    if (N == 0) break;
    int largest = 0;
    int smallest = 1000;
    int sum = 0;
    for (int i = 0; i <N;++i) {
      cin >> S;
      if(largest < S) largest = S;
      if(smallest >S) smallest = S;
      sum += S;
    }
    cout << (sum - largest - smallest)/(N-2) << endl; 
  ++set;
  }
  return 0;
}

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

using namespace std;
int N, S;
int main() {
  while (cin >> N && N > 0) {
    int sum = 0;
    int m = 1001;
    int M = -1;
    for (int i = 0; i < N; ++i) {
      cin >> S;
      sum += S;
      m = min(m, S);
      M = max(M, S);
    }
    sum = sum - m - M;
    int ans = sum / (N-2);
     cout << ans << endl;
  }
  return 0;
}

C++: #include<cstdio>

bool solve(){
	int n,ma = 0,mi = 1000,sum = 0;
	scanf("%d",&n);
	if(n==0) return false;
	for(int i=0;i<n;i++){
		int s;
		scanf("%d",&s);
		if(s<mi) mi = s;
		if(s>ma) ma = s;
		sum += s;
	}
	printf("%d\n",(sum-ma-mi)/(n-2));
	return true;
}

int main(){
	while(solve()){}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n, s, maxn, minn;

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    maxn=0;
    minn=1000;
    int x=0;
    for(int i=0;i<n;i++){
      scanf("%d", &s);
      x+=s;
      maxn=max(s,maxn);
      minn=min(s,minn);
    }

    printf("%d\n",(x-maxn-minn)/(n-2) );
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int judge;
int maxscore =0;
int minscore =0;
int maxnum;
int minnum;
cin >> judge;
int score[judge];
	for(int i=0; i<=judge; i++){
	cin >> score[i];
		if(score[i] > maxscore){
		maxscore = score[i];
		i=maxnum;
		}
		if(score[i] < minscore){
		minscore = score[i];
		i = minnum;
		}
	}
score[maxnum] = 0;
score[minnum] = 0;
int lastscore = 0;
for(int j=0;j<=judge;j++){
lastscore += score[j];
}
lastscore = lastscore/(judge - 2);
cout << lastscore <<endl;
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n;
	while(cin >> n && n){
		vector<int32> x(n);
		int32 sum = 0;
		REP(i, n){
			cin >> x[i];
			sum += x[i];
		}
		cout << (sum-*(max_element(all(x)))-*min_element(all(x)))/(n-2) << endl;
	}
}

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

int main() {
  int n,s,total,max,min;
  while(cin>>n, n) {
    cin>>s;
    max = min = total = s;
    for(int i=0; i<n-1; ++i) {
      cin>>s;
      if(s < min) min = s;
      if(s > max) max = s;
      total += s;
    }
    total = total - min - max;
    cout<<total/(n-2)<<endl;
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0){return 0;}
    int s[n];
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    sort(p,p+n);
    int ans=0;
    for(int i=1;i<n-1;i++){
      ans+=p[i];
    }
    cout<<ans/(n-2)<<endl;
  }
  return 0;}

C++: while true do
    max = -1
    min = 1001
    sum = 0
    n = gets.to_i
    break if n == 0
    n.times do
        v = gets.to_i
        min = v if v < min
        max = v if v > max
        sum += v
    end
    sum -= (min + max)
    p sum / (n-2)
end

C++: #include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1000000000LL;
const ll MOD=1000000007LL;
const ll MAX=100010;
int main(){
	int n;
	while(cin>>n,n){
		int ma=0;
		int mi=INF;
		int sum=0;
		for(int i=0;i<n;i++){
			int s;
			cin>>s;
			sum+=s;
			ma=max(s,ma);
			mi=min(s,mi);
		}
		cout<<(sum-ma-mi)/(n-2)<<endl;
	}
	return 0;
}

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

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)), (x).end())

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 <<29;
const int MOD = 1000000007;

void solve(void) {
  while (1) {
    int N;
    scanf("%d\n", &N);
    if (N == 0) break;
    vector<int> ps;
    rep(N, i) {
      int p;
      scanf("%d\n", &p);
      ps.pb(p);
    }
    sort(all(ps));
    int ans = - ps[0] - ps[N-1];
    for (int t : ps)  ans += t;
    printf("%d\n", ans / (N-2));
  }
}

int main(void) {
  solve();
  return 0;
}

C++: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    while(true){
        ll n;
        cin>>n;
        if(n==0) break;
        vll v(n);
        ll sum=0;
        ll m=LLINF,M=-LLINF;
        rep(i,n){
            cin>>v[i];
            chmax(M,v[i]);
            chmin(m,v[i]);
            sum+=v[i];
        }
        cout<<(sum-m-M)/(n-2)<<endl;
    }
    return 0;
}