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<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];M=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];}
	else if(NUM[i].SUM>M3.SUM){M3=NUM[i];}

}
for(int i=0;i<N;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<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,int> > top(2,mp(0,0)), worst(2,mp(INT_MAX,0));

    REP(i,n){
      int num; cin>>num;
      int total = 0;
      REP(j,4){
	int m, s; cin>>m>>s;
	s += 60 * m;
	total += s;
      }
      pair<int,int> tmp = mp(total,num);

      if(top[1].f < tmp.f){
	top[1] = tmp;
	if(top[1].f > top[0].f)
	  swap(top[1],top[0]);
      }

      if(worst[1].f > tmp.f){
	worst[1] = tmp;
	if(worst[1].f < worst[0].f)
	  swap(worst[1], worst[0]);
      }

    }
    cout << worst[0].s << endl;
    cout << worst[1].s << endl;
    cout << top[1].s << endl;
  }
  return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n;
	while (cin >> n&&n)
	{
		vector<pii> a;
		FOR(i, n)
		{
			INT(id);
			pii t(0, id);
			FOR(j, 4)
			{
				int m, s;
				cin >> m >> s;
				t.first += m * 60 + s;
			}
			a.push_back(t);
		}
		sort(ALL(a));
		a.pop_back();
		cout << a[0].second << endl << a[1].second << endl << a.back().second << endl;
	}
}

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


int main () {

const int cnum = 10;
int **p_teams;        /* teamの配列を入れるポインタのポインタ */
int *p_t;
int *p_t2;

int team_num;

	while (1) {
		cin >> team_num;      /* チームの数を取り込む */

		if (team_num < 2) {
			break;
		}

		p_teams = new int*[team_num]; /* チームのデータを保存する領域を確保　*/

		for (int i = 0;i < team_num;i++)
		{
			p_teams[i] = new int[cnum];      /* チームごとのデータ領域を確保 */
		}

		for (int i = 0; i < team_num; i++) {
			p_t = p_teams[i];

			cin >> p_t[0] >> p_t[1] >> p_t[2] >> p_t[3] >> p_t[4] >> 
			p_t[5] >> p_t[6] >> p_t[7] >> p_t[8];

			int m = p_t[1] + p_t[3] + p_t[5] + p_t[7];
			int s = p_t[2] + p_t[4] + p_t[6] + p_t[8];
			p_t[9] = m * 60 + s;

			p_t++;
		}

		for (int i = 0; i < team_num - 1;i++)
		{
			p_t = p_teams[i];
			for (int j = i + 1;j < team_num;j++)
			{
				p_t2 = p_teams[j];
				// cout << p_t[0] << " " << p_t[9] << " " << p_t2[0] << " " << p_t2[9] << "\n";
				if (p_t[9] > p_t2[9]) {
					int *x = p_teams[i];
					p_teams[i] = p_teams[j];
					p_teams[j] = x;
				}
			}
		}

		cout << p_teams[0][0] << "\n" << p_teams[1][0] << "\n" << p_teams[team_num - 2][0]<< endl;
		
		for (int i = 0;i < team_num;i++)
		{
			delete[] p_teams[i];      /* チームごとのデータ領域を解放 */
			p_t++;
		}

		delete[] p_teams;
	} 
	
  return 0;
}

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

typedef std::pair<int, int> P;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::vector<P> v;

		while( n-- )
		{
			int c, t = 0;
			
			std::cin >> c;
			for( int i = 0; i != 4; ++i )
			{
				int m, s;
				std::cin >> m >> s;
				t += m * 60 + s;
			}

			v.push_back( P( t, c ) );
		}

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

		for( int i = 0; i != 2; ++i )
			std::cout << v[i].second << std::endl;

		std::cout << v[v.size()-2].second << std::endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

class Team {
public:
	int id;
	int time;
};

Team TeamData[10000];

bool cmp(const Team& t1, const Team& t2) {
	return t1.time < t2.time;
}

int main(void) {
	int n, m, s, sum;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> TeamData[i].id;
			sum = 0;
			for (int j = 0; j < 4; j++) {
				cin >> m >> s;
				sum += m * 60 + s;
			}
			TeamData[i].time = sum;
		}

		sort(TeamData, TeamData + n,cmp);
		cout << TeamData[0].id << endl << TeamData[1].id << endl << TeamData[n - 2].id << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n, a, b;
	int m, s;
	vector<P> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n==0)
		{
			return 0;
		}
		REP(i, n)
		{
			cin >> a;
			REP(j, 4){
				cin >> m >> s;
				b = b + m * 60 + s;
			}
			v.push_back(make_pair(b, a));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl
			<< v[1].second << endl
			<< v[n - 2].second << endl;
		
	}
	return 0;
}