You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
453 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int a[N];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
sort(a, a + n);
long long sum = 0;
for (int i = 0, j = n - 1; i < j; i++, j--)
sum += 1ll * (a[i] + a[j]) * (a[i] + a[j]);
printf("%lld", sum);
return 0;
}