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>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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


int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    pii p[100000];
    rep(i,n){
      cin>>p[i].second;
      int sum=0;
      rep(j,4){
        int m,s;
        cin>>m>>s;
        sum+=60*m+s;
      }
      p[i].first=sum;
    }
    sort(p,p+n);
    cout<<p[0].second<<endl;
    cout<<p[1].second<<endl;
    cout<<p[n-2].second<<endl;
  }
}

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

int main() {
    int n;
    while (cin >> n, n) {
        int c1,m1,s1,m2,s2,m3,s3,m4,s4;
        vector<pair<int,int> > data;
        for (int i=0; i<n; ++i) {
            cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
            data.push_back(make_pair((m1+m2+m3+m4)*60+(s1+s2+s3+s4),c1));
        }
        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 <string>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<int, int> > vp;
		for (int i = 0; i < n; i++){
			int id;
			cin >> id;
			int score = 0;
			for (int i = 0; i < 4; i++){
				int m, s;
				cin >> m >> s;
				score += m * 60 + s;
			}
			vp.push_back(make_pair(score, id));
		}
		sort(vp.begin(), vp.end());
		printf("%d\n%d\n%d\n", vp[0].second, vp[1].second, vp[n - 2].second);
	}
	return (0);
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
struct team { ll name, time; };
bool comp(const team& a, const team& b) { return a.time<b.time; };
team t[1000000];
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<n; i++) {
            scanf("%lld",&t[i].name);
            int a,b,c,d,e,f,g,h;scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
            t[i].time=(a+c+e+g)*60+b+d+f+h;
        }
        sort(t, t+n, comp);
        printf("%lld\n%lld\n%lld\n",t[0].name,t[1].name,t[n-2].name);
    }
}

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

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int n;

pair<int, int> T[MAX];

main(){
    int id, m, s;
    while( cin >> n && n ){
	for ( int i = 0; i < n; i++ ){
	    cin >> id;
	    int sum = 0;
	    for ( int j = 0; j < 4; j++ ){
		cin >> m >> s;
		sum += m*60 + s;
	    }
	    T[i] = make_pair(sum, id);
	}
	sort( T, T + n );

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

C++: #include<stdio.h>
#include<iostream>
using namespace std;


struct SKE{int c1;int m1;int s1;int m2;int s2;int m3;int s3;int m4;int s4;int SUM;};
struct SKE NUM[10000001];
int main (){
int N;
struct SKE Te,M1,M2,M3;
while(1){
cin>>N;if(N==0)break;
for(int i=0;i<N;i++){
	cin>>NUM[i].c1>>NUM[i].m1>>NUM[i].s1>>NUM[i].m2>>NUM[i].s2>>NUM[i].m3>>NUM[i].s3>>NUM[i].m4>>NUM[i].s4;
	NUM[i].SUM=NUM[i].s1+NUM[i].s2+NUM[i].s3+NUM[i].s4+60*(NUM[i].m1+NUM[i].m2+NUM[i].m3+NUM[i].m4);
}
M1=NUM[0];M2=NUM[0];M3=NUM[0];
for(int i=1;i<N;i++){
	if(NUM[i].SUM<M1.SUM){M3=M2;M2=M1;M1=NUM[i];}
	else if(NUM[i].SUM<M2.SUM){M3=M2;M2=NUM[i];}
	else if(NUM[i].SUM<M3.SUM){M3=NUM[i];}

}
cout<<M1.c1<<endl<<M2.c1<<endl<<M3.c1<<endl;
for(int i=0;i<N;i++)
{NUM[i].c1=NULL;NUM[i].m1=NULL;NUM[i].s1=NULL;NUM[i].m2=NULL;NUM[i].s2=NULL;NUM[i].m3=NULL;NUM[i].s3=NULL;NUM[i].m4=NULL;NUM[i].s4=NULL;}
}
return 0;
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  int n;
  int const teamname = 0;
  int const point = 1;
  while(cin>>n,n){
    vector < vector<int > > team(n+1,vector<int>(2));
    rep(i,n){
		
      int m,s;
      cin>>team[i][teamname];
      rep(h,4){
				cin>>m>>s;
				team[i][point]+=m*60+s;
			}
	
    }
    
    rep(i,n-1){
			loop(j,i,n){
	  		if(team[i][point]>team[j][point]){
	    		team[n][teamname]=team[i][teamname];
	    		team[i][teamname]=team[j][teamname];
	    		team[j][teamname]=team[n][teamname];
	    		team[n][teamname]=0;
				
	  		  team[n][point]=team[i][point];
	 		   team[i][point]=team[j][point];
	   		 team[j][point]=team[n][point];
	   		 team[n][point]=0;
				
			  }
			}
    }
    
/*    rep(i,n){
    	cout<<team[i][teamname]<<" "<<team[i][point]<<endl;
    }
    */
		rep(i,2){
	
	 	 cout<<team[i][teamname]<<endl;		

		}
		cout<<team[n-2][teamname]<<endl;
  }

}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> P;
int main(){
  P p;
  vector<P> ar;
  int n,c1,m1,s1,m2,s2,m3,s3,m4,s4;
  while(1){
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      p.first = ((m1 + m2 + m3 + m4)*60) + (s1+s2+s3+s4);
      p.second = c1;
      ar.push_back( p );
    }
    sort( ar.begin() , ar.end() );
    cout << ar[0].second << endl;
    cout << ar[1].second << endl; 
    cout << ar[n-2].second << endl;
    ar.clear();
  }
}