P28899 [洛谷] Jump Jump!
普及
题目描述

Problem Description

You are a small jumping frog, exceptionally skilled at hopping around various places.

One day, while playing with your friend Xiao F, you encountered a pile of stones of varying heights. The height of the $i$-th stone is $h_i$, and the height of the ground is $h_0 = 0$. You estimate that the energy cost to jump from the $i$-th stone to the $j$-th stone is $(h_i - h_j)^2$, and the energy cost to jump from the ground to the $i$-th stone is $h_i^2$.

To showcase your super jumping abilities to Xiao F, you decide to jump onto each stone once and end up on any stone, aiming to expend as much energy as possible.

However, as a small jumping frog, you only know how to jump and are unsure how to maximize your energy expenditure to fully demonstrate your skills.

But you're in luck! Xiao F hands you a computer labeled "AK", and you can use a computer program to solve this problem. The powerful computer will tell you how to jump.

So, please—as a coding frog—write this program to take a solid step towards ACing NOIp!

Input Format

The first line of input contains a single positive integer $n$, representing the number of stones.

The second line contains $n$ positive integers, representing the heights $h_i$ of the $i$-th stone.

Output Format

Output a single positive integer, representing the maximum energy you can expend.

Sample Input and Output

Sample Input #1

2
2 1

Sample Output #1

5

Sample Input #2

3
6 3 5

Sample Output #2

49

Notes

Sample Explanation

The optimal solutions for both samples can be achieved by jumping in the order given by the input.

Data Range

For $1 \leq i \leq n$, $0 < h_i \leq 10^4$, and $h_i$ are guaranteed to be distinct.

  • For 10% of the data, $n \leq 3$;
  • For 20% of the data, $n \leq 10$;
  • For 50% of the data, $n \leq 20$;
  • For 80% of the data, $n \leq 50$;
  • For 100% of the data, $n \leq 300$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 1
样例输出
5