Under construction

Still being built. Things may change

Tivoli

Interview

Time limit1sMemory limit1024 MB

Summary
Pick one facility per attraction and an visiting order that gives the shortest closed walk from the origin, with N up to 15.
Level

Medium5 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

The image shows the first sample case and one optimal solution.

Lisa has arrived at the amusement park and has chosen NN attractions to ride. Each attraction has two identical facilities, so there are 2N2N facilities in total. She rides each attraction exactly once. Given the positions of all facilities, choose which NN facilities to visit and the order in which to visit them so that the total distance Lisa walks is as short as possible. She starts at the entrance and must return there. The entrance is at the origin.

Input

The first line contains an integer NN (1≤N≤151 \le N \le 15), the number of attractions. The next NN lines describe attractions 11 to NN in order. Each line contains four integers: the x and y coordinates of the first facility, followed by the x and y coordinates of the second facility. The absolute value of every coordinate is less than one million.

No facility is at the same position as another facility, and no facility is at the origin.

Output

The first line contains the distance Lisa walks as a real number. Then print NN lines, each with two integers. The first integer is the attraction number (11 to NN) that Lisa visits, and the second is the facility number (11 or 22) she uses for it.

If several routes give the same shortest distance, print any of them. Reversing a route gives the same distance, so there are always at least two valid answers. The relative or absolute error must be less than 10−510^{-5}.

Examples1

  1. Example 1

    Input
    3
    3 5 1 -1
    -2 0 0 4
    4 4 0 6
    
    Expected output
    14.233345
    2 2
    1 1
    3 1