Minimum Diameter Sum

Split a set of n planar points into two nonempty groups so that the sum of the two group diameters is minimized, and print the value.

Hard8GeometryBinary searchSortingGreedyNo attempts yetTime limit1sMemory limit512 MB

Problem

A new city has many buildings. To make its administration efficient, the city splits the buildings into two groups, a red one and a blue one. The diameter of a group is the largest distance between two buildings of that group, and it measures how far the group spreads out. The smaller the diameter, the easier the administration. The goal is to find a split whose two diameters have the smallest possible sum.

Each building is a point in the plane, and the distance between two points is the Euclidean distance. The diameter of a point set is the largest distance between two points of the set. You are given a set PP of nn distinct points in the plane. Split PP into two subsets P1P_1 and P2P_2 with P1P_1 \neq \emptyset, P2P_2 \neq \emptyset, P1P2=PP_1 \cup P_2 = P, P1P2=P_1 \cap P_2 = \emptyset, and make the diameter of P1P_1 plus the diameter of P2P_2 as small as possible. A subset that holds a single point has diameter 00.

For example, nine points with integer coordinates are given as in Figure 1(a). Many splits are possible. The split in Figure 1(b) gives the blue points a diameter of 42+32=5\sqrt{4^2+3^2} = 5 and the red points a diameter of 52+12=26\sqrt{5^2+1^2} = \sqrt{26}, so the sum is 5+265 + \sqrt{26}. The split in Figure 1(c) has the sum 4+344 + \sqrt{34}, a bit smaller than the sum in Figure 1(b).

Figure 1. (a) The input points. (b), (c) Two splits. In each one the point pair that decides the diameter of a group is joined by a segment in the colour of that group.

Input

The first line holds the number of points nn (2n5,0002 \le n \le 5{,}000).

Each of the next nn lines holds one point. A line holds the xx coordinate and the yy coordinate of the point, separated by one space. Both values are integers between 00 and 10,00010{,}000, inclusive. The nn given points are distinct.

Output

Print the smallest possible sum of the two diameters, rounded to four digits after the decimal point. Always print exactly four digits after the decimal point. For example, if the answer is 22, print 2.0000.