Utility Poles

No attempts yetTime limit1sMemory limit128 MB

Problem

There are NN utility poles standing in a row on a straight line. Treat the line as the xx-axis and let the pole positions be the xx-coordinates x0,x1,,xN1x_0, x_1, \dots, x_{N-1}. Always x0=0x_0 = 0, every xix_i with i1i \ge 1 is a positive integer, and the coordinates are distinct and given in increasing order.

You want to move some of the poles so that the gap between every pair of neighboring poles becomes equal, while keeping the total moved distance as small as possible. The pole at x0=0x_0 = 0 is fixed and cannot move, and any pole you move must land on an integer coordinate.

The order of the poles never changes, so in the final arrangement the ii-th pole from the left (counting from 00) sits at coordinate idi \cdot d, where dd is the common gap between neighboring poles and is a positive integer.

For example, suppose the poles are at coordinates 0,4,6,90, 4, 6, 9.

If you make the gap 44 by moving the poles at 66 and 99 to 88 and 1212, the total moved distance is 2+3=52 + 3 = 5.

But if you move only the pole at 44 to 33, every gap becomes 33 and the total moved distance is just 11.

Given the positions of the poles, write a program that finds the minimum total moved distance needed to make all neighboring gaps equal, with x0x_0 fixed.

Input

The first line contains the number of poles NN (1N1000001 \le N \le 100000).

The second line contains the distinct xx-coordinates x0,x1,,xN1x_0, x_1, \dots, x_{N-1}, separated by spaces and given in increasing order. Every xix_i is an integer, x0=0x_0 = 0, and 1xi1091 \le x_i \le 10^9 for i1i \ge 1.

Output

Print, on a single line, the minimum total moved distance when the poles are shifted so that all neighboring gaps are equal.

Hint

Intermediate values and the answer can exceed the range of a 32-bit integer, so using a 64-bit integer type is recommended.