Problem:


陸上競技大会

陸上競技大会 200M の準決勝 3 組のレースが行われました。それぞれの組に 8 名（計 24 名）の選手が出場します。各組上位 2 位までの選手と、各組の 3 位以下の全選手の中から上位 2 名の計 8 名が決勝に進出します。

選手番号とタイムを入力とし、決勝進出者 8 名の番号とそのタイムを出力するプログラムを作成してください。

Input

入力は以下の形式で与えられます。

p1 t1
p2 t2
:
p24 t24

1 行目から 8 行目に１組目の選手番号 pi (整数、1 ≤ pi ≤ 10000) とタイム ti (1/100 まで計測した実数、1 ≤ ti ≤ 100)、9 行目から 16 行目に２組目の選手番号 pi とタイム ti、17 行目から 24 行目に３組目の選手番号 pi とタイム ti が与えられます。同じ選手番号の選手、同タイムの選手はいないものとします。

Output

以下の順番で、決勝進出者の選手番号とタイムを空白区切りでそれぞれ１行に出力してください。

1 組目の 1 位の選手

1 組目の 2 位の選手

2 組目の 1 位の選手

2 組目の 2 位の選手

3 組目の 1 位の選手

3 組目の 2 位の選手

各組で 3 位以下の選手の中でタイムが 1 位の選手

各組で 3 位以下の選手の中でタイムが 2 位の選手

Sample Input

18 25.46
16 26.23
3 23.00
10 24.79
5 22.88
11 23.87
19 23.90
1 25.11
23 23.88
4 23.46
7 24.12
12 22.91
13 21.99
14 22.86
21 23.12
9 24.09
17 22.51
22 23.49
6 23.02
20 22.23
24 21.89
15 24.14
8 23.77
2 23.42

Output for the Sample Input

5 22.88
3 23.00
13 21.99
14 22.86
24 21.89
20 22.23
17 22.51
12 22.91



Sample input:
18 25.46
16 26.23
3 23.00
10 24.79
5 22.88
11 23.87
19 23.90
1 25.11
23 23.88
4 23.46
7 24.12
12 22.91
13 21.99
14 22.86
21 23.12
9 24.09
17 22.51
22 23.49
6 23.02
20 22.23
24 21.89
15 24.14
8 23.77
2 23.42


Sample output:
5 22.88
3 23.00
13 21.99
14 22.86
24 21.89
20 22.23
17 22.51
12 22.91

Submission status: Wrong Answer

Solution code:
ls = []
for i in range(24):
    n,t = raw_input().split()
    ls.append([n,float(t)])
ls1 = sorted(ls[:9], key=lambda x:x[1])
ls2 = sorted(ls[9:17], key=lambda x:x[1])
ls3 = sorted(ls[17:], key=lambda x:x[1])
print ' '.join(map(str,ls1[0]))
print ' '.join(map(str,ls1[1]))
print ' '.join(map(str,ls2[0]))
print ' '.join(map(str,ls2[1]))
print ' '.join(map(str,ls3[0]))
print ' '.join(map(str,ls3[1]))
del ls1[0],ls1[1],ls2[0],ls2[1],ls3[0],ls3[1]
ls_merg = sorted(ls1 + ls2 + ls3, key=lambda x:x[1])
print ' '.join(map(str,ls_merg[0]))
print ' '.join(map(str,ls_merg[1]))

Submission status: Wrong Answer

Solution code:
ls = []
for i in range(24):
    n,t = raw_input().split()
    ls.append([n,float(t)])
ls1 = sorted(ls[:8], key=lambda x:x[1])
ls2 = sorted(ls[8:16], key=lambda x:x[1])
ls3 = sorted(ls[16:], key=lambda x:x[1])
print ' '.join(map(str,ls1[0]))
print ' '.join(map(str,ls1[1]))
print ' '.join(map(str,ls2[0]))
print ' '.join(map(str,ls2[1]))
print ' '.join(map(str,ls3[0]))
print ' '.join(map(str,ls3[1]))
del ls1[0],ls1[1],ls2[0],ls2[1],ls3[0],ls3[1]
ls_merg = sorted(ls1 + ls2 + ls3, key=lambda x:x[1])
print ' '.join(map(str,ls_merg[0]))
print ' '.join(map(str,ls_merg[1]))

Submission status: Wrong Answer

