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<algorithm>
using namespace std;
int main(){
	int n,i,j;
	int a,b,data[100001];
	int min,ban;
	while(1){
		for(i=1;i<=100000;i++) data[i]=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>b;
			for(j=0;j<8;j++){
				cin>>a;
				if(j%2==0) data[b]+=a*60;
				else data[b]+=a;
			}
		}
		for(i=0;i<2;i++){
			min=100000000;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min>data[j]) {
					ban=j;
					min=data[j];
				}
			}
			cout<<ban<<endl;
			data[ban]=0;
		}
		for(i=0;i<2;i++){
			min=0;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min<data[j]) {
					ban=j;
					min=data[j];
				}
			}
			data[ban]=0;
		}
		cout<<ban<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a, b, n;
pair<int, int>x[8000000];
int main() {
	while (true){
		memset(x, 0, sizeof(x));
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++){
			cin >> x[i].second;
			for (int i = 0; i < 4; i++) {
				cin >> a >> b;
				x[i].first += a * 60 + b;
			}
		}
		sort(x, x + n);
		cout << x[0].first << endl << x[1].first << endl << x[n - 2].first << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

bool comp(const pair<string,int>& p,const pair<string,int>& q){
    return p.second > q.second;
  }

int main(){

    int n;
    while(cin >> n,n){

        
        vector<P> arr;
        int id,m1,s1,m2,s2,m3,s3,m4,s4;
        REP(i,n){
            int tmp = 0;
            cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            tmp = 60*m1 + s1 + 60*m2 + s2 +60*m3 + s3 +60*m4 + s4;
            arr.pb(make_pair(tmp,id));
        }
        VSORT(arr);
        cout << arr[0].second << endl;
        cout << arr[1].second << endl;
        cout << arr[arr.size()-2].second << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
vector<P> sc;

int main(void){
	while(1){
		sc.clear();
		int n;
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			int res=0;
			int t=0;
			scanf("%d",&t);
			for(int j=0;j<4;j++){
				int m,s;
				scanf("%d%d",&m,&s);
				res+=m*60+s;
			}
			sc.push_back(P(res,t));
		}
		sort(sc.begin(),sc.end());
		cout << sc[0].second << endl;
		cout << sc[1].second << endl;
		cout << sc[n-2].second << endl;
	}
    return 0;
}

C++: #include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
	int n,c,m1,s1,m2,s2,m3,s3,m4,s4;
	while(cin>>n,n){
		vector<pair<int,int> > r;
		for(int i=0;i<n;i++){
			cin>>c>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
			r.push_back(make_pair( ((m1+m2+m3+m4)*60+s1+s2+s3+s4),c) );
		}
		sort(r.begin(),r.end());
		cout<<r[0].second<<endl<<r[1].second<<endl<<r[r.size()-2].second<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, s; pair<int, int> d[1000000];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i].second); d[i].first = 0;
			for (int j = 0; j < 4; j++) scanf("%d%d", &m, &s), d[i].first += m * 60 + s;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[n - 1].second, d[n - 2].second, d[1].second);
	}
	return 0;
}

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

using namespace std;


int main(){
	int temp, i, j, teams, total,number;
	vector<int> name;
	vector<int> time;
	time.insert(time.begin(), 99999);
	

	while (1){
		cin >> teams;
		
		if (teams == 0){
			break;
		}
		
		for (i = 0; i < teams; i++){
			cin >> number;
			total = 0;
			for (j = 0; j < 4; j++){
				cin >> temp;
				total += temp * 60;
				cin >> temp;
				total += temp;
			}

			for (j = 0; j <= i; j++){
				if (total < time[j]){
					name.insert(name.begin()+j, number);
					time.insert(time.begin()+j, total);
					break;
				}
				
			}

		}
		
		cout << name[0] << endl << name[1] << endl << name[i-2] << endl;


		//for (j = 0; j < i; j++){
		//	cout << name[j] << endl;
		//}


		name.clear();
		time.clear();
		time.insert(time.begin(),99999);
	}
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		pii good[3], bad[3];
		fill_n(good, 2, pii(3600, 0));
		fill_n(bad, 2, pii(0, 0));
		
		rep(i, n){
			pii team(0, 0);
			scanf("%d", &team.second);
			rep(j, 4){
				int m, s;
				scanf("%d%d", &m, &s);
				team.first += m * 60 + s;
			}
			good[2] = team;
			sort(good, good+3);
			bad[2] = team;
			sort(bad, bad+3, greater<pii>());
		}
		
		printf("%d\n", good[0].second);
		printf("%d\n", good[1].second);
		printf("%d\n", bad[1].second);
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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