AIM Tech Round 3 (Div. 2)
B
Checkpoints
Codeforces
1500
原题
← AC →
翻译中…

Vasya takes part in the orienteering competition. There are $*n*$ checkpoints located along the line at coordinates $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$. Vasya starts at the point with coordinate $*a*$. His goal is to visit at least $*n* - 1$ checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

翻译中…

Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*a*$ ($1 ≤ *n* ≤ 100 000$, $- 1 000 000 ≤ *a* ≤ 1 000 000$) — the number of checkpoints and Vasya's starting position respectively.

翻译中…

The second line contains $*n*$ integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$ ($- 1 000 000 ≤ *x*_{*i*} ≤ 1 000 000$) — coordinates of the checkpoints.

翻译中…

Output

翻译中…

Print one integer — the minimum distance Vasya has to travel in order to visit at least $*n* - 1$ checkpoint.

翻译中…

Note

翻译中…

In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is $12 - 10 = 2$) and then proceed to the second one (distance is $12 - 7 = 5$). The total distance is equal to $2 + 5 = 7$.

翻译中…

In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point $- 10$.

翻译中…

样例

Input #1
3 10
1 7 12
Output #1
7
InputCopy OutputCopy
Input #2
2 0
11 -10
Output #2
10
InputCopy OutputCopy
Input #3
5 0
0 0 1000 0 0
Output #3
0
InputCopy OutputCopy
题目信息
题号
709B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。