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<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    int key;
    int time;
};

int main(){
    int n;
    while(cin >> n, n){
        struct data d[1000005];
        rep(i,n){
            int key, m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> d[i].key >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            d[i].time = (m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4;
        }
        rep(i,n){
            for(int j = n - 1; j > i; j--){
                if(d[j].time < d[j - 1].time){
                    struct data g = d[j];
                    d[j] = d[j - 1];
                    d[j - 1] = g;
                }
            }
        }
        cout << d[0].key << endl << d[1].key << endl << d[n - 2].key << endl;
    }
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

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

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

using namespace std;

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

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

typedef struct{
	long num;
	long t;
}team;

team a[1000000];
long n, b[1000000];

int main(){
	while(1){
		
		scanf(" %ld", &n);
		if(n==0) break;
		
		for(int i=0; i<n; ++i){
			a[i].t=0;
			scanf(" %ld", &a[i].num);
			for(int j=0; j<4; ++j){
				int p, q;
				scanf(" %d %d", &p, &q);
				a[i].t+=p*60+q;
			}
			b[i]=a[i].t;
		}
		
		sort(b, b+n);
		long c[3];
		c[0]=b[0]; c[1]=b[1]; c[2]=b[n-2];
		
		for(int i=0; i<3; ++i){
			for(long j=0; j<n; ++j){
				if(c[i]==a[j].t) printf("%ld\n", a[j].num);
			}
		}
		
	}
	return 0;
}

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

using namespace std;
class Team{
public:
	int id;
	int time;
	Team(int _id,int _time){
		id=_id;time=_time;
	}
	bool operator < (const Team &o) const{
		return time > o.time;
	}
};
typedef priority_queue<Team> PQ;
int n,c,m,s;
int main(){
	while(cin>>n&&n){
		PQ pq;
		for(int i=0;i<n;i++){
			int sum=0;
			cin>>c;
			for(int j=0;j<4;j++){
				cin>>m>>s;
				sum+=(m*60) + s;
			}

			pq.push(Team(c,sum));
		}
		cout<<pq.top().id<<endl;pq.pop();
		cout<<pq.top().id<<endl;pq.pop();
		while(pq.size()>2){
			pq.pop();
		}
		cout<<pq.top().id<<endl;pq.pop();
	}
	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<long long,int> > team;
		int num,m1,m2,m3,m4,s1,s2,s3,s4;
		
		rep(i,n)
		{
			cin >> num >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;

			long long time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			team.push_back(make_pair(time,num));
		}

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

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	}
	return 0;
}

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

int main()
{
	map<int, int> m;
	map<int, int>::iterator it;
	int n, i, j;
	int a, b, c;
	int t;
	while (cin>>n, n) {
		m.clear();
		for (i = 0; i < n; i++) {
			cin>>c;
			t = 0;
			for (j = 0; j < 4; j++) {
				cin>>a>>b;
				t += a*60 + b;
			}
			m[t] = c;
		}
		it = m.begin();
		cout<<(*it).second<<endl;
		cout<<(*++it).second<<endl;
		cout<<(*----m.end()).second<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;



int main(){
	int win[2]={},semiwin[2]={},dobe[2]={},semidobe[2]={},jointeams,team,i,j,total,firstteam[4]={},firsttotal[4]={};



	cin >> jointeams;


	

	for(i=0;i<=3;i++){
		cin >> firstteam[i];

		for(j=1;j<=4;j++){
			cin >> temp;
			firsttotal[i] += temp*60;
			cin >> temp;
			firsttotal[i] += temp;
		}
	}

	for(i=2;i!=0;i--){
		for(j=0;j<=i;j++){
			if(firsttotal[j] > firsttotal[j+1]){
				temp = firsttotal[j];
				firsttotal[j] = firsttotal[j+1];
				firsttotal[j+1] = temp;
				temp = firstteam[j];
				firstteam[j] = firstteam[j+1];
				firstteam[j+1] = temp;
			}
		}
	}

		













	for(i=5;i<=jointeams;i++){
		total = 0;
		cin >> team
		for(j=1;j<=4;j++){
			cin >> temp;
			total = total + temp*60;
			cin >> temp;
			total = total + temp;
		}
		if(total>win[1]){
			semiwin[0] = win[0];
			semiwin[1] = win[1];
			win[0] = team;
			win[1] = total;

		}else(total>semiwin[1]){
			semiwin[0] = team;
			semiwin[1] = total;

		}else(total<dobe[1]){
			semidobe[0] = dobe[0];
			semidobe[1] = dobe[1];
			dobe[0] = team;
			dobe[1] = total;

		}else(total<semidobe[1]){
			semidobe[0] = team;
			semidobe[1] = total;
		}


	}

	cout << win[0] << endl;

	cout << semiwin[0] << endl;
	
	cout << dobe[0] << endl;
}