Codeforces Round 536 (Div. 2)
C
Lunar New Year and Number Division
Codeforces
900
原题
← BD →
翻译中…

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

翻译中…

There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $2$ numbers. Suppose the numbers are divided into $m$ groups, and the sum of the numbers in the $j$-th group is $s_j$. Bob's aim is to minimize the sum of the square of $s_j$, that is $$\sum_{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 $n$ ($2 \leq n \leq 3 \cdot 10^5$), denoting that there are $n$ integers on Bob's homework paper.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \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 $s_j$, which is $$\sum_{i = j}^{m} s_j^2,$$ where $m$ is the number of groups.

翻译中…

Note

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
4
8 5 2 3
Output #1
164
InputCopy OutputCopy
Input #2
6
1 1 1 2 2 2
Output #2
27
InputCopy OutputCopy
题目信息
题号
1106C
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。