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++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int t_min1 = 60*60*4;
		int t_min2 = 60*60*4;
		int c_min1 = 0;
		int c_min2 = 0;

		int t_max1 = -1;
		int t_max2 = -1;
		int c_max1 = 0;
		int c_max2 = 0;

		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;

			int t = (m1+m2+m3+m4)*60+s1+s2+s3+s4;

			if(t<t_min1){
				t_min2 = t_min1;
				t_min1 = t;
				c_min2 = c_min1;
				c_min1 = c1;
			}
			else if(t<t_min2){
				t_min2 = t;
				c_min2 = c1;
			}

			if(t>t_max1){
				t_max2 = t_max1;
				t_max1 = t;
				c_max2 = c_max1;
				c_max1 = c1;
			}
			else if(t>t_max2){
				t_max2 = t;
				c_max2 = c1;
			}
		}

		cout << c_min1 << endl;
		cout << c_min2 << endl;
		cout << c_max2 << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> PII;
PII t[1000000];
int main()
{
	int n,c,i,m1,m2,m3,m4,s1,s2,s3,s4;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			scanf("%d%d%d%d%d%d%d%d%d",&c,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
			t[i].first=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
			t[i].second=c;
		}
		partial_sort(t,t+2,t+n);
		printf("%d\n%d\n",t[0].second,t[1].second);
		partial_sort(t,t+2,t+n,greater<PII>());
		printf("%d\n",t[1].second);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

const int INF = (1<<20);

typedef struct{
  int ID;
  int sum;
}TEAM;

int main(){

  int in;
  while(cin >> in && in){
    TEAM data[in];
    for(int i = 0; i < in; i++){
      cin >> data[i].ID;
      data[i].sum = 0;
      for(int j = 0; j <4; j++){
	int min, sec;
	cin >> min >> sec;
	data[i].sum += min*60 + sec;
      }
    }

    TEAM max;
    int Tnum;
    max.sum = INF;
    for(int i = 0; i < in; i++){
      if(data[i].sum < max.sum){
	max = data[i];
	Tnum = i;
      }
    }
    cout << max.ID << endl;
    data[Tnum].sum = INF;

    max.sum = INF;
    for(int i = 0; i < in; i++){
      if(data[i].sum < max.sum){
	max = data[i];
	Tnum = i;
      }
    }

    cout << max.ID << endl;
    data[Tnum].sum = INF;

    max.sum = 0;
    for(int i = 0; i < in; i++){
      if(data[i].sum > max.sum && data[i].sum != INF){
	max = data[i];
	Tnum = i;
      }
    }
    data[Tnum].sum = INF;
    max.sum = 0;
    for(int i = 0; i < in; i++){
      if(data[i].sum > max.sum && data[i].sum != INF) max = data[i];
    }
    cout << max.ID << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int n, _time;
vector<PII> _team;

int main() {
	while ( ~scanf( "%d", &n ) && n ) {
		_team.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d", &_team[i].second );
			_team[ i ].first = 0;
			for ( int j = 0; j < 8; j++ ) {
				scanf( "%d", &_time );
				if ( j % 2 ) {
					_team[ i ].first += _time;
				}
				else {
					_team[ i ].first += _time * 60;
				}
			}
		}
		sort( _team.begin(), _team.end() );
		printf( "%d\n", _team[ 0 ].second );
		printf( "%d\n", _team[ 1 ].second );
		printf( "%d\n", _team[ _team.size() - 2 ].second );
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;

pair < int, int > p[1000010];

int main(){

  int n;
  int c1,m1,s1,m2,s2,m3,s3,m4,s4;

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      p[i].S = c1;
      p[i].F = (m1+m2+m3+m4)*60 + s1+s2+s3+s4;
    }

    sort(p, p+n);

    cout << p[0].S << endl << p[1].S << endl << p[n-2].S << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int n,m,s;
pair<int,int> p[1000000];

int main(){
	while(cin>>n&&n){
		rep(i,n){
			cin>>p[i].second;
			int t=0;
			rep(j,4){cin>>m>>s;t+=m*60+s;}
			p[i].first=t;
		}
		sort(p,p+n);
		cout<<p[0].second<<endl<<p[1].second<<endl<<p[n-2].second<<endl;
	}
}

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++){
      cin >> team[i].second;
      team[i].first = 0;
      for(int j=0;j<8;j++){
	int a; cin >> 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 <utility>
using namespace std;

int main()
{
	int a, time, number, m1, s1, m2, s2, m3, s3, m4, s4;
	vector<pair <int, int> > team;
	
	while(1)
	{
		cin >> a;
		if (a == 0)
		{
			break;
		}
		team.clear();
		for(int i = 0; i < a; i++)
		{
			cin >> number;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			time = m1 *60  + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
		
			team. push_back(make_pair(time, number));
		
		}
	
		sort(team.begin(), team.end());
	
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[a - 2].second << endl;
	}
	return 0;
}