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>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;

typedef struct {
    long long int num;
    int min[4];
    int sec[4];
    int sum;
}team;

void quick_sort(team x[], int left, int right);

int main(void) {
    int n;
    
    while(1) {
        scanf("%d", &n);
        if(n == 0) break;
        int i, j;
        team *p;
        p = (team *)calloc(n, sizeof(team));
        if(p == NULL) exit(0);
        
        for(i = 0; i < n; i++) {
            scanf("%lld", &p[i].num);
            for(j = 0; j < 4; j++)
                scanf("%d %d", &p[i].min[j] , &p[i].sec[j]);
        }
        for(i = 0; i < n; i++) {
            p[i].sum = 0;
            for(j = 0; j < 4; j++) {
                p[i].sum += (p[i].min[j] * 60) + p[i].sec[j];
            }
        }
        quick_sort(p, 0, n - 1);
        
        cout << p[0].num << endl << p[1].num << endl << p[n - 2].num << endl;
        free(p);
    }
    
    return(0);
}

void quick_sort(team x[], int left, int right) {
    int i, j;
    team pivot;
    i = left;
    j = right;
    
    pivot.sum = 0;
    pivot.sum += x[(left + right) / 2].sum;

    while(1) {
        while(x[i].sum < pivot.sum) i++;
        while(x[j].sum > pivot.sum) j--;
        
        if(i >= j) break;
        
        swap(team, x[i], x[j]);
        i++;
        j--;
        // DEBUG cout << "OK" << endl;     ここの時点では出力に”OK”と沢山表示される
    }
    
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}

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

		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 << i << " " << j << " " << p_t[0] << " " << p_t[9] << " " << p_t2[0] << " " << p_t2[9] << "\n";
				if (p_teams[i][9] > p_teams[j][9]) {
					//cout << "swap\n";
					int *x = p_teams[i];
					p_teams[i] = p_teams[j];
					p_teams[j] = x;
					// p_t = p_teams[i];
				}
			}
		}

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

using namespace std;

typedef	pair<int,int>	pii;

int main()
{
	int n;
	for(;scanf("%d",&n),n;){
		vector<pii> total(n);
		for(int i=0;i<n;i++){
			int c1,m1,s1,m2,s2,m3,s3,m4,s4;
			scanf("%d%d%d%d%d%d%d%d%d",&c1,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
			total[i]=make_pair(60*m1+s1+60*m2+s2+60*m3+s3+60*m4+s4,c1);
		}
		sort(total.begin(),total.end());
		printf("%d\n%d\n%d\n",total[0].second,total[1].second,total[n-2].second);
	}
	return 0;
}

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

int main()
{

	while(true){

		int n;
		int c1;
		int ma, sa;
		int mb, sb;
		int mc, sc;
		int md, sd;
		int t = 0;
		int min = 60*60*4;
		int semimin = 60*60*4;
		int max = -1;
		int max2 = -1;
		int minx = 0, semiminx = 0, maxx = 0, max2x = 0;

		cin >> n;

		if(n==0)
			break;

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

			cin >> c1 >> ma >> sa >> mb >> sb >> mc >> sc >> md >> sd;

			int a ,b ,c ,d;
			a = ma*60 + sa;
			b = mb*60 + sb;
			c = mc*60 + sc;
			d = md*60 + sd;

			t = a + b + c + d;

			
			if(t < min){
				semimin = min;
				semiminx = minx;
				min = t;
				minx = c1;
			}
			else if(t < semimin){
				
				semimin = t;
				semiminx = c1;
				
			}
			if(t > max){
				max2 = max;
				max2x = maxx;
				max = t;
				maxx = c1;
			
			}
			else if(t > max2){
				max2 = t;
				max2x = c1;
			}

		}
		cout << minx << endl;
		cout << semiminx << endl;
		cout << max2x << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;
bool eq(double a, double b)
{
	return abs(a - b) < Eps;
}

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, int> best[4];
		pair<int, int> worst[3];
		for (int i = 0; i < 4; ++i)
			best[i] = make_pair(10000000, 0);
		for (int i = 0; i < 3; ++i)
			worst[i] = make_pair(0, 0);
		while (n--)
		{
			int id;
			scanf("%d", &id);
			int total = 0;
			for (int i = 0; i < 4; ++i)
			{
				int m, s;
				scanf("%d %d", &m, &s);
				total += m*60 + s;
			}
			best[3] = worst[0] = make_pair(total, id);
			sort(best, best+4);
			sort(worst, worst+3);
		}
		printf("%d\n%d\n%d\n", best[0].second, best[1].second, worst[1].second);
	}

	return 0;
}

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

using namespace std;

void solve(int n){
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++){
        int c;int t=0;
        cin >> c;
        for(int j=0;j<4;j++){
            int m,s;
            cin >> m >> s;
            t += 60*m + s;
        }
        v.push_back(make_pair(t,c));
    }
    sort(v.begin(),v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
}

int main(){
    int n;
    while(cin >> n && n != 0){
        solve(n);
    }
}

C++: #include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){
  typedef pair<int ,int> temp;
  temp sport[1000001];
  int n;
  while( true ){
    int second ,minute;
    cin >> n;
    if( n == 0 ){
      break;
    }

    for( int i=0 ; i<n ; i++ ){ // nチーム分入力
      cin >> sport[i].second; // チーム番号
      sport[i].first = 0;
      for( int j=0 ; j<4 ; j++ ){ // 4競技分の記録
	cin >> minute >> second; 
	if( minute > 0 ){ // 秒で統一
	  second += minute * 60;
	}
	sport[i].first += second;
      }
    }

    sort( sport ,sport+n );

    cout << sport[0].second << endl << sport[1].second << endl;
    cout << sport[n-2].second << endl;
  }
}