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 <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<pair<int, int>> v;
        for (int i = 0; i < n; ++i) {
            int x, y = 0;
            cin >> x;
            for (int j = 0; j < 4; ++j) {
                int a, b;
                scanf("%d %d", &a, &b);
                y += a*60+b;
            }
            v.emplace_back(y, x);
        }
        sort(v.begin(),v.end());
        printf("%d\n%d\n%d\n", v[0].second, v[1].second, v.end()[-2].second);
    }

    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a,b,c,d;
	int aa,bb,cc,dd;
	int n;
	while(n=in()){
		int i;
		aa=bb=0;
		cc=dd=100000000;
		int num;
		for(i=0;i<n;i++){
			cin>>num;
			int m,s;
			int j;
			int sum=0;
			for(j=0;j<4;j++){
				cin>>m>>s;
				sum+=m*60+s;
			}
//cout<<num<<" "<<sum<<endl;
			if(sum>aa){
				b=a;bb=aa;
				a=num;aa=sum;
			}else if(sum>bb){
				b=num;bb=sum;
			}
			if(sum<dd){
				c=d;cc=dd;
				d=num;dd=sum;
			}else if(sum<cc){
				c=num;cc=sum;
			}
//cout<<"a "<<a<<" "<<aa<<endl;
//cout<<"b "<<b<<" "<<bb<<endl;
//cout<<"c "<<c<<" "<<cc<<endl;
//cout<<"d "<<d<<" "<<dd<<endl;
		}
		cout<<d<<endl<<c<<endl<<b<<endl;
	}
	return 0;
}

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

pair<int, int> team[1000000];
//team[i].firstはかかった時間[s]
//team[i].secondはチーム番号

int main()
{
	int n;
	int m, s;
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
		{
			team[i].first = 0;
			cin >> team[i].second;
			for (int j = 0; j < 4; j++)
			{
				cin >> m >> s;
				team[i].first += m * 60 + s;
			}
		}

		int first = 0, worst = 0;
		int second = 0, booby = 0;

		for (int i = 0; i < n; i++)
		{
			if (team[first].first > team[i].first)
			{
				second = first;
				first = i;
			}
			else if (team[second].first > team[i].first)
			{
				second = i;
			}

			if (team[worst].first < team[i].first)
			{
				booby = worst;
				worst = i;
			}
			else if (team[booby].first < team[i].first)
			{
				booby = i;
			}

			if (i == 1)
			{
				second = worst;
				booby = first;
			}
		}
		cout << team[first].second << endl;
		cout << team[second].second << endl;
		cout << team[booby].second << endl;
	}
	
	return 0;
}

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

vector<P> a;

int main() {
  int n,m,s,c1,m1,s1,m2,s2,m3,s3,m4,s4;
  while(cin >> n) {
    a.clear();
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      m = m1+m2+m3+m4;
      s = s1+s2+s3+s4+m*60;
      P temp;
      temp.first = s;
      temp.second = c1;
      a.push_back(temp);
    }
    sort(a.begin(),a.end());
    cout << a[0].second << endl;
    cout << a[1].second << endl;
    cout << a[n-2].second << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,teamnum,b;
	int m1,s1,m2,s2,m3,s3,m4,s4;
	while(1){
		cin >> n;
		if(n==0) break;
		int team[1000000]={0};
		int team2[1000000]={0};
		for(int i=0;i<n;i++){
			cin >> teamnum;
			cin >> m1 >> s1;
			cin >> m2 >> s2;
			cin >> m3 >> s3;
			cin >> m4 >> s4;
			team[teamnum] = m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
			team2[teamnum]=team[teamnum];
		}
		sort(team,team+1000000);
		int cnt=0;
		for(int i=0;i<1000000;i++){
			if(team[i]!=0 && cnt<2){
				for(int j=0;j<1000000;j++){
					if(team2[j]==team[i]){
						cout << j << endl;
						cnt++;
					}
					if(team[999998]==team2[j]){
						b=j;
					}
				}
			}
		}
		cout << b << endl;
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		pii good[3], bad[3];
		fill_n(good, 2, pii(10003600, 0));
		fill_n(bad, 2, pii(-10000000, 0));
		
		rep(i, n){
			pii team(0, 0);
			scanf("%d", &team.second);
			rep(j, 4){
				int m, s;
				scanf("%d%d", &m, &s);
				team.first += m * 60 + s;
			}
			good[2] = team;
			sort(good, good+3);
			bad[2] = team;
			sort(bad, bad+3, greater<pii>());
		}
		
		printf("%d\n", good[0].second);
		printf("%d\n", good[1].second);
		printf("%d\n", bad[1].second);
	}
	
	return 0;
}

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

int main(){
  int h,n,i,j,num[1000][1000],sum[1000],xmax=0;

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

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

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

	if(j>0 && j%2 == 0){
	  sum[i]+=num[i][j];
	}
	else if(j>0 && j%2 != 0){
	  sum[i]+=(num[i][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=num[xmax][0];
      num[xmax][0]=num[i][0];
      num[i][0]=h;
    }

    /*   
    for(i=0;i<n;i++){
	cout << "num["<<i<<"][0]="<<num[i][0];
	cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
    */    


    cout<< num[n-1][0] << endl;
    cout << num[n-2][0] << endl;
    cout<< num[1][0] << endl;






  }







}