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 <algorithm>

using namespace std;

int main()
{
    int n;

    while (cin >> n, n) {
        int ans = 0, s;
        int max_s, min_s;

        max_s = 0;
        min_s = 1000;
        for (int i = 0; i < n; i++) {
            cin >> s;

            ans += s;
            max_s = max(max_s, s);
            min_s = min(min_s, s);
        }

        cout << (ans - max_s - min_s) / (n - 2) << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N;
  while (cin>>N,N!=0){
    int ma = 0, mi = INF;
    int ans=0;
    for(int i=0;i<N;i++){
      int t;cin>>t;
      ma=max(ma,t);
      mi=min(mi,t);
      ans+=t;
    }
    ans-=ma+mi;
    N-=2;
    ans/=N;
    cout<<ans<<endl;
  }
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl;
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// Aliases
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        int sum = 0, smn = INT_MAX, smx = INT_MIN;
        REP(i, n) {
            int s;
            cin >> s;
            sum += s;
            smn = min(smn, s);
            smx = max(smx, s);
        }
        cout << (sum - smn - smx) / (n - 2) << "\n";
    }

    return 0;
}

C++: #include <iostream>
#include <limits.h>

#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<vector>
#include<algorithm>
using namespace std;
int main(){

  int sum = 0, x, total, ans;
  vector<int> p(0);
  int n;
  
    while(1){
      cin >> n;
      if(n==0)
      break;
      for(int i=0; i<n; i++){
        cin >> x;
        p.push_back(x);
      }

      int max = *max_element(p.begin(), p.end());
      int min = *min_element(p.begin(), p.end());

      for(int i=0; i<n; i++){
        sum += p[i];
      }
      total = sum - min - max;
      ans = total / (n-2);
      cout << ans << endl;
    }

  return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = 3.141592653589793;
int n;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    while (n!=0) {
        int  s[105]={};
        rep(i,n) cin >> s[i];
        sort(s,s+n);
        int ans=0;
        rep2(i,1,n-1) ans+=s[i];
        cout << ans /(n-2) << endl;
        cin >> n;
    }
    return 0;
}

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

int main(){
  int n,maxn,minn,ave,sum = 0;

  while(cin >> n){
    if(n == 0) break;
    
    int *s = new int[n];

    cin >> s[0];
    maxn = minn = 0;
    for(int i = 1; i<n ; ++i){
      cin >> s[i];

      if(s[maxn]  <= s[i]){
	maxn = i;
      }
      if(s[minn] >= s[i]){
	minn = i;
      }

      
    }

    for(int i=0; i<n ; ++i){
      if(i != maxn && i != minn){
	sum += s[i];
      }
    }


    
    ave = sum/(n - 2);

    cout << ave << endl;

    sum = 0;
    ave = 0;
    
    delete[] s;
  }
  
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0)return 0;
    vector<int> a(n);
    for(int i=0;i<a.size();i++){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    int sum =0;
    for(int i=1;i<(a.size()-1);i++){
        sum+=a[i];
      }
    int avg = sum/(n-2);
    cout << avg << endl;
  }
}

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

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

using namespace std;

typedef vector<int> vi;

int main(){
	int n;
	while(cin >> n, n){
		vi v(n);
		rep(i, n){
			cin >> v[i];
		}
		sort(all(v));
		int sum = 0;
		for(int i = 1; i < n-1; i++){
			sum += v[i];
		}
		cout << sum/(n-2) << endl;
	}

	return 0;
}

C++: #include<stdio.h>

int sum(int x[], int n)
{
  int a, t_sum=0;
  for(a=1; a<n-1; a++)
    {
      t_sum+=x[a];
    }
  return t_sum;
}


int main(void)
{
  int count=0, check=0, i=0,k=0, avg[10]={0};

  while(1)
    {
      int  temp=0, score[100]={0};
      scanf("%d", &count);
      if(count==0)
	{

	  for(i=1;i<=k;i++)
	    {
	      printf("%d\n", avg[i]);
	    }
	  return 0;
	}
      else
	{
	  k++;
	  for(i=0; i<count; i++)
	    {
	      scanf("%d", &check);
	      score[i]=check;
	    }
int t, j, temp;

  for(t=0;t<count-1;t++)
    {
      for(j=count-1;j>t; j--)
	{
	  if(score[j-1]>score[j])
	    {
	    temp=score[j];
	  score[j]=score[j-1];
	  score[j-1]=temp;
	    }
	}
    }
	  temp=sum(score,count);

	  avg[k]=temp/(count-2);
	  
	}
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<int> s(n);
    for (int i = 0; i < n; i++){
      cin >> s[i];
    }
    sort(s.begin(), s.end());
    int sum = 0;
    for (int i = 1; i < n - 1; i++){
      sum += s[i];
    }
    cout << sum / (n - 2) << endl;
  }
}