Best Relay Team

Time limit1sMemory limit512 MB

Summary
Choose four runners from n, assign one to leg 1 and three to the other legs, minimizing the total time with a lexicographic tie-break.
Level

Medium5 of 10

Topics
Greedy, Sorting, Brute force
Solved
No attempts yet

Problem

You coach the national athletics team and have to choose the sprinters who will represent your country in the 4 × 100 m relay at the coming championships.

As the name says, the relay has four legs of 100 meters each. Picking the four fastest 100 m runners in the nation looks right, but one detail changes the answer: the flying start. On the 2nd, 3rd and 4th legs the runner is already running when the baton arrives, so a runner with a slow acceleration phase does relatively better on one of those legs.

You have a pool of runners to choose from. Given how fast each runner is, decide which four runners make the team and which leg each of them runs. Two times are given for every runner: the time to run the 1st leg, and the time to run any of the other legs. A runner on the team runs exactly one leg.

The time of a team is the sum of its four leg times. Find the fastest team.

Input

The first line contains an integer nn, the number of runners to choose from (4≤n≤5004 \le n \le 500). Each of the next nn lines describes one runner. The ii-th of those lines contains the name of runner ii, the time aia_i for that runner to run the 1st leg, and the time bib_i for that runner to run any of the other legs (8≤bi≤ai<208 \le b_i \le a_i < 20), separated by spaces. A name is a string of 2 to 20 uppercase letters 'A' to 'Z', and no two runners have the same name. The times are given in seconds with exactly two digits after the decimal point.

Output

On the first line, print the time of the fastest team in seconds with exactly two digits after the decimal point. Then print four lines with the names of the runners on that team, the 1st leg first and the 4th leg last.

If several teams share the fastest time, print the team whose four names, listed from the 1st leg to the 4th leg, form the lexicographically smallest sequence. Names are compared as strings of uppercase letters in dictionary order.

Examples2

  1. Example 1

    Input
    6
    ASHMEADE 9.90 8.85
    BLAKE 9.69 8.72
    BOLT 9.58 8.43
    CARTER 9.78 8.93
    FRATER 9.88 8.92
    POWELL 9.72 8.61
    
    Expected output
    35.54
    CARTER
    BLAKE
    BOLT
    POWELL
    
  2. Example 2

    Input
    9
    AUSTRIN 15.60 14.92
    DRANGE 15.14 14.19
    DREGI 15.00 14.99
    LAAKSONEN 16.39 14.97
    LUNDSTROM 15.83 15.35
    MARDELL 13.36 13.20
    POLACEK 13.05 12.55
    SANNEMO 15.23 14.74
    SODERMAN 13.99 12.57
    
    Expected output
    52.67
    MARDELL
    DRANGE
    POLACEK
    SODERMAN