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 <bits/stdc++.h>

using namespace std;

int main()
{
	int n;

	while(cin >> n && n)
	{
		int name,m[4],s[4];
		int ans[3]={};
		int max1=0,max2=0,min1=1000000,min2=1000000;
		int list[100000]={};
		int namelist[100000]={};
		int count=0;

		while(n--)
		{
			cin >> name;

			for(int i=0;i<4;i++)
			{
				cin >>m[i]>>s[i];
				list[count]+=m[i]*60+s[i];
			}

			namelist[count]=name;

			if(min1>=list[count])
			{
				min1=min(list[count],min1);
				ans[0]=name;
			}
			max1=max(max1,list[count]);

			count++;
		}

		for(int i=0;i<count;i++)
		{
			if( list[i]>=max2  && max1!=list[i])
			{
				max2=list[i];
				ans[2]=namelist[i];
			}
			if( list[i]<=min2  && min1!=list[i])
			{
				min2=list[i];
				ans[1]=namelist[i];
			}
		}
		for(int i=0;i<3;i++)cout << ans[i] <<endl;
	}

    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;
    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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int n;
int c1, m1, s1, m2, s2, m3, s3, m4, s4;
pair<int, int> ttt[1000000];

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;
		rep(i,n)
		{
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int sec = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			ttt[i] = pair<int, int>(sec, c1);
		}
		sort(ttt, ttt + n);
		cout << ttt[0].second << endl;
		cout << ttt[1].second << endl;
		cout << ttt[n - 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;
	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;
			cin>>team[i].n; team[i].t = 0;
			for(int j=0;j<4;j++){
				cin>>time.m>>time.s; team[i].t += time.m*60+time.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<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;
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;
}

C++: #include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

struct team {
    int number;
    int time;
};

typedef struct team Team;
bool tfsort (const team &a, const team &b);

int main(){
    int i, n,time, times, second, a, b, c, d, e, f, g, h;
    Team rec[10];
    int number[1000001],team[1000001];
    
    while(scanf("%d", &n), n){
        for(i = 0; i < n; i++){
            scanf("%d %d %d %d %d %d %d %d %d", &number[i], &a, &b, &c, &d, &e, &f, &g, &h);
            times = (b+d+f+h);
            time = times / 60;
            second = times - time * 60;
            team[i] = (a+c+e+g+time)*100 + second;
            rec[i] = (Team){number[i], team[i]};
        }
        sort(rec, rec + n, tfsort);
        
        for(i = 0; i < 2; i++){
            printf("%d\n", rec[i].number);
        }
        printf("%d\n", rec[n -2].number);
    }
    return 0;
}

bool tfsort (const team &a, const team &b){
    if(a.time < b.time) return true;
    return false;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    while (cin >> N, N) {
        vector<pair<int,int> > v;
        for (int i = 0; i < N; i++) {
            int id, am, as, bm, bs, cm, cs, dm, ds;
            cin >> id >> am >> as >> bm >> bs >> cm >> cs >> dm >> ds;
            int sum = (am + bm + cm + dm) * 60 + as + bs + cs + ds;
            v.push_back(pair<int,int>(sum, id));
        }

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

        cout << v[0].second << endl;
        cout << v[1].second << endl;
        cout << v[N-2].second << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<string.h>

typedef struct{
	int no;
	int time;
}team;

team aki[1000000],t;
int n,a,b,i,j;

int main(){
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		memset(aki,0,sizeof(aki));
		
		for(i=0;i<n;i++){
			scanf("%d",&aki[i].no);
			for(j=0;j<4;j++){
				scanf("%d%d",&a,&b);
				aki[i].time+=60*a+b;
			}
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(aki[i].time>aki[j].time){
					t=aki[j];
					aki[j]=aki[i];
					aki[i]=t;
				}
			}
		}
		printf("%d\n%d\n%d\n",aki[0].no,aki[1].no,aki[n-2].no);
	}
	return 0;
}