RETO4 - Punto de Control
Vasya takes part in the competition guidance. There are n control points located along the line at coordinates x1, x2 ... xn. Vasya starts at the point with given coordinate. His goal is to visit at least n - 1 control points in order to finish the race. Participants are allowed to visit checkpoints in any order.
Input
The first line of the input contains two integers n and a (1 ≤ n ≤ 100000, -1000000 ≤ a ≤ 1000000) - the number of checkpoints and the starting position of Vasya, respectively.
The second line contains n integers x1, x2 ... xn (-1000000 ≤ xi ≤ 1000000) - coordinates of the control points.
Output
Print one integer - the minimum distance that Vasya has to travel in order to visit at least n - 1 checkpoint
Example
Input: 3 10 1 7 12 Output: 7
Input: 2 0 11 -10 Output: 10
Input: 5 0 0 0 1000 0 0 Output: 0
Explanation
In the first example Vasya should visit two points. The best way to accomplish this is to go first to the third control point (the distance is 12-10 = 2) and then proceed to the second (the distance is 12-7 = 5). The total distance is 2 + 5 = 7.
The second is enough to visit a single point of control mode Vasya should simply go to the extent -10. Distance 10.
Added by: | MaratónAFDM |
Date: | 2016-10-07 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | MAWK BC C NCSHARP CSHARP C++ 4.3.2 CPP14 COFFEE DART FORTH JAVA JS-RHINO JULIA KTLN NODEJS OCT PHP PROLOG PYTHON PYPY3 PYTHON3 R RACKET SQLITE SWIFT UNLAMBDA |