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>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;

typedef struct {
    long long int num;
    int min[4] = {0};
    int sec[4] = {0};
    int sum = 0;
}team;

void quick_sort(team x[], int left, int right);

int main(void) {
    int n;
    
    while(1) {
        scanf("%d", &n);
        if(n == 0) break;
        int i, j;
        team *p;
        p = (team *)calloc(n, sizeof(team));
        if(p == NULL) exit(0);
        
        for(i = 0; i < n; i++) {
            scanf("%lld", &p[i].num);
            for(j = 0; j < 4; j++)
                scanf("%d %d", &p[i].min[j] , &p[i].sec[j]);
        }
        for(i = 0; i < n; i++) {
            for(j = 0; j < 4; j++)
                p[i].sum += (p[i].min[j] * 60) + p[i].sec[j];
        }
        quick_sort(p, 0, n - 1);
        
        cout << p[0].num << endl << p[1].num << endl << p[n - 2].num << endl;
        free(p);
    }
    
    return(0);
}

void quick_sort(team x[], int left, int right) {
    int i, j;
    team pivot;
    
    i = left;
    j = right;
    pivot.sum += x[(left + right) / 2].sum;
    
    while(1) {
        while(x[i].sum < pivot.sum) i++;
        while(x[j].sum > pivot.sum) j--;
        
        if(i >= j) break;
        
        swap(team, x[i], x[j]);
        i++;
        j--;
        // DEBUG cout << "OK" << endl;     ここの時点では出力に”OK”と沢山表示される
    }
    
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}

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

struct data{
    int number, min;
    data(int n, int m) : number(n), min(m){}

    bool operator<(const data other) const {
        return min < other.min;
    }
};

int main(){
    while(true){
        int n, id, m, s;
        cin >> n;

        if(n == 0)  break;

        vector<data> table;
        for(int i = 0; i < n; i++){
            cin >> id;
            int minutes = 0;
            for(int j = 0; j < 4; j++){
                cin >> m >> s;
                minutes += 60*m+s;
            }
            table.push_back(data(id, minutes));
        }

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

        cout << table[0].number << endl;
        cout << table[1].number << endl;
        cout << table[n-2].number << endl;
    }
}

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

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        vector< pair<long long, int> > team;

        for (int i = 0; i < n; i++) {
            int id;
            long long time;
            int m, s;

            time = 0;
            cin >> id;
            for (int j = 0; j < 4; j++) {
                cin >> m >> s;
                time += m * 60 + s;
            }
            team.push_back(pair<long long, int>(time, id));
        }
        sort(team.begin(), team.end());

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <boost/bind.hpp>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        typedef pair<int, int> value_type;
        vector<value_type> team;
        int c, m, s;
        for(int j=0; j < n; j++){
            cin >> c;
            team.push_back(pair<int, int>(c, 0));
            for(int i=0; i < 4; i++){
                cin>> m >> s;
                team[j].second += 60*m + s;
            }
        }
        sort(team.begin(), team.end(), bind(&value_type::second, _1) < bind(&value_type::second, _2));

        cout << team[0].first << endl;
        cout << team[1].first << endl;
        cout << team[team.size()-2].first;
        team.clear();
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[4];
        int num[4]={-1,-1,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;
            }
            for(int j=0;j<2;j++){
                if(sum<num[j]||num[j]==-1){
                    swap(num[j],sum);
                    swap(str[j],st);
                }
            }
            for(int j=3;j>1;j--){
                if(sum>num[j]){
                    swap(num[j],sum);
                    swap(str[j],st);
                }
            }
        }
        for(int i=0;i<3;i++)cout<<str[i]<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,u1,u2,s1,s2,U1,U2,S1,S2
	,c,a,b,r,d,e,f,g,h,k,x,y,ren,temp;
	while(cin>>n,n){
		u1=100000000;
		u2=100000000;
		s1=0;
		s2=0;
		for(int i=0;i<n;i++){
			cin>>r>>a>>b>>c>>d>>e>>f>>g>>h;
			x=(a+c+e+g)*60+b+d+f+h;
			y=x;
			k=r;
			if(u1>x){
				ren=U1;
				U1=r;
				r=ren;
				temp=u1;
				u1=x;
				x=temp;
			}
			if(u2>x){
				U2=r;
				u2=x;
			}
			if(s1<y){
				ren=S1;
				S1=k;
				k=ren;
				temp=s1;
				s1=y;
				y=temp;
			}
			if(s2<y){
				S2=k;
				s2=y;
			}
		}
		
		cout<<U1<<endl<<U2<<endl<<S2<<endl;
		
		
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
typedef struct{
    int id;
    pii n,n2,n3,n4;
    int sum=0;
}data;
int main(){
    int n;
    while(cin>>n,n){
    vector<data>u(n);
    rep(i,n){
        pii n, n2,n3,n4;int id;
        cin>>id>>n.first>>n.second>>n2.first>>n2.second>>n3.first>>n3.second>>n4.first>>n4.second;
        u[i].id=id;
        u[i].n=n;u[i].n2=n2;u[i].n3=n3;u[i].n4=n4;
        u[i].sum=(n.first+n2.first+n3.first+n4.first)*60+(n.second+n2.second+n3.second+n4.second);
    }
    rep(i,n-1)rep(j,n-1)if(u[j].sum>u[j+1].sum)swap(u[j],u[j+1]);
    rep(i,2)cout<<u[i].id<<endl;
    cout<<u[n-2].id<<endl;
    }
}