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++: #include<stdio.h>
#include<iostream>
using namespace std;


struct SKE{int c1;int m1;int s1;int m2;int s2;int m3;int s3;int m4;int s4;int SUM;};
struct SKE NUM[1000001];
int main (){
int N;
SKE Te,M1,M2,M3,M;
while(1){
cin>>N;if(N==0)break;
for(int i=0;i<N;i++){
	cin>>NUM[i].c1>>NUM[i].m1>>NUM[i].s1>>NUM[i].m2>>NUM[i].s2>>NUM[i].m3>>NUM[i].s3>>NUM[i].m4>>NUM[i].s4;
	NUM[i].SUM=NUM[i].s1+NUM[i].s2+NUM[i].s3+NUM[i].s4+60*(NUM[i].m1+NUM[i].m2+NUM[i].m3+NUM[i].m4);
}

M1=NUM[0];M2=NUM[0];M=NUM[0];M3=NUM[0];
for(int i=1;i<N;i++){
	if(NUM[i].SUM<M1.SUM){M2=M1;M1=NUM[i];}
	else if(NUM[i].SUM<M2.SUM){M2=NUM[i];}
	if(NUM[i].SUM>M.SUM){M3=M;M=NUM[i];}
	else if(NUM[i].SUM>M3.SUM){M3=NUM[i];}

	
for(int i=0;i<N;i++){

}
cout<<M1.c1<<endl<<M2.c1<<endl<<M3.c1<<endl;
for(int i=0;i<N;i++)
{NUM[i].c1=0;NUM[i].m1=0;NUM[i].s1=0;NUM[i].m2=0;NUM[i].s2=0;NUM[i].m3=0;NUM[i].s3=0;NUM[i].m4=0;NUM[i].s4=0;}
}
return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)
#define PP pair< int,PII >
#define Sort(t) sort(t.begin(), t.end())

using namespace std;
typedef pair<int,int> PII;

priority_queue<PII,vector< PII > , greater< PII > > pq;

int main(void){
	int n;
	while(scanf("%d", &n),n){
		rep(i,n){
			int id;
			cin >> id;
			int sum = 0, x;
			rep(j,8){
				cin >> x;
				sum += j%2==0?x*60:x;
			}
			pq.push( pair<int,int>(sum,id));
		}
		/*
		while(!pq.empty()){
			printf("%d %d\n",pq.top().first, pq.top().second);
			pq.pop();
		}*/
		printf("%d\n", pq.top().second);pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		while(pq.size() > 2)pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		pq.pop();
	}
	
	return 0;
}

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

typedef struct{
    int num;
    int sum;
} teams;

void q_sort(teams data[], int begin, int end);

int main(int argc, const char * argv[])
{
    int num = 0;
    while (1) {
        scanf("%d", &num);
        if (num == 0) {
            break;
        }
        teams data[1000000];
        int m[4], s[4];
        for (int i = 0; i < num; i++) {
            data[i].sum = 0;
            scanf("%d %d %d %d %d %d %d %d %d", &data[i].num, &m[0], &s[0], &m[1], &s[1], &m[2], &s[2], &m[3], &s[3]);
            for (int k = 0; k < 4; k++) {
                data[i].sum += m[k] * 60 + s[k];
            }
        }
        q_sort(data, 0, num - 1);
        for (int i = 0; i < 2; i++) {
            printf("%d\n", data[i].num);
        }
        printf("%d\n", data[num - 2].num);
    }
    return 0;
}

void q_sort(teams data[], int begin, int end){
    int i = begin;
    int k = end;
    teams pivot = data[(begin + end) / 2];
    teams temp;
    while (1) {
        while (data[i].sum < pivot.sum) {
            i++;
        }
        while (pivot.sum < data[k].sum) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = data[i];
        data[i] = data[k];
        data[k] = temp;
        i++;
        k--;
    }
    if (begin < i - 1) {
        q_sort(data, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(data, k + 1, end);
    }
}

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

int main()
{
    int a[100000], sum[100000], b, c, n;

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

        for( int i = 0; i < 100000; i++ )
            sum[i] = 0;

        for( int i = 0; i < n; i++ )
        {
            cin >> a[i];
            for( int j = 0; j < 4; j++ )
            {
                cin >> b >> c;
                sum[i] += b * 60 + c;
            }
        }

        for( int j = 0; j < 2; j++ )
        {
            int min = 1000000, max = 0, s = 0, t = 0;
            for( int i = 0; i < n; i++ )
            {
                if( a[i] != -1 && min > sum[i] )
                {
                    min = sum[i];
                    s = i;
                }
                if( a[i] != -1 && max < sum[i] )
                {
                    max = sum[i];
                    t = i;
                }
            }
            cout << a[s] << endl;
            if( j == 1 )
                cout << a[t] << endl;
            a[s] = -1;
            a[t] = -1;
        }
    }
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> PII;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;

		vector<PII> team(n);
		REP(i, n) {
			int m, s;
			scanf("%d", &team[i].second);
			team[i].first = 0;
			REP(j, 4) {
				scanf("%d %d", &m, &s);
				team[i].first += m * 60 + s;
			}
		}
		sort(team.begin(), team.end());
		printf("%d\n%d\n%d\n", team[0].second, team[1].second, team[team.size()-2].second);
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Team{
	int n,t;
	Team(){
		t=0;
	}
	bool operator <(const Team &a)const{
		return t<a.t;
	}
};

struct Time{
	int s,m;
};

Team team[1000000];

int main(){
	int N;
	while(cin>>N,N){
		for(int i=0;i<N;i++){
			Time time;
			cin>>team[i].n;
			for(int j=0;j<4;j++){
				cin>>time.m>>time.s; team[i].t += time.m*60+time.s;
			}
		}
		sort(team,team+N);
		printf("%d\n%d\n%d\n",team[0].n,team[1].n,team[N-2].n);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main(){
    int n;
	while(cin >> n, n) {
		vector<pair<int, int> > v;
		rep(i,n) {
			pair<int, int> p;
			int s=0, m;
			cin >> p.second;
			rep(j,4) {
				cin >> m;
				s += m * 60;
				cin >> m;
				s += m;
			}
			p.first = s;
			v.push_back(p);
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[v.size()-2].second << endl;
	}
    return 0;
}

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

using namespace std;

int main()
{
	int n;

	while (cin >> n, n){
		map<int, int> team;
		int id, m1, m2, m3, m4, s1, s2, s3, s4;
		for (int i = 0; i < n; i++){
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			team.insert(make_pair(60 * (m1 + m2 + m3 + m4) + s1 + s2 + s3 + s4, id));
		}
		map<int, int>::iterator it = team.begin();
		cout << it->second << endl;
		it++;
		cout << it->second << endl;
		it = team.end();
		it--;
		it--;
		cout << it-> second << endl;
	}

	return (0);
}