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<map>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		map<int, int> p;
		for (int i = 0; i < n; i++) {
			int id, m[4], s[4], sum = 0;
			cin >> id >> m[0] >> s[0] >> m[1] >> s[1] >> m[2] >> s[2] >> m[3] >> s[3];
			for (int i = 0; i < 4; i++) 
				sum += (m[i]*60);
			for (int i = 0; i < 4; i++)
				sum += s[i];
			p.insert(map<int, int>::value_type(sum, id));
		}
		map<int, int>::iterator it = p.begin();
		cout << (*it).second << endl;
		it++;
		cout << (*it).second << endl;
		it = p.end();
		it--;
		it--;
		cout << (*it).second << endl;
	}
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back




int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
       
        vector<pair<int,string> > in;
        rep(i,n){
            string s;
            cin>>s;
            int sum=0;
            rep(i,4){
                int a,b;
                cin>>a>>b;
                sum+=a*60+b;
            }
            in.pb(pair<int,string>(sum,s));
        }
        sort(all(in));
        cout<<in[0].second<<endl;
        cout<<in[1].second<<endl;
        cout<<in[(int)in.size()-2].second<<endl;
    }
    
    return 0;
}

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

int main(void){
  int n;
  int id,m1,s1,m2,s2,m3,s3,m4,s4;
  int t;
  while(1){
    cin>>n;
    if(n==0)break;
    map<int,int> d;
    vector<int> v;
    for(int i=0;i<n;i++){
      cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      t=60*(m1+m2+m3+m4)+s1+s2+s3+s4;
      v.push_back(t);
      d[t]=id;
    }
    sort(v.begin(),v.end());
    cout<<d[v[0]]<<endl;
    cout<<d[v[1]]<<endl;
    cout<<d[v[v.size()-2]]<<endl;
  }
  return 0;
}

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

int main(){
	int n;	

	while(true){
		cin >> n;

		if(n==0)break;

		unsigned int c1[100000];
		unsigned int m1[100000];
		unsigned int s1[100000];
		unsigned int m2[100000];
		unsigned int s2[100000];
		unsigned int m3[100000];
		unsigned int s3[100000];
		unsigned int m4[100000];
		unsigned int s4[100000];

		for(int i=0;i<n;i++){
			cin >> c1[i] >> m1[i] >> s1[i] >> m2[i] >> s2[i] >> m3[i] >> s3[i] >> m4[i] >> s4[i];
			}

		unsigned int sum[100000];

		for(int i=0;i<n;i++){
			sum[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+(s1[i]+s2[i]+s3[i]+s4[i]);
			}

		unsigned int copy[100000];

		for(int i=0;i<n;i++){
			copy[i] = sum[i];
			}

		sort(sum,sum+n);

		for(int i=0;i<3;i++){
			int j=0;
			while(true){
				if(sum[i]==copy[j]){
					cout << c1[j] << endl;
					break;
					}
				else{
					j++;
					}
				}
			}
		}

	return 0;
	}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
using namespace std;

pair<int, int> team[1000000];
//team[i].firstはかかった時間[s]
//team[i].secondはチーム番号

int main()
{
	int n;
	int m, s;
	while (cin >> n)
	{
		if (n == 0)
		{
			return 0;
		}

		for (int i = 0; i < n; i++)
		{
			team[i].first = 0;
			cin >> team[i].second;
			for (int j = 0; j < 4; j++)
			{
				cin >> m >> s;
				team[i].first += m * 60 + s;
			}
		}

		int first = 0, worst = 0;
		int second = 0, booby = 0;

		for (int i = 0; i < n; i++)
		{
			if (team[first].first > team[i].first)
			{
				second = first;
				first = i;
			}
			else if (team[second].first > team[i].first)
			{
				second = i;
			}

			if (team[worst].first < team[i].first)
			{
				booby = worst;
				worst = i;
			}
			else if (team[booby].first < team[i].first)
			{
				booby = i;
			}

			if (i == 1)
			{
				second = worst;
				booby = first;
			}
		}
		cout << team[first].second << endl;
		cout << team[second].second << endl;
		cout << team[booby].second << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    pair<int,int>pii[n];
    for(int i=0;i<n;i++){
      int a,b,c,d,e,f,g,h;
      cin>>pii[i].S;
      cin>>a>>b>>c>>d>>e>>f>>g>>h;
      pii[i].F=100*((a+c+e+g)+(b+d+f+h)/60)+(b+d+f+h)%60;
    }
    sort(pii,pii+n);

    cout<<pii[0].S<<endl;
    cout<<pii[1].S<<endl;
    cout<<pii[n-2].S<<endl;
  }
  return 0;
}

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

int main(void){
  int n;
  while(cin >> n && n != 0){
    int c, m1, s1, m2, s2, m3, s3, m4, s4;
    vector<pair<int, int> > team;
    for(int i = 0; i < n; i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int time = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
      team.push_back(pair<int, int>(time, c));
    }
    sort(team.begin(), team.end());
    cout << team[0].second << endl;
    cout << team[1].second << endl;
    cout << team[team.size() - 2].second << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	cin >> n;
	vector< pair<int,int> > ms;
	if(n == 0) break;
	int c,m,s;
	REP(i,n){
	    cin >> c;
	    ms.PB( pair<int,int>(0,c) );
	    for(int j=0;j<4;j++){
		cin >> m >> s;
		ms[i].first += 60 * m + s;
	    }
	}
	sort(ALL(ms));
	cout << ms[0].second << endl;
	cout << ms[1].second << endl;
	cout << ms[ms.size()-2].second << endl;
    }
    return 0;
}