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)
	}
}

Python: def solve() :
    n = int(input())
    if n == 0 : return -1 
    score = [] 
    for i in range(n):
        s = input().split()
        key = int(s[0])
        sumTime = 0
        for j in range(1, len(s)) :
            if j % 2 == 0 : sumTime += int(s[j])
            else : sumTime += int(s[j]) * 60
        score.append((sumTime, key))
    score.sort()
    print(score[0][1], score[1][1], score[-2][1], sep='\n')

while True:
    if solve() == -1 : break

Python: def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

class Team(object):
    def __init__(self, id, score):
        self.id = id
        self.score = score

    def __lt__(self, other):
        return self.score < other.score

while True:
    N = int(input())
    if N == 0:
        break;

    Teams = []
    for i in range(N):
        id,m1,s1,m2,s2,m3,s3,m4,s4 = [int(i) for i in input().split()]
        score = (m1+m2+m3+m4)*60 + (s1+s2+s3+s4)
        Teams.append(Team(id, score))

    Teams.sort()
    print(Teams[0].id)
    print(Teams[1].id)
    print(Teams[N-2].id)

Python: # Aizu Problem 00161: Sport Meet
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



    
while True:
    n = int(input())
    if n == 0:
        break
    teams = []
    for _ in range(n):
        team, m1, s1, m2, s2, m3, s3, m4, s4 = [int(__) for __ in input().split()]
        time = 60 * m1 + s1 + 60 * m2 + s2 + 60 * m3 + s3 + 60 * m4 + s4
        teams.append([team, time])
    teams = sorted(teams, key=lambda x: (x[1], x[0]))
    print(teams[0][0])
    print(teams[1][0])
    print(teams[-2][0])

Python: import operator
while True:
    n = int(input())
    if n==0:
        break
    rst = {}
    for _ in range(n):
        [id,m1,s1,m2,s2,m3,s3,m4,s4] = list(map(int, input().strip().split()))
        rst[id] = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4
    
    r = sorted(rst.items(),key=operator.itemgetter(1))
    print(r[0][0])
    print(r[1][0])
    print(r[-2][0])

Python: while True:
    n = int(input())
    if n==0:break
    d={}
    for i in range(n):
        c,q,w,e,r,t,y,u,o = input().split()
        d[c] = (int(q)+int(e)+int(t)+int(u))*60+int(w)+int(r)+int(y)+int(o)
    ans = sorted(d.items(), key=lambda x: x[1])
    print(ans)
    for j in [0,1,-2]:
        a,b = ans[j]
        print(a)

Python: while True:
  N = input()
  if not N:
    break
  l = []
  for i in range(N):
    c1, m1, s1, m2, s2, m3, s3, m4, s4 = map(int, raw_input().split())
    l.append(((m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4), c1))
  l = sorted(l)
  print(l[0][1])
  print(l[1][1])
  print(l[-2][1])

Python: from datetime import timedelta

while True:

    input_count = int(input())

    if input_count == 0:
        break

    records = []

    for _ in range(input_count):
        record = [int(item) for item in input().split(" ")]

        total_minute = record[1] + record[3] + record[5] + record[7]
        total_second = record[2] + record[4] + record[6] + record[8]

        time = timedelta(minutes=total_minute, seconds=total_second)
        records.append((record[0], time))

    records.sort(key=lambda item: item[1])

    print(records[0][0])
    print(records[1][0])
    print(records[-2][0])

Python: while 1:
    n = int(input())
    if n == 0:
        break
    team = []
    for _ in range(n):
        i, *T = map(int, input().split())
        t = 0
        for m, s in zip(T[::2], T[1::2]):
            t += m*60 + s
        team.append((t, i))
    team.sort()
    print(*[team[0][1], team[1][1], team[-2][1]], sep='\n')

C++: #include <iostream>
using namespace std;
struct T {int m, s;};
struct {T t[4]; int n, p;} d[1000000], x;
int main()
{
	int n, i, j;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> d[i].n;
			for (j = d[i].p = 0; j < 4; j++)
			{
				cin >> d[i].t[j].m >> d[i].t[j].s;
				d[i].p += d[i].t[j].m * 60 + d[i].t[j].s;
			}
		}
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (d[j].p > d[j+1].p)
				{
					x = d[j];
					d[j] = d[j+1];
					d[j+1] = x;
				}
			}
		}
		cout << d[0].n << endl << d[1].n << endl << d[n-2].n << endl;
	}
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

bool pairCompare(const std::pair<int, int>& firstElem, const std::pair<int, int>& secondElem) {
    return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int ,int> > v;
        rep(i,n){
            int id;
            cin >> id;
            int t = 0;
            rep(j, 4){
                int m, s;
                cin >> m >> s;
                t += m*60+s;
            }
            v.pb(mp(id, t));
        }
        sort(all(v), pairCompare);

        rep(i, 2){
            cout << v[i].first << endl;
        }
        cout << v[v.size()-2].first << endl;
    }
}

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

typedef struct{
    int num;
    int sum = 0;
} teams;

void q_sort(teams data[], int begin, int end);

int main(int argc, const char * argv[])
{
    int num = 0;
    while (1) {
        scanf("%d", &num);
        if (num == 0) {
            break;
        }
        teams data[1000000];
        int m[4], s[4];
        for (int i = 0; i < num; i++) {
            scanf("%d %d %d %d %d %d %d %d %d", &data[i].num, &m[0], &s[0], &m[1], &s[1], &m[2], &s[2], &m[3], &s[3]);
            for (int k = 0; k < 4; k++) {
                data[i].sum += m[k] * 60 + s[k];
            }
        }
        q_sort(data, 0, num - 1);
        for (int i = 0; i < 2; i++) {
            printf("%d\n", data[i].num);
        }
        printf("%d\n", data[num - 2].num);
    }
    return 0;
}

void q_sort(teams data[], int begin, int end){
    int i = begin;
    int k = end;
    teams pivot = data[(begin + end) / 2];
    teams temp;
    while (1) {
        while (data[i].sum < pivot.sum) {
            i++;
        }
        while (pivot.sum < data[k].sum) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = data[i];
        data[i] = data[k];
        data[k] = temp;
        i++;
        k--;
    }
    if (begin < i - 1) {
        q_sort(data, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(data, k + 1, end);
    }
}