Heavy Hauling
시간 제한3초메모리 제한2048 MB
정렬된 상자 위치들이 주어질 때, 모든 위치가 서로 다르도록 상자를 옮기면서 이동 거리의 제곱 합을 최소로 만드는 값을 구한다.
문제
The warehouse of the Boxes And Parcels Center (BAPC) just received an official warning from the inspector: apparently, it does not conform to the latest safety requirements. In the past, it was allowed to stack multiple boxes at the same shelf location, but due to the potential fire hazard, this is no longer allowed. In a hurry, all employees of the BAPC are roused to move the boxes to distinct positions.
After moving the boxes, the automated parcel retriever robot needs to be reprogrammed such that it knows the correct location of the boxes. Per box that is moved positions, it takes time to do this reprogramming. Of course, the BAPC should be up and running as soon as possible after moving the boxes, so the boxes should be moved in such a way that this total reprogramming time is as small as possible. Calculate the minimal time for the reprogramming for an optimal moving of boxes.
The warehouse of the BAPC is unbounded in both directions.
As an example, consider Figure H.1, corresponding to the first sample case. One box at position is moved to the left, which costs time for the reprogramming. The box at position is moved one position to the right, to make place for one of the boxes at position , costing time as well. Two boxes at position are moved to the left (costing and ), and one box at position is moved to the right (costing ), making the total cost .

Figure H.1: Visualisation of the first sample case.
입력
The input consists of:
- One line with an integer (), the number of boxes.
- One line with integers (), the position of each box. The box positions are ordered non-decreasingly.
출력
Output the minimal time to reprogram the parcel retriever robot for an optimal moving of boxes.