Solution code:
ls = []
for i in range(24):
    n,t = raw_input().split()
    ls.append([n,float(t)])
ls1 = sorted(ls[:8], key=lambda x:x[1])
ls2 = sorted(ls[8:16], key=lambda x:x[1])
ls3 = sorted(ls[16:], key=lambda x:x[1])
print ' '.join(map(str,ls1[0]))
print ' '.join(map(str,ls1[1]))
print ' '.join(map(str,ls2[0]))
print ' '.join(map(str,ls2[1]))
print ' '.join(map(str,ls3[0]))
print ' '.join(map(str,ls3[1]))
del ls1[0],ls1[1],ls2[0],ls2[1],ls3[0],ls3[1]
tmp = ls1 + ls2 + ls3
ls_merg = sorted(tmp, key=lambda x:x[1])
print ' '.join(map(str,ls_merg[0]))
print ' '.join(map(str,ls_merg[1]))

Submission status: Wrong Answer

Solution code:
import sys
R = lambda:map(int,raw_input().split())

t2 = [[] for i in xrange(3)]
for i in xrange(3):
    t = []
    for j in xrange(8):
        num,time = raw_input().split()
        t.append((float(time),int(num)))
    t.sort()
    for j in xrange(4):
        t2[i].append(t[j])

t3 = []
for i in xrange(3):
        t3.append(t2[i][2])
        t3.append(t2[i][3])
t3.sort()
print t3

for i in xrange(3):
    print "%d %.2f" % (t2[i][0][1], t2[i][0][0])
    print "%d %.2f" % (t2[i][1][1], t2[i][1][0])

print "%d %.2f" % (t3[0][1], t3[0][0])
print "%d %.2f" % (t3[1][1], t3[1][0])

Submission status: Wrong Answer

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    for j in range(8):
        n1, t1, n2, t2 = 0, 1000, 0, 1000
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n ; t2 = t
        else:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
    print n1, t1
    print n2, t2
print an1, at1
print an2, at2

Submission status: Wrong Answer

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    for j in range(8):
        n1, t1, n2, t2 = 0, 1000, 0, 1000
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n ; t2 = t
        else:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
    print int(n1), t1
    print int(n2), t2
print int(an1), at1
print int(an2), at2

Submission status: Wrong Answer

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    for j in range(8):
        n1, t1, n2, t2 = 0, 1000, 0, 1000
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n ; t2 = t
        else:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
    print "%d %4.2f"%(int(n1), t1)
    print "%d %4.2f"%(int(n2), t2)
print "%d %4.2f"%(int(an1), at1)
print "%d %4.2f"%(int(an2), at2)

Submission status: Wrong Answer

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    for j in range(8):
        n1, t1, n2, t2 = 0, 1000, 0, 1000
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = n2
            n2 = n ; t2 = t
        else:
            if t < at1:
                an1 = n2; at1 = t2
            elif t < at2:
                an2 = n2; at2 = n2
    print "%d %4.2f"%(int(n1), t1)
    print "%d %4.2f"%(int(n2), t2)
print "%d %4.2f"%(int(an1), at1)
print "%d %4.2f"%(int(an2), at2)

Submission status: Wrong Answer

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    for j in range(8):
        n1, t1, n2, t2 = 0, 1000, 0, 1000
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = t2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = t2
            n2 = n ; t2 = t
        else:
            if t < at1:
                an1 = n; at1 = t
            elif t < at2:
                an2 = n; at2 = t
    print "%d %4.2f"%(int(n1), t1)
    print "%d %4.2f"%(int(n2), t2)
print "%d %4.2f"%(int(an1), at1)
print "%d %4.2f"%(int(an2), at2)

Submission status: Accepted

Solution code:
import sys
def f(A):
  return sorted(A, key=lambda x:x[1])

A = [map(float,s.split()) for s in sys.stdin]
A1 = f(A[0:8])
A2 = f(A[8:16])
A3 = f(A[16:24])
A4 = f(A1[2:]+A2[2:]+A3[2:])

B1 = A1[0:2]+A2[0:2]+A3[0:2]+A4[0:2]

for e in B1:
  print '%d %.2f' %(e[0], e[1])

Submission status: Accepted

Solution code:
x=[]
y=[]
for _ in [0]*3:
  a = sorted([raw_input().split()[::-1] for _ in [0]*8])
  x += a[0:2]
  y += a[2:4]
