#ABC471C. 饼干与贪心高桥 / Cookies and Greedy Takahashi

饼干与贪心高桥 / Cookies and Greedy Takahashi

Problem Statement

There are cookies at NN positions on a number line. The coordinate of the ii-th cookie is AiA_i.

Takahashi is initially at coordinate 00 on the number line, and repeats the following action until he has picked up all NN cookies.

  • Action: Move to the coordinate of the nearest cookie from his current position (if there are multiple such cookies, the one with the smallest coordinate), and pick up that cookie.

Find the total distance Takahashi travels until he picks up all the cookies.

Input

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

  • NN
  • A1A_1 \dots ANA_N

Output

Output the answer.

Constraints

  • 1N3×1051 \leq N \leq 3\times 10^5
  • 109Ai109-10^9 \leq A_i \leq 10^9
  • Ai0A_i\neq 0
  • The AiA_i are distinct.
  • All input values are integers.
4
-1 -4 2 -11
23

Takahashi acts as follows.

  • He moves from coordinate 00 to coordinate 1-1 and picks up the cookie. The distance traveled is 11.
  • He moves from coordinate 1-1 to coordinate 4-4 and picks up the cookie. The distance traveled is 33.
  • He moves from coordinate 4-4 to coordinate 22 and picks up the cookie. The distance traveled is 66.
  • He moves from coordinate 22 to coordinate 11-11 and picks up the cookie. The distance traveled is 1313.

Thus, the total distance traveled is 1+3+6+13=231+3+6+13=23.

In the second action, the distances to the cookie at coordinate 4-4 and the cookie at coordinate 22 are both 33, and Takahashi moves to 4-4, the smaller coordinate.

10
1 2 3 4 5 -1 -2 -3 -4 -6
17