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,
Input Specification
The first line contains a single integer
The second line contains a single integer
The next
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