Programming-trampoline-athlon!
Programming competitions are fun and exciting. Programming should be an Olympic sport! At least, this is what we believe. However, when we suggested this to some of our friends, they did not seem to share our excitement. So, we decided to suggest a combined sport that will be more interesting to watch. Programming-trampoline-athlon! (we are still working on the name.)
The idea is as follows. This is a team sport, where each team comprises of members. The team has at its disposal hour, computer, and trampoline. At all times, there must be at most one team member using the computer and at least one team member jumping the trampoline. At the beginning of the competition, the team is given programming problems, and trampoline elements (exercises). The team decides how to partition the trampoline elements between its members, such that each team member has to perform of the given elements on the trampoline. The programming tasks are solved cooperatively by the team members, but no one member can spend more than minutes on the computer in total. The scoring is comprised of two parts, which are added together:
The programming score ranges between and . The team receives points for every correctly solved problem.
The trampoline score ranges between and . Each of the trampoline elements receives a score from the judges that ranges between and . The final trampoline execution score is determined by dropping the highest and lowest of the scores, and then adding up the remaining scores.
Before we pitch this new sport to the International Olympic Committee, we want everything to be ready in order to show them just how serious we are. Thus, each team should receive a medal when no more than two other teams obtained a strictly higher score. However, in order to cope with a recent shortage of medals, the jury was instructed to make sure that there would be no more than teams deserving a medal. We ask you to write a program that determines the medallists, given the performance of the different teams.
Input
The first line contains the number of competing teams. Then follow lines. Each of these lines describes a team and contains values ; is a five-letter code used to identify the team, is an integer specifying the number of problems the team solved, and is an integer specifying the execution score of trampoline element number . Different teams always have different team codes.
Output
Print lines, where is the number of medallists. Each line should represent a medallist team, by containing two values and , where is the team code and is the total score of the team. Medallist teams should be listed by decreasing total score and, in case of ties, by input order.