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;

typedef pair<int, int> pii;

bool cmp(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			int num, t = 0;
			cin >> num;
			for (int j = 0; j < 4; j++){
				int m, s;
				cin >> m >> s;
				t += m * 60 + s;
			}
			p[i] = make_pair(num, t);
		}
		
		sort(p.begin(), p.end(), cmp);
		
		cout << p[0].first << endl << p[1].first << endl << p[n - 2].first << endl;
	}
	
	return (0);
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		for(int i = 0; i < n; i++) {
			int c;
			cin >> c;
			int pts = 0;
			for(int i = 0; i < 4; i++) {
				int m, s;
				cin >> m >> s;
				pts += m * 60 + s;
			}
			v.push_back(pair<int,int>(pts, c));
		}
		sort(v.begin(), v.end());

		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
}

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

class Team {
public:
  int time;
  int id;
  bool operator <(const Team &t) const {
    return time < t.time;
  }
};

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    Team t[n];
    for(int i = 0; i < n; i++) { 
      int c;
      cin >> c;
      t[i].id = c;
      t[i].time = 0;
      for(int j = 0; j < 4; j++) {
	int s, m;
	cin >> m >> s;
	t[i].time += s + m * 60;
      }
    }
    sort(&t[0], &t[n]);
    cout << t[0].id << endl;
    cout << t[1].id << endl;
    cout << t[n-2].id << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n, a, b = 0;
	int m, s;
	vector<P> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n==0)
		{
			return 0;
		}
		REP(i, n)
		{
			cin >> a;
			REP(j, 4){
				cin >> m >> s;
				b = b + m * 60 + s;
			}
			v.push_back(P(b, a));
			b = 0;
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl
			<< v[1].second << endl
			<< v[n - 2].second << endl;
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int id,m,s;
            std::map<int, int> map;
            for (int i=0;i<n;i++) {
                cin>>id;
                int sum=0;
                for (int j=0;j<4;j++) {
                    cin>>m>>s;
                    sum+=60*m+s;
                }
                map.insert(make_pair(sum,id));
            }
            auto itr=map.begin();
            for (int k=0;k<n;k++) {
                if (k==0||k==1||k==n-2) {
                    cout<<(itr->second)<<endl;
                    itr=next(itr,1);
                } else {
                    itr=next(itr,1);
                }
            }
        }
    }
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.sportmeet", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;

		if (n == 0 ){
			break;
		} // end if

		int i,j;
		map <int, int> rank;

		for (i = 0; i < n; ++i){
			int c1;
			vector <int> m(4, 0), s(4, 0);
			int total = 0;
			getline (cin, str );
			stringstream ss(str);
			ss >> c1;
			for (j = 0; j < 4; ++j){
				ss >> m[j] >> s[j];
			} // end for
			total += accumulate (m.begin(), m.end(), 0 );
			total *= 60;
			total += accumulate (s.begin(), s.end(), 0 );
			rank[total] = c1;
		} // end for

		map<int,int>::iterator it = rank.begin();
		cout << (*it).second << endl;
		++it;
		cout << (*it).second << endl;
		map<int, int>::reverse_iterator itr = rank.rbegin();		
		++itr;
		cout << (*itr).second << endl;
	} // end loop
		
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#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 all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,id,m1,m2,m3,m4,s1,s2,s3,s4;
  pi score[100005];
  while(cin>>n){
    if(n==0)break;
    rep(i,n){
      cin>>score[i].second>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      score[i].first=(m1+m2+m3+m4)*60+(s1+s2+s3+s4);
    }
    sort(score,score+n);
    cout<<score[0].second<<endl<<score[1].second<<endl<<score[n-2].second<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	static pii a[1000010] = {};
	for (int n; cin >> n&&n;) {
		memset(a, 0, sizeof(a));
		rep(h, 0, n) {
			int c, m, s;
			cin >> c;
			a[h].second = c;
			rep(i, 0, 4) {
				cin >> m >> s;
				a[h].first += m * 60 + s;
			}
		}
		sort(a, a + n);
		cout << a[0].second << endl;
		cout << a[1].second << endl;
		cout << a[n - 2].second << endl;
	}
	return 0;
}