This page is still under construction.

Parts of this page are still being built. What you see may change.

IOI Selection

Time limit1sMemory limit1024 MB

Summary
Given each participant's four raw contest scores and school year, normalize scores per contest, sum the final plus the two best KATT results, then pick the IOI and BOI teams.
Level

Medium5 of 10

Topics
Sorting, Implementation, Math, Simulation
Solved
No attempts yet

Problem

The organizing group of the Programming Olympiad wants to go out and play in the snow. Unfortunately, as organizers they have countless duties that come before playing. They have to write problems, supervise contests, travel as team leaders, and compute which participants are selected for the national team based on this year's results.

It occurred to the organizers, however, that the last part could be handled by someone else. For example, you.

The rules for national team selection are as follows. In total there are four contests that form the basis for selection: the final contest and three so-called KATT contests (KATT1, KATT2 and KATT3).

After all contests, the results are added up, and the four contestants with the best scores are selected for the International Olympiad in Informatics, IOI. In addition to IOI, a team must also be chosen for the Baltic Olympiad in Informatics, BOI. This team consists of the IOI team plus the two best contestants who are not in year 9 and did not qualify for IOI.

When the results are added up, the two best results from the three KATT contests are chosen, along with the result from the final, and summed.

Within a contest, the result is computed by normalizing the score a contestant received. First, the best score among all participants MAXMAX and the median score among all participants MEDMED are computed. If a contestant received x≤MEDx \le MED points, the contestant's result is 50⋅xMED50 \cdot \frac{x}{MED}. If a contestant received MED≤x≤MAXMED \le x \le MAX points, the contestant's result is 50+50⋅x−MEDMAX−MED50 + 50 \cdot \frac{x - MED}{MAX - MED}. This means the result increases linearly from 0 to 50 as the score increases from 0 to MEDMED, and from 50 to 100 as the score increases from MEDMED to MAXMAX.

For each participant in the contest, you will be given the participant's result in the four contests, as well as the participant's year. Determine who is selected for IOI and BOI.

Input

The first line contains an integer 6≤N≤406 \le N \le 40, the number of participants.

The next NN lines describe a participant and their results. A line begins with the participant's name, which consists of up to 20 lowercase letters from aa to zz, with no spaces. Then follows a number that is either 7,8,9,1,2,37, 8, 9, 1, 2, 3 and describes the participant's year. The years 7,8,97, 8, 9 represent here students in lower secondary school. Finally come four integers 0≤F,K1,K2,K3≤7000 \le F, K1, K2, K3 \le 700, the scores from the final, KATT1, KATT2 and KATT3 respectively.

In a contest, the median and the maximum score will always be different from each other. There will always be exactly one possible team according to the rules above.

Output

On the first line, print the names of the four participants who were selected for IOI.

The next line must contain two names: the additional participants who qualified for BOI.

On each line, the names you print must be sorted in alphabetical order.

Examples2

  1. Example 1

    Input
    33
    lisavallfors 3 505 362 145 0
    adamhasselwander 3 200 0 0 0
    martinjakobsson 3 247 101 69 272
    arvidlunnemark 1 461 40 160 343
    nicolehedblom 2 450 328 0 139
    fredrikekholm 8 216 168 229 265
    davidwarn 2 653 400 400 387
    fredrikhernqvist 3 608 400 400 100
    bjornmagnusson 1 320 181 175 227
    karllundstig 3 657 306 360 265
    johanbostrom 3 0 40 0 178
    ivarmatstoms 1 216 0 0 0
    simonhalvdansson 3 100 0 0 0
    mattiasgrenfeldt 1 445 159 215 35
    joakimblikstad 3 644 400 400 331
    gustavlindqvist 3 149 0 0 0
    erikprantare 2 361 101 0 0
    johannesagestam 3 207 61 0 142
    carlagrell 2 500 0 130 35
    jonatannilsson 2 415 100 75 100
    hannesbredberg 3 229 85 0 35
    carlenlund 2 116 40 0 0
    kristofferahgren 3 450 281 105 235
    markoproloscic 2 337 0 0 0
    eriksundqvist 3 200 0 0 0
    lucasunnerfelt 2 528 0 200 0
    johanvikstrom 3 339 128 76 79
    victorsellstedt 3 283 0 0 0
    bjornthoren 3 345 0 100 0
    hermankarlsson 2 557 362 360 303
    jacoberiksson 2 236 106 30 135
    hugoeberhard 9 386 115 105 276
    erikrimskog 3 200 0 0 0
    
    Expected output
    davidwarn fredrikhernqvist joakimblikstad karllundstig 
    arvidlunnemark hermankarlsson 
    
  2. Example 2

    Input
    7
    annbrittcaroline 3 100 100 100 100
    gandalf 1 0 75 75 75
    byteasar 3 75 0 75 75
    jultomten 2 50 50 50 50
    pelle 3 25 25 25 0
    alice 8 25 0 25 25
    bob 9 0 0 0 0
    
    Expected output
    annbrittcaroline byteasar gandalf jultomten 
    alice bob