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<algorithm>

using namespace std;

struct DATA{
  int ID;
  int Time;
};

bool compare(const DATA&, const DATA&);

int main(){
  int i, n;
  int c1, m1, s1, m2, s2, m3, s3, m4, s4;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      _data.ID = c1;
      _data.Time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4;
      data.push_back(_data);
    }

    sort(data.begin(), data.end(), compare);

    cout << data[0].ID << endl;
    cout << data[1].ID << endl;
    cout << data[data.size()-2].ID << endl;

    data.clear();
  }

  return 0;
}

bool compare(const DATA& x, const DATA& y){
  return (x.Time < y.Time);
}

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


//DATA構造体
typedef struct struct_data
{
	int time;
	int number;
}S_data;


//入力構造体
typedef struct struct_input
{
	int m1 , n1;
	int m2 , n2;
	int m3 , n3;
	int m4 , n4;
}S_input;


int main(void)
{
	//最大値
	int n = 0;
	//構造体変数宣言
	S_data s_data[1000000] = {0};
	//入力変数
	S_input s_input;
	//交換構造体
	S_data s_tmp1 , s_tmp2;
	//交換構造体ポインタ
	S_data *ptr_tmp1 = &s_tmp1;
	S_data *ptr_tmp2 = &s_tmp2;

	while (cin >> n)
	{
		if (n == 0)
		{
			return 0;
		}
		for (int i = 0; i < n; i++)
		{
			cin >> s_data[i].number;

			//長い
			cin >> s_input.m1 >> s_input.n1 >> s_input.m2 >> s_input.n2;
			cin >> s_input.m3 >> s_input.n3 >> s_input.m4 >> s_input.n4;

			//時間の計測
			s_data[i].time = (s_input.m1 + s_input.m2 + s_input.m3 + s_input.m4) * 60 + s_input.n1 + s_input.n2 + s_input.n3 + s_input.n4;
		}

		//ソート
		for (int i = 0; i < n - 1; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				if (s_data[i].time > s_data[j].time)
				{
					*ptr_tmp1 = s_data[i];
					*ptr_tmp2 = s_data[j];
					s_data[i] = *ptr_tmp2;
					s_data[j] = *ptr_tmp1;
				}
			}
		}

		//出力
		cout << s_data[0].number << endl;
		cout << s_data[1].number << endl;
		cout << s_data[n - 2].number << endl;

	}

	return 0;
}

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

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector< pair<int, int> > info;
    for(int i=0; i<N; i++) {
        int id; cin >> id;
        int sum = 0;
        for(int k=0; k<4; k++) {
            int m, s; cin >> m >> s;
            int total_time = m * 60 + s;
            sum += total_time;
        }
        info.emplace_back(sum, id);
    }

    sort(info.begin(), info.end());
    cout << info[0].second << endl;
    cout << info[1].second << endl;
    cout << info[N-2].second << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}

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

using namespace std;

int main()
{
	vector<pair<int, int>> team;
	int n, min[4], sec[4], Sec, name;
	
	while(1){
		Sec = 0;

		cin >> n;

		if(n == 0)    break;

		for (int i = 0; i < n; i++){
			cin >> name;

				cin >> min[0] >> sec[0] >> min[1] >> sec[1] >> min[2] >> sec[2] >> min[3] >> sec[3];
			
			for (int j = 0; j < 4; j++){
				Sec += ((min[j] * 60) + sec[j]);
			}

			team.push_back(make_pair(Sec, name));
		}

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

		for(int j = 0; j < n; j++)
			cout << team[j].second << " " << team[j].first << endl;
	
		team.clear();
	}

	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[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];}

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> team(n);
		for(int i = 0; i < n; ++i)
		{
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			team[i].second = c1;
			team[i].first = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4);
		}
		sort(team.begin(), team.end());
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[n - 2].second << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi> s;
int dp[1024];
int main() {
	int nn;
	while ((cin >> nn) && nn) {
		s.clear();
		for (int i = 0; i < nn; ++i) {
			int  a, b, c, d, e, f, g, h,iiii;
			cin >> a >> b >> c >> d >> e >> f >> g >> h>>iiii;
			s.push_back(make_pair(b*60+c+d*60+e+f*60+g+h*60+iiii,a));
		}
		sort(s.begin(),s.end());
		cout<<s[0].second<<endl;
		cout<<s[1].second<<endl;
		cout<<s[nn-2].second<<endl;
	}
	return 0;

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    vector<pair<int,string>> V;
    for(int i = 0; i < n; ++i){
      string id;
      cin >> id;
      int t = 0;
      for(int i = 0; i < 4; ++i){
        int m, s;
        cin >> m >> s;
        t += m*60 + s;
      }
      V.emplace_back(t,id);
    }
    sort(V.begin(),V.end());
    cout << V[0].second << endl;
    cout << V[1].second << endl;
    cout << V[n-2].second << endl;
  }
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int id[100010], t[100010] = {}, ord[100010];
    iota(ord, ord + n, 0);
    for (int i = 0; i < n; i++) {
      cin >> id[i];
      for (int j = 0; j < 4; j++) {
        int m, s;
        cin >> m >> s;
        t[i] += m * 60 + s;
      }
    }
    sort(ord, ord + n, [&](int a, int b) {
      return t[a] < t[b];
    });
    cout << id[ord[0]] << endl;
    cout << id[ord[1]] << endl;
    cout << id[ord[n - 2]] << endl;
  }

  return 0;
}