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>
struct team{
  int n;
  int ti;
};

bool ascending_time_team(const team& _t1,const team& _t2){
  return _t1.ti<_t2.ti;
}
int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<team> v;
    for(int i=0;i<n;i++){
    int c1,m[4],s[4];
    std::cin>>c1>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
    int tsec=0;
    for(int i=0;i<4;i++)
      tsec+=m[i]*60+s[i];
    team t;
    t.n=c1;
    t.ti=tsec;
    v.push_back(t);
    }
    std::sort(v.begin(),v.end(),ascending_time_team);
    std::cout<<v[0].n<<"\n"<<v[1].n<<"\n"<<v[v.size()-2].n<<"\n";
  }
}

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

using namespace std;

int main(void)
{
	vector<pair<int, int>> team;
	int n, min[4], sec[4], Sec, name;
	
	while(1){
		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];

			Sec = 0;

			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());

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	
		team.clear();
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,c,m1,s1,m2,s2,m3,s3,m4,s4,time;
  while(cin>>n){
    if(n==0) break;
    int anst[4]={0};
    int ans[4];
    for(int i=0;i<2;i++) anst[i] = 1000000;
    for(int i=0;i<n;i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      time=m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
      if(anst[0]>time){
	anst[1] = anst[0];
	ans[1] = ans[0]; 
	anst[0] = time;
	ans[0] = c; 
      }
      else if(anst[1]>time){
	anst[1] = time;
	ans[1] = c;
      }
      if(anst[3]<time){
	anst[2] = anst[3];
	ans[2] = ans[3];
	anst[3] = time;
	ans[3] = c;
      }
      else if(anst[2]<time){
	anst[2] = time;
	ans[2] = c;
      }
    }
    cout << ans[0] << endl << ans[1] << endl << ans[2] << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
string str[1000000];
int num[1000000]={};
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++){
            cin>>str[i];
            for(int j=0,minute,second;j<4;j++){
                cin>>minute>>second;
                num[i]+=60*minute+second;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=n-1;j>0;j--){
                if(num[j]<num[j-1]){
                    swap(num[j],num[j-1]);
                    swap(str[j],str[j-1]);
                }
            }
        }
        cout<<str[0]<<endl<<str[1]<<endl<<str[n-2]<<endl;
    }
}

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;
		}
		
		for(int i = 0; i < n; 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 <map>
using namespace std;

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		map<int,int> memo;
		int name,a,b,c,d,e,f,g,h,time=0;
		for(int i=0;i<n;i++){
			cin >> name >> a >> b >> c >> d >> e >> f >> g >> h;
			time = a*60+b+c*60+d+e*60+f+g*60+h;
			memo[time] = name;
		}
		map<int,int>::iterator it = memo.begin();
		cout << it->second << endl;
		it++;
		cout << it->second << endl;
		it = memo.end();
		it--;
		it--;
		cout << it->second << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,int>in;
    vector<int>time;
    rep(i,n){
      int sum=0;
      int num;
      cin>>num;
      rep(i,4){
	int a,b;
	cin>>a>>b;
	sum+=a*60+b;
      }
      in[sum]=num;
      time.pb(sum);
    }
    sort(all(time));
    cout<<in[time[0]]<<endl<<in[time[1]]<<endl<<in[time[n-2]]<<endl;
  }
}

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

typedef vector <int> VI;

int main( void )
{
	int n, no, mm, ss;
	while ( cin >> n && n )
	{
		VI no_list( n );
		VI time_list( n );

		for ( int j = 0; j < n; j++ )
		{
			cin >> no;
			int sum = 0;
			for ( int i = 0; i < 4; i++ )
			{
				cin >> mm >> ss;
				ss += mm * 60;
				sum += ss;
			}
			no_list[j] = no;
			time_list[j] = sum;
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i+1; j < n; j++ )
			{
				if ( time_list[i] > time_list[j] )
				{
					swap( time_list[i], time_list[j] );
					swap( no_list[i], no_list[j] );
				}
			}
		}

		cout << no_list[0] << endl;
		cout << no_list[1] << endl;
		cout << no_list[n-2] << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int n;
int w[1000];
int v[1000];

int dp[1000][1000];
int rec(int i, int j){
	if (dp[i][j]>0) return dp[i][j];
		int res;
	if (i == n) res = 0;
	else if (j<w[i]){
		res = rec(i + 1, j);
	}
	else{
		res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
	}
	dp[i][j] = res;
	return res;
}

int main(int argc, char **argv){
	int n;
	while (cin >> n && n > 0) {
		pair<int, int> p;
		vector<pair<pair<int, int>, int>> v;
		int ci;
		int m, s;
		for (int i = 0; i < n; i++) {
			cin >> ci;
			p.first = 0;
			p.second = 0;
			for (int j = 0; j < 4; j++) {
				cin >> m >> s;
				p.first += m;
				p.second += s;
			}
			p.first += p.second / 60;
			p.second %= 60;
			v.push_back(make_pair(p, ci));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
	return 0;
}