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

class Score{
public:
    int num;
    int time;
    
    Score(){
        this->num = 0;
        this->time = 0;
    }
    
    Score(int num, int time){
        this->num = num;
        this->time = time;
    }
    
};

int main(int argc, const char * argv[]) {
    
    while (true) {
        int n;
        cin >> n;
        
        Score max,pre,biri,boobie;
        
        for(int i=0;i<n;i++){
            int c1;
            cin >> c1;
            int sum = 0;
            for(int i=0;i<4;i++){
                int m, s;
                cin >> m >> s;
                sum+= 60*m + s;
            }
            
            if(max.time == 0 || max.time > sum){
                pre = max;
                max = Score(c1,sum);
            }
            else if(pre.time == 0 || pre.time > sum){
                if(biri.time == 0){
                    biri = pre;
                }
                else if(boobie.time == 0){
                    boobie = pre;
                }
                pre = Score(c1,sum);
            }
            else if(biri.time < sum){
                boobie = biri;
                biri = Score(c1,sum);
            }
            else if(boobie.time < sum){
                boobie = Score(c1,sum);
            }
            
        }
        
        cout << max.num << endl;
        cout << pre.num << endl;
        cout << boobie.num << endl;
        
    }
    
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    vector<pair<int,int>> v;
    int n;
    cin>>n;
    if(!n)break;
    REP(i,n){
      int c,m1,s1,m2,s2,m3,s3,m4,s4;
      cin>>c>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      v.push_back(make_pair(m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4,c));
    }
    sort(begin(v),end(v));
    cout<<v[0].second<<endl;
    cout<<v[1].second<<endl;
    cout<<v[v.size()-2].second<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > time(n);
        for(int i=0; i<n; ++i){
            cin >> time[i].second;
            time[i].first = 0;
            for(int j=0; j<4; ++j){
                int m, s;
                cin >> m >> s;
                time[i].first += m * 60 + s;
            }
        }
        sort(time.begin(), time.end());

        cout << time[0].second << endl;
        cout << time[1].second << endl;
        cout << time[n-2].second << endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, s; pair<int, int> d[1000000];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i].second); d[i].first = 0;
			for (int j = 0; j < 4; j++) scanf("%d%d", &m, &s), d[i].first += m + s * 60;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[n - 1].second, d[n - 2].second, d[1].second);
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int main(){
    int n;
    while(scanf("%d",&n),n){
	map<int,int>data;
	rep(i,n){
	    int c1,m1,s1,m2,s2,m3,s3,m4,s4;
	    int sum = 0;
	    scanf("%d%d%d%d%d%d%d%d%d",&c1,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
	    sum = (m1+m2+m3+m4)*60+(s1+s2+s3+s4);
	    data[sum] = c1;
	}
	int cnt = 0;
	map<int,int>::iterator it = data.begin();
	while(cnt < 2){
	    cout << (*it).second << endl;
	    it++;
	    cnt++;
	}
	it = data.end();
	it--;
	it--;
	cout << (*it).second << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		vector<pair<int,int> > d;
		rep(i,0,n){
			int name,m,s,sum=0;
			cin>>name;
			rep(i,0,4){
				cin>>m>>s;
				sum+=60*m+s;
			}
			d.push_back(make_pair(sum,name));
		}
		sort(all(d));
		o(d[0].second);
		o(d[1].second);
		o(d[n-2].second);
	}
}

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

int main(){
  int h,n,i,j,sum[100000],xmax=0,num1[100000],num2[100000];

  while(1){
    xmax=0;
    for(i=0;i<100000;i++)sum[i]=0;
    

    cin >> n;
    if(n == 0)break;

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

	cin >> num2[j];

	if(j>0 && j%2 == 0){
	  sum[i]+=num2[j];
	}
	else if(j>0 && j%2 != 0){
	  sum[i]+=(num2[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=num1[xmax];
      num1[xmax]=num1[i];
      num1[i]=h;
    }
    /*
       
    for(i=0;i<n;i++){
	cout << "num1["<<i<<"]="<<num1[i];
	cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
      
    */  


    cout<< num1[n-1] << endl;
    cout << num1[n-2] << endl;
    cout<< num1[1] << endl;






  }







}

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

class Team{
public:
  int n,m,s;
  bool operator < (const Team &t)const{
    if(m == t.m) return s < t.s;
    else return m < t.m;
  }
};

int main(){
  int i,j,n;
  while(1){
    cin >> n;
    if(n == 0) break;
    Team t[1000000];

    for(i=0;i<n;i++){
      cin >> t[i].n;
      t[i].m = t[i].s = 0;

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

      while(t[i].s >= 60){
	t[i].m++;
	t[i].s -= 60;
      }
    }

    sort(t,t+n);
    cout << t[0].n << endl;
    cout << t[1].n << endl;
    cout << t[n-2].n << endl;
  }  
  return 0;
}