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>

#define int long long

using namespace std;


class Solver {

};

signed main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		map<int, int> vals;
		for (int i = 0; i < n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int val = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			vals.emplace(val,id);
		}

		int itr = 0;
		for (auto val : vals) {
			if (itr == 0 || itr == 1 || itr == vals.size() - 2) {
				cout << val.second << endl;
			}
			itr++;
		}
	}

}

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

using namespace std;

typedef tuple<int, int> P;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<P> v;
		for (int i = 0; i < n; ++i) {
			int c; cin >> c;
			int t = 0;
			for (int i = 0; i < 4; ++i) {
				int m, s; cin >> m >> s;
				t += m * 60 + s;
			}
			v.push_back( P(c, t) );
		}
		sort(v.begin(), v.end(), [](const P& p1, const P& p2) {
			return get<1>(p1) < get<1>(p2);
		});
		cout << get<0>(v[0]) << endl;
		cout << get<0>(v[1]) << endl;
		cout << get<0>(v[n-2]) << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
P sum[1000001];
int N;
main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    for(int i=0;i<N;i++){
      int c;
      scanf("%d",&c);
      sum[i].first=0;
      sum[i].second=c;
      for(int j=0;j<4;j++){
	int m,s;
	scanf("%d %d",&m,&s);
	sum[i].first += m*60+s;
      } 
    }
    sort(sum,sum+N);
    printf("%d\n%d\n%d\n",sum[0].second,sum[1].second,sum[N-2].second);
  }
}

C++: using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var n = int.Parse(line);
            var teams = new Dictionary<int, int>();

            for (var i = 0; i < n; i++) {
                var l = Console.ReadLine().Split();
                var id = int.Parse(l[0]);
                var time = int.Parse(l[1]) * 60 + int.Parse(l[2])
                         + int.Parse(l[3]) * 60 + int.Parse(l[4])
                         + int.Parse(l[5]) * 60 + int.Parse(l[6])
                         + int.Parse(l[7]) * 60 + int.Parse(l[8]);

                teams.Add(id, time);
            }

            var sortedTeams = teams.OrderBy(kv => kv.Value).ToArray();
            Console.WriteLine(sortedTeams[0]);
            Console.WriteLine(sortedTeams[1]);
            Console.WriteLine(sortedTeams[n - 2]);
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;
  P team[1000010];
  while(cin >> n , n){
    for(int i=0;i<n;i++){
      scanf("%d",&team[i].second);
      team[i].first = 0;
      for(int j=0;j<8;j++){
	int a; scanf("%d",&a);
	if(j % 2 == 0) team[i].first += a*60;
	else team[i].first += a;
      }
    }
    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<algorithm>
#include<utility>

using namespace std;

int main(void)
{
	int n, c1, m1, s1, m2, s2, m3, s3, m4, s4;
	vector< pair<int, int> >g;
	while((cin >> n) != 0){
		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<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(void)
{
	int n, c1, m1, s1, m2, s2, m3, s3, m4, s4;
	vector<pair<int, int>>g;

	cin >> n;
	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;
	auto itr = g.end();
	itr -= 2;
		
	cout << itr -> second << endl;


	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		vector<pair<int,int> > data;
		int c1,m1,m2,m3,m4,s1,s2,s3,s4;
		while(n--){
			cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
			int sum=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
			data.push_back(make_pair(sum,c1));
		}
		sort(data.begin(),data.end());
		cout<<data[0].second<<endl;
		cout<<data[1].second<<endl;
		cout<<data[data.size()-2].second<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
struct team{
  int num;
  int time;
};

bool ascending_time_team(const team& _t1,const team& _t2){
  return _t1.time<_t2.time;
}
int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<team> v;
    /*
    //Å¬AñÔèAu[r[Ì`[ÔAÔðÛ·éB
    int fteam=0,fsec=0,steam=0,ssec=0,bteam=0,bsec=0;
    */
    for(int i=0;i<n;i++){
    int c1,m[4],s[4];
    std::cin>>c1>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
    int tsec=0;//êIÉg¢Ü·B
    for(int i=0;i<4;i++){
      tsec+=m[i]*60+s[i];
    }
    team t;
    t.num=c1;
    t.time=tsec;
    v.push_back(t);
    }
    std::sort(v.begin(),v.end(),ascending_time_team);
    std::cout<<v[0].num<<std::endl<<v[1].num<<std::endl<<v[v.size()-2].num<<std::endl;
  }
}
/*
Sample Input
8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0
Output for the Sample Input
54092
34001
10001
1
3
2
*/

C++: #include <stdio.h>
int main (void)
{
int a,i,k,j,temp;
int s[1000000][9]={{}};
int sec[1000000]={};
int min[1000000]={};
int sumsec[1000000]={};
int sumsec2[1000000]={};
 
while(1){
scanf("%d",&a);
if(a==0)
break;
 
for(i=0;i<a;i++)
for(k=0;k<9;k++)
scanf("%d",&s[i][k]);
 
for(i=0;i<a;i++){
sec[i]=s[i][2]+s[i][4]+s[i][6]+s[i][8];
min[i]=(s[i][1]+s[i][3]+s[i][5]+s[i][7])*60;
sumsec[i]=sec[i]+min[i];
sumsec2[i]=sumsec[i];
}
 
for(i=0;i<a-1;i++)
for(k=0;k<a-1;k++)
if(sumsec[k]>sumsec[k+1]){
temp=sumsec[k];
sumsec[k]=sumsec[k+1];
sumsec[k+1]=temp;
}
 
int num[3]={};
int p=0;
for(i=0;i<3;i++)
for(j=0;j<a;j++){
if(sumsec2[j]==sumsec[i]){
num[p]=j;
p++;
}}

int y;
for(i=0;i<a;i++)
if(sumsec2[i]==sumsec[a-2])
y=i;
 
for(i=0;i<2;i++)
printf("%d\n",s[num[i]][0]);
printf("%d\n",s[y][0]);

}
return 0;
}