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>

using namespace std;

int main() {
  int n,id,m1,s1,m2,s2,m3,s3,m4,s4,sum;
  pair<int,int> p;

  while(1){
    vector<pair<int,int>> v;
    cin>>n;

    if(n == 0){
      break;
    }

    for(int i = 0;i<n;++i){
      cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      sum = (m1+m2+m3+m4)*60+(s1+s2+s3+s4);
      v.push_back(make_pair(sum,id));
    }

    sort(v.begin(),v.end());

    p = v[0];

    cout<<p.second<<endl;

    p = v[1];

    cout<<p.second<<endl;

    p = v[n-2];

    cout<<p.second<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);

int main()
{
  int n;
  while( cin >> n, n ) {
    int max1 = 0, max2 = 0, min1 = INF, min2 = INF;
    int max1_n, max2_n, min1_n, min2_n;

    for(int i=0; i<n; i++) {
      int c1, m1, s1, m2, s2, m3, s3, m4, s4;
      int sum = 0;
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      sum += m1*60 +  s1 + m2*60 +  s2 + m3*60 +  s3 + m4*60 + s4;
      if( sum > max1 ) {
	max2 = max1; 
	max2_n = max1_n;
	max1 = sum;
	max1_n = c1;
      } 
      else if( sum > max2 ) {
	max2 = sum;
	max2_n = c1;
      }
      if( sum < min1 ) {
	min2 = min1; 
	min2_n = min1_n;
	min1 = sum;
	min1_n = c1;
      }
      else if( sum < min2 ) {
	min2 = sum;
	min2_n = c1;
      }
    }

    cout << min1_n << endl << min2_n << endl << max2_n << endl;
  }

}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vpii v;
    rep(i, n) {
      int id, m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      v.pb(mp((m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4), id));
    }
    sort(all(v));
    cout << v[0].se << '\n'
         << v[1].se << '\n'
         << v[v.size() - 2].se << endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int n;
	while(cin>>n,n){
		vector<Pii> v(n);
		FOR(i,n){
			int id; cin>>id;
			int t = 0;
			FOR(j,4){
				int x,y; cin>>x>>y;
				t += x*60+y;
			}
			v[i].first = t,v[i].second = id;
		}

		int id1 = min_element(v.begin(),v.end()) - v.begin();
		cout << v[id1].second << endl;
		int id1_val = INF;
		swap(v[id1].first,id1_val);
		int id2 = min_element(v.begin(),v.end()) - v.begin();
		cout << v[id2].second << endl;
		swap(v[id1].first,id1_val);

		id1 = max_element(v.begin(),v.end()) - v.begin();
		id1_val = -1;
		swap(v[id1].first,id1_val);
		id2 = max_element(v.begin(),v.end()) - v.begin();
		cout << v[id2].second << endl;
	}

	return 0;
}

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

typedef pair<int, int> pii;

bool cmp(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			int num, t = 0;
			cin >> num;
			for (int j = 0; j < 4; j++){
				int m, s;
				cin >> m >> s;
				t += m * 60 + s;
			}
			p[i] = make_pair(num, t);
		}
		
		sort(p.begin(), p.end(), cmp);
		
		cout << p[0].first << endl << p[1].first << endl << p[n - 2].first << endl;
	}
	
	return (0);
}

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(1){
		cin >> n;
		if(n == 0) break;
		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;
}

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

using namespace std;

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