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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vector<pii> res(n);
		rep(i,n){
			int id; cin>>id;
			int t=0;
			rep(j,4){
				int m,s; cin>>m>>s;
				t+=m*60+s;
			}
			res[i]=mp(t,id);
		}
		sort(allof(res));
		cout<<res[0].second<<endl;
		cout<<res[1].second<<endl;
		cout<<res[res.size()-2].second<<endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 1<<28;

int main() {
  int n;
  while(cin >> n && n) {
    pair<int,int> A(INF,0), B(INF,0), C(-INF,0), D(-INF,0);
    for(int i = 0; i < n; ++i) {
      int id, a, b, c, d, e, f, g, h;
      cin >> id >> a >> b >> c >> d >> e >> f >> g >> h;
      pair<int,int> p(a*60+b + c*60+d + e*60+f + g*60+h, id);
      if(p < A) {
        B = A;
        A = p;
      } else if(p < B) {
        B = p;
      }
      if(p > D) {
        C = D;
        D = p;
      } else if(p > C) {
        C = p;
      }
    }
    cout << A.second << endl;
    cout << B.second << endl;
    cout << C.second << endl;
  }
  return 0;
}

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 < 3; i++) {
			cout << team[i].second << endl;
		}
	}

	return 0;
}

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


int main () {

const int cnum = 10;
int **p_teams;        /* teamの配列を入れるポインタのポインタ */
int *p_t;
int *p_t2;

int team_num;

	while (1) {
		cin >> team_num;      /* チームの数を取り込む */

		if (team_num < 2) {
			break;
		}

		p_teams = new int*[team_num]; /* チームのデータを保存する領域を確保　*/

		for (int i = 0;i < team_num;i++)
		{
			p_teams[i] = new int[cnum];      /* チームごとのデータ領域を確保 */
		}

		for (int i = 0; i < team_num; i++) {
			p_t = p_teams[i];

			cin >> p_t[0] >> p_t[1] >> p_t[2] >> p_t[3] >> p_t[4] >> 
			p_t[5] >> p_t[6] >> p_t[7] >> p_t[8];

			int m = p_t[1] + p_t[3] + p_t[5] + p_t[7];
			int s = p_t[2] + p_t[4] + p_t[6] + p_t[8];
			p_t[9] = m * 60 + s;

			p_t++;
		}

		for (int i = 0; i < team_num - 1;i++)
		{
			p_t = p_teams[i];
			for (int j = i + 1;j < team_num;j++)
			{
				p_t2 = p_teams[j];
				// cout << p_t[0] << " " << p_t[9] << " " << p_t2[0] << " " << p_t2[9] << "\n";
				if (p_t[9] > p_t2[9]) {
					int *x = p_teams[i];
					p_teams[i] = p_teams[j];
					p_teams[j] = x;
				}
			}
		}

		cout << p_teams[0][0] << "\n" << p_teams[1][0] << "\n" << p_teams[team_num - 2][0]<< endl;
		
		for (int i = 0;i < team_num;i++)
		{
			delete[] p_teams[i];      /* チームごとのデータ領域を解放 */
			p_t++;
		}

		delete[] p_teams;
	} 
	
  return 0;
}

C++: M(int*a){return*a-*1[&a];}n,T[9999][2];j,m,s;main(i){for(;~scanf("%d",&n);qsort(T,n,8,M),n&&printf("%d\n%d\n%d\n",1[*T],T[1][1],T[n-2][1]))for(i=n;i--;)for(scanf("%d",T[i]+1),*T[i]=0,j=4;j--;*T[i]+=m*60+s)scanf("%d%d",&m,&s);}

C++: #include<stdio.h>
#include<iostream>
using namespace std;


struct SKE{int c1;int m1;int s1;int m2;int s2;int m3;int s3;int m4;int s4;int SUM;};
struct SKE NUM[1000001];
int main (){
int N;
SKE Te,M1,M2,M3,M;
while(1){
cin>>N;if(N==0)break;
for(int i=0;i<N;i++){
	cin>>NUM[i].c1>>NUM[i].m1>>NUM[i].s1>>NUM[i].m2>>NUM[i].s2>>NUM[i].m3>>NUM[i].s3>>NUM[i].m4>>NUM[i].s4;
	NUM[i].SUM=NUM[i].s1+NUM[i].s2+NUM[i].s3+NUM[i].s4+60*(NUM[i].m1+NUM[i].m2+NUM[i].m3+NUM[i].m4);
}
M1=NUM[0];M2=NUM[0];M=NUM[0];
for(int i=1;i<N;i++){
	if(NUM[i].SUM<M1.SUM){M2=M1;M1=NUM[i];}
	else if(NUM[i].SUM<M2.SUM){M2=NUM[i];}
	if(NUM[i].SUM>M.SUM){M3=M;M=NUM[i];}

}
cout<<M1.c1<<endl<<M2.c1<<endl<<M3.c1<<endl;
for(int i=0;i<N;i++)
{NUM[i].c1=0;NUM[i].m1=0;NUM[i].s1=0;NUM[i].m2=0;NUM[i].s2=0;NUM[i].m3=0;NUM[i].s3=0;NUM[i].m4=0;NUM[i].s4=0;}
}
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());

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

using namespace std;

typedef tuple<int, int> P;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<P> v;
		for (int i = 0; i < n; ++i) {
			int c; cin >> c;
			int t = 0;
			for (int i = 0; i < 4; ++i) {
				int m, s; cin >> m >> s;
				t += m * 60 + s;
			}
			v.push_back( P(c, t) );
		}
		sort(v.begin(), v.end(), [](const P& p1, const P& p2) {
			return get<1>(p1) < get<1>(p2);
		});
		cout << get<0>(v[0]) << endl;
		cout << get<0>(v[1]) << endl;
		cout << get<0>(v[n-2]) << endl;
	}
}