Problem:


体育祭Sport Meet

秋の体育祭が行われます。種目は徒競走、ボール運び、障害物競走、リレーの4種目です。参加チームは n チームで、この4種目の合計タイムが最も小さいチームが「優勝」、次に小さいチームが「準優勝」、そして、最下位より2番目のチームを「ブービー賞」として表彰したいと思います。

各チームの成績を入力として、「優勝」、「準優勝」、「ブービー賞」のチームを出力するプログラムを作成してください。
ただし、チームにはそれぞれ 1 から n のチーム番号が割り当てられています。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。

n
record1
record2
:
recordn

１行目に対象となるチームの数 n (4 ≤ n ≤ 100000)、続く n 行に i 番目のチームの情報が与えられます。各チームの情報は以下の形式で与えられます。

id m1 s1 m2 s2 m3 s3 m4 s4

id (1 ≤ id ≤ n)はチーム番号、m1, s1 はそれぞれ徒競走のタイムの分と秒、m2, s2 はそれぞれボール運びのタイムの分と秒、m3, s3 はそれぞれ障害物競走のタイムの分と秒、m4, s4 はそれぞれリレーのタイムの分と秒を表します。分と秒はともに0 以上 59 以下の整数です。また、合計タイムが複数のチームで同じになるような入力はないものとします。
 

Output

入力データセットごとに以下の形式でチーム番号を出力します。

1 行目 優勝のチーム番号

2 行目 準優勝のチーム番号

3 行目 ブービー賞のチーム番号

Sample Input

8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0

Output for the Sample Input

54092
34001
10001
1
3
2



Sample input:
8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0


Sample output:
54092
34001
10001
1
3
2

Submission status: Wrong Answer

Solution code:
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)

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  d = [0]*n
  for i in range(n):
    x = map(int, raw_input().split())
    d[i]=[sum(x[1::2])*60+sum(x[2::2]),x[0]]
  d = sorted(d)
  print d[0][1]
  print d[1][1]
  print d[-2][1]

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  D = [0]*n
  for j in range(n):
    a,b,c,d,e,f,g,h,i = map(int, raw_input().split())
    D[j] = [(b+d+f+h)*60 + c+e+g+i, a]
  D = sorted(D)
  print D[0][1]
  print D[1][1]
  print D[-2][1]

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  D = {}
  for j in range(n):
    a,b,c,d,e,f,g,h,i = map(int, raw_input().split())
    D[(b+d+f+h)*60 + c+e+g+i] = a
  A = sorted(D)
  for i in [0,1,-2]: print D[A[i]]

Submission status: Accepted

Solution code:
while True:
    N = input()
    if N == 0: break
    res = []
    for i in range(N):
        L = map(int, raw_input().split())
        m = 0
        s = 0
        for i, v in enumerate(L[1:]):
            if (i+1) % 2 == 0:
                s += v
            else:
                m += v
        else:
            s += (m*60)
            res.append([L[0], s])
    
    ans = sorted(res, key=lambda x: x[1])
    print ans[0][0]
    print ans[1][0]
    print ans[-2][0]

Submission status: Accepted

