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>
#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++: /*
	0161:Spoot Meet
*/
#include	<iostream>
#include	<vector>
#include	<algorithm>

using namespace std;

int main(void) {
	int n;
	while(1) {
		cin >> n;
		if(n == 0) { break; }
		vector< pair<int, int> > total(n);
		for(int i = 0; i < n; i++) {
			int c, m1, s1, m2, s2, m3, s3, m4, s4, ts1, ts2, ts3, ts4;
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			ts1 = 60 * m1 + s1;
			ts2 = 60 * m2 + s2;
			ts3 = 60 * m3 + s3;
			ts4 = 60 * m4 + s4;
			total[i] = make_pair(ts1 + ts2 + ts3 + ts4, c);
		}
		sort( total.begin(), total.end() );
		cout << total[0].second << endl << total[1].second << endl << total[n-2].second << endl;
	}
}

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

typedef pair<int, int> Team;

int main(void){  
  int n;
  
  while (cin >> n){
    vector<Team> v;
    if (n==0) break;
    for (int i=0; i<n; i++){
      int id, t;
      cin >> id;
      t = 0;
      for (int j=0; j<4; j++){
        int m,s;
        cin >> m >> s;
        t += m*60+s;
      }
      v.push_back(make_pair(t, id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[n-2].second << endl;
  }
  
  return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n, n) {
    vector<pii> a;
    rep(i, n) {
      int c, m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int sum = (m1+m2+m3+m4)*60 + (s1+s2+s3+s4);
      a.push_back(make_pair(sum, c));
    }
    sort(all(a));
    vector<pii>::iterator it = a.begin();
    cout << it->second << endl; it++;
    cout << it->second << endl;

    it = a.end(); it -= 2;
    cout << it->second << endl;
  }
}

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

struct hoge{
	int num, timem, times;
};

int main(){
	int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
	hoge set[100];
	while(1){
		cin >>n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >>c >>m1 >>s1 >>m2 >>s2 >>m3 >>s3 >>m4 >>s4;
			set[i].num = c;
			set[i].timem = m1 + m2 + m3 + m4;
			set[i].times = s1 + s2 + s3 + s4;
		}
		
		for(int i = 0; i < n; i++){
			for(int j = (i + 1); j < n; j++){
				if(set[j].timem < set[i].timem){
					swap(set[i].num, set[j].num);
					swap(set[i].timem, set[j].timem);
					swap(set[i].times, set[j].times);
				} else if(set[j].timem == set[i].timem){
					if(set[j].times < set[i].times){
						swap(set[i].num, set[j].num);
						swap(set[i].timem, set[j].timem);
						swap(set[i].times, set[j].times);
					}
				}
			}
		}
		
		cout <<set[0].num <<endl <<set[1].num <<endl <<set[n - 2].num <<endl;
	}
	return 0;
}

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

int main()
{
	int a, time, number, m1, s1, m2, s2, m3, s3, m4, s4;
	vector<pair<int, int> > team;
	
	while(1)
	{
		cin >> a;
		if (a == 0)
		{
			break;
		}
		team.clear();
		for(int i = 0; i < a; i++)
		{
			cin >> number;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			time = m1 *60  + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
		
			team.push_back(make_pair(time, number));
		
		}
	
		sort(team.begin(), team.end());
	
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[a - 2].second << endl;
	}
	return 0;
}

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

using namespace std;
 
typedef pair<int, int> P;
 
int main()
{
    int n;
    while (cin >> n, n) {
	vector<P> v, b;
	for (int i = 0; i < n; i++) {
	    int m, s, sum = 0, num;
	    cin >> num;
	    for (int j = 0; j < 4; j++) {
		cin >> m >> s;
		sum += m*60 + s;
	    }
	    v.push_back(P(-sum, num));
	    b.push_back(P(sum, num));
	}
	sort(v.begin(), v.end());
	sort(b.begin(), b.end());
	cout << b[0].second << endl;
	cout << b[1].second << endl;
	cout << v[1].second << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll are=1000000007;

int main() {
    while  (true){
        int n;
        cin >> n;
        if (n==0) break;
        vector<pp> a(n);
        rep(i,n){
            a.at(i).first=0;
            int u=0,y=0;
            cin >> a.at(i).second;
            rep(j,4){
                cin >> u >> y;
                a.at(i).first+=u*60+y;
            }
        }
        sort(a.begin(),a.end());
        cout << a.at(0).second << endl << a.at(1).second << endl <<  a.at(n-2).second << endl;
    }
}

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

using namespace std;


int main(){
	int temp, i, j, teams, total,number;
	vector<int> name;
	vector<int> time;
	time.insert(time.begin(), 99999);
	

	while (1){
		cin >> teams;
		
		if (teams == 0){
			break;
		}
		
		for (i = 0; i < teams; i++){
			cin >> number;
			total = 0;
			for (j = 0; j < 4; j++){
				cin >> temp;
				total += temp * 60;
				cin >> temp;
				total += temp;
			}

			for (j = 0; j <= i; j++){
				if (total < time[j]){
					name.insert(name.begin()+j, number);
					time.insert(time.begin()+j, total);
					break;
				}
				
			}

		}
		
		cout << name[0] << endl << name[1] << endl << name[i-2] << endl;


		//for (j = 0; j < i; j++){
		//	cout << name[j] << endl;
		//}


		name.clear();
		time.clear();
		time.insert(time.begin(),99999);
	}
}