Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Id int
	Time int
}

type ByTime []Team
func (a ByTime) Len() int {
	return len(a)
}
func (a ByTime) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a ByTime) Less(i, j int) bool {
	return a[i].Time < a[j].Time
}

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			id, _ := strconv.Atoi(buf[0])
			m1, _ := strconv.Atoi(buf[1])
			s1, _ := strconv.Atoi(buf[2])
			m2, _ := strconv.Atoi(buf[3])
			s2, _ := strconv.Atoi(buf[4])
			m3, _ := strconv.Atoi(buf[5])
			s3, _ := strconv.Atoi(buf[6])
			m4, _ := strconv.Atoi(buf[7])
			s4, _ := strconv.Atoi(buf[8])
			team := Team{id, m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4}
			teams[i] = team
		}
		sort.Sort(ByTime(teams))
		fmt.Println(teams[0].Id)
		fmt.Println(teams[1].Id)
		fmt.Println(teams[len(teams)-2].Id)
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-8;

int main(){

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

		vector<P> data;
		for(int i=0;i<n;i++){
			int c1,m1,s1,m2,s2,m3,s3,m4,s4;
			scanf("%d %d %d %d %d %d %d %d %d",&c1,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
			int sum = 60*(m1+m2+m3+m4)+(s1+s2+s3+s4);
			data.push_back(P(sum,c1));
		}

		sort(data.begin(),data.end());

		printf("%d\n",data[0].second);
		printf("%d\n",data[1].second);
		printf("%d\n",data[data.size()-2].second);
	}
}

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

class Score{
public:
    int num;
    int time;
    
    Score(){
        this->num = 0;
        this->time = 0;
    }
    
    Score(int num, int time){
        this->num = num;
        this->time = time;
    }
    
};

int main(int argc, const char * argv[]) {
    
    while (true) {
        int n;
        cin >> n;
        
        Score max,pre,biri,boobie;
        
        for(int i=0;i<n;i++){
            int c1;
            cin >> c1;
            int sum = 0;
            for(int i=0;i<4;i++){
                int m, s;
                cin >> m >> s;
                sum+= 60*m + s;
            }
            
            if(max.time == 0 || max.time > sum){
                pre = max;
                max = Score(c1,sum);
            }
            else if(pre.time == 0 || pre.time > sum){
                if(biri.time == 0){
                    biri = pre;
                }
                else if(boobie.time == 0){
                    boobie = pre;
                }
                pre = Score(c1,sum);
            }
            else if(biri.time < sum){
                boobie = biri;
                biri = Score(c1,sum);
            }
            else if(boobie.time < sum){
                boobie = Score(c1,sum);
            }
            
        }
        
        cout << max.num << endl;
        cout << pre.num << endl;
        cout << boobie.num << endl;
        
    }
    
    return 0;
}

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

using namespace std;

int main(void)
{
	vector< pair<int,int> > team;

	int n;

	while( cin >> n && n != 0 ){
		for( int i = 0;i < n;i++ ){
			int sum = 0;;
			int m,s;
			int number;

			cin >> number;

			for( int j = 0;j < 4;j++ ){
				cin >> m >> s;
				sum += m * 60 + s;
			}
			team.push_back( pair<int, int>( sum, number ) );
		}

		sort( team.begin(), team.end() );

		for( int i = 0;i < 2;i++ ){
			cout << team[i].second << endl;
		}
		cout << team[n - 2].second << endl;
	}

	return 0;
}

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

int main()
{
	int a, time, number, m1, s1, m2, s2, m3, s3, m4, s4;
	vector<pair <int, int> > team;
	
	while(1)
	{
		cin >> a;
		if (a == 0)
		{
			break;
		}
		team.clear();
		for(int i = 0; i < a; i++)
		{
			cin >> number;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			time = m1 *60  + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
		
			team. push_back(make_pair(time, number));
		
		}
	
		sort(team.begin(), team.end());
	
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[a - 2].second << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[4]={"a","b","c","d"};
        int num[4]={100000,100000,0,0};
        for(int i=0,sum;i<n;i++){
            string st;
            cin>>st;
            sum=0;
            for(int j=0,minute,second;j<4;j++){
                cin>>minute>>second;
                sum+=60*minute+second;
            }
            if(sum<num[1]){
                num[1]=sum;
                str[1]=st;
                if(num[1]<num[0]){
                    swap(num[0],num[1]);
                    swap(str[0],str[1]);
                }
            }
            if(sum>num[2]){
                num[2]=sum;
                str[2]=st;
                if(num[2]>num[3]){
                    swap(num[2],num[2]);
                    swap(str[2],str[3]);
                }
            }
        }
        for(int i=0;i<3;i++)cout<<str[i]<<endl;
    }
}

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

int main(){
  int n,i,a,b,c,d,e,f,g,h;
  for(;scanf("%d",&n),n;){
    vector<pair<int,int> >v;
    for(;n--;)scanf("%d%d%d%d%d%d%d%d%d",&i,&a,&b,&c,&d,&e,&f,&g,&h),v.push_back(make_pair(a*60+b+c*60+d+e*60+f+g*60+h,i));
    sort(v.begin(),v.end());
    printf("%d\n%d\n%d\n",v[0].second,v[1].second,v[v.size()-2].second);
  }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
#define M 256

int I[M+1];
int R[M+1];
int O[M+1];
int N;

long double getEntropy( int S, int A, int C ){
    R[0] = S;
    for ( int i = 1; i <= N; i++ ){
	R[i] = (A*R[i-1]+C)%M;
    }
    for ( int i = 1; i <= N; i++ ){
	O[i] = (I[i] + R[i])%M;
    }

    long double H = 0;
    int cnt[M+1];
    for ( int i = 0; i <= M; i++ ) cnt[i] = 0;
    for ( int i = 1; i <= N; i++ ) cnt[O[i]]++;

    for ( int i = 0; i <= M; i++ ){
	if ( cnt[i] > 0){
	    long double x = 1.0*cnt[i]/N;
	    H += x*log(x);
	} 
    }
    return -1*H;
}
#define EPS (1e-12)
void compute(){
    int S, A, C;
    long double minv = (1<<21);
    //long double maxv = -1*(1<<21);
    for ( int s = 0; s <= 15; s++ ){
	for ( int a = 0; a <= 15; a++ ){
	    for ( int c = 0; c <= 15; c++ ){
		long double e = getEntropy(s, a, c);
		if ( minv-EPS > e ){
		    //		    cout << e << endl;
		    S = s; A = a; C = c;
		    minv = e;
		}
	    }
	}
    }
    cout << S << " " << A << " " << C << endl;
}

main(){
    while(1){
	cin >> N;
	if ( N == 0 ) break;
	for ( int i = 1; i <= N; i++ ) cin >> I[i];
	compute();
    }
}