This page is still under construction.

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

Alicia's Afternoon Amble

Time limit1sMemory limit256 MB

Summary
Visit all points on a bitonic tour from the leftmost hotel to the rightmost parlour and back, minimizing total Euclidean length.
Level

Medium7 of 10

Topics
Dynamic programming, Geometry, Sorting
Solved
No attempts yet

Problem

Alicia is staying at a hotel on the edge of town. She sets out in the morning with a list of landmarks scattered across the city. The day of sightseeing takes her through the city, past a number of locations, all the way to Pete's Polygon Pizza Parlour on the far side, where she stops for lunch. Any location she misses on the way out, she visits on the evening walk back to the hotel.

Given the locations Alicia wants to see, find the length of the shortest tour that starts at the hotel, visits every location, and returns to the hotel. Apart from the starting location, each location is visited exactly once.

The hotel is the location with the smallest x-coordinate, and Pete's Parlour is the location with the largest x-coordinate. On the way out the tour visits locations in strictly increasing order of x-coordinate until it reaches Pete's Parlour. On the way back it visits every remaining location in strictly decreasing order of x-coordinate. The distance between two locations is the Euclidean distance, and the x-coordinate of every location is distinct.

Input

The first line contains one integer nn, the number of locations (1≤n≤10001 \le n \le 1000).

Each of the next nn lines contains two integers xx and yy, the coordinates of one location (0≤x,y≤1000000 \le x, y \le 100000).

Output

Print the total length of the tour on one line, rounded to two decimal places.

Hint

The locations and the optimal tour for the first example.

Examples2

  1. Example 1

    Input
    5
    1 3
    2 1
    3 4
    4 4
    5 2
    
    Expected output
    10.87
    
  2. Example 2

    Input
    10
    4 1
    13 4
    21 3
    25 9
    28 10
    42 1
    43 2
    50 4
    67 10
    68 9
    
    Expected output
    131.65