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.


-----Examples-----
Input
4
8 5 2 3

Output
164

Input
6
1 1 1 2 2 2

Output
27



-----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$.

Difficulty: EASY
Tags: Mathematics

Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
l = list(map(int, input().split()))
l.sort()
sum = 0
for i in range(len(l) // 2):
	sum = sum + (l[i] + l[len(l) - 1 - i]) ** 2
print(sum)


n = int(input())
l = list(map(int, input().split()))
l.sort()
o = 0
a = 0
for i in range(n // 2):
	a = l[i] + l[-(i + 1)]
	o += a * a
print(o)


import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
A.sort()
result = sum(((A[i] + A[N - i - 1]) ** 2 for i in range(N // 2)))
print(result)


amount = int(input())
array = [int(s) for s in input().split()]
sorted_array = sorted(array)
sum_ = 0
for i in range(len(sorted_array) // 2):
	sum_ += (sorted_array[i] + sorted_array[len(sorted_array) - 1 - i]) ** 2
print(sum_)


n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
c = sorted(a, reverse=True)
sum = 0
for i in range(n // 2):
	sum += (b[i] + c[i]) ** 2
print(sum)


n = int(input())
a = list(map(int, input().split()))
a.sort()
sum1 = 0
for i in range(n // 2):
	sum1 += (a[i] + a[n - i - 1]) ** 2
print(sum1)


x = int(input())
y = list(map(int, input().split()))
y.sort()
a = 0
for i in range(int(x / 2)):
	a += (y[i] + y[x - i - 1]) ** 2
print(a)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(1, n // 2 + 1):
	ans += (l[i - 1] + l[-1 * i]) ** 2
print(ans)


(n, a) = (int(input()), sorted(map(int, input().split())))
print(sum([(a[i] + a[n - i - 1]) ** 2 for i in range(n // 2)]))


n = int(input())
a = sorted(map(int, input().split()))
s = 0
for i in range(n // 2):
	s += (a[i] + a[-i - 1]) ** 2
print(s)


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
ara.sort()
l = 0
r = n - 1
ans = 0
while l < r:
	ans += (ara[l] + ara[r]) ** 2
	l += 1
	r -= 1
print(ans)


n = input()
n = int(n)
x = input()
x = x.split()
y = list(map(int, x))
y = sorted(y)
count = 0
for i in range(n // 2):
	count += (y[i] + y[n - i - 1]) ** 2
print(count)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
total = 0
Arr.sort()
i = 0
j = n - 1
while i < j:
	total += (Arr[i] + Arr[j]) * (Arr[i] + Arr[j])
	i += 1
	j -= 1
print(total)


from sys import stdin
n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
ans = 0
if n % 2 == 1:
	j = n - 2
	ans = l[n - 1] ** 2
while i < j:
	ans += (l[i] + l[j]) ** 2
	i += 1
	j -= 1
print(ans)


import collections
import time
import os
import sys
import bisect
import heapq
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
ans = 0
for i in range(N // 2):
	ans += (A[i] + A[N - i - 1]) ** 2
print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 1000000007
PMOD = 998244353
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	a.sort()
	ans = 0
	for i in range(n // 2):
		ans += (a[n - i - 1] + a[i]) ** 2
	print(ans)


n = int(input())
m = [int(x) for x in input().split(' ')]
m.sort()
count = 0
for i in range(n):
	if i != n / 2:
		a = 0
		a = (m[i] + m[n - i - 1]) ** 2
		count += a
	else:
		break
print(count)


inputone = int(input())
numberinput = str(input())
listofnumbers = []
totalsum = 0
listofnumbers = numberinput.split(' ')
for i in range(0, len(listofnumbers)):
	listofnumbers[i] = int(listofnumbers[i])
listofnumbers.sort()
for i in range(0, int(inputone / 2)):
	curmax = listofnumbers[i]
	curmin = listofnumbers[inputone - 1 - i]
	totalsum = totalsum + (curmax + curmin) * (curmax + curmin)
print(totalsum)


t = int(input())
l = list(map(int, input().split()))
l.sort()
s = 0
for i in range(t // 2):
	r = l[i] + l[t - i - 1]
	s += r * r
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = 0
j = n - 1
for x in range(int(n / 2)):
	s += pow(l[x] + l[j], 2)
	j -= 1
print(s)


n = int(input())
a = list(map(int, input().strip().split()))
b = sorted(a)
s = 0
for i in range(n // 2):
	s = s + (b[i] + b[n - i - 1]) ** 2
print(s)


n = int(input())
sum1 = 0
a = [int(k) for k in input().split()]
a.sort()
for i in range(n // 2):
	sum1 += (int(a[i]) + int(a[n - i - 1])) * (int(a[i]) + int(a[n - i - 1]))
print(sum1)


n = int(input())
a = [int(j) for j in input().split()]
a.sort()
su = 0
for x in range(int(len(a) / 2)):
	su += (a[x] + a[n - x - 1]) ** 2
print(su)


n = int(input())
l = list(map(int, input().split()))
l.sort()
su = 0
for i in range(n // 2):
	sj = l[i] + l[-i - 1]
	su += sj * sj
print(su)


(ans, n, a) = (0, int(input()), sorted(map(int, input().split())))
for i in range(n // 2):
	ans += pow(a[-i - 1] + a[i], 2)
print(ans)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
a.sort()
s = 0
for i in range(n // 2):
	s += (a[i] + a[n - 1 - i]) ** 2
print(s)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
a.sort()
for i in range(len(a) // 2):
	ans += (a[i] + a[n - i - 1]) ** 2
print(ans)


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
n = ii()
a = li()
a.sort()
(i, j) = (0, n - 1)
ans = 0
while i < j:
	ans += (a[i] + a[j]) ** 2
	i += 1
	j -= 1
print(ans)


number = int(input())
l = [0] + [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(1, number // 2 + 1):
	ans += (l[i] + l[-i]) ** 2
print(ans)


n = int(input())
ans = int(0)
nn = int(n / 2)
a = sorted(list(map(int, input().split())))
for i in range(0, nn):
	ans += (a[i] + a[-i - 1]) ** 2
print(ans)


n = int(input())
l = [0] + [int(x) for x in input().split()]
l.sort()
res = 0
for i in range(1, n // 2 + 1):
	res += (l[i] + l[-i]) ** 2
print(res)


n = int(input())
m = input()
m = [int(i) for i in m.split(' ')]
m.sort()
s = 0
for i in range(n // 2):
	s += (m[i] + m[n - 1 - i]) * (m[i] + m[n - 1 - i])
print(s)


inputone = input()
numberinput = str(input())
listofnumbers = []
totalsum = 0
listofnumbers = numberinput.split(' ')
listofnumbers = list(map(int, listofnumbers))
listofnumbers.sort()
timestorun = int(len(listofnumbers)) / 2
for i in range(int(timestorun)):
	groupone = listofnumbers[i]
	grouponetwo = listofnumbers[len(listofnumbers) - 1 - i]
	totalsum = totalsum + (int(grouponetwo) + int(groupone)) ** 2
print(totalsum)


n = int(input())
a = [*map(int, input().split())]
a.sort()
i = 0
ans = 0
while i < n:
	ans += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1])
	i += 1
ans = int(ans / 2)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
x = 0
for i in range(n // 2):
	x += pow(l[i] + l[~i], 2)
print(x)


n = int(input())
k = list(map(int, input().strip().split()[:n]))
k.sort()
s = 0
for x in range(0, len(k) // 2):
	s += (k[x] + k[len(k) - x - 1]) ** 2
print(s)


a = int(input())
b = input().split()
c = list()
for i in b:
	c.append(int(i))
c.sort()
total = 0
for i in range(int(a / 2)):
	tmp = c[i] + c[a - 1 - i]
	total += pow(tmp, 2)
print(total)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
answer = 0
for i in range(n // 2):
	answer = answer + (arr[i] + arr[-(i + 1)]) ** 2
print(answer)


n = int(input())
np = [*map(int, input().split())]
np.sort()
ans = 0
for i in range(n // 2):
	ans += (np[i] + np[-(i + 1)]) ** 2
print(ans)


n = int(input())
arr = input()
arr = arr.split()
arr = [int(i) for i in arr]
count = 0
arr = sorted(arr)
for i in range(int(n / 2)):
	count += (arr[i] + arr[n - 1 - i]) ** 2
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n // 2):
	temp = (a[i] + a[n - i - 1]) ** 2
	ans += temp
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l = sorted(l)
ans = 0
for i in range(n // 2):
	ans = ans + (l[i] + l[n - i - 1]) * (l[i] + l[n - i - 1])
print(ans)


n = input()
A = [int(x) for x in input().split()]
A.sort()
s = 0
e = len(A) - 1
t = 0
for i in range(len(A) // 2):
	t += (A[s] + A[e]) ** 2
	s += 1
	e -= 1
print(t)


(n, ls, s) = (int(input()), sorted(list(map(int, input().split()))), 0)
for i in range(n // 2):
	s += (ls[i] + ls[n - i - 1]) ** 2
print(s)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest

def binNumber(n, size):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())
n = ini()
a = iar()
a.sort()
i = 0
j = n - 1
s = 0
while i < j:
	s += (a[i] + a[j]) * (a[i] + a[j])
	i += 1
	j -= 1
print(s)


n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
l1 = l[:n // 2]
l2 = l[n // 2:]
sums = 0
for i in range(n // 2):
	sums += (l1[i] + l2[-(i + 1)]) ** 2
print(sums)


n = int(input())
a = list(map(int, input().split()))
t = sorted(a)
s = 0
for i in range(n // 2):
	x = t[i] + t[n - 1 - i]
	s = s + x ** 2
print(s)


t = int(input(''))
ans = 0
a = list(map(int, input().split()))
a.sort()
for i in range(t // 2):
	ans += (a[i] + a[-1 * (i + 1)]) ** 2
print(ans)


n = int(input())
array = list(map(int, input().split()))
count = 0
array.sort()
for i in range(n // 2):
	count += (array[i] + array[n - i - 1]) ** 2
print(count)


n = int(input())
a = [int(s) for s in input().split()]
a.sort()
sum = 0
L = a[:len(a) // 2]
R = a[len(a) // 2:]
R.sort(reverse=True)
for i in range(len(L)):
	sum += (L[i] + R[i]) ** 2
print(sum)


n = int(input())
x = list(map(int, input().split()))
x.sort()
sum = 0
for i in range(n // 2):
	sum += (x[i] + x[n - i - 1]) ** 2
print(sum)


n = int(input())
a = [int(i) for i in input().split(' ')]
r = 0
a.sort()
for i in range(n // 2):
	r += (a[i] + a[n - i - 1]) ** 2
print(r)


n = int(input())
L = sorted(list(map(int, input().split())))
suma = 0
for k in range(n // 2):
	suma += (L[k] + L[-1 - k]) ** 2
print(suma)


def sol():
	n = int(input())
	A = [int(i) for i in input().split()]
	A.sort()
	(i, j) = (0, n - 1)
	ans = 0
	while i < j:
		ans += (A[i] + A[j]) ** 2
		i += 1
		j -= 1
	print(ans)
sol()


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
count = defaultdict(lambda : 0)
for i in arr:
	count[i] += 1
x = len(arr)
start = 0
end = len(arr) - 1
sum = 0
for i in range(x // 2):
	a = arr[start]
	b = arr[end]
	sum += (a + b) ** 2
	start += 1
	end -= 1
print(sum)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
print(sum(((x + y) ** 2 for (x, y) in zip(a[:n // 2], a[:n // 2 - 1:-1]))))


import math
n = int(input())
l = sorted(list(map(int, input().split())))
sum = 0
for i in range(n // 2):
	sum += math.pow(l[i] + l[n - i - 1], 2)
print(int(sum))


n = int(input())
a = list(map(int, input().split()))
a.sort()
k = n // 2
p = 0
i = 0
while i < k:
	p = p + (a[i] + a[n - 1 - i]) ** 2
	i += 1
print(p)


import sys
for n in sys.stdin:
	n = int(n)
	ar = list(map(int, input().split(' ')))
	ar.sort()
	tot = 0
	for i in range(0, n // 2):
		tot += (ar[i] + ar[-1 * i - 1]) ** 2
	print(tot)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = 0
for _ in range(n // 2):
	s += (a[_] + a[n - _ - 1]) ** 2
print(s)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
n = get_int()
lst = sorted(get_int_list())
s = 0
for i in range(n // 2):
	s += (lst[i] + lst[~i]) ** 2
print(s)


from collections import deque
import pdb
import heapq
from heapq import *
from pprint import pprint

def rI():
	return [int(i) for i in input().split()]
n = rI()[0]
dat = rI()
dat.sort()
s = 0
for i in range(n // 2):
	s += (dat[i] + dat[i * -1 - 1]) ** 2
print(s)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
i = 0
j = n - 1
k = 1
ans = 0
while i < j:
	ans += (arr[i] + arr[j]) ** 2
	i += 1
	j -= 1
print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
a.sort()
s = 0
i = 0
while i < n // 2:
	s = s + (a[i] + a[n - i - 1]) ** 2
	i = i + 1
print(s)


x = int(input())
ar = sorted(map(int, input().split(' ')))
ans = 0
for i in range(x // 2):
	ans += (ar[i] + ar[-1 - i]) * (ar[i] + ar[-1 - i])
print(ans)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = 0
	for i in range(int(n / 2)):
		ans += (a[i] + a[n - 1 - i]) ** 2
	print(f'{ans}')
main()


n = int(input())
nums = sorted(list(map(int, input().split())))
ans = 0
for i in range(n // 2):
	ans += (nums[i] + nums[-i - 1]) ** 2
print(ans)


x = int(input())
l = list(map(int, input().split()))
l.sort()
a = l[:x // 2]
b = l[x // 2:][::-1]
s = 0
for i in range(len(a)):
	s = s + (a[i] + b[i]) ** 2
print(s)


n = int(input())
s = list(map(int, input().split()))
s.sort()
m = list(reversed(s))
sum = 0
for i in range(n // 2):
	sum += (s[i] + m[i]) ** 2
print(sum)


n = int(input())
c = list(map(int, input().split()))
cum = 0
c = sorted(c)
for i in range(n // 2):
	a = c[i]
	b = c[-i - 1]
	cum += (a + b) ** 2
print(cum)


n = int(input())
x = sorted(list(map(int, input().split())))
(ans, cur) = (0, 0)
for i in range(n // 2):
	cur += x[i]
	cur += x[-(i + 1)]
	ans += cur ** 2
	cur = 0
print(ans)


import math
n = int(input())
list = [int(i) for i in input().split()]
list.sort()
sum = 0
for i in range(int(n / 2)):
	sum += math.pow(list[i] + list[n - 1 - i], 2)
print(int(sum))


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
a.sort()
for i in range(n // 2):
	sm = a[i] + a[n - i - 1]
	ans += sm ** 2
print(ans)


n = int(input())
alist = list(map(int, input().split()))
alist.sort()
l = len(alist)
ll = l // 2
blist = [0] * ll
for i in range(ll):
	a = alist[i] + alist[l - i - 1]
	blist[i] = a ** 2
asum = 0
for i in blist:
	asum = asum + i
print(asum)


n = int(input())
s = list(map(int, input().split()))
s.sort()
summ = 0
for i in range(n // 2):
	summ = summ + (int(s[i]) + int(s[n - 1 - i])) ** 2
print(summ)


n = int(input())
lis = sorted(map(int, input().split()))
ans = 0
for i in range(n // 2):
	ans += (lis[i] + lis[-(i + 1)]) ** 2
print(ans)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
sum_ = 0
for i in range(n // 2):
	sum_ += (a[i] + a[~i]) ** 2
print(sum_)


n = int(input())
a = sorted(list(map(int, input().split(' '))), reverse=True)
ans = []
for i in range(n):
	ans.append(a[i] + a[n - 1 - i])
print(sum([x * x for x in ans]) // 2)


x = int(input())
p = list(sorted(map(int, input().split())))
k = [(p[i] + p[x - i - 1]) ** 2 for i in range(x // 2)]
print(sum(k))


n = int(input())
b = list(map(int, input().split()))
b.sort()
c = 0
for i in range(n // 2):
	c += (b[i] + b[-i - 1]) ** 2
print(c)


n = int(input())
l = list(map(int, input().split()))
l.sort()
x = n // 2
s = 0
i = 0
while i < x:
	r1 = l[i]
	k = n - i - 1
	r2 = l[k]
	m = r1 + r2
	m = pow(m, 2)
	s += m
	i += 1
print(s)


n = int(input())
a = sorted(map(int, input().split()))
print(sum(((x + y) ** 2 for (x, y) in zip(a[:n // 2], a[::-1]))))


n = int(input())
a = n // 2
sum = 0
arr = list(map(int, input().split()))
arr.sort()
arr2 = list(reversed(arr))
for i in range(a):
	sum += (arr[i] + arr2[i]) ** 2
print(sum)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
n = iread()
arr = sorted(viread())
ans = 0
for i in range(n // 2):
	ans += (arr[i] + arr[-(i + 1)]) ** 2
print(ans)


n = int(input())
a = [int(q) for q in input().strip().split()]
a.sort()
sum = 0
for k in range(int(n / 2)):
	sum += (a[k] + a[n - 1 - k]) ** 2
if n % 2 == 1:
	p = int(n / 2)
	sum -= (a[p - 1] + a[p + 1]) ** 2
	sum += (a[p - 1] + a[p + 1] + a[p]) ** 2
print(sum)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
res = 0
for i in range(0, n // 2):
	res += (arr[i] + arr[n - i - 1]) ** 2
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum(map(lambda x: sum(x) ** 2, zip(a[:n // 2], a[-1:n // 2 - 1:-1]))))


import math

def main_function():
	input()
	b = sorted([int(i) for i in input().split(' ')])
	s = 0
	for i in range(len(b) // 2):
		s += (b[i] + b[-(i + 1)]) ** 2
	return s
print(main_function())


n = int(input())
li = [int(x) for x in input().split()]
li.sort()
i = 0
sum = 0
while i < n // 2:
	sum += pow(li[i] + li[n - i - 1], 2)
	i = i + 1
print(sum)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
res = 0
pair = []
for i in range(n // 2):
	pair.append((arr[i], arr[n - i - 1]))
for el in pair:
	res += (el[0] + el[1]) ** 2
print(res)


import random

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
random.shuffle(a)
a = sorted(a)
ans = 0
for i in range(n // 2):
	ans += pow(a[i] + a[n - i - 1], 2)
print(ans)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)
s = 0
while n:
	x = a.popleft()
	y = a.pop()
	s += (x + y) ** 2
	n -= 2
print(s)


n = int(input())
a = list(map(int, input().split()))
a.sort()
j = n - 1
s = 0
for i in range(n // 2):
	s += (a[i] + a[j]) ** 2
	j -= 1
print(s)


n = int(input())
x = list(input().split())
for i in range(n):
	x[i] = int(x[i])
x.sort()
y = x[::-1]
ans = 0
for i in range(int(n / 2)):
	ans += (x[i] + y[i]) ** 2
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ret = 0
	for i in range(n // 2):
		ret += (a[i] + a[n - i - 1]) ** 2
	print(ret)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = sorted(list(map(int, input().split())))
ans = sum([(a[i] + a[n - 1 - i]) ** 2 for i in range(n) if i < n - 1 - i])
print(ans)


input()
s = input().split()
for i in range(len(s)):
	s[i] = int(s[i])
s.sort()
summ = 0
for i in range(len(s)):
	summ += (s[i] + s[-i - 1]) ** 2
print(summ // 2)


n = int(input())
arr = [int(j) for j in input().split(' ')]
arr.sort()
sum = 0
for j in range(n // 2):
	sum += (arr[j] + arr[n - j - 1]) ** 2
print(sum)


n = int(input())
a = sorted([int(x) for x in input().split()])
k = 0
x = 0
l = []
q = []
for i in range(n):
	k = a[i] + a[n - i - 1]
	l.append(k)
m = list(l[0:len(l) // 2])
for j in m:
	x = j * j
	q.append(x)
print(sum(q))


input()
a = sorted(map(int, input().split()))
print(sum(map(lambda x: sum(x) ** 2, zip(a, a[::-1]))) // 2)


n = int(input())
s = input()
l = list(map(int, s.split(' ')))
l.sort()
count = 0
p = n // 2
for i in range(n // 2, n):
	count = (l[i] + l[p - 1]) ** 2 + count
	p = p - 1
print(count)


n = int(input())
l1 = [int(x) for x in input().split()]
l1.sort()
l2 = l1.copy()
l2.reverse()
top = n // 2
ans = 0
for x in range(top):
	ans += (l2[x] + l1[x]) ** 2
print(ans)


n = int(input())
seq = input().split(' ')
seq = [int(element) for element in seq]
seq.sort()
seq1 = seq[:n // 2]
seq2 = sorted(seq[n // 2:], reverse=True)
sum = 0
for i in range(n // 2):
	sum += (seq1[i] + seq2[i]) ** 2
print(sum)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for (x, y) in zip(a[:n // 2], a[::-1]):
	ans += (x + y) ** 2
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
l = [(l[i] + l[-i - 1]) ** 2 for i in range(n // 2)]
print(sum(l))


n = int(input())
l = list(map(int, input().split()))
l.sort()
f = 0
b = n - 1
s = 0
while b > f:
	x = l[f] + l[b]
	s = s + x * x
	b -= 1
	f += 1
print(s)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
a = ai()
a.sort()
i = 0
j = n - 1
x = 0
while i < j:
	x += (a[i] + a[j]) ** 2
	i += 1
	j -= 1
print(x)


def func(i, j):
	return i < j

def rangeSort(arr, l, r, func):
	if r - l <= 1:
		return
	mid = l + r >> 1
	rangeSort(arr, l, mid, func)
	rangeSort(arr, mid, r, func)
	aux = [0] * (r - l)
	(ptl, ptr) = (l, mid)
	for i in range(len(aux)):
		if ptr == r or (ptl < mid and func(arr[ptl], arr[ptr])):
			aux[i] = arr[ptl]
			ptl = ptl + 1
		else:
			aux[i] = arr[ptr]
			ptr = ptr + 1
	for i in range(len(aux)):
		arr[l + i] = aux[i]
n = int(input())
a = [int(x) for x in input().split()]
rangeSort(a, 0, len(a), func)
ans = 0
for i in range(n >> 1):
	ans = ans + (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1])
print(ans)


n = int(input())
x = sorted(list(map(int, input().split())))
a = x[0:int(n // 2)]
b = x[int(n // 2):n]
b.sort()
b.reverse()
s = 0
for i in range(0, int(n // 2)):
	p = a[i] + b[i]
	s += p ** 2
print(s)


num_of_ele = int(input())
arr = sorted(list(map(int, input().split(' '))))
arrLen = len(arr)
i = 0
tot = 0
while i < arrLen // 2:
	tot += (arr[i] + arr[arrLen - i - 1]) ** 2
	i += 1
print(tot)


inp = int(input())
l = sorted(list(map(int, input().split())))
i = 0
sum = 0
while i < inp // 2:
	sum += pow(l[i] + l[-(i + 1)], 2)
	i += 1
print(sum)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s.sort()
x = 0
for i in range(n // 2):
	x += (s[i] + s[n - i - 1]) ** 2
print(x)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
s = 0
n1 = int(n / 2)
for i in range(0, n1):
	k = l[i] + l[n - i - 1]
	s = s + pow(k, 2)
print(s)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
end = int(n / 2)
for x in range(end):
	new = (a[x] + a[-(x + 1)]) ** 2
	ans += new
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
add = 0
for i in range(n // 2):
	add += (arr[i] + arr[n - 1 - i]) ** 2
print(add)


def main():
	n = int(input())
	nums = list(map(int, input().split()))
	nums.sort()
	i = 0
	j = n - 1
	total = 0
	while i < j:
		s = nums[i]
		s += nums[j]
		i += 1
		j -= 1
		total += s ** 2
	print(total)
main()


n = int(input())
a = input().split()
b = [0] * (n + 1)
answer = [0] * (n + 1)
for i in range(n):
	b[i + 1] = int(a[i])
sort_list = sorted(b)
answer = 0
for i in range(1, n // 2 + 1):
	tmp = sort_list[i] + sort_list[n - i + 1]
	answer = answer + tmp * tmp
print(answer)


input()
X = list(map(int, input().split()))
SUM = 0
X = sorted(X)
for i in range(int(len(X) / 2)):
	SUM += (X[i] + X[-i - 1]) ** 2
print(SUM)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
s = 0
for i in range(0, n // 2):
	s += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1])
print(s)


import math
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
result = 0
for i in range(n // 2):
	result += (a[i] + a[n - i - 1]) ** 2
print(result)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = l[:n // 2]
l2 = l[n // 2:][::-1]
c = 0
for i in range(len(l1)):
	c += (l1[i] + l2[i]) ** 2
print(c)


def f(l):
	l.sort()
	n = len(l)
	return sum([(l[i] + l[n - 1 - i]) ** 2 for i in range(n // 2)])
_ = input()
l = list(map(int, input().split()))
print(f(l))


from sys import stdin, stdout
from collections import defaultdict, Counter
from bisect import bisect, bisect_left
import math
from itertools import permutations
I = stdin.readline
n = int(I())
arr = list(map(int, I().split()))
arr.sort()
ans = 0
for i in range(1, n // 2 + 1):
	ans += (arr[i - 1] + arr[-i]) ** 2
print(ans)


n = int(input().lstrip())
a = sorted(map(int, input().lstrip().split(' ')))
res = 0
for i in range(n // 2):
	group_sum = a[i] + a[n - i - 1]
	res += group_sum * group_sum
print(res)


n = int(input())
a = list(map(int, input().split()))
m = n // 2
a.sort()
b = [i + j for (i, j) in zip(a, a[::-1])]
c = [i ** 2 for i in b[:m]]
print(sum(c))


n = int(input())
s = str(input())
help_list = s.split()
i = 0
while i < n:
	help_list[i] = int(help_list[i])
	i += 1
help_list.sort()
result = 0
i = 0
while i < n / 2:
	result += (help_list[i] + help_list[n - 1 - i]) ** 2
	i += 1
print(result)


R = lambda : map(int, input().split())
n = int(input())
arr = sorted(R())
l = 0
r = n - 1
ans = 0
while l <= r:
	ans += (arr[l] + arr[r]) ** 2
	l += 1
	r -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
num = 0
for i in range(n // 2):
	num += (a[i] + a[n - i - 1]) ** 2
print(num)


from math import *
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
l2 = sorted(l)
n1 = int(n / 2)
li = []
for i in range(n1):
	li.append(pow(l[i] + l2[i], 2))
ab = sum(li)
print(int(ab))


n = int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort()
s = 0
for i in range(n // 2):
	p = lst[i] + lst[n - i - 1]
	s += p * p
print(s)


def ii():
	return int(input())

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
a = ii()
s = si()
s.sort()
ans = 0
for i in range(a // 2):
	ans += (s[i] + s[a - i - 1]) ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
c = 0
for i in range(n // 2):
	c += (l[i] + l[-1 - i]) ** 2
print(c)


n = int(input())
a = sorted(list(map(int, input().split())))
if n % 2 == 0:
	a1 = a[0:n // 2]
	a2 = a[n // 2:][::-1]
	a = [(a1[i] + a2[i]) ** 2 for i in range(n // 2)]
	print(sum(a))
elif n % 2 != 0:
	b = a
	l = a[n // 2]
	a = a[n // 2 + 1:] + a[:n // 2]
	a1 = a[0:n // 2]
	a2 = a[n // 2:][::-1]
	a = [a1[i] + a2[i] for i in range(n // 2)]
	a[a.index(min(a))] = min(a) + l
	a = [item ** 2 for item in a]
	print(sum(a))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
l.sort()
ans = 0
for i in range(n // 2):
	ans += l[i] ** 2 + l[n - i - 1] ** 2 + 2 * (l[i] * l[n - i - 1])
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
a.sort()
r = 0
for i in range(n // 2):
	s = a[i] + a[n - i - 1]
	r += s * s
print(r)


a = int(input())
b = sorted(list(map(int, input().split())))
print(sum(((b[i] + b[-i - 1]) ** 2 for i in range(a // 2))))


import math
n = int(input())
s = input()
li = s.split()
arr = []
for i in range(n):
	arr.append(eval(li[i]))
arr.sort()
i = 0
temp = []
for i in range(n // 2):
	temp.append(arr[i] + arr[n - i - 1])
if n % 2 != 0:
	temp[len(temp) - 1] += arr[n // 2]
sum = 0
for i in range(len(temp)):
	temp[i] = math.pow(temp[i], 2)
	sum += temp[i]
sum = int(sum)
print(sum)


n = int(input())
if n == 0:
	print(0)
else:
	numbers = [int(i) for i in input().split(' ')]
	numbers.sort()
	result = 0
	for i in range(0, n // 2):
		result += (numbers[i] + numbers[n - i - 1]) ** 2
	print(result)


import sys
n = int(input())
l = list(map(int, input().split()))
co = 0
l.sort()
for i in range(int(len(l) / 2)):
	co += (l[i] + l[n - 1 - i]) ** 2
print(co)


n = int(input())
li = list(map(int, input().split()))
li.sort()
s = 0
for i in range(len(li) // 2):
	s += (li[i] + li[-i - 1]) ** 2
print(s)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
answer = 0
for i in range(len(a) // 2):
	answer += (a[i] + a[-i - 1]) * (a[i] + a[-i - 1])
print(answer)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
s = 0
for i in range(0, n // 2):
	k = a[i] + a[n - i - 1]
	s = s + pow(k, 2)
print(s)


n = int(input())
s = sorted(list(map(int, input().split())))
sums_square = 0
for i in range(n // 2):
	k = s[i] + s[n - i - 1]
	sums_square += k * k
print(sums_square)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
print(sum(((a + b) ** 2 for (a, b) in zip(arr, arr[::-1]))) // 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum((int((a[i] + a[-(i + 1)]) ** 2) for i in range(int(n / 2)))))


def inpl():
	return list(map(int, input().split()))
N = int(input())
A = inpl()
A.sort()
print(sum([(i + j) ** 2 for (i, j) in zip(A[:N // 2], A[::-1][:N // 2])]))


n = int(input())
T = [int(x) for x in input().split()]
T.sort()
s = 0
for (x, y) in zip(T, reversed(T)):
	s += x * (x + y)
print(s)


i_liczb = int(input())
liczby = [int(x) for x in input().split()]
liczby.sort()
suma = 0
for x in range(i_liczb // 2):
	suma += (liczby[x] + liczby[i_liczb - 1 - x]) ** 2
print(suma)


n = int(input())
arr = sorted(list(map(int, input().split())))
summ = sum([(arr[i] + arr[n - i - 1]) ** 2 for i in range(n // 2)])
print(summ)


n = int(input())
l = [*map(int, input().split())]
l.sort()
(i, j) = (0, n - 1)
res = 0
while i <= j:
	res += (l[i] + l[j]) ** 2
	i += 1
	j -= 1
print(res)


n = int(input())
data = list(map(int, input().split()))
data.sort()
nd = 0
for i in range(n // 2):
	nd += (data[i] + data[n - i - 1]) * (data[i] + data[n - i - 1])
print(nd)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
s = 0
while i < j:
	s = s + (l[i] + l[j]) ** 2
	i = i + 1
	j = j - 1
print(s)


k = eval(input())
x = list(map(int, input().split()))
m = k // 2
x = sorted(x)
i = 0
j = len(x) - 1
sum = 0
while i < len(x) // 2:
	sum = sum + (x[i] + x[j]) ** 2
	i += 1
	j -= 1
print(sum)


n = int(input())
s = 0
count = 0
ar = sorted(list(map(int, input().split())))
for i in range(n // 2):
	count += ar[i] + ar[n - i - 1]
	s += count * count
	count = 0
print(s)


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	n = int(input())
	a = sorted(map(int, input().split()))
	s = 0
	for (i, j) in zip(a[:n // 2], a[n // 2:][::-1]):
		s += (i + j) ** 2
	print(s)
sync_with_stdio(False)
main()


n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
s = 0
for i in range(n // 2):
	a = arr[i]
	b = arr[n - i - 1]
	s += (a + b) ** 2
print(s)


n = int(input())
M = list(map(int, input().split()))
M.sort()
cnt = 0
for j in range(0, n // 2):
	cnt += (M[j] + M[-j - 1]) ** 2
print(cnt)


nb_elements = int(input())
elements = sorted([int(x) for x in input().split()])
a = elements[:nb_elements // 2]
b = elements[nb_elements // 2:][::-1]
ans = sum([(x + y) ** 2 for (x, y) in zip(a, b)])
print(ans)


n = int(input())
arr = sorted(list(map(int, input().split())))
ans = 0
for i in range(n // 2):
	ans += pow(arr[i] + arr[n - i - 1], 2)
print(ans)


n = int(input())
entrada = input()
numbers = [int(x) for x in entrada.split()]
numbers.sort()
num_sum = sum(numbers)
suma = 0
for i in range(int(n / 2)):
	suma += (numbers[i] + numbers[n - i - 1]) ** 2
print(suma)


n = int(input())
a = [int(x) for x in input().strip().split()]
a = sorted(a)
(l, r) = (0, len(a) - 1)
s = 0
while l < r:
	s += (a[l] + a[r]) ** 2
	l += 1
	r -= 1
print(s)


for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	a = 0
	for i in range(n // 2):
		a += (arr[i] + arr[n - 1 - i]) ** 2
	print(a)


n = int(input())
s = input().split(' ')
s = [int(i) for i in s]
s.sort()
ans = 0
n1 = n
n = n // 2
for i in range(n):
	ans += (s[i] + s[n1 - i - 1]) * (s[i] + s[n1 - i - 1])
print(ans)


n = int(input())
s = input().split()
s = list(s)
for i in range(n):
	s[i] = int(s[i])
s.sort()
sum = 0
for i in range(n // 2):
	sum += (s[i] + s[n - 1 - i]) ** 2
print(sum)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
i = 0
j = n - 1
sum = 0
while 1:
	sum = sum + (a[i] + a[j]) ** 2
	i = i + 1
	if i == j:
		break
	j = j - 1
	if i == j:
		break
print(sum)


n = int(input())
v = list(map(int, input().split()))
v.sort()
ans = 0
promej = []
if n % 2 == 0:
	for i in range(n // 2):
		promej.append(v[i] + v[n - i - 1])
else:
	for i in range(n // 2):
		promej.append(v[i] + v[n - i - 1])
	promej.append(v[n // 2 + 1])
for i in range(len(promej)):
	ans += promej[i] * promej[i]
print(ans)


n = int(input())
stri = input()
a = [int(indiv) for indiv in stri.split()]
a.sort()
b = []
c = []
for i in range(0, int(n / 2)):
	b.append(a[i])
i = n - 1
while i >= n / 2:
	c.append(a[i])
	i -= 1
i = 0
sum = []
while i < len(b):
	sum.append(b[i] + c[i])
	i += 1
total = 0
for ele in sum:
	total += ele ** 2
print(total)


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
if n == 2:
	val = sum(arr)
	print(val * val)
else:
	arrx = []
	for i in range(n // 2):
		arrx.append(arr[i])
	j = n // 2
	j -= 1
	for i in range(n // 2, n):
		arrx[j] += arr[i]
		j -= 1
	ans = 0
	for i in range(len(arrx)):
		ans += arrx[i] * arrx[i]
	print(ans)


def min_of_sum_of_group_squares(nums):
	nums.sort()
	n = len(nums)
	ssum = 0
	for i in range(n // 2):
		si = nums[i] + nums[n - i - 1]
		ssum += si * si
	return ssum
n = int(input().strip())
nums = [int(s) for s in input().strip().split()]
result = min_of_sum_of_group_squares(nums)
print(result)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
sum = 0
for i in range(n // 2):
	sum = sum + pow(a[i] + a[n - 1 - i], 2)
print(sum)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
ss = 0
for i in range(int(len(l1) / 2)):
	sum1 = l1[i] + l1[len(l1) - 1 - i]
	ss += sum1 ** 2
print(ss)


input()
as_ = sorted(map(int, input().split()))
print(sum(((a + b) ** 2 for (a, b) in zip(as_[:], as_[::-1]))) // 2)


n = int(input())
sp = list(map(int, input().split()))
sp.sort()
reversed(sp)
ot = 0
i = n - 1
k = 0
while k < i:
	ot += (sp[k] + sp[i]) ** 2
	i -= 1
	k += 1
print(ot)


n = input()
n = int(n)
arr = []
arr = list(map(int, input().strip().split()))
arr.sort()
j = n - 2
i = 1
square_sum = []
square_sum.insert(0, pow(arr[0] + arr[n - 1], 2))
while j > i:
	square_sum.append(pow(arr[i] + arr[j], 2) + square_sum[i - 1])
	i = i + 1
	j = j - 1
print(square_sum[len(square_sum) - 1])


n = int(input())
a = list(map(int, input().split()))
a.sort()
sum = 0
for i in range(len(a)):
	if i == n // 2:
		break
	sum += (a[i] + a[n - 1 - i]) ** 2
print(sum)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
ans = 0
for i in range(n // 2):
	ans += (a[i] + a[n - 1 - i]) ** 2
print(ans)


f = lambda : map(int, input().split())
n = int(input())
a = list(f())
a.sort()
sum = 0
for i in range(n // 2):
	sum += (a[i] + a[-1 - i]) ** 2
print(sum)


n = int(input())
li = list(map(int, input().split()))
li.sort()
su = 0
for i in range(0, n // 2):
	su += (li[i] + li[n - 1 - i]) ** 2
print(su)


def razdelenie(lst):
	result = 0
	for i in range(len(lst) // 2):
		if len(lst) - i - 1 < len(lst):
			result += (lst[i] + lst[len(lst) - i - 1]) * (lst[i] + lst[len(lst) - i - 1])
	return result
n = int(input())
a = [int(j) for j in input().split()]
print(razdelenie(sorted(a)))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = sorted(LI())
	r = 0
	for i in range(n // 2):
		r += pow(a[i] + a[-1 - i], 2)
	return r
print(main())


numberOfNums = int(input())
numbers = list(map(int, input().split()))
numbers.sort()
total = 0
for x in range(numberOfNums // 2):
	total = total + (numbers[x] + numbers[numberOfNums - 1 - x]) ** 2
print(total)


x = int(input())
a = list(map(int, input().split()))
a.sort()
k = 0
t = 0
if len(a) % 2 == 0:
	for i in range(x // 2):
		t = a[i] + a[x - i - 1]
		r = t * t
		k = k + r
	print(k)
elif len(a) % 2 == 1:
	r = []
	for i in range(x // 2):
		t = a[i] + a[x - i - 1]
		r.append(t)
	k = min(t)
	c = k.index(k)
	t[c] = t[c] + k
	r = 0
	for i in range(len(t)):
		k = t[i] * t[i]
		r = r + k
	print(r)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = ri()
a.sort()
ans = 0
for i in range(n // 2):
	ans += (a[i] + a[n - i - 1]) ** 2
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
min_sum = 0
i = 0
j = n - 1
while i <= j:
	if i == j:
		min_sum += a[j]
	else:
		min_sum += (a[i] + a[j]) ** 2
	i += 1
	j -= 1
print(min_sum)


n = int(input())
M = list(map(int, input().split()))
M.sort()
i = 0
n = n - 1
s = 0
while i < n:
	s += (M[i] + M[n]) ** 2
	i += 1
	n -= 1
print(s)


n = int(input())
L = sorted(map(int, input().split()))
(i, j) = (0, n - 1)
res = 0
while i < j:
	res += (L[i] + L[j]) ** 2
	i += 1
	j -= 1
print(res)


from sys import stdin, stdout

def inp():
	return stdin.readline()

def minp():
	return map(int, stdin.readline().rstrip().split())

def linp():
	return list(minp())

def main():
	n = int(inp())
	lst = linp()
	lst.sort()
	s = 0
	for i in range(int(n / 2)):
		s += (lst[n - i - 1] + lst[i]) ** 2
	print(s)

def __starting_point():
	main()
__starting_point()


nn = int(input())
l = list(map(int, input().split()))
l.sort()
a = 0
for i in range(nn // 2):
	a += (l[i] + l[nn - 1 - i]) ** 2
print(a)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
i = 0
j = n - 1
while i < j:
	ans = ans + (l[i] + l[j]) * (l[i] + l[j])
	i = i + 1
	j = j - 1
print(ans)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
if n & 1:
	sum = int(0)
	for i in range(0, n // 2 - 1):
		sum += (l[i] + l[n - i - 1]) ** 2
	sum += (l[n // 2 - 1] + l[n // 2] + l[n // 2 + 1]) ** 2
else:
	sum = int(0)
	for i in range(0, n // 2):
		sum += (l[i] + l[n - i - 1]) ** 2
print(sum)


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 5)

def li():
	return map(int, stdin.readline().split())

def li_():
	return map(lambda x: int(x) - 1, stdin.readline().split())

def lf():
	return map(float, stdin.readline().split())

def ls():
	return stdin.readline().split()

def ns():
	return stdin.readline().rstrip()

def lc():
	return list(ns())

def ni():
	return int(stdin.readline())

def nf():
	return float(stdin.readline())
n = ni()
a = list(li())
a.sort()
fst = a[:n // 2]
scd = a[n // 2:][::-1]
ans = 0
for (fi, si) in zip(fst, scd):
	ans += (fi + si) ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
uk1 = 0
uk2 = n - 1
while uk1 < uk2:
	ans += (l[uk1] + l[uk2]) * (l[uk1] + l[uk2])
	uk1 += 1
	uk2 -= 1
print(ans)


n = int(input())
lis = list(map(int, input().split()))
lis.sort()
sums = 0
for i in range(0, int(n / 2)):
	a = lis[i]
	b = lis[n - 1 - i]
	sums = sums + (a + b) * (a + b)
print(sums)


n = int(input())
a = sorted([int(x) for x in input().split()])
new = []
m = n // 2
for i in range(m):
	new.append(a[i] + a[n - i - 1])
cnt = 0
for i in new:
	cnt += i * i
print(cnt)


n = int(input())
inList = list(map(int, input().split()))
inList.sort()
result = 0
for i in range(n // 2):
	result += (inList[i] + inList[n - (1 + i)]) ** 2
print(result)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr.sort()
total = 0
i = 0
j = n - 1
while i < j:
	total += (arr[i] + arr[j]) ** 2
	i += 1
	j -= 1
print(total)


nb = int(input())
l = list(map(int, input().split(' ')))
l.sort()
s = 0
for i in range(nb // 2):
	s += (l[i] + l[-(i + 1)]) ** 2
print(s)


n = int(input())
li = sorted(list(map(int, input().split())), reverse=True)
sum = 0
k = -1
for i in range(n // 2):
	sum += (li[i] + li[k]) ** 2
	k = -1 + k
print(sum)


n = int(input())
numbers = list(map(int, input().split()))
numbers.sort()
res = 0
l = 5
for i in range(n // 2):
	res += (numbers[i] + numbers[n - i - 1]) ** 2
print(res)


n = int(input())
lis = list(map(int, input().split()))
lis.sort()
total = 0
left = 0
right = len(lis) - 1
while left < right:
	total += (lis[left] + lis[right]) ** 2
	left += 1
	right -= 1
print(total)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	s = 0
	for i in range(n // 2):
		x = (a[i] + a[n - i - 1]) ** 2
		s += x
	print(s)
while TN != 0:
	solution()
	TN -= 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
l = 0
r = n - 1
while l < r:
	ans += (a[r] + a[l]) * (a[r] + a[l])
	r -= 1
	l += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = []
row = []
j = 0
for i in range(n // 2):
	row.append(a[i])
	row.append(a[n - i - 1])
	m.append(row)
	row = []
c = []
sum = 0
for i in range(n // 2):
	c.append(int(m[i][0]) + int(m[i][1]))
	sum += c[i] ** 2
print(sum)


import math
s = []
s1 = []
n = int(input())
s = input().split(' ')
for ele in s:
	s1.append(int(ele))
s1.sort()
s = []
i = 0
j = len(s1) - 1
while i < len(s1) / 2:
	s.append(s1[i] + s1[j])
	i += 1
	j -= 1
j = i = 0
while i < len(s):
	j += math.pow(s[i], 2)
	i += 1
print(int(j))


from sys import stdin

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	ans = 0
	n = N // 2
	for i in range(n):
		ans += (A[i] + A[-(i + 1)]) ** 2
	print(ans)
input = lambda : stdin.readline()
main()


from sys import stdin
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
arr.sort()
if n == 2:
	print(sum(arr) ** 2)
	exit()
m = n // 2
i = 0
s = 0
while i < m:
	s += (arr[i] + arr[n - 1 - i]) ** 2
	i += 1
print(s)


n = int(input())
numbers = list(map(int, input().split()))
numbers.sort()
import math
nb_groups = math.floor(n / 2)
groups = [[] for _ in range(nb_groups)]
for i in range(len(numbers)):
	if len(numbers) - 1 - i < i:
		break
	elif len(numbers) - 1 - i == i:
		groups[i % nb_groups].append(numbers[i])
	else:
		groups[i % nb_groups].append(numbers[i])
		groups[i % nb_groups].append(numbers[len(numbers) - 1 - i])
total = 0
for group in groups:
	total += sum(group) ** 2
print(total)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip('\n')
n = int(input())
l = get_array()
l.sort()
ans = 0
for i in range(n // 2):
	ans += (l[i] + l[-1 - i]) * (l[i] + l[-1 - i])
print(ans)


n = int(input(''))
num = list(map(int, input().split()))
num.sort()
sol = 0
for i in range(n):
	sol += (num[i] + num[n - i - 1]) ** 2
	if n - i - 1 - i == 1:
		break
print(sol)


def rlist():
	return list(map(int, input().split()))

def rdi():
	return int(input())
n = rdi()
line = sorted(rlist())
s = 0
for i in range(n // 2):
	s += (line[i] + line[n - i - 1]) ** 2
print(s)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = sorted(inl())
ans = 0
for i in range(n // 2):
	ans += (a[i] + a[-i - 1]) ** 2
print(ans)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline()
n = intIn()
a = listIn()
a = sorted(a)
m = 0
for i in range(n // 2):
	s = a[i] + a[n - i - 1]
	m += s * s
print(m)


d = int(input())
l = list(sorted(map(int, input().split())))
s = 0
if len(l) % 2 != 0:
	for i in range(int(d / 2)):
		s += (l[i] + l[-i]) ** 2
	s += l[int(len(l) / 2) + 1] ** 2
else:
	for i in range(int(d / 2)):
		s += (l[i] + l[-i - 1]) ** 2
print(s)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
A.sort()
A = deque(A)
Ans = 0
while A:
	x = A.pop()
	y = A.popleft()
	Ans += (x + y) ** 2
print(Ans)


import math
import collections
n = int(input())
l = sorted([int(i) for i in input().split()])
s = 0
for i in range(n // 2):
	s += (l[i] + l[n - 1 - i]) ** 2
print(s)


x = int(input())
array = [int(y) for y in input().split()]
array.sort()
sum = 0
for i in range(0, int(x / 2)):
	sum = sum + (array[i] + array[(i + 1) * -1]) ** 2
print(sum)


n = int(input())
X = [int(x) for x in input().split(' ')]
X.sort()
c = 0
for i in range(int(n / 2)):
	c = c + (X[i] + X[n - 1 - i]) ** 2
print(c)


def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n,) = read_nums()
	nums = sorted(read_nums())
	res = 0
	for i in range(n // 2):
		res += (nums[i] + nums[n - i - 1]) ** 2
	print(res)
main()


n = int(input())
arr = []
arr = list(map(int, input().split()))
arr.sort()
nim = int(n / 2)
ans = 0
for i in range(nim):
	ans += (arr[i] + arr[n - i - 1]) * (arr[i] + arr[n - i - 1])
print(ans)


z = input
lx = []
n = int(z())
l = sorted(list(map(int, z().split())))
s1 = l[:n // 2]
s2 = l[n // 2:][::-1]
c = 0
for (i, j) in zip(s1, s2):
	c += (i + j) ** 2
print(c)


a = int(input())
A = list(map(int, input().split()))
A.sort()
k = 0
for i in range(a // 2):
	k += (A[i] + A[-i - 1]) ** 2
print(k)


n = int(input())
p = input().rstrip().split(' ')
p.sort(key=int)
a = 0
t = 0
S = 0
D = 0
for i in range(0, n):
	if a == 0 and D == 0:
		D += 1
		a += 1
		t = t + int(p[i])
	elif a == 1 and D == 1:
		D = 0
		a = 0
		t = t + int(p[len(p) - i])
		S = S + t ** 2
		t = 0
print(S)


R = lambda : map(int, input().split())
a = int(input())
b = sorted(list(R()))
s = 0
for i in range(a // 2):
	s += (b[i] + b[a - 1 - i]) ** 2
print(s)


n = int(input())
s = input()
a = s.split(' ')
a = list(map(int, a))
a.sort()
out = list()
for i in range(int(n / 2)):
	s = int(a[i] + a[n - i - 1])
	out.append(s)
if n % 2 != 0:
	out[int(len(out) - 1)] = out[int(len(out) - 1)] + a[int(n / 2)]
output = 0
for i in range(len(out)):
	output = output + out[i] * out[i]
print(output)


n = int(input())
A = list(map(int, input().split()))
A.sort()
j = int(n / 2)
sum = 0
for i in range(j):
	sum += (A[i] + A[n - i - 1]) ** 2
print(sum)


import sys
import math
import bisect
import itertools
import random

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	ans = 0
	for i in range(n // 2):
		val = A[i] + A[n - 1 - i]
		ans += val ** 2
	print(ans)
main()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
tot = 0
for i in range(n // 2):
	sum = arr[i] + arr[-(i + 1)]
	tot += sum * sum
print(tot)


n = int(input())
l = [int(i) for i in input().split()]
sl = sorted(l)
j = n
s = 0
for i in range(0, n // 2):
	j = j - 1
	s = (sl[i] + sl[j]) * (sl[i] + sl[j]) + s
print(s)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
A.sort()
ANS = 0
for i in range(n // 2):
	ANS += (A[i] + A[-i - 1]) ** 2
print(ANS)


n = int(input())
m = list(map(int, input().split(' ')))
m = sorted(m)
s = 0
for l in range(n // 2):
	s += (m[l] + m[n - l - 1]) ** 2
print(s)
pass


n = int(input())
arr = input().split()
a = [0]
for each in arr:
	x = int(each)
	a.append(x)
a.sort()
cnt = 0
for i in range(1, int(n / 2) + 1):
	ans = a[i] + a[n - i + 1]
	cnt += ans ** 2
print(cnt)


list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)
n = int(input())
a = list_int_input(input())
a = sorted(a)
(i, j) = (0, len(a) - 1)
b = []
while i < j:
	b.append(a[i] + a[j])
	i += 1
	j -= 1
b = sorted(b)
if i == j:
	b[0] += a[i]
sqr = lambda x: x * x
print(sum(map(sqr, b)))


num = int(input())
arr = sorted(map(int, input().split()))
mid = num // 2
first_half = arr[:mid]
second_half = arr[mid:][::-1]
ans = 0
for (i, j) in zip(first_half, second_half):
	ans += (i + j) ** 2
print(ans)


import copy
import fractions
import itertools
import numbers
import string
import sys

def powmod(x, p, m):
	if p <= 0:
		return 1
	if p <= 1:
		return x % m
	return powmod(x * x % m, p // 2, m) * (x % m) ** (p % 2) % m

def to_basex(num, x):
	while num > 0:
		yield (num % x)
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d * p
		p *= x
	return ret

def core():
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	ans = 0
	for i in range(n // 2):
		ans += (a[i] + a[-1 - i]) ** 2
	print(ans)
core()


n = int(input())
l = [int(num) for num in input().split()]
sum1 = 0
l.sort(reverse=True)
for i in range(n // 2):
	sum1 = sum1 + (l[i] + l[n - 1 - i]) ** 2
print(sum1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	n = ri()
	a = ria()
	a = sorted(a)
	ans = sum([(a[i] + a[n - i - 1]) ** 2 for i in range(n // 2)])
	wi(ans)
main()


def ans(arr):
	arr.sort()
	arr1 = arr[0:n // 2]
	arr2 = arr[n // 2:n]
	arr2.reverse()
	cnt = 0
	for (i, j) in zip(arr1, arr2):
		cnt += (i + j) ** 2
	return cnt
n = int(input())
a = list(map(int, input().strip().split()))
print(ans(a))


n = int(input())
x = sorted(list(map(int, input().split(' '))))
(i, j, sum) = (0, n - 1, 0)
while i < j:
	sum += (x[i] + x[j]) ** 2
	i += 1
	j -= 1
print(sum)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
a1 = a[:n // 2]
a2 = a[n // 2:]
a2.sort()
zipped = zip(a1, a2)
total = 0
total = sum([(i[0] + i[1]) ** 2 for i in zipped])
print(total)


n = int(input())
d = list(map(int, input().split()))
d.sort()
i = ans = 0
while i < n // 2:
	ans += (d[i] + d[-1 - i]) * (d[i] + d[-1 - i])
	i += 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
sums = 0
for l in range(0, int(n / 2)):
	sums += (a[l] + a[n - l - 1]) * (a[l] + a[n - l - 1])
print(sums)


n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
sum = 0
(i, j) = (0, n - 1)
while i < j:
	sum += (l[i] + l[j]) ** 2
	i += 1
	j -= 1
print(sum)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
i = 0
s = 0
while i != n // 2:
	s += (arr[i] + arr[n - i - 1]) ** 2
	i += 1
print(s)


n = int(input())
m = [int(i) for i in input().split()]
cnt = 0
m.sort()
for i in range(n // 2):
	if n % 2 == 1 and i == n // 2 - 1:
		cnt += (m[i] + m[n - i - 1] + m[i + 1]) * (m[i] + m[n - i - 1] + m[i + 1])
	else:
		cnt += (m[i] + m[n - i - 1]) * (m[i] + m[n - i - 1])
print(cnt)


import math
import bisect as bis
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
res = 0
for i in range(n // 2):
	res += (a[i] + a[n - 1 - i]) * (a[i] + a[n - 1 - i])
print(res)


n = int(input())
a = sorted([int(x) for x in input().split()])
s = 0
if n % 2 == 0:
	for i in range(n // 2):
		s += (a[i] + a[n - i - 1]) ** 2
else:
	x = a[0]
	b = []
	for i in range(1, n // 2 + 1):
		b.append(a[i] + a[n - i])
	mn = 1000000
	for i in range(len(b)):
		if b[i] < mn:
			mn = b[i]
			key = i
	b[key] += x
	for c in b:
		s += c ** 2
print(s)


input()
A = list(map(int, input().split()))
A.sort()
an = 0
for i in range(len(A) // 2):
	an += (A[i] + A[len(A) - 1 - i]) ** 2
print(an)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort()
res = 0
for i in range(n // 2):
	res += (a[i] + a[-i - 1]) ** 2
print(res)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
i = 0
j = len(a) - 1
total = 0
while i < j:
	total += (a[i] + a[j]) ** 2
	j -= 1
	i += 1
print(total)


n = int(input())
k = sorted([int(i) for i in input('').split(' ')])
a = k[:len(k) // 2]
b = k[len(k) // 2:]
b.reverse()
s = 0
for (i, v) in enumerate(a):
	s += (a[i] + b[i]) * (a[i] + b[i])
print(s, end='')


n = int(input())
a = sorted([int(x) for x in input().split(' ')])
res = 0
mid = n // 2
for i in range(1, mid + 1):
	res += (a[i - 1] + a[-i]) ** 2
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = int(0)
i = int(0)
while i < n:
	s = s + (a[i] + a[n - 1]) * (a[i] + a[n - 1])
	i += 1
	n -= 1
print(s)


import sys
data = sys.stdin.read().splitlines()
n = int(data[0])
nums = list(map(int, data[1].split()))
nums.sort()
ans = 0
for i in range(n // 2):
	ans += (nums[i] + nums[n - 1 - i]) ** 2
print(ans)


n = int(input())
nums = sorted(map(int, input().split()))
ans = 0
i = 0
ln = len(nums)
while i < ln // 2:
	ans += (nums[i] + nums[ln - i - 1]) ** 2
	i += 1
print(ans)


n = int(input())
numbers = list(map(int, input().rstrip().split()))
numbers.sort()
total = 0
for i in range(n // 2):
	s = numbers[i] + numbers[-i - 1]
	total = total + s * s
print(total)


n = int(input())
arr = sorted(map(int, input().split()))
s = 0
for i in range(len(arr) // 2):
	s += (arr[i] + arr[-i - 1]) ** 2
print(s)


import sys

def read_matrix():
	for line in sys.stdin:
		line
	return sorted([int(x) for x in line.split(' ')])

def sol():
	data = read_matrix()
	s = 0
	for i in range(len(data) // 2):
		s += (data[i] + data[len(data) - (i + 1)]) ** 2
	return s
print(sol())


t = int(input())
li = [int(x) for x in input().split()]
li.sort()
res = 0
for i in range(t // 2):
	res += (li[i] + li[-1 - i]) * (li[i] + li[-1 - i])
print(res)


n = int(input())
L = list(map(int, input().split()))
L.sort()
L2 = L[:]
L.reverse()
L1 = L[:]
zbroj = 0
for i in range(n // 2):
	zbroj += (L2[i] + L1[i]) ** 2
print(zbroj)


a = int(input())
mas = input().split(' ')
for i in range(a):
	mas[i] = int(mas[i])
mas.sort()
mas_n = []
for i in range(int(a / 2)):
	mas_n.append((mas[i] + mas[a - 1 - i]) ** 2)
print(sum(mas_n))


num = int(input().strip())
nums = [int(i) for i in input().strip().split()]
(i, j) = (0, num - 1)
ans = 0
nums.sort()
while i < j:
	ans += (nums[i] + nums[j]) ** 2
	i += 1
	j -= 1
print(ans)


import math
import sys
from collections import *
from bisect import bisect_left, bisect_right

def cint():
	return list(map(int, sys.stdin.readline().strip().split()))

def cstr():
	return list(map(str, input().split(' ')))

def solve():
	n = int(input())
	lst = cint()
	lst.sort()
	ans = 0
	for i in range(n // 2):
		ans += int(math.pow(lst[i] + lst[n - i - 1], 2))
	print(ans)
t = 1
while t != 0:
	solve()
	t -= 1


n = int(input())
a = [int(a) for a in input().split()]
a.sort()
s = 0
p = -1
for i in range(n // 2):
	s += pow(a[i] + a[p], 2)
	p -= 1
print(s)


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
a.sort()
s = 0
for i in range(n // 2):
	s += (a[i] + a[n - 1 - i]) ** 2
print(s)


import math
import statistics
n = int(input())
v = list(map(int, input().split()))
v.sort()
res = 0
for i in range(int(n / 2)):
	res += pow(v[i] + v[n - i - 1], 2)
print(res)


n = input()
lst = sorted([int(i) for i in input().split()])
ss = 0
for i in range(0, len(lst) // 2):
	ss += (lst[i] + lst[-(i + 1)]) ** 2
print(ss)


n = int(input())
chisla = [int(i) for i in input().split()]
chisla.sort()
suma = 0
for i in range(int(chisla.__len__() / 2)):
	suma += (chisla[i] + chisla[-i - 1]) ** 2
print(suma)


t = int(input())
s = list(map(int, input().split()))
s.sort()
p = 0
for k in range(t // 2):
	p += (s[k] + s[-(1 + k)]) ** 2
print(p)


n = int(input())
sum1 = 0
sum2 = 0
list1 = [int(k) for k in input().split(' ')]
list1.sort()
for i in range(int(len(list1) / 2)):
	sum1 = int(list1[i]) + int(list1[len(list1) - i - 1])
	sum2 += sum1 * sum1
print(sum2)


n = int(input())
m = list(map(int, input().split()))
m = sorted(m)
k = 0
j = -1
i = 0
summ = 0
while i != n / 2:
	p = m[k] + m[j]
	p = p ** 2
	summ = summ + p
	j -= 1
	k += 1
	i += 1
print(summ)


t = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
j = t - 1
s = 0
while i <= t / 2 - 1 and j >= t / 2:
	s = s + (a[i] + a[j]) ** 2
	i += 1
	j -= 1
print(s)


n = int(input())
d = [*map(int, input().split())]
d.sort()
sum = 0
for i in range(n // 2):
	sum = sum + pow(d[i] + d[n - i - 1], 2)
print(sum)


import sys
import queue
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = 0
r = n - 1
sum = 0
while l < r:
	sum = sum + pow(a[l] + a[r], 2)
	l = l + 1
	r = r - 1
print(sum)


from math import pow
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
sum = 0
for i in range(n // 2):
	sum += pow(l[i] + l[n - i - 1], 2)
print(int(sum))


t = int(input())
a = list(map(int, input().split()))[:t]
a.sort()
s = 0
for i in range(len(a) // 2):
	s = s + (a[-i - 1] + a[i]) ** 2
print(s)


from collections import deque
n = int(input())
res = 0
N = deque(sorted(list(map(int, input().split()))))
while len(N) != 0:
	res += (N[0] + N[-1]) ** 2
	N.popleft()
	N.pop()
print(res)


n = int(input())
sq = [int(x) for x in input().split()]
sq.sort()
res = 0
for i in range(len(sq) // 2):
	res += (sq[i] + sq[-1 - i]) ** 2
print(res)


n = int(input())
g = n // 2
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)
print(sum(((nums[x] + nums[n - 1 - x]) ** 2 for x in range(g))))


def sumofsquares(arr1):
	res = 0
	arr1.sort()
	n = len(arr1)
	for i in range(n):
		res += (arr1[i] + arr1[n - i - 1]) ** 2
	return res // 2
n = int(input())
arr1 = list(map(int, input().split()))
print(sumofsquares(arr1))


n = int(input()) - 1
arr = sorted(map(int, input().strip().split()))
answer = 0
i = 0
while i < n:
	answer += (arr[i] + arr[n]) ** 2
	i += 1
	n -= 1
print(answer)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
num = 0
ans = 0
for i in range(n // 2):
	temp = ai[i] + ai[n - i - 1]
	ans += temp ** 2
	num = min(num, temp)
if n % 2:
	ans -= num
	ans += (num + ai[n // 2]) ** 2
print(ans)


from sys import stdin, stdout
Input = lambda : stdin.readline().strip()
Print = lambda text: stdout.write(str(text))
n = int(Input())
ans = 0
m = map(int, Input().split())
m = sorted(m)
for i in range(n // 2):
	ans += (m[i] + m[-(i + 1)]) ** 2
Print(ans)


import sys
import math
n = int(input())
alim = [int(x) for x in input().strip().split()]
rt = sorted(alim)
s = 0
for i in range(n // 2):
	(a, b) = (rt[i], rt[n - i - 1])
	s += (a + b) ** 2
if n & 1:
	s += rt[(n + 1) // 2 - 1] ** 2
print(s)


n = int(input())
a = input().split()
a = [int(i) for i in a]
a = sorted(a)
result = 0
for i in range(n // 2):
	result += (a[i] + a[n - 1 - i]) ** 2
print(result)


N = int(input())
L = list(map(int, input().split()))
L.sort()
SUM = 0
for i in range(N // 2):
	SUM = SUM + (L[i] + L[N - 1 - i]) * (L[i] + L[N - 1 - i])
print(SUM)


n = int(input())
vet = list(map(int, input().split(' ')))
vet.sort()
(l, d) = (0, n - 1)
sum = 0
while True:
	sum += pow(vet[l] + vet[d], 2)
	l += 1
	if l == d:
		break
	d -= 1
print(sum)


n = int(input())
a = [int(s) for s in input().split(' ')]
a.sort()
min_sum = 0
for i in range(len(a)):
	min_sum += (a[i] + a[n - 1 - i]) ** 2
print(int(min_sum / 2))


N = int(input())
line = input().split()
arr = []
for i in line:
	arr.append(int(i))
arr.sort()
res = 0
for i in range(N // 2):
	res += (arr[i] + arr[N - i - 1]) * (arr[i] + arr[N - i - 1])
print(res)


n = int(input())
a = sorted(list(map(int, input().split())))
(ans, L, R) = (0, 0, n - 1)
while L < R:
	ans += (a[L] + a[R]) ** 2
	L += 1
	R -= 1
print(ans)


def minsum(arr):
	sums = 0
	arr.sort()
	n = len(arr)
	for i in range(n // 2):
		sums += arr[i] * arr[i] + arr[n - i - 1] * arr[n - i - 1] + 2 * arr[i] * arr[n - i - 1]
	return sums
line = input()
n = int(line)
line = input()
arr = line.split()
for i in range(n):
	arr[i] = int(arr[i])
print(minsum(arr))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(0, int(n / 2)):
	cur = a[i] + a[n - i - 1]
	if n % 2 == 1 and i == n / 2 - 1:
		cur += a[n / 2]
	ans += cur * cur
print(ans)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int, input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
n = read_int()
arr = read_int_list()
ans = 0
arr.sort()
for i in range(n // 2):
	ans += (arr[i] + arr[n - i - 1]) ** 2
print(ans)


n = int(input())
lst = list(map(int, input().split()))
lst = sorted(lst)
i = 0
j = n - 1
ans = 0
while i < j:
	ans += (lst[i] + lst[j]) * (lst[i] + lst[j])
	i += 1
	j -= 1
print(ans)


n = int(input())
a = sorted(map(int, input().split()))
print(sum(((i + j) ** 2 for (i, j) in zip(a[:n // 2], tuple(reversed(a))[:n // 2]))))


n = int(input())
m = list(map(int, input().split()))
m.sort()
cnt = 0
for i in range(n // 2):
	cnt += (m[i] + m[n - 1 - i]) ** 2
print(cnt)


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n // 2):
	cnt = cnt + pow(l[i] + l[-i - 1], 2)
print(cnt)


n = int(input())
nums = [int(x) for x in input().split(' ')]
nums.sort()
tot = 0
for i in range(int(len(nums) / 2)):
	tot += (nums[i] + nums[n - i - 1]) ** 2
print(tot)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(sm, i, j) = (0, 0, n - 1)
while i < j:
	sm += (arr[i] + arr[j]) ** 2
	(i, j) = (i + 1, j - 1)
print(sm)


import sys
n = int(input())
lista = sorted(list(map(int, input().split())))
sum = 0
index = 0
length = n
while n:
	sum = sum + (lista[index] + lista[length - 1 - index]) ** 2
	index = index + 1
	n = n - 2
print(sum)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
sum = 0
while True:
	sum += abs((l[i] + l[j]) ** 2)
	i += 1
	j -= 1
	if i == n // 2:
		break
print(sum)


n = int(input())
cl = list(map(int, input().split()))
cl = sorted(cl)
pos = n // 2
res = 0
for i in range(1, n // 2 + 1):
	res += (cl[n // 2 - i] + cl[n // 2 + i - 1]) ** 2
print(res)


n = int(input())
m = sorted(map(int, input().split()))
print(sum(map(lambda x, y: (x + y) ** 2, m, m[::-1])) // 2)


n = eval(input())
x = input().split()
ls = []
s = 0
for i in x:
	ls.append(eval(i))
ls = sorted(ls)
for i in range(int(n / 2)):
	s += (ls[i] + ls[-1 - i]) ** 2
print(s)


number = int(input())
data = list(map(int, input().split()))
data.sort()
tem_number = int(number / 2)
number -= 1
result = []
for m in range(tem_number):
	result.append((data[m] + data[number - m]) * (data[m] + data[number - m]))
print(sum(result))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(i, j) = (0, n - 1)
ans = 0
if n % 2 == 1:
	ans += arr[-1] ** 2
	j = n - 2
while i <= j:
	if i < j:
		ans += (arr[i] + arr[j]) ** 2
		i += 1
		j -= 1
	else:
		print('lol')
print(ans)


n = int(input(''))
A = list(input('').split(' '))
for i in range(n):
	A[i] = int(A[i])
A.sort()
l = len(A) - 1
a = 0
sum = 0
while a < l:
	sum = sum + pow(A[a] + A[l], 2)
	a += 1
	l -= 1
print(sum)


n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
su = 0
for i in range(n // 2):
	su = su + (l[i] + l[n - 1 - i]) * (l[i] + l[n - i - 1])
print(su)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[:len(a) // 2]
y = a[len(a) // 2:]
sol = 0
for (i, j) in zip(y, reversed(x)):
	sol += (i + j) * (i + j)
print(sol)


n = int(input())
v = [int(i) for i in input().split()]
v = sorted(v)
sum = 0
for i in range(int(n / 2)):
	sum += (v[i] + v[n - i - 1]) * (v[i] + v[n - 1 - i])
print(sum)


def ri(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = ri(1)
l = ri(0)
l.sort()
ans = 0
for i in range(n // 2):
	ans += (l[i] + l[n - i - 1]) ** 2
print(ans)


n = int(input())
arr = [int(num) for num in input().split()]
lb = 0
ub = n - 1
ans = 0
arr.sort()
while ub > lb:
	ans += (arr[ub] + arr[lb]) ** 2
	lb += 1
	ub -= 1
print(ans)


m = int(input())
num = [int(x) for x in input().split()]
num.sort()
counter = 0
for i in range(m // 2):
	counter += (num[i] + num[m - i - 1]) ** 2
print(counter)