Computer game (platforms) with quadratic jumps#5849

Computer game (platforms) with quadratic jumps

1 second
64 megabytes
Medium

Can you remember even a single acquaintance of yours who is less than twenty years old and did not play computer games in childhood? If so, perhaps you are not familiar with this kind of entertainment yourself. In any case, this should not prevent you from solving the problem.

In many older video games with 2D graphics, it is common to encounter the following situation. The game hero jumps across platforms suspended in mid-air. The objective is to move from one side of the screen to the other.

When the hero jumps from one platform to the next, he spends |y_2 - y_1|^2 units of energy, where y_1 and y_2 are the heights at which these platforms are located. Additionally, the hero has a special skill: he can make a super jump, skipping exactly one platform, but this jump costs 3 \cdot |y_3 - y_1|^2 units of energy. Naturally, the hero wants to reach the final platform using as little energy as possible.

You are given the heights of the platforms in order from left to right. Can you determine the minimum amount of energy the hero needs to get from the first (starting) platform to the -th (last) platform?

Input

The first line contains the number of platforms (2 \le N \le 100\,000). The second line contains integers, the heights of the platforms, whose absolute values do not exceed .

Output

Print a single integer: the minimum amount of energy required to travel from the first platform to the last platform (assuming the player is forbidden to use cheat codes).

Examples

Example 1

Loading
Loading