x += sorted(y)[0:2]

for e in x:
  print " ".join(e[::-1])

Submission status: Accepted

Solution code:
x=[]
for e in [[raw_input() for _ in [0]*8] for _ in [0]*3]+[x]:
  b = sorted(e, key = lambda x: x.split()[1])
  x += b[2:4]
  print '\n'.join(b[:2])

Submission status: Accepted

Solution code:
tformat = lambda num, time: '{} {:.2f}'.format(num, time)
runners = [[] for _ in range(3)]
thirds = []
for i in range(3):
    for _ in range(8):
        num, time = input().split()
        runners[i].append((float(time), int(num)))
    runners[i].sort()
    thirds += runners[i][2:]
thirds.sort()
for run in runners:
    for time, num in run[:2]:
        print(tformat(num, time))
for time, num in thirds[:2]:
    print(tformat(num, time))

Submission status: Accepted

Solution code:
import sys
res = []
t_lis = []
first = None
second = None
third = None
for i, line in enumerate(sys.stdin):
    n = int(line.rstrip().split(' ')[0])
    t = float(line.rstrip().split(' ')[1])
    if first == None or first[1] > t:
        first, second, third = (n,t), first, second
    elif second == None or second[1] > t: 
        second, third = (n,t), second
    elif third == None or third[1] > t:
        third = [n,t]
    if (i+1) % 8 == 0:
        res.append(first)
        res.append(second)
        t_lis.append(third)
        first = None
        second = None
        third = None
else:
    res.extend(sorted(t_lis, key=lambda x:x[1])[:2])
    for v in res:
        print '%s %.2f' % (v[0], v[1])

Submission status: Accepted

Solution code:
p = [sorted(map((lambda x: (float(x[1]), x[1], x[0])), [raw_input().split() for i in xrange(8)]), reverse=True) for j in xrange(3)]
for i in xrange(3):
    for j in xrange(2):
        print "%s %s" % tuple(p[i].pop()[-1:0:-1])
for i in xrange(2):
    e = p[0][-1], p[1][-1], p[2][-1]
    k = 2
    if e[0]<e[1] and e[0]<e[2]: k=0
    elif e[1]<e[2]: k=1
    print "%s %s" % tuple(p[k].pop()[-1:0:-1])

Submission status: Accepted

Solution code:
l = [[], [], []]
ans = []
for i in range(3):
  for j in range(8):
    s = raw_input().split()
    l[i].append([float(s[1]), int(s[0])])
for i in range(3):
  l[i].sort()
  ans.append(l[i].pop(0))
  ans.append(l[i].pop(0))
l = l[0] + l[1] + l[2]
l.sort()
ans.append(l.pop(0))
ans.append(l.pop(0))
for n in ans:
  print str(n[1]) + " " + str(n[0])

Submission status: Accepted

Solution code:
cnt=0
l,p=[],[]
m,q={},{}
while 1:
    n,k=map(str,raw_input().split())
    cnt+=1
    n,k=int(n),float(k)
    l.append(k)
    m[k]=n
    if cnt%8==0:
        l.sort()
        for i in range(8):
            if i<2:
                print m[l[i]],'%.2f'%l[i]
            else:
                p.append(l[i])
                q[l[i]]=m[l[i]]
        l=[]
        m={}
    if cnt==24:
        break
p.sort()
for i in range(2):
    print q[p[i]],'%.2f'%p[i]

Submission status: Accepted

Solution code:
A_lis = []
for i in range(3):
    S_lis = []
    for j in range(8):
        p,t = map(float,input().split())
        S_lis.append([int(p),t])
    S_lis = sorted(S_lis, key=lambda x: x[1])
    print(S_lis[0][0],S_lis[0][1])
    S_lis.remove(S_lis[0])
    print(S_lis[0][0],S_lis[0][1])
    S_lis.remove(S_lis[0])
    A_lis += S_lis
A_lis = sorted(A_lis, key=lambda x: x[1])
print(A_lis[0][0],A_lis[0][1])
print(A_lis[1][0],A_lis[1][1])

Submission status: Accepted

