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

using namespace std;

struct team{
	int name;
	int s;
};

int main() {
	int n;
	int m[4];
	int s[4];
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<team> t(n);
		for (int i = 0; i < n; i++) {
			cin >> t[i].name >> m[0] >> s[0] >> m[1] >> s[1] >> m[2] >> s[2] >> m[3] >> s[3]; 
			t[i].s = 0;
			for (int j = 0; j < 4; j++) {
				t[i].s += s[j];
				t[i].s += (m[j] * 60);
			}
		}
		int juni[4][2];
		for (int i = 3; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (t[j].s > t[j+1].s) {
					swap(t[j].s, t[j+1].s);
					swap(t[j].name, t[j+1].name);
				}
			}
		}
		for (int i = 0; i < 4; i++) {
			juni[i][0] = t[i].name;
			juni[i][1] = t[i].s;
		}
		for (int i = 4; i < n; i++) {
			if (t[i].s < juni[0][1]) {
				juni[1][1] = juni[0][1];
				juni[1][0] = juni[0][0];
				juni[0][1] = t[i].s;
				juni[0][0] = t[i].name;
			} else if (t[i].s < juni[1][1]) {
				juni[1][1] = t[i].s;
				juni[1][0] = t[i].name;
			} else if (t[i].s > juni[3][1]) {
				juni[2][1] = juni[3][1];
				juni[2][0] = juni[3][0];
				juni[3][1] = t[i].s;
				juni[3][0] = t[i].name;
			} else if (t[i].s > juni[2][1]) {
				juni[2][1] = t[i].s;
				juni[2][0] = t[i].name;
			}
		}
		for (int i = 0; i < 3; i++) {
			cout << juni[i][0] << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,c1,m1,s1,m2,s2,m3,s3,m4,s4,a[4],b[4],i,j,k;
while(cin>>n){
if(n==0)break;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[0]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[0]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[1]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[1]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[2]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[2]=c1;
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
a[3]=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
b[3]=c1;
for(i=0;i<4;i++)
for(j=i+1;j<4;j++){
if(a[i]>a[j]){m1=a[i];a[i]=a[j];a[j]=m1;m1=b[i];b[i]=b[j];b[j]=m1;}
}
for(i=4;i<n;i++){
cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
m1=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
if(m1<a[0]){a[1]=a[0];a[0]=m1;b[1]=b[0];b[0]=c1;}
else if(m1<a[1]){a[1]=m1;b[1]=c1;}
else if(m1>a[3]){a[2]=a[3];a[3]=m1;b[2]=b[3];b[3]=c1;}
else if(m1>a[2]){a[2]=m1;b[2]=c1;}
}
cout<<b[0]<<endl;
cout<<b[1]<<endl;
cout<<b[2]<<endl;
}
return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  while(cin>>n,n){
    pair<int,int>a[n];
    for(int i=0;i<n;i++){
      int q,w,e,r,t,y,u,o,p;
      cin>>q>>w>>e>>r>>t>>y>>u>>o>>p;
      a[i].second=q;
      a[i].first=(w+r+y+o)*60+e+t+u+p;
    }
    sort(a,a+n);
    cout<<a[0].second<<endl<<a[1].second<<endl<<a[n-1].second<<endl;
  }
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v(n);
		rep(i,n){
			int id;
			cin>>id;
			int t=0;
			rep(i,4){
				int a,b;
				cin>>a>>b;
				t+=a*60+b;
			}
			v[i]=mkp(t,id);
		}
		sort(ALL(v));
		cout<<v[0].S<<endl;
		cout<<v[1].S<<endl;
		cout<<v[v.size()-2].S<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;

typedef struct {
    long long int num;
    int min[4] = {0};
    int sec[4] = {0};
    int sum = 0;
}team;

void quick_sort(team x[], int left, int right);

int main(void) {
    int n;
    
    while(1) {
        scanf("%d", &n);
        if(n == 0) break;
        int i, j;
        team *p;
        p = (team *)calloc(n, sizeof(team));
        if(p == NULL) exit(0);
        
        for(i = 0; i < n; i++) {
            scanf("%lld", &p[i].num);
            for(j = 0; j < 4; j++)
                scanf("%d %d", &p[i].min[j] , &p[i].sec[j]);
        }
        for(i = 0; i < n; i++) {
            for(j = 0; j < 4; j++)
                p[i].sum += (p[i].min[j] * 60) + p[i].sec[j];
        }
        quick_sort(p, 0, n - 1);
        
        cout << p[0].num << endl << p[1].num << endl << p[n - 2].num << endl;
        free(p);
    }
    
    return(0);
}

void quick_sort(team x[], int left, int right) {
    int i, j;
    team pivot;
    
    i = left;
    j = right;
    pivot.sum += x[(left + right) / 2].sum;
    
    while(1) {
        while(x[i].sum < pivot.sum) i++;
        while(x[j].sum > pivot.sum) j--;
        
        if(i >= j) break;
        
        swap(team, x[i], x[j]);
        i++;
        j--;
        // DEBUG cout << "OK" << endl;     ここの時点では出力に”OK”と沢山表示される
    }
    
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}

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 * 60 + s;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[0].second, d[1].second, d[n - 2].second);
	}
	return 0;
}