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

class Score{
public:
    int num;
    int time;
    
    Score(){
        this->num = 0;
        this->time = 0;
    }
    
    Score(int num, int time){
        this->num = num;
        this->time = time;
    }
    
};

int main(int argc, const char * argv[]) {
    
    while (true) {
        int n;
        cin >> n;
        
        if(n==0){
            break;
        }
        
        Score max,pre,biri,boobie;
        
        for(int i=0;i<n;i++){
            int c1;
            cin >> c1;
            int sum = 0;
            for(int i=0;i<4;i++){
                int m, s;
                cin >> m >> s;
                sum+= 60*m + s;
            }
            
            if(max.time == 0 || max.time > sum){
                pre = max;
                max = Score(c1,sum);
            }
            else if(pre.time == 0 || pre.time > sum){
                if(biri.time == 0){
                    biri = pre;
                }
                else if(boobie.time == 0){
                    boobie = pre;
                }
                pre = Score(c1,sum);
            }
            else if(biri.time < sum){
                boobie = biri;
                biri = Score(c1,sum);
            }
            else if(boobie.time < sum){
                boobie = Score(c1,sum);
            }
            
        }
        
        cout << max.num << endl;
        cout << pre.num << endl;
        cout << boobie.num << endl;
        
    }
    
    return 0;
}

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

class Team{
public:
	Team(int x,int y){n=x;t=y;}
	int n;
	int t;
	bool operator<(const Team arg)const{
		if(t < arg.t){
			return true;
		}else{
			return false;
		}
	}
};
int main(void){
	int n,m,s,t,no;
	while(cin >> n && n){
		vector<Team> v;
		for(int i=0;i<n;i++){
			cin >> no;
			t=0;
			for(int j=0;j<4;j++){
				cin >> m >> s;
				t += m*60+s;
			}
			v.push_back(Team(no,t));
		}
		sort(v.begin(), v.end());
		cout << v[0].n << endl;
		cout << v[1].n << endl;
		cout << v[v.size()-2].n << endl;
	}
}

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

int main() {
  int n, c, m, s, t, a[4], b[4];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    a[0] = a[1] = INT_MAX;
    a[2] = a[3] = -INT_MAX;
    b[0] = b[1] = b[2] = b[3] = -1;
    for (int i=0; i<n; i++) {
      scanf("%d", &c);
      t = 0.;
      for (int j=0; j<4; j++) {
        scanf("%d %d", &m, &s);
        t += 60 * m + s;
      }
      if (t < a[0]) {
        a[1] = a[0];
        a[0] = t;
        b[1] = b[0];
        b[0] = c;
      } else if (t < a[1]) {
        a[1] = t;
        b[1] = c;
      }
      if (t > a[3]) {
        a[2] = a[3];
        a[3] = t;
        b[2] = b[3];
        b[3] = c;
      } else if (t > a[2]) {
        a[2] = t;
        b[2] = c;
      }
    }
    for (int i=0; i<3; i++) {
      printf("%d\n", b[i]);
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

typedef std::pair< unsigned int, unsigned int > P;

unsigned int n;

int main() {
    unsigned int id;
    unsigned int m, s;
    while ( std::cin >> n, n ) {
        std::vector< P > vec;
        for (int i=0; i<n; ++i) {
            unsigned int time = 0;
            std::cin >> id;
            for (int j=0; j<4; ++j) {
                std::cin >> m >> s;
                time += m*60 + s;
            }
            vec.push_back( std::make_pair( time, id ) );
        }
        std::sort( vec.begin(), vec.end() );
        // std::vector< P >::iterator itr=vec.begin();
        std::cout << vec[0].second << '\n'
                  << vec[1].second << '\n'
                  << vec[n-2].second
                  << std::endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
  int n;
  while(cin>>n,n){
    pair<int,int>a[n];
    for(int i=0;i<n;i++){
      int q,w,e,r,t,y,u,o,p;
      cin>>q>>w>>e>>r>>t>>y>>u>>o>>p;
      a[i].second=q;
      a[i].first=(w+r+y+o)*60+e+t+u+p;
    }
    sort(a,a+n);
    cout<<a[0].second<<endl<<a[1].second<<endl<<a[n-1].second<<endl;
  }
}

C++: #include <iostream>
#include <cstdlib>

using namespace std;

struct team{
	unsigned int time;
	unsigned int tm;
};

void func(team *a, int n)
{
	team t;
	for(int i = n-1; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j].time < a[j-1].time){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	
	return ;
}

int main(int argc, char **argv)
{
	int n, m, s;
	team *a;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (team *)calloc(n, sizeof(team));
		
		for(int i = 0; i < n; i++){
			cin >> a[i].tm;
			for(int j = 0; j < 4; j++){
				cin >> m >> s;
				a[i].time += 60*m+s;
			}
		}
		func(a, n);
		
		cout << a[0].tm << endl << a[1].tm << endl << a[n-2].tm << endl;
		free(a);
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
	int N;
	while(true){
		cin >> N;
		if(N == 0)break;
		int DATA[N+1][2];
		int score = 0,n1,n2;
		for(int i = 0;i < N;i++){
			cin >> DATA[i][0];
			for(int j = 0;j < 8 / 2;j++){
				cin >> n1 >> n2;
				score += (n1 * 60) + n2; 
			}
			DATA[i][1] = score;
			score = 0;
		}
		int max = -1;
		int z = 0,c = 0;
		for(int i = 0;i < N;i++){
			for(int j = 0;j < N;j++){
				if(max < 0){
					max = DATA[j][1];
					c = j;
				}else if(max > DATA[j][1] and DATA[j][1] >= 0){
					max = DATA[j][1];
					c = j;
				}
			}
			if(i <= 1 or i == N-2){
			cout << DATA[c][0] << endl;
			}
			DATA[c][1] = -1;
			c=0;
			max = -1;
		}
	}
}

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

using namespace std;

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<int, int> > vp;
		for (int i = 0; i < n; i++){
			int id;
			cin >> id;
			int score = 0;
			for (int i = 0; i < 3; i++){
				int m, s;
				cin >> m >> s;
				score += m * 60 + s;
			}
			vp.push_back(make_pair(score, id));
		}
		sort(vp.begin(), vp.end());
		printf("%d\n%d\n%d\n", vp[0].second, vp[1].second, v[n - 2].second);
	}
	return (0);
}