# ADA University - February 3 - Dijkstra

# Mathematical platforms

In older games, which have 2D graphics, one can run into the next situation. The hero jumps along the platforms or islands that hang in the air. He must move himself from one side of the screen to the other. The hero can jump from any platform number **i** to any platform number **k**, spending (**i** - **k**) * (**i** - **k**) * (`y`

- _{i}`y`

) * (_{k}`y`

- _{i}`y`

) energy, where _{k}`y`

and _{i}`y`

are the heights where these platforms hang. Obviously energy should be spent frugally._{k}

You are given the heights of the platforms in order from the left side to the right. Can you find the minimum amount of energy to get from the **1**-st (start) platform to the **n**-th (last)?

#### Input

The first line contains the number of platforms **n** (**1** ≤ **n** ≤ **4000**). The second line gives **n** integers - the heights of the platforms, which absolute values are not greater than **200000**.

#### Output

Print the singe integer which is the minimum amount of energy to get from the **1**-st platform to the **n**-th.

4 1 2 3 30

731