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 <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> scores;
        for(int i = 0; i < n; ++i) {
            int id; cin >> id;
            int t = 0;
            for(int j = 0; j < 4; ++j) {
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            scores.emplace_back(t, id);
        }
        sort(begin(scores), end(scores));

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

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

using namespace std;


typedef struct rec {

  int id;
  int time;

} record;

record rank[1000001];

int comp(const void* a,const void* b) {

  record t1=*(record*) a;
  record t2=*(record*) b;

  return t1.time-t2.time;

}

int main() {

  int n;
  int c1,m1,s1,m2,s2,m3,s3,m4,s4;


  while(cin >> n,n) {

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

      record tmp;

      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;

      rank[i].id=c1;

      rank[i].time=(60*m1+s1)+(60*m2+s2)+(60*m3+s3)+(60*m4+s4);

    }

    //for(int i=0;i<n;i++) cout << rank[i].id << " " << rank[i].time << endl;

    qsort(rank,n,sizeof(rank[0]),comp);

    //for(int i=0;i<n;i++) cout << rank[i].id << " " << rank[i].time << endl;

    cout << rank[0].id << endl;

    cout << rank[1].id << endl;

    cout << rank[n-2].id << endl;

  }

  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 PII pair<int,int>
#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 <bits/stdc++.h>
using namespace std;
void solve(int n){
	vector<pair<int,int> >v;
	for(int i;i<n;i++){
		int id;cin>>id;
		int cnt=0;
		for(int j=0;j<4;j++){int a,b;cin>>a>>b;cnt+=a*60+b;}
		v.push_back(make_pair(cnt,id));
	}
	sort(v.begin(),v.end());
	cout<<v[0].second<<endl;
	cout<<v[1].second<<endl;
	cout<<v[n-2].second<<endl;
	return;
}
int main() {
	int n;while(cin>>n){
		if(!n)return 0;
		solve(n);
	}
	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		map<int,int> data;
		for(int i=0,num;i<n;++i){
			int sum=0;
			cin>>num;
			for(int j=0,m,s;j<4;++j){
				cin>>m>>s;
				sum+=m*60+s;
			}
			data.insert(map<int,int>::value_type(sum,num));
		}
		map<int,int>::iterator it = data.begin();
		cout<<(*it).second<<"\n";
		++it;
		cout<<(*it).second<<"\n";
		map<int,int>::reverse_iterator rit = data.rbegin();
		++rit;
		cout<<(*rit).second<<"\n";
	}
	return 0;
}

C++: // 2011/02/07 Tazoe

#include <iostream>
using namespace std;

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

		int p1 = 0;
		int p2 = 0;
		int p3 = 0;
		int p4 = 0;
		int t1 = 60*60*4;
		int t2 = 60*60*4;
		int t3 = -1;
		int t4 = -1;

		for(int i=0; i<n; i++){
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int t = (m1+m2+m3+m4)*60+s1+s2+s3+s4;

			if(t<t1){
				p2 = p1;
				t2 = t1;
				p1 = c1;
				t1 = t;
			}
			else if(t<t2){
				p2 = c1;
				t2 = t;
			}

			if(t>t4){
				p3 = p4;
				t3 = t4;
				p4 = c1;
				t4 = t;
			}
			else if(t>t3){
				p3 = c1;
				t3 = t;
			}
		}

		cout << p1 << endl;
		cout << p2 << endl;
		cout << p3 << endl;
	}

	return 0;
}

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

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

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i].second;
			int sum = 0;
			for(int j = 0; j < 8; ++j)
			{
				int temp;
				cin >> temp;
				if(j % 2 == 0)
				{
					sum += temp * 60;
				}
				else
				{
					sum += temp;
				}
			}
			Vec[i].first = sum;
		}
		sort(Vec.begin(), Vec.end());
		cout << Vec[0].second << endl;
		cout << Vec[1].second << endl;
		cout << Vec[n - 2].second << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

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

		if ( !n )
		{
			break;
		}

		vector< PII > teams( n );
		REP( i, 0, n )
		{
			int c;
			VI times( 8 );
			cin >> c;
			FOR( t, times )
			{
				cin >> t;
			}

			int total = 0;
			for ( int i = 0; i < 8; i += 2 )
			{
				total += times[i] * 60 + times[ i + 1 ];
			}

			teams[i] = MP( total, c );
		}
		sort( ALL( teams ) );

		cout << teams[0].snd << endl;
		cout << teams[1].snd << endl;
		cout << teams[ n - 2 ].snd << endl;
	}

	return 0;
}