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 <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		vector<P> vc;

		for(int i=0 ; i < n ; i++ ){
			int c,m1,m2,m3,m4,s1,s2,s3,s4;
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			P p( time , c );
			vc.push_back( p );
		}
		sort( vc.begin() , vc.end() );
		cout << vc[0].second << endl;
		cout << vc[1].second << endl;
		cout << vc[vc.size()-2].second << endl;
	}
}

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[1000001];
int main (){
int N;
SKE Te,M1,M2,M3,M;
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){M2=M1;M1=NUM[i];}
	else if(NUM[i].SUM<M2.SUM){M2=NUM[i];}
	if(NUM[i].SUM>M.SUM){M3=M;M=NUM[i];}

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

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int>pii;
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<pii>V;
        for(int i=0;i<n;i++){
            int p,sum=0;
            scanf("%d",&p);
            for(int i=0;i<4;i++){
                int m,s;
                scanf("%d%d",&m,&s);
                sum+=m*60+s;
            }
            V.push_back(pii(sum,p));
        }

        sort(V.begin(),V.end());
        printf("%d\n",V[0].second);
        printf("%d\n",V[1].second);
        printf("%d\n",V[n-2].second);
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

    int n;
    while(cin>>n,n){
        map < int , int > a;

        for(int i=0;i<n;i++){
            int t;
            cin>>t;
            int z=0;
            for(int j=0;j<4;j++){
                int x,y;
                cin>>x>>y;
                z += x*60+y;
            }
            a[z] = t;


        }
        map<int, int>::iterator it = a.begin();

        cout<<(*it).second<<endl;
        it++;
        cout<<(*it).second<<endl;
        it = a.end();
        it--;
        it--;
        cout<<(*it).second<<endl;
    }

    return 0;
}

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

int main(){
  int n,i,a,b,c,d,e,f,g,h;
  for(;scanf("%d",&n),n;){
    vector<pair<int,int> >v;
    for(;n--;)scanf("%d%d%d%d%d%d%d%d%d",&i,&a,&b,&c,&d,&e,&f,&g,&h),v.push_back(make_pair(a*60+b+c*60+d+e*60+f+g*60+h,i));
    sort(v.begin(),v.end());
    printf("%d\n%d\n%d\n",v[0].second,v[1].second,v[v.size()-2].second);
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	while(1){
		int n=0;
		int c[100001];
		int m1[100001];
		int m2[100001];
		int m3[100001];
		int m4[100001];

		int s1[100001];
		int s2[100001];
		int s3[100001];
		int s4[100001];

		int A[100001];
		int Ad[100001];

		int A1=0;
		int A2=0;
		int Ab=0;

		cin>>n;
		if(n==0){
			break;
		}
	
		for(int i=0;n>i;i++){
			cin>>c[i];
			cin>>m1[i];
			cin>>s1[i];
			cin>>m2[i];
			cin>>s2[i];
			cin>>m3[i];
			cin>>s3[i];
			cin>>m4[i];
			cin>>s4[i];
			m1[i]=60*m1[i];
			m2[i]=60*m2[i];
			m3[i]=60*m3[i];
			m4[i]=60*m4[i];
			A[i]=m1[i]
			+m2[i]
			+m3[i]
			+m4[i]
			+s1[i]
			+s2[i]
			+s3[i]
			+s4[i];
			Ad[i]=m1[i]
			+m2[i]
			+m3[i]
			+m4[i]
			+s1[i]
			+s2[i]
			+s3[i]
			+s4[i];
		}
		sort(A,A+n);
		
		for(int i=0;n>i;i++){
			if(A[0]==Ad[i]){
				A1=c[i];
			}
			if(A[1]==Ad[i]){
				A2=c[i];
			}
			if(A[n-2]==Ad[i]){
				Ab=c[i];
			}
		}
		cout<<A1<<endl;
		cout<<A2<<endl;
		cout<<Ab<<endl;
		
}
return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
struct team{
	int n;
	long long int t;
};
team a[1000000];
bool comp(const team &t1,const team &t2){
	return t1.t < t2.t;
}
int main(){
	int n,i,c,m1,s1,m2,s2,m3,s3,m4,s4,t;
	team x;
	while(cin >> n && n){
		for(i = 0;i < n;i++){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			t = (m1 * 60 + s1) + (m2 * 60 + s2) + (m3 * 60 + s3) + (m4 * 60 + s4);
			x.n = c;
			x.t = t;
			a[i] = x;
		}
		sort(a,a+n,comp);
		cout << a[0].n << "\n" << a[1].n << "\n" << a[n - 2].n << endl;
	}
	return 0;
}

C++: #include<cstdio>
#define MAX 100000
#define INF (1<<21)

int id[MAX], total[MAX];
int n;

int searchMin(){
    int minv = INF;
    int target;
    for ( int i = 0; i < n; i++ ){
	if ( total[i] < 0 ) continue;
	if ( total[i] < minv ){
	    minv = total[i];
	    target = i;
	}
    }
    total[target] = -1;
    return id[target];
}

int searchMax(){
    int maxv = 0;
    int target;
    for ( int i = 0; i < n; i++ ){
	if ( total[i] < 0 ) continue;
	if ( total[i] > maxv ){
	    maxv = total[i];
	    target = i;
	}
    }
    total[target] = -1;
    return id[target];
}

main(){
    int m, s;
    while(1){
	scanf("%d", &n);
	if ( n == 0 ) break;
	for ( int i = 0; i < n; i++ ){
	    scanf("%d", &id[i]);
	    total[i] = 0;
	    for ( int j = 0; j < 4; j++ ){
		scanf("%d %d", &m, &s);
		total[i] += m*60+s;
	    }
	}

	printf("%d\n", searchMin());
	printf("%d\n", searchMin());
	searchMax();
	printf("%d\n", searchMax());
    }
}

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=0;NUM[i].m1=0;NUM[i].s1=0;NUM[i].m2=0;NUM[i].s2=0;NUM[i].m3=0;NUM[i].s3=0;NUM[i].m4=0;NUM[i].s4=0;}
}
return 0;
}