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

using namespace std;

struct Team {
	int num;
	int min[4];
	int s[4];
	int total;
};

int compute(Team group);
bool compare(Team i, Team j) {
	return (i.total < j.total);
}

int main() {

	int n;
	while (cin >> n && n != 0) {

		Team *group = new Team[n];

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

			cin >> group[i].num;

			for (int j = 0; j < 4; j++)
				cin >> group[i].min[j] >> group[i].s[j];

			group[i].total = compute(group[i]);
		}

		sort(group, group + n, compare);
		cout << group[0].num << "\n"
			 << group[1].num << "\n"
			 << group[n - 2].num<< "\n";
	}

	

	return 0;

}

int compute(Team group) {

	int total = 0;
	for (int i = 0; i < 4; i++)
		total += (group.min[i] * 60 + group.s[i]);

	return total;
}

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

class sorting{
public:
  bool operator()(const pair<int,int>& left,const pair<int,int>& right)const{
    return left.first < right.first;
  }
};

int main(){
  int n;
  while(cin >> n,n){
    vector<pair<int,int> > dat;
    int m,s,id;
    for(int i=0;i<n;i++){
      int total = 0;
      cin >> id;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	total += m*60 + s;
      }
      dat.push_back(make_pair(total,id));
    }
    sort(dat.begin(),dat.end(),sorting());
    cout << dat[0].second << endl << dat[1].second << endl << dat[n-2].second << endl;
  }
}

C++: #include <iostream>
#include<algorithm>
using namespace std;
int main()
{
  while(true){
	int n;
	cin>>n;
	if(n==0)
		break;

	int t[1000000];
        int c[1000000];
        
      
	for(int i=0;i<n;i++){
		int c1,m1,s1,m2,s2,m3,s3,m4,s4;
		cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
	       t[i]=(m1+m2+m3+m4)*60+(s1+s2+s3+s4);
		c[i]=c1;
	}

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

        int p1=c[0];
	 int p2=c[1];
	 int p3=c[n-2];

	cout<<p1<<endl;
	cout<<p2<<endl;
	cout<<p3<<endl;
}
       
        return 0;
}

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

bool func(pair< int, int > a, pair< int, int > b){
	return a.second < b.second;
}

int main() {
	int n;
	int c, m1, s1, m2, s2, m3, s3, m4, s4;
	vector< pair< int, int > > data;
	
	while(cin >> n, n){
		
		data.clear();
		
		for(int i = 0; i < n; ++i){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			data.push_back(make_pair(c, (m1+m2+m3+m4) * 60 + s1+s2+s3+s4));
		}
		
		sort(data.begin(), data.end(), func);
		
		cout << data[0].first << endl;
		cout << data[1].first << endl;
		cout << data[n - 2].first << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(void) {
  int n;
  while(cin >> n, n) {
    vector<P> vc;
    for(int i = 0 ; i < n ; i++) {
      int c, m1, m2, m3, m4, s1, s2, s3, s4;
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
    
      P p(time, c);
      vc.push_back(p);
    }
    sort(vc.begin() , vc.end());
    
    cout << vc[0].second << endl;
    cout << vc[1].second << endl;
    cout << vc[vc.size()-2].second << endl;
  }
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
using namespace std;
typedef pair<int,int> P;

int main(){
    int n,i;
    while(cin>>n&&n){
        vector<P> ra;
        for(i=0;i<n;i++){
            int id,m1,m2,m3,m4,s1,s2,s3,s4;
            cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
            int t=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
            P p(t,id);
            ra.push_back(p);
        }
        sort(ra.begin(),ra.end());
        cout<<ra[0].second<<endl;
        cout<<ra[1].second<<endl;
        cout<<ra[ra.size()-2].second<<endl;
    }
    return 0;
}