시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB111100.000%

문제

At ultrarunning competitions participants must cover as long of a distance as they can within a certain time. Ranking will be determined by the distance covered; if this is equal, the faster competitor wins. In individual competitions there are two classes: men (M) and women (N).

Additionally there is a team ranking. Every competitor can belong to at most one team. Teams are divided into three classes: men (M), women (N) and mixed teams (S). Team that has competitors of both genders in it is a mixed team; team class is determined based on all of its members. Team result is determined by the sum of the results of the three best members that satisfy the conditions for the team class (this means that the result of a mixed team must be based on results of either two men and one woman or two women and one man).

Write a program that finds team results based on individual results.

입력

The first line of input contains one integer: number of participants $N$. On each of the next $N$ lines there are attributes of one competitor: name, class, distance covered, time, team name (missing if the competitor does not belong to a team). All names contain only capital Latin letters and spaces. Amount of data and values of attributes are realistic.

출력

Write the team results into output in ranked order starting from the best, one line per team: place in overall ranking, class and place within class, team name, distance, time. If team does not have three results, output DQ, class, team name. Teams with equal results should be ordered in lexicographic ordering of the names, as a place output the place (or place within class) of the first team. Disqualified (DQ) teams should be listed last.

예제 입력 1

11
TOOMAS HUNT,M,211.0KM,24:09:10,METSARAHVAS
MARTIN PODER,M,211.0KM,27:07:45,METSARAHVAS
PEETER KARU,M,DQ,,METSARAHVAS
PILLE KASK,N,178.0KM,30:21:19,TAIMED JA LIBLIKAD
GETTER MATAS,N,162.0KM,27:40:30,TAIMED JA LIBLIKAD
MARI PURAVIK,N,42.2KM,4:30:10
JANA PILVEMAGI,N,112.4KM,18:40:11,TAIMED JA LIBLIKAD
TONIS ROHT,M,199.0KM,30:34:10,TAIMED JA LIBLIKAD
JAAK MAASIKAS,M,208.0KM,28:23:14,PIKK JA ROHELINE
JAAN MAASIKAS,M,203.0KM,27:27:43,PIKK JA ROHELINE
JAAGUP MAASIKAS,M,201.0KM,29:13:34,PIKK JA ROHELINE

예제 출력 1

1,M1,PIKK JA ROHELINE,612.0KM,85:04:31
2,S1,TAIMED JA LIBLIKAD,539.0KM,88:35:59
DQ,M,METSARAHVAS