시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB44141433.333%

문제

Alice and Bob are driving on a very long road that stretches from points $-10^9$ to $10^9$. Alice starts at point $A$ while Bob starts at point $B$. There are $n$ events to visit, where event $i$ is at position $t_i$. Either Alice or Bob must visit each event, but they must be visited in order (they must visit event $1$, then event $2$, then event $3$, \dots then event $n$).

Find the minimum total distance Alice and Bob can drive to visit all events.

입력

The first line contains a single integer $n$ ($1\le n\le3\cdot10^5$) --- the number of events.

The second line contains two integers $A$ and $B$ ($-10^9\le A,B\le10^9$) --- Alice and Bob's starting points.

The third line contains $n$ integers $t_1,t_2,\dots,t_n$ ($-10^9\le t_i\le10^9$) --- the locations of events either Alice or Bob must get to.

출력

Output an integer --- the minimum total distance Alice and Bob drive.

서브태스크

번호배점제한
15

$|t_i|,|A|\le1000,B=10^9$

28

$n\le20$

319

$n\le3000$

412

$n\le10^5,|t_i|,|A|,|B|\le100$

543

$|t_i|,|A|,|B|\le2\cdot10^5$

613

No additional constraints

예제 입력 1

5
2 3
5 1 4 4 7

예제 출력 1

7

예제 입력 2

6
540 152
450 600 532 496 325 336

예제 출력 2

526

예제 입력 3

8
35 315
-406 -543 114 205 -840 161 540 -731

예제 출력 3

1699

노트

In the first example:

  • Bob moves from position $3$ to position $5$ to attend event $1$, driving $2$ units.
  • Alice moves from position $2$ to position $1$ to attend event $2$, driving $1$ unit.
  • Bob moves from position $5$ to position $4$ for event $3$, driving $1$ unit.
  • Bob stays at position $4$, attending event $4$, driving $0$ units.
  • Bob moves from position $4$ to position $7$ for event $5$, driving $3$ units.

The total distance travelled is $2+1+1+0+3=7$.

In the second example, Alice visits all events.

채점 및 기타 정보

  • 예제는 채점하지 않는다.