#abc375b. B - Traveling Takahashi Problem

B - Traveling Takahashi Problem

Score : 150150 points

问题陈述

高桥在二维坐标平面的原点上。

他从点 (a,b)(a, b) 移动到点 (c,d)(c, d) 的成本是 (ac)2+(bd)2\sqrt{(a - c)^2 + (b - d)^2}

当他从原点开始,按顺序访问 NN 个点 (X1,Y1),,(XN,YN)(X_1, Y_1), \ldots, (X_N, Y_N),然后返回原点时,找出总成本。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Takahashi is at the origin on a two-dimensional coordinate plane.

The cost for him to move from point (a,b)(a, b) to point (c,d)(c, d) is (ac)2+(bd)2\sqrt{(a - c)^2 + (b - d)^2}.

Find the total cost when he starts at the origin, visits NN points (X1,Y1),,(XN,YN)(X_1, Y_1), \ldots, (X_N, Y_N) in this order, and then returns to the origin.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 109Xi,Yi109-10^9 \leq X_i, Y_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

X1X_1 Y1Y_1

\vdots

XNX_N YNY_N

Output

Print the answer.
Your output will be considered correct if its absolute or relative error from the true value is at most 10610^{-6}.

Sample Input 1

2
1 2
-1 0

Sample Output 1

6.06449510224597979401

The journey consists of the following three steps:

  • Move from (0,0)(0, 0) to (1,2)(1, 2). The cost is $\sqrt{(0 - 1)^2 + (0 - 2)^2} = \sqrt{5} = 2.236067977...$.
  • Move from (1,2)(1, 2) to (1,0)(-1, 0). The cost is $\sqrt{(1 - (-1))^2 + (2 - 0)^2} = \sqrt{8} = 2.828427124...$.
  • Move from (1,0)(-1, 0) to (0,0)(0, 0). The cost is (10)2+(00)2=1=1\sqrt{(-1 - 0)^2 + (0 - 0)^2} = \sqrt{1} = 1.

The total cost is 6.064495102...6.064495102....

Sample Input 2

7
-14142 13562
-17320 50807
-22360 67977
24494 89742
-26457 51311
28284 27124
31622 77660

Sample Output 2

384694.57587932075868509383

Sample Input 3

5
-100000 100000
100000 -100000
-100000 100000
100000 -100000
-100000 100000

Sample Output 3

1414213.56237309504880168872