It's almost Halloween, and that means that Bruno needs to help carve out spooky pumpkins. However, before Bruno starts carving, he first needs to get the pumpkins. Unfortunately, the only place to get super high quality pumpkins is the line of dread. Why is it called the line of dread? Because all the pumpkins grow on a single line, and some years the distances between the pumpkins are … far from favourable. This year, pumpkins have grown on the line of dread, each located on an integer coordinate from -1000 to 1000, relative to position 0 representing the entrance to the line. Bruno wishes to pick up pumpkins and put them all in his giant backpack. Obviously, being a true computer scientist, Bruno wants to minimize the distance he needs to walk. Bruno starts at the entrance, but does not need to go back to the entrance after he picks up the pumpkins. Can you figure out the least distance Bruno needs to walk in order to pick up pumpkins?
Input Specification
The first line contains a single integer .
The second line contains a single integer .
The next lines each contain one integer, the coordinate position of a pumpkin. The coordinate will not be 0. It is also guaranteed there are no two pumpkins in the same coordinate.
Note: It is not guaranteed the pumpkins are given in sorted order.
Output Specification
Output a single integer, the minimum distance Bruno needs to walk, given he starts at coordinate 0 and it does not matter where he ends at.
Sample Input
5
3
-3
-7
2
4
11
Sample Output
10
Explanation for Sample Output
The line of dread looks as follows, with the blue diamond representing the entrance:
One optimal way of getting 3 pumpkins would be to walk to the pumpkin at coordinate -3, then to the pumpkin at coordinate 2, then to the pumpkin at coordinate 4. This gives the total distance of:
Comments