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>
using namespace std;
typedef pair<int,int> P;
int n,m,s;
P t[1000000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].second;
      t[i].first=0;
      for(int j=0;j<4;j++){
	cin>>m>>s;
	t[i].first+=(m*60+s);
      } 
    }
    sort(t,t+n);
    cout<<t[0].second<<endl;
    cout<<t[1].second<<endl;
    cout<<t[n-2].second<<endl;
  }
}

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;
    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;






  }







}

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

using namespace std;

int main(void)
{
	vector< pair<unsigned long,unsigned long> > team;

	unsigned long n;

	while( cin >> n && n != 0 ){
		team.clear();
		for( long i = 0;i < n;i++ ){
			unsigned long sum = 0;;
			unsigned long m,s;
			unsigned long number;

			cin >> number;

			for( long j = 0;j < 4;j++ ){
				cin >> m >> s;
				sum += m * 60 + s;
			}
			team.push_back( pair<unsigned long, unsigned long>( sum, number ) );
		}

		sort( team.begin(), team.end() );

		for( long i = 0;i < 2;i++ ){
			cout << team[i].second << endl;
		}
		cout << team[n - 2].second << endl;
	}

	return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while (cin >> n && n){
        vector<pair<int, int>> v(n);
        rep(i, n){
            cin >> v[i].second;
            int t = 0;
            rep(j, 4){
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            v[i].first = t;
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
        cout << v[1].second << endl;
        cout << v[v.size() - 2].second << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Team{
	int n,t;
	Team(){
		t=0;
	}
	bool operator <(const Team &a)const{
		return t<a.t;
	}
};

struct Time{
	int s,m;
};

Team team[1000000];

int main(){
	int N;
	while(cin>>N,N){
		for(int i=0;i<N;i++){
			Time time[4];
			cin>>team[i].n;
			for(int j=0;j<4;j++) cin>>time[j].m>>time[j].s, team[i].t += time[j].m*60+time[j].s;
		}
		sort(team,team+N);
		printf("%d\n%d\n%d\n",team[0].n,team[1].n,team[N-2].n);
	}
	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)
	{
		if (n == 0)
		{
			return 0;
		}

		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;
			}
		}

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

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

int main() {
	while (1) {
		map<int, int>s;
		int a;
		cin >> a;
		if (a == 0)break;
		for (int b = 0; b < a; b++) {
			int c, d, e, f, g, h, i, j, k;
			cin >> c >> d >> e >> f >> g >> h >> i >> j >> k;
			s.insert(pair<int, int>((d + f + h + j) * 60 + e + g + i + k, c));
		}
		auto u = s.begin();
		cout << u->second << endl;
		u++;
		cout << u->second << endl;
		u = s.end();
		u--;
		u--;
		cout << u->second << endl;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>vs;
		while (N--) {
			int id; cin >> id;
			int sum = 0;
			for (int i = 0; i < 4; ++i) {
				int m, s; cin >> m >> s;
				sum += m * 60 + s;
			}
			vs.push_back(make_pair(sum, id));
			
		}
		sort(vs.begin(), vs.end());
		cout << vs[0].second << endl;
		cout << vs[1].second << endl;
		cout << vs[vs.size() - 2].second << endl;
	}
	return 0;
}

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

using namespace std;

int main(void)
{
	
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int c1, m1, s1, m2, s2, m3, s3, m4, s4;
		vector< pair<int, int> >g;
		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++: #include<stdio.h>
#include<iostream>
using namespace std;


struct SKE{int c1;int m1;int s1;int m2;int s2;int m3;int s3;int m4;int s4;int SUM;};
struct SKE NUM[10000001];
int main (){
int N;
struct SKE Te,M1,M2,M3;
while(1){
cin>>N;if(N==0)break;
for(int i=0;i<N;i++){
	cin>>NUM[i].c1>>NUM[i].m1>>NUM[i].s1>>NUM[i].m2>>NUM[i].s2>>NUM[i].m3>>NUM[i].s3>>NUM[i].m4>>NUM[i].s4;
	NUM[i].SUM=NUM[i].s1+NUM[i].s2+NUM[i].s3+NUM[i].s4+60*(NUM[i].m1+NUM[i].m2+NUM[i].m3+NUM[i].m4);
}
M1=NUM[0];M2=NUM[0];M3=NUM[0];
for(int i=1;i<N;i++){
	if(NUM[i].SUM<M1.SUM){M3=M2;M2=M1;M1=NUM[i];}
	else if(NUM[i].SUM<M2.SUM){M3=M2;M2=NUM[i];}
	else if(NUM[i].SUM<M3.SUM){M3=NUM[i];}

}
cout<<M1.c1<<endl<<M2.c1<<endl<<M3.c1<<endl;
for(int i=0;i<N;i++)
{NUM[i].c1=NULL;NUM[i].m1=NULL;NUM[i].s1=NULL;NUM[i].m2=NULL;NUM[i].s2=NULL;NUM[i].m3=NULL;NUM[i].s3=NULL;NUM[i].m4=NULL;NUM[i].s4=NULL;}
}
return 0;
}