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;
int main(){
	
	while(1){
		int n;
		cin >> n;
		if(n==0)
			break;

		int c[100000];

		int m1[100000];
		int m2[100000];
		int m3[100000];
		int m4[100000];
	
		int s1[100000];
		int s2[100000];
		int s3[100000];
		int s4[100000];
		
		int ans[100000];
		int ans2[100000];
		int ans3[100000];
		for(int i=0;i<n;i++){
			cin >> c[i] >> m1[i] >> s1[i] >> m2[i] >> s2[i] >> m3[i] >> s3[i] >> m4[i] >> s4[i];
			ans[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans2[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans3[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
		}

		sort(ans, ans + n);
		sort(ans2, ans2 + n, greater<int>());

		for(int i=0;i<2;i++){
			for(int j=0;j<n;j++){
				if(ans[i] == ans3[j]){
					cout << c[j] << endl;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			if(ans2[1] == ans3[i]){
				cout << c[i] << endl;
			}
		}

	}
		

		
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

struct team{
	long number;
	int time;
};

int main(){
	while(1){
		int n, num;
		cin>>n;
		if(n==0) break;
		
		vector<struct team> a;
		a.resize(n);

		for(int i=0;i<n;i++){
			cin>>a[i].number;
			a[i].time = 0;

			for(int j=0;j<8;j++){
				cin>>num;
				if(j%2 == 0)
					a[i].time += num * 60;
				else
					a[i].time += num;
			}
		}

		int win, pre, boo, los;
		if(a[0].time < a[1].time){
			win = 0;
			pre = 1;
			boo = 0;
			los = 1;
		}else{
			win = 1; 
			pre = 0;
			boo = 1;
			los = 0;
		}
		
		for(int i=2;i<n;i++){
			if(a[i].time < a[win].time){
				pre = win;
				win = i;
			}else if(a[i].time < a[pre].time){
				pre = i;
			}
			

			if(a[i].time > a[los].time){
				boo = los;
				los = i;
			}else if(a[i].time > a[boo].time){
				boo = i;
			}
		}

		cout<<a[win].number<<endl<<a[pre].number<<endl<<a[boo].number<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int first = 100000;
		int second = 100000;
		int boobee = -1;
		int last = -1;
		
		string fir = "";
		string sec = "";
		string boo = "";
		string las = "";
		
		for(int loop = 0; loop < n; loop++){
			string str;
			int a, b;
			cin >> str;
			int sum = 0;
			for(int i = 0; i < 4; i++){
				cin >> a >> b;
				sum += a * 60 + b;
			}
			if(sum < first){
				second = first;
				first = sum;
				sec = fir;
				fir = str;
			}else if(sum < second){
				second = sum;
				sec = str;
			}
			if(sum > last){
				boobee = last;
				last = sum;
				boo = las;
				las = str;
			}else if(sum > boobee){
				boobee = sum;
				boo = str;
			}
		}
		
		cout << fir << endl << sec << endl << boo << endl;
		
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
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,i,j;
	int a,b,data[100001];
	int min,ban;
	while(1){
		for(i=1;i<=100000;i++) data[i]=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>b;
			for(j=0;j<8;j++){
				cin>>a;
				if(j%2==0) data[b]+=a*60;
				else data[b]+=a;
			}
		}
		for(i=0;i<2;i++){
			min=100000000;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min>data[j]) {
					ban=j;
					min=data[j];
				}
			}
			cout<<ban<<endl;
			data[ban]=0;
		}
		for(i=0;i<2;i++){
			min=0;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min<data[j]) {
					ban=j;
					min=data[j];
				}
			}
			data[ban]=0;
		}
		cout<<ban<<endl;
	}
	return 0;
}

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

int main()
{
	int n;

	while( cin >> n && n ){
		vector< pair< int, int > > list;
		for( int i = 0; i < n; ++i ){
			int id, m, s, time = 0;
			cin >> id;
			for( int j = 0; j < 4; ++j ){
				cin >> m >> s;
				time += ( m * 60 + s );
			}
			list.push_back( make_pair( time, id ) );
		}
		sort( list.begin(), list.end() );

		cout << list[ 0 ].second << endl;
		cout << list[ 1 ].second << endl;
		cout << list[ list.size() - 2 ].second << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		vector< PII > teams( n );
		REP( i, 0, n )
		{
			int c;
			VI times( 8 );
			cin >> c;
			FOR( t, times )
			{
				cin >> t;
			}

			int total = 0;
			for ( int j = 0; j < 8; j += 2 )
			{
				total += times[j] * 60 + times[ j + 1 ];
			}

			teams[i] = MP( total, c );
		}
		sort( ALL( teams ) );

		cout << teams[0].snd << endl;
		cout << teams[1].snd << endl;
		cout << teams[ n - 2 ].snd << endl;
	}

	return 0;
}