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 <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e5+10;
struct t{
    int m;
    int s;
    void operator +=(const t &a){
        m+=a.m;
        s+=a.s;
        pull();
        return ;
    }
    void pull(){
        m+=s/60;
        s%=60;
        return ;
    }
    void in(){
        scanf("%d%d",&m,&s);
        return ;
    }
};
t a[N];
int f[N];
bool cmp(const int &l,const int &r){return a[l].m==a[r].m?a[l].s<a[r].s:a[l].m<a[r].m;}
int main(){
    int n,s[N];
    t temp;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            scanf("%d",&s[i]);
            f[i]=i;
            a[i].in();
            for(int j=0;j<3;j++){
                temp.in();
                a[i]+=temp;
            }
        }
        sort(f,f+n,cmp);
        printf("%d\n%d\n%d\n",s[f[0]],s[f[1]],s[f[n-2]]);
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[1000000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			int r,s,t,u,v,w,x,y,z;
			scanf("%d%d%d%d%d%d%d%d%d",&r,&s,&t,&u,&v,&w,&x,&y,&z);
			int q=(s+u+w+y)*60+t+v+x+z;
			dat[i]=make_pair(q,r);
		}
		std::sort(dat,dat+a);
		printf("%d\n%d\n%d\n",dat[0].second,dat[1].second,dat[a-2].second);
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

ll n, a, c[1000010][5],no[10];
vector<ll> vl;

int main(){
	while (cin >> n){
		if (!n)break;
		REP(i, n){
			c[i][1] = 0;
			REP(j, 9){
				if (j == 0){
					cin >> c[i][j];
					continue;
				}
				cin >> a;
				if (j % 2 != 0){
					a *= 60;
				}
				c[i][1] += a;
			}
			vl.push_back(c[i][1]);
		}
		sort(ALL(vl));
		REP(i, n){
			if (c[i][1] == vl[0])no[0] = c[i][0];
			if (c[i][1] == vl[1])no[1] = c[i][0];
			if (c[i][1] == vl[n - 2])no[2] = c[i][0];
		}
		REP(i, 3){
			cout << no[i] << endl;
		}
	}
}

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;
  sum = 0;

  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<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> pp;

int main()
{
    int n, c, m[4], s[4], sum[4];

    while(cin >> n && n)
    {
        vector<pp> res;
        REP(n)
        {
            cin >> c;
            rep(j,4)cin>> m[j] >> s[j]; 
            res.push_back(pp((m[0]+m[1]+m[2]+m[3])*60 + s[0]+s[1]+s[2]+s[3], c));
        }
        sort(all(res));
        cout << res[0].second << endl;
        cout << res[1].second << endl;
        cout << res[n-2].second << endl;
    }

    return 0;
}

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

typedef pair<int, int> P;

int n;
vector<P> ps;

int main()
{
    int c, m, s, sum;
    while(cin >> n && n) {
        ps.clear();
        for(int k = 0; k < n; k++) {
            cin >> c;
            sum = 0;
            for(int i = 0; i < 4; i++) {
                cin >> m >> s;
                sum += m * 60 + s;
            }
            ps.push_back(P(sum, c));
        }
        sort(ps.begin(), ps.end());
        
        cout << ps[0].second << endl;
        cout << ps[1].second << endl;
        cout << ps[ps.size() - 2].second << endl;

    }
    
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
main()
{
    while(cin>>n,n)
    {
        vector<pair<int,int> >s;
        for(;n--;)
        {
            int i;cin>>i;
            s.push_back(make_pair(0,i));
            for(int j=4;j--;)
            {
                int a,b;cin>>a>>b;
                s.back().first+=a*60+b;
            }
        }
        sort(s.begin(),s.end());
        cout<<s[0].second<<endl<<s[1].second<<endl<<s[s.size()-2].second<<endl;
    }
}

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

struct team{int id;int data;};

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

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

int main(void)
{
	int n;
	while (cin >> n, n){
		int c1, m1, s1, m2, s2, m3, s3, m4, s4;
		vector < pair < pair <int, int>, int> > data;
		for (int i = 0; i < n; i++){
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int minute = m1 + m2 + m3 + m4;
			int sec = s1 + s2 + s3 + s4;
			minute += (sec / 60);
			sec %= 60;
			data.push_back(make_pair(make_pair(minute, sec), c1));
		}
		sort(data.begin(), data.end());
		cout << data[0].second << endl;
		cout << data[1].second << endl;
		cout << data[data.size() - 2].second << endl;
	}

	return 0;
}