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 <algorithm>
#include <iostream>
#include <utility>
#include <vector>

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

using namespace std;

int n;
int id[100005], m[100005][4], s[100005][4];
void solve() {
    vector<pair<int, int>> vec;
    rep(i, n) {
        int sum = 0;
        rep(j, 4) sum += m[i][j] * 60 + s[i][j];
        vec.emplace_back(sum, id[i]);
    }
    sort(vec.begin(), vec.end());
    cout << vec[0].second << endl;
    cout << vec[1].second << endl;
    cout << vec[n - 2].second << endl;
}
int main() {
    while (cin >> n, n) {
        rep(i, n) {
            cin >> id[i];
            cin >> m[i][0] >> s[i][0];
            cin >> m[i][1] >> s[i][1];
            cin >> m[i][2] >> s[i][2];
            cin >> m[i][3] >> s[i][3];
        }
        solve();
    }
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		vp a(n);
		int c,m1,m2,m3,m4,s1,s2,s3,s4;
		for(int i=0;i<n;i++){
			cin>>c>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
			a[i]=P((m1+m2+m3+m4)*60+s1+s2+s3+s4,c);
		}
		sort(a.begin(),a.end());
		cout<<a[0].second<<endl;
		cout<<a[1].second<<endl;
		cout<<a[n-2].second<<endl;
	}
}

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

typedef struct
{
  int id, time;
} Team;

class LessTime
{
public:
  bool operator() (const Team& lhs, const Team& rhs) const
  {
    return lhs.time < rhs.time;
  }
};

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

    vector<Team> team(n);
    for (int i = 0; i < n; ++i) {
      cin >> team[i].id;
      int m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      team[i].time = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4;
    }
    sort(team.begin(), team.end(), LessTime());

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

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

int num[MAX];
int rtime[MAX];

void bubble_sort(int n){

  for( int i = 0 ; i < n - 1 ; i++ ){
    for( int j = n - 1 ; j > i ; j-- ){
      if( rtime[j - 1] > rtime[j] ){

	int temp = rtime[j - 1];
	rtime[j - 1] = rtime[j];
	rtime[j] = temp;

	temp = num[j - 1];
	num[j - 1] = num[j];
	num[j] = temp;

      }
    }
  }

}


int main(void){

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

    int m1,s1,m2,s2,m3,s3,m4,s4;
    for( int i = 0 ; i < n ; i++ ){
      cin >> num[i] >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      rtime[i] = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
    }
    bubble_sort(n);

    cout << num[0] << endl;
    cout << num[1] << endl;
    cout << num[n - 2] << endl;

  }
  return 0;
}

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

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<PII> data;
    REP(i,n){
      int num,sum = 0;
      cin>>num;
      REP(j,4){
        int m,s;
        cin>>m>>s;
        sum += m*60 + s;
      }
      data.push_back(PII(sum,num));
    }
    sort(data.begin(),data.end());
    cout<<data[0].second<<endl;
    cout<<data[1].second<<endl;
    cout<<data[n-2].second<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
int main(){
    int n;
    while(cin>>n,n){
        vector<P>V(n);
        for(int i=0;i<n;i++){
            cin>>V[i].second;
            V[i].first=0;
            for(int i=0;i<4;i++){
                int a,b;
                cin>>a>>b;
                V[i].first+=a*60+b;
            }
        }
        sort(V.begin(),V.end());
        cout<<V[0].second<<endl;
        cout<<V[1].second<<endl;
        cout<<V[n-2].second<<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int win[4],win2[4],booby[4],ssteam,sstime;
	int n,i,j;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		for(i=1;i<4;i+=2)
		{
			win[i]=10000000;
			win2[i]=10000000;
			booby[i]=0;
		}
		for(i=0;i<n;i++)
		{
			sstime=0;
			cin >> ssteam ;
			for(j=0;j<8;j++)
			{
				int a;
				cin >> a ;
				if(j%2==0)
					sstime+=a*60;
				else
					sstime+=a;
			}
			if(win[1]>sstime)
			{
				win2[0]=win[0];
				win2[1]=win[1];
				win[0]=ssteam;
				win[1]=sstime;
			}
			else if(win2[1]>sstime)
			{
				win2[0]=ssteam;
				win2[1]=sstime;
			}
			if(booby[3]<sstime)
			{
				booby[0]=booby[2];
				booby[1]=booby[3];
				booby[2]=ssteam;
				booby[3]=sstime;
			}
			else if(booby[1]<sstime)
			{
				booby[0]=ssteam;
				booby[1]=sstime;
			}
		}
		cout << win[0] << endl;
		cout << win2[0] << endl;
		cout << booby[0] << endl;
	}
}