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 <cstring>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int n;
vector<P> ps;

int main()
{
    int c, m, s, sum;
    while(cin >> n && n) {
        ps.clear();
        for(int k = 0; k < n; k++) {
            cin >> c;
            sum = 0;
            for(int i = 0; i < 4; i++) {
                cin >> m >> s;
                sum += m * 60 + s;
            }
            ps.push_back(P(sum, c));
        }
        sort(ps.begin(), ps.end());
        
        cout << ps[0].second << endl;
        cout << ps[1].second << endl;
        cout << ps[ps.size() - 2].second << endl;

    }
    
}

C++: #include<cstdio>
#define buf 100000
using namespace std;

typedef struct{
	int s,m;
}Sport;
void BubbleSort(int n);
int B[buf];

int main(void){
	Sport t,b,g,r;
	int i,k,n,z,sum,A[buf];
	char str[1000];

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);
		if(n==0) break; k=0; sum=0;
		for(i=0;i<n;i++){
			fgets(str,sizeof(str),stdin);
			sscanf(str,"%d %d %d %d %d %d %d %d %d",&z,&t.m,&t.s,&b.m,&b.s,&g.m,&g.s,&r.m,&r.s);
			sum=(t.m*60)+t.s+(b.m*60)+b.s+(g.m*60)+g.s+(r.m*60)+r.s;
			A[sum]=z; B[k]=sum; k++;
		}
		BubbleSort(n);
		printf("%d\n%d\n%d\n",A[B[0]],A[B[1]],A[B[n-2]]);
	}
	return 0;
}

void BubbleSort(int n){
	int i,j,tmp;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){	
			if(B[j] < B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
}