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 <cmath>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> score(n);
        for (int i = 0; i < n; i++) {
            cin >> score[i];
        }
        sort(score.begin(), score.end());

        int s = 0;
        for (int i = 1; i < n - 1; i++) {
            s += score[i];
        }
        cout << s / (n - 2) << endl;
    }

    return 0;
}

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

int main()
{
  int n;
  while(cin >> n){
    int sum = 0;
    int s[100];
    if(n == 0) break;
    else{
      for(int i = 0; i < n; i++){
	cin >> s[i];
      }
      sort(s, s + n);
      s[0] = 0;
      s[n - 1] = 0;
      for(int i = 0; i < n; i++){
	sum += s[i];
      }
      cout << sum / (n - 2) << endl;
    }
  }
}

C++: #include<bits/stdc++.h>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,s[105];

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

C++: import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj1147().doIt();
	}
	class aoj1147{
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int num[] = new int [n];
				int max = 0;
				int min = Integer.MAX_VALUE;
				int ave = 0;
				for(int i = 0;i < n;i++){
					num[i] = sc.nextInt();
					if(num[i] > max)max = num[i];
					if(num[i] < min)min = num[i];
				}
				for(int i = 0;i < n;i++){
					if(num[i] == max){
						max = Integer.MAX_VALUE;
					}else if(num[i] == min){
						min = Integer.MAX_VALUE;
					}else{
						ave = ave + num[i];
					}
				}
				ave = ave / (n - 2);
				System.out.println(ave);
			}
		}
	}
}

C++: int main()
{
    int a,b[100];
    int max=0,min=100,sum=0,result;
    for(int i=0;i<a;i++){
        cin>>b[i];
        sum+=b[i];
        if(b[i]<min){
            min=b[i];
        }
        else if(b[i]>max){
            max=b[i];
        }
    }
    result=sum-min-max;
    cout<<result;
    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> Score(n);
            REP(i, n) cin >> Score[i];
            int ave = 0;
            whole(sort, Score);
            for(int i = 1; i < n - 1; i++) ave += Score[i];
            ave /= n - 2;
            cout << ave << endl;
        }
    }
}

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

C++: #include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int x,sum=0,mx=0,mn=1000;
		for(int i=0;i<n;i++){
			cin>>x; sum+=x;
			if(x>mx) mx=x;
			if(x<mn) mn=x;
		}
		cout<<(sum-mn-mx)/(n-2)<<endl;
	}
	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;
}

C++: #include <iostream>

#define el endl
#define fd fixed

using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    int m = n;
    if (n == 0) break;
    int max = INT_MIN;
    int min = INT_MAX;
    int ave = 0;
    while (m--) {
      int x;
      cin >> x;
      ave += x;
      if (x < min) min = x;
      if (x > max) max = x;
    }
    ave = ave - (max + min);
    ave = ave / (n-2);
    cout << ave << el;
  }
}

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