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 <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 -1;
    }
    
    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;
}

C++: 
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
#include<type_traits>
long long int D[10000];
long long int E[400000];

using namespace std;
int main() {
	long long int N;
	long long int Y = -1;
	cin >> N;
	while (N) {
		Y++;
		for (long long int i = 0; i < N; i++) {
			cin >> D[i];
		}

		sort(D, D + N);
		long long int W = 0;
		for (long long int i = 1; i < N-1; i++) {
			W += D[i];
		}
		E[Y] = W / (N-2);
		cin >> N;
		
	}

	for (long long int i = 0; i <=Y ;i++) {
		cout << E[i] << endl;
	}
	return 0;
}

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

int N;
vector<int> scores;
int judge;

int main()
{
        while(cin >> N){
                if(N==0) break;
                int sum = 0;
                for(int i=0;i<N;i++){
                        cin >> judge;
                        scores.push_back(judge);
                }

                sort(scores.begin(),scores.end());
                scores.erase(scores.begin());
                scores.erase(scores.end()-1);
                for(int i=0;i<N-2;i++){
                        sum += scores[i];
                }
                cout << sum/scores.size() << endl;
                scores.clear();
        }

        return 0;
}

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

int main() {
  int n;

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

C++: //
//  main.cpp
//  no.1
//
//  Created by MacBook_Virgo on 2015/04/23.
//  Copyright (c) 2015??´ MacBook_Virgo. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    while(cin >> n,n!=0){
    int max,min;
    max = 0;
    min = 1000;
    int x;
    int sum = 0;
    for(int i = 0;i <n;i = i+1){
        cin >> x;
        sum = sum + x;
        if(x >max){
            max = x;}
        if(x < min){
            min = x;}
    }
    cout << (sum - max - min) / (n-2) << endl;
    }return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main() {
	int c[20];   // int[] c = new int[20];
	int w = 0;
	while (true)
	{
		int a;
		cin >>  a;// int a = int.Parse(Console.ReadLine());
		if (a == 0)
			break;
		int sum = 0;
		int b[a];
		for (int j = 0; j < a; j++)
		{
			cin >> b[j];
			sum += b[j];
		}
		sum -= b.Max() + b.Min();
		c[w] = (sum / (a - 2));
		w++;
	}
	for (int j = 0; j<w; j++)
	{
		cout << c[j] << endl;
	}
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int n,s[100];

int main()
{
        scanf("%d",&n);
        if (n==0) return 0;
        for (int i=0;i<n;i++){
                scanf("%d",s+i);
        }
        sort(s, s+n);
        int k=0;
        for (int i=1;i<n-1;i++){
                k+=s[i];
        }
        k/=n-2;
        printf("%d\n",k);
        main();
}

C++: #include<iostream> 
using namespace std; 
int main(){ 
  int n; 
  int t[100],mx,mn,sum; 
  while(1){ 
    cin>>n; 
    if(n==0)break; 
    mx=sum=0; 
    mn=1000; 
    for(int i=0;i<n;i++){ 
      cin>>t[i]; 
      if(mn>t[i])mn=t[i]; 
      if(mx<t[i])mx=t[i]; 
      sum+=t[i]; 
    } 
    sum-=mn; 
    sum-=mx; 
    cout<<sum/(n-2)<<endl; 
      
  } 
  return 0; 
}

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

using namespace std;

void solve(int n){
  list <int> s;
  for(int i = 0 ; i < n ; i++ ){
    int a;
    cin >> a;
    s.push_back(a);
  }
  
  int s_max = 0;
  int s_min = 0xFFFF;
  list<int>::iterator s_max_it;
  list<int>::iterator s_min_it;

  for(auto it = s.begin() ; it != s.end() ; it++ ){
    if(*it > s_max){
      s_max = *it;
      s_max_it = it;
    }
    if(*it < s_min){
      s_min = *it;
      s_min_it = it;
    }
  }
  
  s.erase(s_max_it);
  s.erase(s_min_it);

  int sum = 0;
  for(auto it = s.begin() ; it != s.end() ; it++ ){
    sum += *it;
  } 
  cout << sum / (n-2) << endl;
  return;
}

int main(){
  
  while(1){
  
  int n;
  cin >> n;
  
  if(n > 0)
    solve(n);
  else
    break;

  }

  return 0;
}

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

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

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	int tem;
	int sum;


	while(1){
		cin>>n;
		if(n==0) break;

		sum=0;
		vector<int> v;
		for(int i1=0; i1<n; i1++){
			cin>>tem;
			v.push_back(tem);
			sum+=tem;
		}
		sort(v.begin(), v.end());
		sum-=(v[0]+v[v.size()-1]);
		cout<<sum/(n-2)<<endl;
		
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n; //審判の数

    while(true){
        int s[1010]; //各審判のつけた点数
        cin >> n;
        if(n == 0) break;

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

        int max = 0, min = 1000; //点数の最小値、最大値
        for(int i = 0; i < n; i++){
            if(s[i] > max) max = s[i];
            if(s[i] < min) min = s[i];
        }

        int sum = 0; //最高点と最低値を除いた点数たちの和
        int mean; //最高点と最低値を除いた点数の平均値
        for(int i = 0; i < n; i++){
            sum += s[i];
        }
        mean = (sum - max - min) / (n - 2);

        cout << mean << endl;
    }
}