Solution code:
pts = [[input().split() for _ in range(8)] for _ in range(3)]
npts = [sorted(pts[i], key=lambda x: float(x[1]))[:4] for i in range(3)]
ts = [sorted((npts[i][j] for i in range(3) for j in range(2, 4)), key=lambda x: float(x[1]))[:2]]
gen = (print(*npts[i][j]) for i in range(3) for j in range(2))
ans = lambda *x: print(*ts[0][0])
ans(*gen)
print(*ts[0][1])

Submission status: Accepted

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

import sys
import os
import math

N = 24
A = []
for i in range(N):
    id, t = map(float, input().split())
    id = int(id)
    A.append((t, id))

B = A[:8]
C = A[8:16]
D = A[16:]

B.sort()
C.sort()
D.sort()

def print_data(A, index):
    data = A[index]
    t = data[0]
    id = data[1]
    print(id, t)

print_data(B, 0)
print_data(B, 1)
print_data(C, 0)
print_data(C, 1)
print_data(D, 0)
print_data(D, 1)

B = B[2:]
C = C[2:]
D = D[2:]

E = B + C + D
E.sort()
print_data(E, 0)
print_data(E, 1)

Submission status: Accepted

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

"""
import sys
from sys import stdin
from operator import itemgetter
input = stdin.readline

def solve(data):
    data.sort(key=itemgetter(1))
    top2 = data[:2]
    others = data[2:]
    return top2, others         #  ??????2?????¨????????\??????id??¨?????????????????????


def main(args):
    others_results = []
    for _ in range(3):
        round_results = []
        for _ in range(8):
            id, time = input().split()
            round_results.append([int(id), float(time)])
        top2, others = solve(round_results)
        others_results.extend(others)

        # ????????????2???????????±
        for id, time in top2:
            print('{} {}'.format(id, time))

    # ????????????3?????\?????????????????????2???????????±
    top2, others = solve(others_results)
    for id, time in top2:
        print('{} {}'.format(id, time))


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

Submission status: Accepted

Solution code:
# Aizu Problem 00138: Track and Field Competition
#
import sys, math, os, copy

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


top3 = []
for run in range(3):
    field = []
    for runner in range(8):
        s = input().split()
        field.append([runner, int(s[0]), float(s[1])])
    field = sorted(field, key=lambda x: (x[2], x[0]))
    print("%d %.2f" % (field[0][1], field[0][2]))
    print("%d %.2f" % (field[1][1], field[1][2]))
    top3.append(field[2])

top3 = sorted(top3, key=lambda x: (x[2], x[0]))
print("%d %.2f" % (top3[0][1], top3[0][2]))
print("%d %.2f" % (top3[1][1], top3[1][2]))

Submission status: Accepted

Solution code:
import heapq
from collections import namedtuple

Data = namedtuple("Data", "time number")

all_player = []

for _ in range(3):
    player = [input().split(" ") for lp in range(8)]
    player = [Data(float(time), number) for number, time in player]

    heapq.heapify(player)
    data = heapq.heappop(player)
    print(data.number, data.time)
    data = heapq.heappop(player)
    print(data.number, data.time)

    all_player.extend(player)

heapq.heapify(all_player)
data = heapq.heappop(all_player)
print(data.number, data.time)
data = heapq.heappop(all_player)
print(data.number, data.time)

Submission status: Accepted

Solution code:
class Player:

    def __init__(self, id, score):
        self.id = id
        self.score = score

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

    def print(self):
        print(self.id, self.score)

g1 = []
for l in range(8):
    p,t = input().split()
    g1.append(Player(p, t))

g2 = []
for l in range(8):
    p,t = input().split()
    g2.append(Player(p,t))

g3 = []
for l in range(8):
    p,t = input().split()
    g3.append(Player(p,t))

g1.sort()
g2.sort()
g3.sort()

g4 = []
g4.append(g1[2])
g4.append(g2[2])
g4.append(g3[2])
g4.sort()

g1[0].print()
g1[1].print()
g2[0].print()
g2[1].print()
g3[0].print()
g3[1].print()
g4[0].print()
g4[1].print()

Submission status: Accepted

Solution code:
def inp():
  return sorted([list(map(float, input().split())) for _ in range(8)], key=lambda x:x[1])
lst1 = inp()
lst2 = inp()
lst3 = inp()
rest = lst1[2:] + lst2[2:] + lst3[2:]
rest.sort(key=lambda x:x[1])
select = lst1[:2] + lst2[:2] + lst3[:2] + rest[:2]
for p, t in select:
  print(int(p), t)

Submission status: Accepted

Solution code:
# AOJ 0138 Track and Field Competition
# Python3 2018.6.19 bal4u

q = {}
for i in range(3):
	g = {}
	for j in range(8):
		p, t = list(input().split())
		g[p] = t
	x = list(sorted(g.items(), key=lambda x:x[1]))
	print(*x[0])
	print(*x[1])
	del g[x[0][0]]
	del g[x[1][0]]
	q.update(g)
x = sorted(q.items(), key=lambda x:x[1])
print(*x[0])
print(*x[1])

Submission status: Accepted

Solution code:
import sys
R = lambda:map(int,raw_input().split())

t2 = [[] for i in xrange(3)]
for i in xrange(3):
    t = []
    for j in xrange(8):
        num,time = raw_input().split()
        t.append((float(time),int(num)))
    t.sort()
    for j in xrange(4):
        t2[i].append(t[j])

t3 = []
for i in xrange(3):
        t3.append(t2[i][2])
        t3.append(t2[i][3])
t3.sort()

for i in xrange(3):
    print "%d %.2f" % (t2[i][0][1], t2[i][0][0])
    print "%d %.2f" % (t2[i][1][1], t2[i][1][0])

print "%d %.2f" % (t3[0][1], t3[0][0])
print "%d %.2f" % (t3[1][1], t3[1][0])

Submission status: Accepted

Solution code:
drop = []
drop_time = []

for group in range(3):
    n = []
    time = []
    for person in range(8):
        result = raw_input().split()
        n.append(int(result[0]))
        time.append(float(result[1]))
    for i in range(2):
        fastest_index = time.index(min(time))
        print n[fastest_index], time[fastest_index]
        del n[fastest_index]
        del time[fastest_index]
    drop += n
    drop_time += time

for i in range(2):
    fastest_index = drop_time.index(min(drop_time))
    print drop[fastest_index], drop_time[fastest_index]
    del drop[fastest_index]
    del drop_time[fastest_index]

Submission status: Accepted

Solution code:
O=[]
dic={}
for i in range(3):
    d={}
    for j in range(8):
        n,t=map(float,raw_input().split())
        d[t]=int(n)
    ls=sorted(d)
    for j in ls[:2]:
        O.append((d[j],j))
    for j in ls[2:]:
        dic[j]=d[j]
for i in sorted(dic)[:2]:
    O.append((dic[i],i))
for i in O:
    print i[0],i[1]

Submission status: Accepted

Solution code:
L = []
for _ in xrange(3):
    S = sorted(map(lambda (a,b):(a,float(b)),
                   [raw_input().split()for _ in xrange(8)]),
               key=lambda (n,m):m)
    print "{} {}".format(*S.pop(0))
    print "{} {}".format(*S.pop(0))
    L.extend(S)
L.sort(key=lambda (n,m):m)
print "{} {}".format(*L[0])
print "{} {}".format(*L[1])

Submission status: Accepted

Solution code:
an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    n1, t1, n2, t2 = 0, 1000, 0, 1000
    for j in range(8):
        n, t = map(float, raw_input().split())
        if t < t1:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = t2
            n2 = n1; t2 = t1
            n1 = n ; t1 = t
        elif t < t2:
            if t2 < at1:
                an1 = n2; at1 = t2
            elif t2 < at2:
                an2 = n2; at2 = t2
            n2 = n ; t2 = t
        else:
            if t < at1:
                an1 = n; at1 = t
            elif t < at2:
                an2 = n; at2 = t
    print "%d %4.2f"%(int(n1), t1)
    print "%d %4.2f"%(int(n2), t2)
print "%d %4.2f"%(int(an1), at1)
print "%d %4.2f"%(int(an2), at2)

Submission status: Accepted

Solution code:
def check(x,y):
    global an1,at1,an2,at2
    if y < at1:
        an1,at1 = x,y
    elif y < at2:
        an2,at2 = x,y

an1, at1, an2, at2 = 0, 1000, 0, 1000
for i in range(3):
    n1, t1, n2, t2 = 0, 1000, 0, 1000
    for j in range(8):
        n, t = map(float, raw_input().split())
        if t < t1:
            check(n2,t2)
            n1,t1,n2,t2 = n,t,n1,t1
        elif t < t2:
            check(n2,t2)
            n2, t2 = n, t
        else:
            check(n,t)
    print "%d %4.2f"%(int(n1), t1)
    print "%d %4.2f"%(int(n2), t2)
print "%d %4.2f"%(int(an1), at1)
print "%d %4.2f"%(int(an2), at2)

Submission status: Accepted

Solution code:
data = []
tmp = []
ans = []

def pushAns(d):
    for j in range(2):
        ans.append((d[0][0],d[0][1]))
        d.pop(0)    

for i in range(24):
    a,b = (float(x) for x in input().split())
    tmp.append((a,b))
    if (i + 1) % 8 == 0:
        tmp.sort(key=lambda x:x[1])
        pushAns(tmp)
        data.extend(tmp)
        tmp.clear()
        
data.sort(key=lambda x:x[1])
pushAns(data)

for i in range(8):
    print(int(ans[i][0]),ans[i][1])

Submission status: Accepted

Solution code:
hoketsu_1 = [0, 100]
hoketsu_2 = [0, 100]
for x in range(3) :
    Time = []
    for i in range(8) :
        p, t = input().split()
        Time.append([p, t])
    Time.sort(key = lambda x: x[1])
    print(*Time[0])
    print(*Time[1])
    
    if float(Time[2][1]) < float(hoketsu_1[1]) :
        hoketsu_2 = hoketsu_1
        hoketsu_1 = Time[2]
    elif float(Time[2][1]) < float(hoketsu_2[1]) :
        hoketsu_2 = Time[2]
    if float(Time[3][1]) < float(hoketsu_2[1]) :
        hoketsu_2 = Time[3]
print(*hoketsu_1)
print(*hoketsu_2)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


class Info:
    def __init__(self,arg_id,arg_score):
        self.id = arg_id
        self.score = arg_score
        self.float_score = float(self.score)

    def __lt__(self,another):
        return self.float_score < another.float_score


rest = []

for loop in range(3):

    work = []

    for row in range(8):
        tmp_id,score = input().split()
        work.append(Info(int(tmp_id),score))

    work.sort()
    print("%d %s"%(work[0].id,work[0].score))
    print("%d %s"%(work[1].id,work[1].score))

    for row in range(2,len(work)):
        rest.append(work[row])

rest.sort()
print("%d %s"%(rest[0].id,rest[0].score))
print("%d %s"%(rest[1].id,rest[1].score))

Submission status: Accepted

Solution code:
R = []

for _ in range(3):
    L = []
    for i in range(8):
        p, t = input().split()
        p = int(p)
        t = float(t)
        L.append((p,t))
    
    L.sort(key=lambda x: x[1])
    for i in [0, 1]:
        print(*L[i])
    R.extend(L[2:])

R.sort(key=lambda x: x[1])
for i in [0, 1]:
    print(*R[i])

Submission status: Accepted

Solution code:
l1,l2,l3=[],[],[]
final=[]
count=0
for i in range(24):
    p,t=map(float,input().split())
    if count<=7:l1.append([t,p])
    elif 7<count<=15:l2.append([t,p])
    elif 15<count<=23:l3.append([t,p])
    count +=1
l1=sorted(l1)
l2=sorted(l2)
l3=sorted(l3)
final +=[l1[0],l1[1],l2[0],l2[1],l3[0],l3[1]]
del l1[0],l1[0],l2[0],l2[0],l3[0],l3[0]
third=sorted(l1+l2+l3)
final +=[third[0],third[1]]
for i in range(8):print(int(final[i][1]),final[i][0])

Submission status: Accepted

Solution code:
ans=[0]*8
group=[]
re=[]
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[0]=group.pop(0)
ans[1]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[2]=group.pop(0)
ans[3]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[4]=group.pop(0)
ans[5]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
re.sort()
ans[6]=re.pop(0)
ans[7]=re.pop(0)
for i in ans:
    print(i[1],i[0])

Submission status: Accepted

Solution code:
first = []
for _ in range(8):
    num, time = map(float, input().split())
    first.append([int(num), time])

second = []
for _ in range(8):
    num, time = map(float, input().split())
    second.append([int(num), time])

third = []
for _ in range(8):
    num, time = map(float, input().split())
    third.append([int(num), time])

loser = []

first_s = sorted(first, key=lambda x: x[1])
print(first_s[0][0], '{0:.2f}'.format(first_s[0][1]))
print(first_s[1][0], '{0:.2f}'.format(first_s[1][1]))
loser.append(first_s[2])
loser.append(first_s[3])

second_s = sorted(second, key=lambda x: x[1])
print(second_s[0][0], '{0:.2f}'.format(second_s[0][1]))
print(second_s[1][0], '{0:.2f}'.format(second_s[1][1]))
loser.append(second_s[2])
loser.append(second_s[3])

third_s = sorted(third, key=lambda x: x[1])
print(third_s[0][0], '{0:.2f}'.format(third_s[0][1]))
print(third_s[1][0], '{0:.2f}'.format(third_s[1][1]))
loser.append(third_s[2])
loser.append(third_s[3])

loser_s = sorted(loser, key=lambda x: x[1])
print(loser_s[0][0], '{0:.2f}'.format(loser_s[0][1]))
print(loser_s[1][0], '{0:.2f}'.format(loser_s[1][1]))

Submission status: Accepted

Solution code:
race1 = {}
for i in range(8):
    p, t = input().split()
    race1[int(p)] = float(t)
race2 = {}
for i in range(8):
    p, t = input().split()
    race2[int(p)] = float(t)
race3 = {}
for i in range(8):
    p, t = input().split()
    race3[int(p)] = float(t)
for p,t in sorted(race1.items(), key = lambda x: x[1])[:2]:
    print(p,race1.pop(p))
for p,t in sorted(race2.items(), key = lambda x: x[1])[:2]:
    print(p,race2.pop(p))
for p,t in sorted(race3.items(), key = lambda x: x[1])[:2]:
    print(p,race3.pop(p))
race1.update(race2)
race1.update(race3)
for p,t in sorted(race1.items(), key = lambda x: x[1])[:2]:
    print(p,race1.pop(p))

Submission status: Runtime Error

Solution code:
ls = []
for i in range(2):
    n,t = raw_input().split()
    ls.append([n,float(t)])
ls1 = sorted(ls[:9], key=lambda x:x[1])
ls2 = sorted(ls[9:17], key=lambda x:x[1])
ls3 = sorted(ls[17:], key=lambda x:x[1])
print ' '.join(map(str,ls1[0]))
print ' '.join(map(str,ls1[1]))
print ' '.join(map(str,ls2[0]))
print ' '.join(map(str,ls2[1]))
print ' '.join(map(str,ls3[0]))
print ' '.join(map(str,ls3[1]))
del ls1[0],ls1[1],ls2[0],ls2[1],ls3[0],ls3[1]
ls_merg = sorted(ls1 + ls2 + ls3, key=lambda x:x[1])
print ' '.join(map(str,ls_merg[0]))
print ' '.join(map(str,ls_merg[1]))

Submission status: Runtime Error

Solution code:
l = [[], [], []]
ans = []
for i in range(3):
  for j in range(8):
    s = raw_input().split()
    l[i].append(float(s[1]), int(s[0]))
for i in range(3):
  l[i].sort()
  l[i].reverse()
  ans.append(l[i].pop(0))
  ans.append(l[i].pop(0))
l = l[0] + l[1] + [2]
l.sort()
l.reverse()
ans.append(l.pop(0))
ans.append(l.pop(0))
for n in ans:
  print str(n[1]) + " " + str(n[0])

Submission status: Runtime Error

Solution code:
dataset = [[input().split() for _ in range(8)] for _ in range(3)]
tmp = []
for i in range(3):
    s = sorted(dataset[i], key=lambda x: x[1])[:3]
    tmp.append(s[-1])
    for p in s[:2]:
        print(*p)
a, b = sorted(tmp, key=lambda x: x[1])[:2]
print(*a, "\n", *b)

Submission status: Runtime Error

Solution code:
import heapq
from collections import namedtuple

Data = namedtuple("Data", ("time", "number"))

all_player = []

for _ in range(3):
    player = [input().split(" ") for lp in range(8)]
    player = [Data(float(time), number) for number, time in player]

    heapq.heapify(player)
    data = heapq.heappop(player)
    print(data.number, data.time)
    data = heapq.heappop(player)
    print(data.number, data.time)

    all_player.extend(player)

heapq.heapify(all_player)
data = heapq.heappop(all_player)
print(data.number, data.time)
data = heapq.heappop(all_player)
print(data.number, data.time)