Everyone knows that the files are stored in the magnetic disk. It reads the information according to the horizontal movement of the magnetic head on the track and the rotation of the magnetic disk. In order to reduce the file access time, many excellent disk scheduling algorithms have appeared.
In this problem, Shortest Seek Time First Algorithm (SSTF), which requires that the track to be accessed next is closest to the track where the current magnetic head is located. For example, given that the current magnetic head is on a track of 100, the number of tracks which need to be accessed is (55, 58, 39, 18, 90, 160, 150, 38, 184). Because 90 is the closest track to 100, the head moves to track 90 with a distance of 10 (| 100-90 |), and then finds the closest track to 90 is 58 and the distance is 32 (| 90-58 |), followed by 55 ... Finally, the resulting access sequence is (90, 58, 55, 39, 38, 18, 150, 160, 184), and the sum of the travel distances is | 100-90 | + | 90-58 | + | 58-55 | + | 55-39 | + | 39-38 | + | 38-18 | + | 18-150 | + | 150-160 | + | 160-184 | = 10 + 32 + 3 + 16 + 1 + 20 + 132 + 10 + 24 = 248.
Note that if there are multiple tracks with the smallest distance from the current track, the track with the smallest number will be taken as the next track.
Now given the number of the current magnetic head and the track sequence which you need to access, Little Gyro wants to calculate the sum of the magnetic head's moving distance.
输入描述:
Each input file only contains one test case.
The first line contains two integer n, m (1 ≤ n ≤
, 1 ≤ m ≤
), indicating the length of the track sequence and the number of the current magnetic head.
The second line contains n integers
(1 ≤
≤
), indicating the track sequence.
输出描述:
For each test case output an integer indicating the sum of the magnetic head's moving distance.
示例1
输入
复制
9 100
55 58 39 18 90 160 150 38 184