Frog Leaps

Find the minimum sum of squared jump distances to travel from the first stop to the last, given sorted positions.

Medium4GreedyDynamic programmingMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Frogs want to enter the programming contest in Amsterdam too. Getting there means crossing a lot of rivers. This frog is in good shape and jumps as far as it wants, but a jump of ii meters costs i2i^2 units of energy. The only way across a river is to jump from stop to stop.

The frog is lazy and wants to spend as little energy as possible. Compute the minimum amount of energy it needs to reach Amsterdam.

Input

The first line contains one integer nn, the number of stops (2n1062 \le n \le 10^6).

Each of the next nn lines contains one integer xix_i, the position of the ii-th stop in meters (0xi1060 \le x_i \le 10^6, xi<xi+1x_i < x_{i+1}).

The frog starts at the first stop x0x_0, and Amsterdam is at the last stop xn1x_{n-1}.

Output

Print one integer, the minimum number of units of energy the frog needs to reach Amsterdam.