#P5143. 攀爬者

攀爬者

Description

He marked NN points on a topographic map, where each point PiP_i has coordinates (xi,yi,zi)(x_i, y_i, z_i). Among all points, the height values zz are pairwise distinct. HKE plans to climb from the lowest point to the highest point, and his climbing satisfies the following conditions:

(1) He visits every point he marked.

(2) Starting from the second point, the height zz of each visited point is higher than that of the previous point.

(3) HKE can fly. The distance he travels from a point PiP_i to PjP_j is the Euclidean distance between the two points, i.e., (XiXj)2+(YiYj)2+(ZiZj)2\sqrt{(X_i-X_j)^2+(Y_i-Y_j)^2+(Z_i-Z_j)^2}.

Now, HKE wants you to compute the total distance of his climb.

Input Format

The first line contains an integer NN indicating the number of points on the map.

Each of the next NN lines contains three integers xi,yi,zix_i, y_i, z_i, representing the coordinates of the ii-th point.

Output Format

Output a real number representing the total distance HKE needs to climb (rounded to three decimal places).

5
2 2 2
1 1 1
4 4 4
3 3 3
5 5 5

6.928

Hint

For 100% of the testdata, 1N500001\leq N\leq 50000, and the answer is within the range of a double.

Translated by ChatGPT 5