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<algorithm>
using namespace std;

struct hoge{
	int num, timem, times;
};

int main(){
	int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
	hoge set[1000000];
	while(1){
		cin >>n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >>c >>m1 >>s1 >>m2 >>s2 >>m3 >>s3 >>m4 >>s4;
			set[i].num = c;
			set[i].timem = m1 + m2 + m3 + m4;
			set[i].times = s1 + s2 + s3 + s4;
			if(set[i].times >= 60){
				set[i].timem += set[i].times / 60;
				set[i].times %= 60;
			}
		}
		
		for(int i = 0; i < (n - 1); i++){
			for(int j = (i + 1); j < n; j++){
				if(set[j].timem < set[i].timem){
					swap(set[i].num, set[j].num);
					swap(set[i].timem, set[j].timem);
					swap(set[i].times, set[j].times);
				} else if(set[j].timem == set[i].timem){
					if(set[j].times < set[i].times){
						swap(set[i].num, set[j].num);
						swap(set[i].timem, set[j].timem);
						swap(set[i].times, set[j].times);
					}
				}
			}
		}
		
		cout <<set[0].num <<endl <<set[1].num <<endl <<set[n - 2].num <<endl;
	}
	return 0;
}

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

bool ope(const pair<int,int>&left, const pair<int,int>&right){
	return left.second < right.second;
}

int main(){
	int n,c1,m1,s1,m2,s2,m3,s3,m4,s4;
	vector<pair<int,int> > v;
	while(cin >> n,n){
		v.clear();
		for(int i = 0;i < n;i++) {
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			v.push_back(make_pair(c1,m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4));
		}
		sort(v.begin(),v.end(),ope);
		cout << v[0].first << endl << v[1].first << endl << v[v.size() - 2].first << endl;
	}
	return 0;
}

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; 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 <stdio.h>

using namespace std;

int main() {
 int n,ti,id,tp,sc,bb,ed,tpn=-1,scn,bbn=-1,edn=-1,m1,m2,m3,m4,s1,s2,s3,s4;
 while(cin >> n) {
	 if (n==0) break;
	 tp=sc=99999; bb=ed=0;
	 for (;n>0;n--) {
		 cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
		 ti=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
		 if (tp>ti) { sc=tp; scn=tpn; tp=ti; tpn=id; }
		 if (tp<ti && sc>ti) { sc=ti; scn=id;}
		 if (ed<ti) { bb=ed; bbn=edn; ed=ti; edn=id;}
		 if (ed>ti && bb<ti) { bb=ti; bbn=id;}
	 }
	 cout << tpn << endl;
	 cout << scn << endl;
	 cout << bbn << endl;
 }
 return 0;
 }

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

int main(){
	int n;	

	while(true){
		cin >> n;

		if(n==0)break;

		unsigned int c1[100000];
		unsigned int m1[100000];
		unsigned int s1[100000];
		unsigned int m2[100000];
		unsigned int s2[100000];
		unsigned int m3[100000];
		unsigned int s3[100000];
		unsigned int m4[100000];
		unsigned int s4[100000];

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

		unsigned int sum[100000];

		for(int i=0;i<n;i++){
			sum[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+(s1[i]+s2[i]+s3[i]+s4[i]);
			}

		unsigned int copy[100000];

		for(int i=0;i<n;i++){
			copy[i] = sum[i];
			}

		sort(sum,sum+n);

		for(int i=0;i<2;i++){
			int j=0;
			while(true){
				if(sum[i]==copy[j]){
					cout << c1[j] << endl;
					break;
					}
				else{
					j++;
					}
				}
			}

		int cnt=0;
		while(true){
			if(sum[n-2]==copy[cnt]){
					cout << c1[cnt] << endl;
					break;
					}
			else{
				cnt++;
				}
			}

		}

	return 0;
	}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n, n) {
    vector<pii> a;
    rep(i, n) {
      int c, m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int sum = (m1+m2+m3+m4)*60 + (s1+s2+s3+s4);
      a.push_back(make_pair(sum, c));
    }
    sort(all(a));
    vector<pii>::iterator it = a.begin();
    cout << it->second << endl; it++;
    cout << it->second << endl;

    it = a.end(); it -= 2;
    cout << it->second << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int n; cin >> n && n;)
	{
		vector<pint> v(n);
		
		rep(i, n)
		{
			int num, m[4], s[4];
			cin >> num;
			
			rep(j, 4) cin >> m[j] >> s[j];
			
			v[i] = mp(accumulate(m, m + 4, 0) * 60 + accumulate(s, s + 4, 0), num);
		}
		
		sort(ALL(v));
		
		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 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;
}