This page is still under construction.

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

Tidying up

Time limit2sMemory limit512 MB

Summary
Place N points so the configuration is symmetric about the y-axis with equal multiplicities; minimize the total Euclidean distance moved.
Level

Medium6 of 10

Topics
Geometry, Greedy, Sorting, Math
Solved
No attempts yet

Problem

Objects lie scattered on the floor of a room. Let LL be the straight line that cuts the room exactly in half. The room is tidy when, for every position that holds an object, the position mirrored across LL also holds an object, and both positions hold the same number of objects.

Carrying objects around is hard work, so you move them one at a time and keep the total carried distance as small as possible. Distance walked while carrying nothing does not count.

In this problem LL is the yy axis, and the position of each object is given as a point on the plane. Find the smallest possible sum of the distances the objects travel when the room ends up tidy. Distance is the Euclidean distance D=(x1−x2)2+(y1−y2)2D = \sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}. An object may be put down at a position with non-integer coordinates.

For example, with the objects placed as in the picture above, moving the right object down by 1 makes the room tidy, and the total distance is 1.

Input

The first line has the number of objects NN (1≤N≤1001 \le N \le 100). Each of the next NN lines has the position of one object as xx yy. Both coordinates are integers between −1000-1000 and 10001000. No two objects start at the same position.

Output

Print the smallest possible sum of the travel distances after the room is tidy, rounded to three decimal places. Print all three digits after the decimal point even when the value is an integer.

Examples8

  1. Example 1

    Input
    8
    2 2
    7 1
    9 -4
    -10 1
    -6 -9
    -6 10
    8 8
    2 -4
    
    Expected output
    15.659
    
  2. Example 2

    Input
    1
    0 0
    
    Expected output
    0.000
    
  3. Example 3

    Input
    1
    -1000 -1000
    
    Expected output
    1000.000
    
  4. Example 4

    Input
    2
    3 5
    -3 5
    
    Expected output
    0.000
    
  5. Example 5

    Input
    2
    1 -1000
    1 1000
    
    Expected output
    2.000
    
  6. Example 6

    Input
    2
    -5 0
    3 0
    
    Expected output
    2.000
    
  7. Example 7

    Input
    3
    0 0
    4 1
    -4 3
    
    Expected output
    2.000
    
  8. Example 8

    Input
    5
    0 -1000
    0 -1
    0 0
    0 7
    0 1000
    
    Expected output
    0.000