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 dd positions, it takes d2d^2 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 1-1 is moved to the left, which costs 11 time for the reprogramming. The box at position 44 is moved one position to the right, to make place for one of the boxes at position 33, costing 11 time as well. Two boxes at position 33 are moved to the left (costing 11 and 44), and one box at position 33 is moved to the right (costing 11), making the total cost 1+1+1+4+1=81+1+1+4+1=8.

Figure H.1: Visualisation of the first sample case.

입력

The input consists of:

  • One line with an integer nn (1n1061\leq n\leq 10^6), the number of boxes.
  • One line with nn integers xx (x109\left| x \right| \leq 10^9), 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.