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>
#include<string>
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		map<int, string>m;
		for (int i = 0;i < n;i++) {
			string s;
			int a[8];
			cin >> s;
			for (int j = 0;j < 8;j++)cin >> a[j];
			int t = 0, se = 0;
			for (int j = 0;j < 8;j += 2)t += a[j];
			for (int j = 1;j < 8;j += 2)se += a[j];
			int b = t * 60 + se;
			m.insert(make_pair(b, s));
		}
		auto itr = m.begin();
		cout << itr->second << endl;
		itr++;
		cout << itr->second << endl;
		auto it= m.rbegin();
		it++;
		cout << it->second << endl;

	}
	return 0;
}

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

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

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			std::cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			teams[i].id = id;
			teams[i].time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4; 
		}
		std::sort(teams, teams + n);
		std::cout << teams[0].id << std::endl;
		std::cout << teams[1].id << std::endl;
		std::cout << teams[n-2].id << std::endl;
		delete[] teams;
	}
	return 0;
}

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

int main(){
  int h,n,i,j,num[1000][1000],sum[1000],xmax=0;

  while(1){
    xmax=0;
    cin >> n;
    for(i=0;i<n;i++){

      for(j=0;j<9;j++){
	cin >> num[i][j];

	if(j>0 && j%2 == 0){
	  sum[i]+=num[i][j];
	}
	else if(j>0 && j%2 != 0){
	  sum[i]+=(num[i][j]*60);
	}

      }

    }

    for(i=0;i<n;i++){
      xmax=i;
      for(j=i;j<n;j++){
	if(sum[xmax]<sum[j])xmax=j;
      }
      h=sum[xmax];
      sum[xmax]=sum[i];
      sum[i]=h;

      h=num[xmax][0];
      num[xmax][0]=num[i][0];
      num[i][0]=h;
    }

    /*
    for(i=0;i<n;i++){
	cout << "num["<<i<<"][0]="<<num[i][0];
	cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
    */

    cout<< num[n-1][0] << endl;
    cout << num[n-2][0] << endl;
    cout<< num[1][0] << endl;






  }

}

C++: #include <cstdio>
#include <cfloat>
using namespace std;

int main() {
  int n, c, m, s, b[4];
  double t, a[4];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    a[0] = a[1] = DBL_MAX;
    a[2] = a[3] = -DBL_MAX;
    b[0] = b[1] = b[2] = b[3] = -1;
    for (int i=0; i<n; i++) {
      scanf("%d", &c);
      t = 0.;
      for (int j=0; j<4; j++) {
        scanf("%d %d", &m, &s);
        t += 60 * m + s;
      }
      if (t < a[0]) {
        a[1] = a[0];
        a[0] = t;
        b[1] = b[0];
        b[0] = c;
      } else if (t < a[1]) {
        a[1] = t;
        b[1] = c;
      }
      if (t > a[3]) {
        a[2] = a[3];
        a[3] = t;
        b[2] = b[3];
        b[3] = c;
      } else if (t > a[2]) {
        a[2] = t;
        b[2] = c;
      }
    }
    for (int i=0; i<3; i++) {
      printf("%d\n", b[i]);
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<int, int> > vp;
		for (int i = 0; i < n; i++){
			int id;
			cin >> id;
			int score = 0;
			for (int i = 0; i < 3; i++){
				int m, s;
				cin >> m >> s;
				score += m * 60 + s;
			}
			vp.push_back(make_pair(score, id));
		}
		sort(vp.begin(), vp.end());
		printf("%d\n%d\n%d\n", vp[0].second, vp[1].second, vp[n - 2].second);
	}
	return (0);
}

C++: //08
#include<iostream>
#include<utility>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    static pair<int,int> a[1000000];
    for(int i=0;i<n;i++){
      int c;
      cin>>c;
      int t=0;
      for(int j=0;j<4;j++){
	int m,s;
	cin>>m>>s;
	t+=m*60+s;
      }
      a[i]=make_pair(t,c);
    }
    sort(a,a+n);
    cout<<a[0].second<<endl;
    cout<<a[1].second<<endl;
    cout<<a[n-2].second<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<int, int> > vp;
		for (int i = 0; i < n; i++){
			int id;
			cin >> id;
			int score = 0;
			for (int i = 0; i < 3; i++){
				int m, s;
				cin >> m >> s;
				score += m * 60 + s;
			}
			vp.push_back(make_pair(score, id));
		}
		sort(vp.begin(), vp.end());
		printf("%d\n%d\n%d\n", vp[0].second, vp[1].second, vp[n - 2].second);
	}
	return (0);
}

C++: #include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
vector<pair<int,int> > v;
int main(void){
  int n;
  while(cin >> n){
    if(!n) break;
    v.clear();
    for(int j = 0; j < n; j++){
      int c = 0;
      int id;
      cin >> id;
      for(int i = 0; i < 4; i++){
	int m,s;
	cin >> m >> s;
	c += m*60 + s;
      }
      v.push_back(make_pair(c,id));
    }
    sort(v.begin(),v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
  }
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

void solveAndOutput(MAPII result){
	int count = 0;
	MAPII::iterator it_end = result.end();
	it_end--; it_end--;
	foreach_it(MAPII, it, result){
		count++;
		if (count <= 2)
			cout << (*it).second << endl;
		if (it == it_end)
			cout << (*it).second << endl;
	}
}

int main(){
	int n;
	int c1, m1, s1, m2, s2, m3, s3, m4, s4;
	MAPII result;
	fastIO;

	while (cin >> n, n){
		while (n--){
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			result.insert(MP(m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4, c1));
		}
		solveAndOutput(result);
		result.clear();
	}
	return 0;
}