CF709B Checkpoints

题目描述

数轴上有 $n$ 个点,分别编号为 $1, 2, ..., n $。你初始位置在 $a$ ,要经过其中的 $n-1$ 个点,求最小总行走距离。

输入格式

第一行两个正整数 $n$ 和 $a$。 第二行 $n$ 个正整数 $x_1, x_2, ..., x_n$,表示各个点的位置。 $1 \leq n \leq 10^5, -10^6 \leq a, x_i \leq 10^6$

输出格式

一行,一个正整数,表示最小的总行走距离。

说明/提示

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 $ .