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;

const double eps = 0.001;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

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

C++: #include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

P ts[10000];

int main(){
	int n;
	int c, m1, s1, m2, s2, m3, s3, m4, s4;
	while(cin >> n && n){
		rep(i, n){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			ts[i] = P((m1+m2+m3+m4)*60+s1+s2+s3+s4, c);
		}
		sort(ts, ts + n);
		cout << ts[0].second << endl;
		cout << ts[1].second << endl;
		cout << ts[n-2].second << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  int n;
  while(cin >> n && n)
    {
      vector<pair<int,int>> teams;
      for(int i=0;i<n;i++)
	{
	  int id,m1,s1,m2,s2,m3,s3,m4,s4;
	  cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
	  teams.push_back(make_pair(60*(m1+m2+m3+m4)+(s1+s2+s3+s4),id));
	}
      sort(teams.begin(),teams.end());
      for(int i=0;i<n;i++)
	{
	  if(i==0 || i==1 || i==n-2)
	    {
	      cout << teams[i].second << endl;
	    }
	}
    }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

ll n, a, c[1000010][5],no[10];
vector<ll> vl;

int main(){
	while (cin >> n){
		if (!n)break;
		REP(i, n){
			c[i][1] = 0;
			REP(j, 9){
				if (j == 0){
					cin >> c[i][j];
					continue;
				}
				cin >> a;
				if (j % 2 != 0){
					a *= 60;
				}
				c[i][1] += a;
			}
			vl.push_back(c[i][1]);
		}
		sort(ALL(vl));
		REP(i, n){
			if (c[i][1] == vl[0])no[0] = c[i][0];
			if (c[i][1] == vl[1])no[1] = c[i][0];
			if (c[i][1] == vl[n - 2])no[2] = c[i][0];
		}
		REP(i, 3){
			cout << no[i] << endl;
		}
	}
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, s; pair<int, int> d[1000000];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i].second); d[i].first = 0;
			for (int j = 0; j < 4; j++) scanf("%d%d", &m, &s), d[i].first += m * 60 + s;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[0].second, d[1].second, d[n - 1].second);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<map>

using namespace std;

map<int, int>m;
pair<int, int>mm[100000];

int main() {
	int N;
	while (cin >> N, N) {
		for (int i = 0; i < N; i++) {
			int team;
			cin >> team;
			int m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			mm[i].first = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			mm[i].second = team;
		}
		sort(mm,mm+N);
		//for (int i = 0; i < N; i++) {
		//	cout << mm[i].second << endl;
		//}
		cout << mm[0].second << endl << mm[1].second << endl << mm[N-2].second << endl;
	}
}

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

struct Team
{
  int num;
  int time;   //sec
};

int main()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    Team victory = { 0, INT_MAX, };
    Team second  = { 0, INT_MAX, };
    Team booby   = { 0, 0,       };
    Team lowest  = { 0, 0,       };
    for (int data=0; data<n; data++)
    {
      Team tmp_team;
      cin >> tmp_team.num;
      tmp_team.time = 0;
      for (int i=0; i<4; i++)
      {
        int min,sec;
        cin >> min >> sec;
        tmp_team.time += min*60 + sec;
      }

      if ( tmp_team.time < victory.time )
      {
        second = victory;
        victory = tmp_team;
      }
      else if ( tmp_team.time < second.time )
      {
        second = tmp_team;
      }

      if ( lowest.time < tmp_team.time )
      {
        booby = lowest;
        lowest = tmp_team;
      }
      else if ( booby.time < tmp_team.time )
      {
        booby = tmp_team;
      }
    }
    cout << victory.num << endl
         << second.num  << endl
         << booby.num   << endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s


int main()
{
	int n, a, b, m[8];
	vector<pair<int, int>> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n == 0) return 0;
		REP(i, n)
		{
			cin >> a;
			REP(j, 8) cin >> m[j];
			b = (m[0] + m[2] + m[4] + m[6]) * 60 + (m[1] + m[3] + m[5] + m[7]);
			v.push_back(make_pair(b, a));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[n - 2].second << endl;
	}
	return 0;
}