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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,c,m,s,m1,s1,m2,s2,m3,s3;
  while(cin>>n&&n){
    vector<pii> v(n);
    rep(i,n){
      cin >> c >> m >> s >> m1 >> s1 >> m2 >> s2 >> m3>>s3;
      v[i].se = c;
      v[i].fi = (m+m1+m2+m3)*60 + s+s1+s2+s3;
    }
    sort(all(v));
    cout << v[0].se << endl;
    cout << v[1].se << endl;
    cout << v[v.size()-2].se << endl;
  }
  return 0;
}

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

using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pii;
int main() {
  int n;
  while(cin >> n && n) {
    vector<Pii> vec(n);
    for(int ii=0; ii<n; ii++) {
      int S, m, s;
      cin >> S;
      int t = 0;
      for(int i=0; i<4; i++) {
	cin >> m >> s;
	t += s+m*60;
      }
      vec[ii] = Pii(t, S);
    }
    sort(vec.begin(),vec.end());
    cout << vec[0].second << endl << vec[1].second << endl << vec[vec.size()-2].second << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

ll n, a, c[1000010][5],no[10];
vector<ll> vl;

int main(){
	while (cin >> n){
		if (!n)break;
		REP(i, n){
			c[i][1] = 0;
			REP(j, 9){
				if (j == 0){
					cin >> c[i][j];
					continue;
				}
				cin >> a;
				if (j % 2 != 0){
					a *= 60;
				}
				c[i][1] += a;
			}
			vl.push_back(c[i][1]);
		}
		sort(ALL(vl));
		REP(i, n){
			if (c[i][1] == vl[0]){
				no[0] = c[i][0];
			}
			else if (c[i][1] == vl[1]){
				no[1] = c[i][0];
			}
			if (c[i][1] == vl[n - 2]){
				no[2] = c[i][0];
			}
		}
		REP(i, 3){
			cout << no[i] << endl;
		}
		vl.clear();
	}
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;

int main() {

	int n;
	while (cin >> n&&n) {
		vector<pair<int, int> >team(n);
		int s, m, id;
		for (int j = 0; j < n; j++) {
			cin >> id;
			team[j].second = id;
			team[j].first = 0;
			for (int i = 0; i < 4; i++) {
				cin >> m >> s;
				team[j].first += 60 * m + s;

			}
		}
		sort(team.begin(), team.end());
		for (int i = 0; i < 2; i++) {
			cout << team[i].second << endl;
		}
		cout << team[n - 2].second << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int n;
	while (cin >> n, n) {
		vector<P>v;
		rep(i, n) {
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			v.push_back(P((m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4, c1));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[n - 2].second << endl;
	}
}

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

class sorting{
public:
  bool operator()(const pair<int,int>& left,const pair<int,int>& right)const{
    return left.first < right.first;
  }
};

int main(){
  int n;
  while(cin >> n,n){
    vector<pair<int,int> > dat;
    int m,s,id;
    for(int i=0;i<n;i++){
      int total = 0;
      cin >> id;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	total += m*60 + s;
      }
      dat.push_back(make_pair(total,id));
    }
    sort(dat.begin(),dat.end(),sorting());
    cout << dat[0].second << endl << dat[1].second << endl << dat[n-2].second << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
string str[1000000];
int num[1000000];
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++){
            cin>>str[i];
            for(int j=0,minute,second;j<4;j++){
                cin>>minute>>second;
                num[i]+=60*minute+second;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=n-1;j>0;j--){
                if(num[j]<num[j-1]){
                    swap(num[j],num[j-1]);
                    swap(str[j],str[j-1]);
                }
            }
        }
        cout<<str[0]<<endl<<str[1]<<endl<<str[n-2]<<endl;
    }
}