luogu#P4995. 跳跳!

跳跳!

Problem Description

You are a little jumping frog, and you are especially good at jumping around in all kinds of places.

One day, when you went out to play with your friend Little F, you came across a pile of stones with different heights. The height of the ii-th stone is hih_i, and the ground height is h0=0h_0 = 0. You estimate that the stamina cost to jump from stone ii to stone jj is (hihj)2(h_i - h_j) ^ 2, and the stamina cost to jump from the ground to stone ii is (hi)2(h_i) ^ 2.

To show Little F your amazing jumping skills, you decide to jump onto each stone exactly once, and finally stop on any stone. Also, the little frog wants to spend as much stamina as possible.

Of course, you are just a little frog. You can only jump, and you do not know how to jump in a way that shows your skills best.

But you are saved! Little F hands you a computer with “AK” written on it, and you can use a computer program to solve this problem. The almighty computer will tell you how to jump.

So please, you little frog who can write code, write this program and take a solid step toward getting NOIp AK!

Input Format

The first line contains a positive integer nn, the number of stones.

The second line contains nn positive integers, where the ii-th integer is the height hih_i of the ii-th stone.

Output Format

Output one positive integer in a single line, the maximum stamina cost you can spend.

2
2 1
5
3
6 3 5

49

Hint

Sample Explanation

For both samples, jumping in the order given in the input is one of the optimal solutions.

Constraints

For 1in1 \leq i \leq n, 0<hi1040 < h_i \leq 10 ^ 4, and all hih_i are distinct.

For 10%10\% of the testdata, n3n \leq 3.

For 20%20\% of the testdata, n10n \leq 10.

For 50%50\% of the testdata, n20n \leq 20.

For 80%80\% of the testdata, n50n \leq 50.

For 100%100\% of the testdata, n300n \leq 300.

Translated by ChatGPT 5