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

using namespace std;

typedef struct{
	int id,timeSum;
}data;

bool operator<(const data &a,const data &b){
	return (a.timeSum<b.timeSum);
}

int main(void){
	int n,m,s;
	
	while(cin>>n,n){
		vector<data> inp(n);
		
		for(int i=0;i<n;i++){
			cin>>inp[i].id;
			inp[i].timeSum=0;
			for(int j=0;j<4;j++){
				cin>>m>>s;
				inp[i].timeSum=inp[i].timeSum+m*60+s;
			}
		}
		sort(inp.begin(),inp.end());
		cout<<inp[0].id<<endl<<inp[1].id<<endl<<inp[n-2].id<<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;	
		cout << g[n - 2].second	<< endl;
	}
	return 0;
}

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

typedef pair<int, int> P;
P sum[1000001];

int main()
{
  int n;
  while (cin >> n, n){
    for (int i = 0; i < n; i++){
      int c;
      cin >> c;
      sum[i].first = 0;
      sum[i].second = c;
      for (int j = 0; j < 4; j++){
        int m, s;
        cin >> m >> s;
        sum[i].first += m * 60 + s;
      }
    }
    sort(sum, sum + n);
    cout << sum[0].second << endl << sum[1].second << endl << sum[n - 2].second << endl;
  }
  return (0);
}

C++: #include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

struct team {
    int number;
    int time;
};

typedef struct team Team;
bool tfsort (const team &a, const team &b);

int main(){
    int i, n=1,time, times, second, a, b, c, d, e, f, g, h;
    Team rec[10];
    int number[1000001],team[1000001];
    
    for (;n>0;n--){
        scanf("%d",&n);
//        printf("%d\n",n);
        for(i = 0; i < n; i++){
            scanf("%d %d %d %d %d %d %d %d %d", &number[i], &a, &b, &c, &d, &e, &f, &g, &h);
            times = (b+d+f+h);
            time = times / 60;
            second = times - time * 60;
            team[i] = (a+c+e+g+time)*100 + second;
            rec[i] = (Team){number[i], team[i]};
        }
        sort(rec, rec + n, tfsort);
        
        for(i = 0; i < 2; i++){
            printf("%d\n", rec[i].number);
        }
        printf("%d\n", rec[n -2].number);
    }
    return 0;
}

bool tfsort (const team &a, const team &b){
    if(a.time < b.time) return true;
    return false;
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi> s;
int dp[1024];
int main() {
	int nn;
	while ((cin >> nn) && nn) {
		s.clear();
		for (int i = 0; i < nn; ++i) {
			int  a, b, c, d, e, f, g, h,iiii;
			cin >> a >> b >> c >> d >> e >> f >> g >> h>>iiii;
			s.push_back(make_pair(b*60+c+d*60+e+f*60+g+h*60+iiii,a));
		}
		sort(s.begin(),s.end());
		cout<<s[0].second<<endl;
		cout<<s[1].second<<endl;
		cout<<s[nn-2].second<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	vector<pair<int, int> > team;
	int n, min[4], sec[4], Sec, name;
	
	while(1){
		cin >> n;

		if(n == 0)    break;

		for (int i = 0; i < n; i++){
			cin >> name;

			cin >> min[0] >> sec[0] >> min[1] >> sec[1] >> min[2] >> sec[2] >> min[3] >> sec[3];

			Sec = 0;

			for (int j = 0; j < 4; j++){
				Sec += ((min[j] * 60) + sec[j]);
			}

			team.push_back(make_pair(Sec, name));
		}

		sort(team.begin(), team.end());

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	
		team.clear();
	}

	return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    int c[n];
    int score[n];

    for(int i = 0; i < n; i++){
      cin >> c[i];
      score[i] = 0;

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

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        if(score[i] > score[j]){
          swap(c[i], c[j]);
          swap(score[i], score[j]);
        }
      }
    }

    cout << c[0] << endl;
    cout << c[1] << endl;
    cout << c[n - 2] << endl;
  }
}

C++: #include <iostream>
#include <set>
using namespace std;
#define P pair<int,int>
int main()
{
  int n,i;
  for(;;){
    cin >> n;
    if(n==0)break;
    set< P > se;
    while(n--){
      int c,m,s,j=0;
      cin >> c;
      for(i=0;i<4;i++){
	cin >> m >> s;
	j += m*60+s;
      }
      se.insert( P(j,c) );
    }
    set< P >::iterator it = se.begin();
    for(i=0;i<2;i++){
      cout << (*it).second << endl;
      it++;
    }
    set< P >::reverse_iterator r = se.rbegin();
    r++;
    cout << (*r).second << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Team{
	int id;
	int result;
	bool operator<(const Team &t)const{return result<t.result;}
};
void Input(Team &t){
	int c,m1,s1,m2,s2,m3,s3,m4,s4;
	scanf("%d%d%d%d%d%d%d%d%d",&c,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
	t.id = c;
	t.result = m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
}
int main(){
	while(true){
		int n;
		vector<Team> vteams;
		scanf("%d", &n);
		if(n==0)break;
		vteams.resize(n);
		for(int i = 0; i < n; ++i){Input(vteams[i]);}
		sort(vteams.begin(),vteams.end());
		printf("%d\n%d\n%d\n",vteams[0].id,vteams[1].id,vteams[n-2].id);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  while(cin>>n,n){
    pair<int,int>a[n];
    for(int i=0;i<n;i++){
      int q,w,e,r,t,y,u,o,p;
      cin>>q>>w>>e>>r>>t>>y>>u>>o>>p;
      a[i].second=q;
      a[i].first=(w+r+y+o)*60+e+t+u+p;
    }
    sort(a,a+n);
    cout<<a[0].second<<endl<<a[1].second<<endl<<a[n-2].second<<endl;
  }
}