CF1106C.Lunar New Year and Number Division

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Lunar New Year and Number Division

Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.

There are nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n on Bob's homework paper, where nn is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 22 numbers. Suppose the numbers are divided into mm groups, and the sum of the numbers in the jj-th group is sjs_j. Bob's aim is to minimize the sum of the square of sjs_j, that is $$ um_{j = 1}^{m} s_j^2.$$

Bob is puzzled by this hard problem. Could you please help him solve it?

Input

The first line contains an even integer nn (2n31052 \leq n \leq 3 \cdot 10^5), denoting that there are nn integers on Bob's homework paper.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1041 \leq a_i \leq 10^4), describing the numbers you need to deal with.

Output

A single line containing one integer, denoting the minimum of the sum of the square of sjs_j, which is $$ um_{i = j}^{m} s_j^2,$$wheremm is the number of groups.

Note

In the first sample, one of the optimal solutions is to divide those 44 numbers into 22 groups {2,8},{5,3}\{2, 8\}, \{5, 3\}. Thus the answer is (2+8)2+(5+3)2=164(2 + 8)^2 + (5 + 3)^2 = 164.

In the second sample, one of the optimal solutions is to divide those 66 numbers into 33 groups {1,2},{1,2},{1,2}\{1, 2\}, \{1, 2\}, \{1, 2\}. Thus the answer is (1+2)2+(1+2)2+(1+2)2=27(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27.

Samples

4
8 5 2 3
164
6
1 1 1 2 2 2
27

在线编程 IDE

建议全屏模式获得最佳体验