Two Point Removal
题号:NC230995
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

In geometry, the polygonal chain, or polyline, is a connected series of points. The length of a polyline is the summation of lengths of all segments between adjacent points in the polyline.

In this problem, you're given a polyline defined by a series of points (0, 0), (1, y_1), (2, y_2), (3, y_3), ..., (n, y_n) and . You need to calculate the minimum length of the polyline after removing two points from (1, y_1), (2, y_2), (3, y_3), ..., (n, y_n). Note that after the removal, the remaining points are connected from left to right to form the new polyline.

输入描述:

The first line contains an integer n, representing the number of points between (0, 0) and .

The next line contains n integers y_1, y_2, ..., y_n, representing the y coordinates of these points on the polyline.

, .

输出描述:

Output one line with the minimum polyline length after removing two points. Your answer will be considered correct if the absolute or relative error is less than .
示例1

输入

复制
2
1 -1

输出

复制
3.0000000000000000
示例2

输入

复制
3
1 1 1

输出

复制
4.4721359549995796

说明

Remove point (1,1) and (3,1). Then the new polyline connects (0,0),(2,1) and (2,1),(4,0), whose length is 2\sqrt 5.