Solution code:
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])
    for j in [0,1,-2]:
        a,b = ans[j]
        print(a)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    Run = []
    for i in range(n):
        num,m_1,s_1,m_2,s_2,m_3,s_3,m_4,s_4 = map(int,input().split())
        Run.append([(m_1 + m_2 + m_3 + m_4)*60 +s_1 +s_2+s_3+s_4,num])
    Run = sorted(Run)
    print(Run[0][1])
    print(Run[1][1])
    print(Run[len(Run) - 2][1])

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a={}
    for _ in range(n):
        b=list(map(int,input().split()))
        a[b[0]]=sum(b[1:8:2])*60+sum(b[2:9:2])
    a=sorted(a.items(),key=lambda x:x[1])
    for i in [0,1,-2]:print(a[i][0])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:break
    d = dict()
    for _ in range(n):
        l = list(map(int, input().split()))
        a, b = divmod((l[2]+l[4]+l[6]+l[8]), 60)
        d[l[0]] = (l[1]+l[3]+l[5]+l[7])*60 + a*60 + b
    for i in [0,1,-2]: print(sorted(d.items(), key=lambda x: x[1])[i][0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    N = int(s)
    if N == 0:
        break

    A = []
    for i in range(N):
        lst = list(map(int, input().split()))
        id = lst[0]
        data = lst[1:]
        time_sum = data[0] * 60 + data[1] + \
                   data[2] * 60 + data[3] + \
                   data[4] * 60 + data[5] + \
                   data[6] * 60 + data[7]
        A.append((time_sum, id))
    A.sort()

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# 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])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0161

"""
import sys
from sys import stdin
input = stdin.readline
from collections import defaultdict


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        data = []
        for _ in range(n):
            id, m1, s1, m2, s2, m3, s3, m4, s4 = [int(x) for x in input().split()]
            total_time = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)
            data.append([total_time, id])
        data.sort()

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


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def main():
    while True:
        n = int(input())
        if n == 0: break

        res = []
        for i in range(n):
            row = input().split()
            res.append([row[0], 0])
            s_m = 0
            s_s = 0
            for j in range(1, 9):
                if j % 2 == 0:
                    s_s += int(row[j])
                else:
                    s_m += int(row[j])
            res[i][1] = s_s + s_m * 60

        ans = sorted(res, key=lambda x: x[1])
        print(ans[0][0])
        print(ans[1][0])
        print(ans[-2][0])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
# AOJ 0161 Sport Meet
# Python3 2018.6.18 bal4u

while True:
	n = int(input())
	if n == 0: break
	team = {}
	for i in range(n):
		a = list(map(int, input().split()))
		s = 0
		for j in range(1, 8, 2):
			s += 60*a[j] + a[j+1]
		team[a[0]] = s
	ans = sorted(team.items(), key=lambda x: x[1])
	print(ans[0][0], ans[1][0], ans[n-2][0], sep='\n')

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  pairs = []
  for _ in range(n):
    i, m1, s1, m2, s2, m3, s3, m4, s4 = map(int, input().split())
    score = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)
    pairs.append((score, i))
  pairs.sort()
  print(pairs[0][1])
  print(pairs[1][1])
  print(pairs[-2][1])

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    d={}
    for i in range(n):
        c1,m1,s1,m2,s2,m3,s3,m4,s4=map(int,raw_input().split())
        d[(m1+m2+m3+m4)*60+(s1+s2+s3+s4)]=c1
    t=sorted(d)
    for i in t[:2]:
        print d[i]
    print d[t[-2]]

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    R = sorted([map(int,raw_input().split()) for _ in xrange(n)],
                key = lambda x:sum(60*m+s for m,s in zip(x[1::2],x[2::2])))
    print "\n".join(map(str,[R[0][0],R[1][0],R[-2][0]]))

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0:
        break
    R = sorted([map(int,raw_input().split()) for _ in xrange(n)],
                key = lambda x:sum(60*m+s for m,s in zip(x[1::2],x[2::2])))
    print "\n".join(map(str,[R[0][0],R[1][0],R[-2][0]]))

Submission status: Accepted

Solution code:
while True:
	n = int(raw_input())
	if n == 0: break
	a = []
	for i in range(n):
		d = map(int, raw_input().split())
		t = 60*(d[1]+d[3]+d[5]+d[7])+d[2]+d[4]+d[6]+d[8]
		a.append([d[0],t])
	a = sorted(a,key=lambda x:x[1])
	print "{}\n{}\n{}".format(a[0][0],a[1][0],a[-2][0])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    x = {}
    for i in range(n):
        ID,m1,s1,m2,s2,m3,s3,m4,s4 = map(int,input().split())
        r = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4
        x[ID] = r
    x = sorted(x.items(), key=lambda i: i[1])
    print(x[0][0])
    print(x[1][0])
    print(x[n-2][0])

Submission status: Accepted

Solution code:
while True:
    num = int(input())
    if num == 0:
        break
    L = []
    for i in range(num):
        id, m1, s1, m2, s2, m3, s3, m4, s4 = [int(x) for x in input().split()]
        t = (m1 + m2 + m3 + m4) *60 + s1 + s2 + s3 + s4
        L.append([t, id])
    L.sort()
    print(L[0][1])
    print(L[1][1])
    print(L[-2][1])

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a={}
    for _ in range(n):
        b=list(map(int,input().split()))
        a[b[0]]=sum(b[1:8:2])*60+sum(b[2:9:2])
    a=sorted(a.items(),key=lambda x:x[1])
    for i in [0,1,-2]:print(a[i][0])

Submission status: Accepted

Solution code:
while True:
  n =int(input())
  if n==0:
    break
  A=[]
  for i in range(n):
    id,m1,s1,m2,s2,m3,s3,m4,s4=map(int, input().split())
    time=(m1+m2+m3+m4)*60+s1+s2+s3+s4
    A.append((time,id))
  A.sort()
  print(A[0][1])
  print(A[1][1])
  print(A[n-2][1])

Submission status: Accepted

Solution code:
# from sys import exit
while(True):
    N = int(input())
    if N == 0:
        break
    L = []
    for i in range(N):
        r = [int(n) for n in input().split()]
        time = sum([r[i]*60 + r[i+1] for i in range(1, 9, 2)])
        L.append((r[0], time))
        # print(abs(22- w/((h/100)**2)))
    L = sorted(L, key=lambda x: x[1])
    print(L[0][0])
    print(L[1][0])
    print(L[-2][0])

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    score = []
    for _ in range(n):
        datas = list(map(int, input().split()))
        num = datas.pop(0)

        time = 0
        for _ in range(4):
            time += datas.pop(0) * 60 + datas.pop(0)

        score.append([num, time])

    score = sorted(score, key=lambda x: x[1])
    print(score[0][0])
    print(score[1][0])
    print(score[-2][0])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    record = {}
    for _ in range(n):
        num, m1, s1, m2, s2, m3, s3, m4, s4 = \
            map(int, input().split())
        record[num] = (m1*60+s1) + (m2*60+s2) + \
                        (m3*60+s3) + (m4*60+s4)
    record = sorted(record.items(), key=lambda x: x[1])
    result = record[:2]
    result.append(record[-2])
    for res in result:
        print(res[0])

Submission status: Accepted

Solution code:
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)

Submission status: Runtime Error

Solution code:
while 1:
    n = int(input())
    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')

Submission status: Runtime Error

Solution code:
while 1:
    n = int(input())
    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])
    print(team[1][1])
    print(team[-2][1])