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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {

		vector<PII> data(n);
		rep(i, n) {
			int id; cin >> id;
			int sec = 0;
			rep(i, 4) {
				int m, s; cin >> m >> s; sec += m * 60 + s;
			}
			data[i] = mp(sec, id);
		}

		sort(all(data));
		cout << data[0].second << endl << data[1].second << endl << data[sz(data) - 2].second << endl;
	}
}

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

int main(){
  int n;
  int id[5],t[5];
  int m,s;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<4;i++){
      cin >> id[i];
      t[i] = 0;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	t[i] += m*60 + s;
      }
    }

    for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
	if(t[i]>t[j]){
	  swap(t[i],t[j]);
	  swap(id[i],id[j]);
	}
      }
    }

    for(int i=4;i<n;i++){
      cin >> id[4];
      t[4] = 0;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	t[4] += m*60 + s;
      }
      if(t[4] < t[0]){
	swap(t[0],t[1]);
	swap(id[0],id[1]);
	swap(t[0],t[4]);
	swap(id[0],id[4]);
      }else if(t[4] < t[1]){
	swap(t[1],t[4]);
	swap(id[1],id[4]);
      }

      if(t[4] > t[3]){
	swap(t[2],t[3]);
	swap(id[2],id[3]);
	swap(t[3],t[4]);
	swap(id[3],id[4]);
      }else if(t[4] > t[2]){
	swap(t[2],t[4]);
	swap(id[2],id[4]);
      }
    }

    cout << id[0] << endl << id[1] << endl << id[2] << endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	int set[4]={0},best[4];
	best[0]=100000,best[1]=100000,best[2]=0,best[3]=0;
	int c,ans,m,s;
	for(int i=0;i<n;i++){
		cin>>c;
		ans=0;
		for(int j=0;j<4;j++){
			cin>>m>>s;
			ans+=m*60+s;
		}
		if(ans<best[1]){
			set[1]=c;
			best[1]=ans;
		}
		if(ans<best[0]){
			best[1]=best[0];
			best[0]=ans;
			set[1]=set[0];
			set[0]=c;
		}
		if(ans>best[2]){
			set[2]=c;
			best[2]=ans;
		}
		if(ans>best[3]){
			best[2]=best[3];
			best[3]=ans;
			set[2]=set[3];
			set[3]=c;
		}
	}
	for(int i=0;i<3;i++)
		cout<<set[i]<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int n,id,m1,s1,m2,s2,m3,s3,m4,s4,sum;
  vector<pair<int,int>> v;
  pair<int,int> p;

  cin>>n;

  for(int i = 0;i<n;++i){
    cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
    sum = (m1+m2+m3+m4)*60+(s1+s2+s3+s4);
    v.push_back(make_pair(sum,id));
  }

  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());

  p = v[0];

  cout<<p.second<<endl;

  p = v[1];

  cout<<p.second<<endl;

  p = v[n-2];

  cout<<p.second<<endl;

  return 0;
}

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

struct Team{
    int id;
    int time;
    bool operator<(const Team& other)const{
        return time < other.time;
    }
};

int main(){
    int n, id, m, s, i, j;
    while(cin >> n, n){
        vector< Team > v(n);
        for(i = 0; i < n; i++){
            cin >> id;
            v[i].id = id;
            v[i].time = 0;
            for(j = 4;j--;){
                cin >> m >> s;
                v[i].time += m*60 + s;
            }
        }
        sort(v.begin(), v.end());
        cout << v[0].id << '\n' << v[1].id
             << '\n' << v[n-2].id << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		vector<P> vc;

		for(int i=0 ; i < n ; i++ ){
			int c,m1,m2,m3,m4,s1,s2,s3,s4;
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			P p( time , c );
			vc.push_back( p );
		}
		sort( vc.begin() , vc.end() );
		cout << vc[0].second << endl;
		cout << vc[1].second << endl;
		cout << vc[vc.size()-2].second << endl;
	}
}

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

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;



int main(){
	int n;
	int m,s,c;
	while(cin>>n && n>0){
		vector<pair<pair<int,int>,int>  > v(n,mp(mp(0,0),0));
		for(int i=0; i<n; i++){
			cin>>c;
			v[i].se=c;
			for(int j=0; j<4; j++){
				cin>>m>>s;
				v[i].fi.se+=s;
				v[i].fi.fi+=(m+v[i].fi.se/60);
				v[i].fi.se%=60;
			}
		}
		sort(all(v));
		cout<<v[0].se<<endl;
		cout<<v[1].se<<endl;
		cout<<v[n-2].se<<endl;

		// cout<<endl;
		// for(int i=0; i<n; i++){
		// 	cout<<v[i].se<<" "<<v[i].fi<<endl;
		// }
	}
}