Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.

The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point $(0, 0)$. While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to $OX$ or $OY$ axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification.

Alexey wants to make a polyline in such a way that its end is as far as possible from $(0, 0)$. Please help him to grow the tree this way.

Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches.


-----Input-----

The first line contains an integer $n$ ($1 \le n \le 100\,000$) — the number of sticks Alexey got as a present.

The second line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10\,000$) — the lengths of the sticks.


-----Output-----

Print one integer — the square of the largest possible distance from $(0, 0)$ to the tree end.


-----Examples-----
Input
3
1 2 3

Output
26
Input
4
1 1 2 2

Output
20


-----Note-----

The following pictures show optimal trees for example tests. The squared distance in the first example equals $5 \cdot 5 + 1 \cdot 1 = 26$, and in the second example $4 \cdot 4 + 2 \cdot 2 = 20$.

 [Image] 

 [Image]

Difficulty: EASY
Tags: Sorting

Mathematics

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
def f(l):
	l.sort()
	h = len(l) // 2
	y = sum(l[:h])
	x = sum(l[h:])
	return x * x + y * y
_ = input()
l = list(map(int, input().split()))
print(f(l))


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
(x, y, c) = (0, 0, 0)
(i, j) = (0, n - 1)
while c < n:
	if i >= j:
		break
	else:
		x += ar[j]
		j -= 1
		c += 1
		y += ar[i]
		i += 1
		c += 1
if n % 2 != 0:
	x += ar[i]
print(x * x + y * y)


n = int(input())
a = list((int(i) for i in input().split()))
a.sort()
(x, y) = (0, 0)
while a:
	x += a[-1]
	a.pop()
	if a:
		y += a[0]
		a.pop(0)
print(x ** 2 + y ** 2)


n = int(input())
a = list(map(int, input().split()))
md = n // 2
a.sort()
print(sum(a[:md]) * sum(a[:md]) + sum(a[md:]) * sum(a[md:]))


n = int(input())
lis = input()
j = 0
k = 0
lis = lis.split()
for i in range(n):
	lis[i] = int(lis[i])
lis.sort()
for i in range(n):
	if i < n // 2:
		k += lis[i]
	else:
		j += lis[i]
print(k ** 2 + j ** 2)


n = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
p = len(sticks) // 2
first = sticks[:p]
first = sum(first)
second = sticks[p:]
second = sum(second)
print(first ** 2 + second ** 2)


a = int(input())
l = list(map(int, input().split()))
l.sort()
s = sum(l[0:a // 2])
print(s ** 2 + (sum(l) - s) ** 2)


n = int(input())
n2 = n // 2
arr = sorted(map(lambda x: int(x), input().split()))
s1 = 0
s2 = 0
for i in range(n):
	if i < n2:
		s1 += arr[i]
	else:
		s2 += arr[i]
print(s1 * s1 + s2 * s2)


n = int(input())
a = sorted(map(int, input().split()))
(p, q) = (sum(a[:n // 2]), sum(a[n // 2:]))
print(p * p + q * q)


import math
from sys import stdin, stdout

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

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

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

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

def main():
	n = I()
	l = Si()
	t = n // 2
	x = 0
	y = 0
	for i in range(t):
		x += l[i]
	for i in range(t, n):
		y += l[i]
	print(x * x + y * y)
main()


n = int(input())
lens = [int(x) for x in input().split(' ')]
lens = sorted(lens)
mid = int(n / 2)
print(sum(lens[:mid]) ** 2 + sum(lens[mid:]) ** 2)


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


t = int(input())
l = sorted(list(map(int, input().split(' '))))
(x, y) = (0, 0)
l1 = l[:t // 2]
l2 = l[t // 2:]
x += sum(l2)
y += sum(l1)
print(x ** 2 + y ** 2)


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


from math import ceil
n = int(input())
l = sorted(list(map(int, input().split())), reverse=True)
t = ceil(n / 2)
(sum1, sum2) = (sum(l[:t]), sum(l[t:]))
print(pow(sum1, 2) + pow(sum2, 2))


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
h = []
v = []
if len(l) % 2 == 0:
	h = l[int(len(l) / 2):]
	v = l[:int(len(l) / 2)]
else:
	h = l[int(len(l) / 2):]
	v = l[:int(len(l) / 2)]
h = sum(h)
v = sum(v)
print(h ** 2 + v ** 2)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
x = []
y = []
mid = n // 2
y = a[0:mid]
x = a[mid:]
print(sum(x) ** 2 + sum(y) ** 2)


Scount = int(input())
sticks = [int(x) for x in input().split(' ')]
sticks.sort()
horizontal = 0
for i in range(Scount - 1, Scount // 2 - 1, -1):
	horizontal += sticks[i]
vertical = 0
for i in range(Scount // 2 - 1, -1, -1):
	vertical += sticks[i]
print(horizontal ** 2 + vertical ** 2)


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


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = sum(a[:n // 2])
y = sum(a[n // 2:])
print(x ** 2 + y ** 2)


import sys
t = int(input())
xn = list(map(int, sys.stdin.readline().split()))
xn.sort()
i = 0
if t % 2 == 0:
	xx = sum(xn[:t // 2])
	yy = sum(xn) - xx
else:
	xx = sum(xn[:t // 2])
	yy = sum(xn) - xx
print(xx * xx + yy * yy)


from math import floor
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mid = floor(len(a) / 2)
x = sum(a[mid:])
y = sum(a[0:mid])
print(x ** 2 + y ** 2)


a = int(input())
x = [int(i) for i in input().split()]
(p, q, w) = ([], [], sorted(x))
for i in range(0, a // 2):
	p.append(w[i])
for i in range(a // 2, a):
	q.append(w[i])
print(sum(p) ** 2 + sum(q) ** 2)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	a = lis()
	a = sorted(a)
	end = n - 1
	st = 0
	hor = 0
	ver = 0
	cnt = 0
	while st <= end:
		if cnt % 2 == 0:
			hor += a[end]
			cnt += 1
			end -= 1
		else:
			ver += a[st]
			cnt += 1
			st += 1
	print(hor ** 2 + ver ** 2)
testcase(1)


for _ in range(1):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	k = sum(li)
	p = sum(li[:n // 2])
	print(p * p + (k - p) * (k - p))


import sys
line = sys.stdin.readline()
number_of_sticks = int(line)
sticks = []
sticks_line = sys.stdin.readline().split()
for number in sticks_line:
	sticks.append(int(number))
sticks.sort()
x = []
y = []
i = 0
j = 0
length = len(sticks) // 2
while i < length:
	y.append(sticks[i])
	x.append(sticks[-(i + 1)])
	i += 1
if len(sticks) % 2 != 0:
	x.append(sticks[length])
sum_x = sum(x)
sum_y = sum(y)
sys.stdout.write(str(sum_x * sum_x + sum_y * sum_y) + '\n')


n = int(input())
a = [int(o) for o in input().split()]
a = sorted(a)
lol = a[n // 2:]
lol1 = a[:n // 2]
print(sum(lol) ** 2 + sum(lol1) ** 2)


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


n = int(input())
a = list(map(lambda x: int(x), input().split(' ')))
a = sorted(a)
x = 0
y = 0
f = True
while a:
	if f:
		i = a.pop()
		x += i
	else:
		i = a.pop(0)
		y += i
	f = not f
print(x * x + y * y)


n = int(input())
l = list(map(int, input().split()))
l.sort()
p = []
m = []
for i in range(n // 2):
	p.append(l[n - 1 - i])
	m.append(l[i])
if len(p) + len(m) == n - 1:
	p.append(l[n // 2])
t = sum(p)
r = sum(m)
print(t * t + r * r)


n = int(input())
s = sorted(map(int, input().split()))
i = 0
j = n - 1
cnt = 1
x = y = 0
while i <= j:
	if cnt % 2:
		x += s[j]
		j -= 1
	else:
		y += s[i]
		i += 1
	cnt += 1
print(x * x + y * y)


n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
small = sum(a_list[:n // 2])
big = sum(a_list[n // 2:])
print(small ** 2 + big ** 2)


n = int(input())
lis = list(map(int, input().split()))
sumx = 0
sumy = 0
lis.sort()
p = 0
if n % 2 == 0:
	p = n // 2
else:
	p = (n - 1) // 2
for i in range(0, p):
	sumx += lis[i]
for i in range(p, len(lis)):
	sumy += lis[i]
value = sumx ** 2 + sumy ** 2
print(value)


def listsum(numList):
	s = 0
	for i in numList:
		s += i
	return s
am = int(input())
sticks = sorted(list(map(int, input().split())))
x = listsum(sticks[:len(sticks) // 2])
y = listsum(sticks[len(sticks) // 2:])
print(x * x + y * y)


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


n = int(input())
lens = list(map(int, input().split()))
lens.sort()
print(sum(lens[:n // 2]) ** 2 + sum(lens[n // 2:]) ** 2)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = n // 2
y = a[0:x]
z = a[x:]
s1 = 0
s2 = 0
for i in y:
	s1 = s1 + i
for j in z:
	s2 = s2 + j
w = s1 ** 2 + s2 ** 2
print(w)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
s = 0
x = 0
y = 0
while True:
	if s % 2 == 1:
		y = y + l[i]
		i = i + 1
	if s % 2 == 0:
		x = x + l[j]
		j = j - 1
	s = s + 1
	if i > j:
		break
print(x ** 2 + y ** 2)


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


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


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
s1 = sum(a)
s2 = sum(a[n // 2:])
print(s2 * s2 + (s1 - s2) * (s1 - s2))


n = int(input())
ls = list(map(int, input().split()))
x = 0
y = 0
ls.sort()
for i in range(n):
	if i % 2 == 0:
		x += ls.pop(-1)
	else:
		y += ls.pop(0)
print(y ** 2 + x ** 2)


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


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


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	a.sort()
	up = sum(a[0:int(n / 2)])
	down = sum(a[int(n / 2):n])
	print(up ** 2 + down ** 2)
main()


def inp(type):
	return type(input())

def minput(type):
	return map(type, input().split())

def linput(type):
	return list(minput(type))

def check(map, elem):
	if not map.__contains__(elem):
		map[elem] = set()
n = inp(int)
l = sorted(linput(int))
x = y = 0
for i in range(n // 2):
	x += l[i]
for i in range(n // 2, n):
	y += l[i]
print(x * x + y * y)


import itertools

def main():
	n = int(input())
	data = [int(v) for v in input().split()]
	val = 0
	data.sort(reverse=True)
	m = n // 2 if n % 2 == 0 else n // 2 + 1
	a = sum(data[0:m])
	b = sum(data[m:])
	print(a * a + b * b)
main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = sum(a[:n // 2])
ans2 = sum(a) - ans1
ans = ans1 * ans1 + ans2 * ans2
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
a1 = sum(a[:n // 2])
a2 = sum(a[n // 2:])
print(a1 ** 2 + a2 ** 2)


t1 = t2 = 0
a = int(input())
l = list(map(int, input().split()))
l.sort()
k = len(l) // 2
for i in range(k, len(l)):
	t1 += l[i]
for i in range(0, k):
	t2 += l[i]
print(t2 * t2 + t1 * t1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = sum(l[:n // 2]) * sum(l[:n // 2])
b = sum(l[n // 2:]) * sum(l[n // 2:])
print(a + b)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = 0
y = 0
while n:
	x += a[0]
	a.pop(0)
	n -= 1
	if n == 0:
		break
	else:
		y += a[-1]
		a.pop(-1)
		n -= 1
d = x ** 2 + y ** 2
print(d)


t = int(input())
n = list(map(int, input().split()))
n.sort()
m = len(n) // 2
print(sum(n[:m]) ** 2 + sum(n[m:]) ** 2)


import sys
input = sys.stdin.readline
N = int(input())
l = list(map(int, input().split()))
l.sort()
x1 = 0
y1 = 0
for i in range(N // 2):
	x1 += l[i]
for i in range(N // 2, N):
	y1 += l[i]
ans = x1 ** 2 + y1 ** 2
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
s1 = 0
s2 = 0
i = 0
j = n - 1
while j >= i:
	if j == i:
		s2 += arr[i]
		break
	s1 += arr[i]
	s2 += arr[j]
	i += 1
	j -= 1
print(s1 ** 2 + s2 ** 2)


input = __import__('sys').stdin.readline
N = int(input())
nums = list(sorted(map(int, input().split()), reverse=True))
A = list()
B = list()
if N % 2 == 0:
	A = nums[:len(nums) // 2]
	B = nums[len(nums) // 2:]
else:
	A = nums[:len(nums) // 2 + 1]
	B = nums[len(nums) // 2 + 1:]
print(sum(A) ** 2 + sum(B) ** 2)


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
k = n // 2 + 1 if n % 2 else n // 2
ans = sum(a[:k]) ** 2 + sum(a[k:]) ** 2
print(ans)


import sys
n = int(input())
arr = list(map(lambda x: int(x), input().split()))
arr.sort()
sum1 = 0
sum2 = 0
if n % 2 == 0:
	for i in range(n // 2):
		sum1 += arr[i]
	for i in range(n // 2, n):
		sum2 += arr[i]
	print(sum1 ** 2 + sum2 ** 2)
else:
	for i in range(n // 2):
		sum1 += arr[i]
	for i in range(n // 2, n):
		sum2 += arr[i]
	x1 = sum1 ** 2 + sum2 ** 2
	sum1 = 0
	sum2 = 0
	for i in range(n // 2 + 1):
		sum1 += arr[i]
	for i in range(n // 2 + 1, n):
		sum2 += arr[i]
	x2 = sum1 ** 2 + sum2 ** 2
	print(max(x1, x2))


nos = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
small = nos // 2
a = sum(sticks[:nos // 2]) ** 2
b = sum(sticks[nos // 2:]) ** 2
print(a + b)


def tree(size):
	x = 0
	y = 0
	size = sorted(size)
	while size:
		if size:
			y += size.pop(-1)
		if size:
			x += size.pop(0)
	return x * x + y * y
n = int(input())
size = list(map(int, input().split()))
print(tree(size))


n = int(input())
s = sorted(list(map(int, input().split())))
h = n // 2
print(sum(s[:h]) ** 2 + sum(s[h:]) ** 2)


k = int(input())
a = list(map(int, input().split()))
a.sort()
lenn = len(a)
r = lenn // 2
l = r - 1
cor = [0, 0]
while l >= 0 or r < lenn:
	if r < lenn:
		cor[0] += a[r]
		r += 1
	if l >= 0:
		cor[1] += a[l]
		l -= 1
print(pow(cor[0], 2) + pow(cor[1], 2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
	mid = n // 2
else:
	mid = n // 2
h = 0
b = 0
for i in range(mid):
	h += a[i]
for i in range(mid, n):
	b += a[i]
res = pow(h, 2) + pow(b, 2)
print(res)


n = int(input())
a = list(map(int, input().split()))
x = [0] * n
a.sort(reverse=True)
j = 0
for i in range(int(n / 2)):
	x[j] = a[i]
	x[j + 1] = a[n - i - 1]
	j += 2
if n % 2 != 0:
	x[n - 1] = a[n // 2]
c1 = 0
c2 = 0
for i in range(0, n - 1, 2):
	c1 += x[i]
	c2 += x[i + 1]
if n % 2 != 0:
	c1 += x[n - 1]
print(c2 ** 2 + c1 ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
r = n - 1
p = 0
h = 0
v = 0
test = 0
while p <= r:
	if test == 0:
		h += a[r]
		test = 1
		r -= 1
	else:
		v += a[p]
		test = 0
		p += 1
print(v ** 2 + h ** 2)


def power(x, y):
	res = 1
	x = x
	while y > 0:
		if y & 1 == 1:
			res = res * x
		y = y >> 1
		x = x * x
	return res
import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
fsum = 0
lsum = 0
ans = 0
for i in range(n // 2):
	fsum += arr[i]
for j in range(n // 2, n):
	lsum += arr[j]
ans = power(fsum, 2) + power(lsum, 2)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
a1 = a[:n // 2]
a2 = a[n // 2:]
print(sum(a1) * sum(a1) + sum(a2) * sum(a2))


s = int(input())
l = list(map(int, input().split()))
flag = 0
if s % 2 == 0:
	k = int(s / 2)
else:
	k = s // 2
	flag = 1
l.sort()
if flag == 1:
	p1 = l[::-1][:k + 1]
	p2 = l[::-1][k + 1:]
	print(pow(sum(p1), 2) + pow(sum(p2), 2))
else:
	p1 = l[::-1][:k]
	p2 = l[::-1][k:]
	print(pow(sum(p1), 2) + pow(sum(p2), 2))


n = int(input())
arr = [int(j) for j in input().split()]
arr.sort()
up = sum(arr[:n // 2])
left = sum(arr[n // 2:])
print(up ** 2 + left ** 2)


n = int(input())
l = input().split()
li = [int(i) for i in l]
li.sort()
num1 = sum(li[0:n // 2])
num2 = sum(li) - num1
print(num1 ** 2 + num2 ** 2)


import math
n = int(input())
arr = list(map(int, input().split()))
up = math.ceil(n / 2)
down = math.floor(n / 2)
arr.sort()
print(max(sum(arr[down:]) ** 2 + sum(arr[:down]) ** 2, sum(arr[up:]) ** 2 + sum(arr[:up]) ** 2))


n = int(input())
a = sorted([int(x) for x in input().split()])
x = 0
y = 0
i = 0
j = n - 1
while i < j:
	x += a[i]
	y += a[j]
	i += 1
	j -= 1
if i == j:
	y += a[i]
print(x * x + y * y)


n = int(input())
a = sorted(map(int, input().split()))
t = n // 2
s1 = sum(a[:t])
s2 = sum(a[t:])
print(s1 ** 2 + s2 ** 2)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = sum(A[:n // 2]) ** 2 + sum(A[n // 2:]) ** 2
print(ans)


from math import *
from collections import *
import sys
input = sys.stdin.readline
n = int(input())
n = n // 2
a = list(map(int, input().split()))
a.sort()
(x, y) = (sum(a[:n]), sum(a[n:]))
print(x ** 2 + y ** 2)


N = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
a_left = a[:int(N / 2)]
a_right = a[int(N / 2):]
print(sum(a_left) ** 2 + sum(a_right) ** 2)


def mergeSort(myList):
	if len(myList) > 1:
		mid = len(myList) // 2
		left = myList[:mid]
		right = myList[mid:]
		mergeSort(left)
		mergeSort(right)
		i = 0
		j = 0
		k = 0
		while i < len(left) and j < len(right):
			if left[i] < right[j]:
				myList[k] = left[i]
				i += 1
			else:
				myList[k] = right[j]
				j += 1
			k += 1
		while i < len(left):
			myList[k] = left[i]
			i += 1
			k += 1
		while j < len(right):
			myList[k] = right[j]
			j += 1
			k += 1
x = input()
S = [int(x) for x in input().split()]
if len(S) == 1:
	print(S[0] ** 2)
elif len(S) == 2:
	print(S[0] ** 2 + S[1] ** 2)
else:
	mergeSort(S)
	meio = len(S) // 2
	x = sum(S[:meio])
	y = sum(S[meio:])
	print(x ** 2 + y ** 2)


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


def distance(a, arr):
	horizontal = a - a // 2
	x = sum(arr[:horizontal])
	y = sum(arr[horizontal:])
	return x ** 2 + y ** 2
a = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
print(distance(a, arr))


n = int(input())
a = sorted(map(int, input().split()))
print(sum(a[:n // 2]) ** 2 + sum(a[n // 2:]) ** 2)


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = li()
	l.sort()
	(i, j) = (0, n - 1)
	(x, y) = (0, 0)
	c = 1
	while i <= j:
		if c:
			x += l[j]
			c = 0
			j -= 1
		else:
			y += l[i]
			c = 1
			i += 1
	pr(x * x + y * y)
for _ in range(1):
	solve()


n = int(input())
(s1, s2) = (0, 0)
aarr = [int(c) for c in input().split()]
aarr.sort()
if n % 2 == 1:
	s2 = aarr[n - 1]
	for i in range(int(n / 2)):
		s1 = s1 + aarr[i]
		s2 = s2 + aarr[i + int(n / 2)]
else:
	for i in range(int(n / 2)):
		s1 = s1 + aarr[i]
		s2 = s2 + aarr[i + int(n / 2)]
s = s1 ** 2 + s2 ** 2
print(s)


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


N = int(input())
sk = [int(x) for x in input().split()]
sk.sort()
print(sum(sk[:N // 2]) ** 2 + sum(sk[N // 2:]) ** 2)


n = int(input())
n_arr = list(map(int, input().split()))
s_arr = list(sorted(n_arr, reverse=True))
ans = 0
if len(s_arr) % 2 == 0:
	ans += sum(s_arr[:len(s_arr) // 2]) ** 2
	ans += sum(s_arr[len(s_arr) // 2:]) ** 2
else:
	ans += sum(s_arr[:len(s_arr) // 2 + 1]) ** 2
	ans += sum(s_arr[len(s_arr) // 2 + 1:]) ** 2
print(ans)


class MainProgram:

	def main(argv: list):
		n = int(input())
		a = list(map(int, input().split()))
		a.sort()
		x = sum(a[len(a) // 2:])
		y = sum(a) - x
		print(x ** 2 + y ** 2)
		return 0
import sys, os, math, random
retcode = MainProgram.main(sys.argv)
exit(retcode)


t = int(input())
l = sorted(list(map(int, input().split())))
n = len(l) // 2
a = sum(l[:n])
b = sum(l[n:])
print(a ** 2 + b ** 2)


n = int(input())
a = list(sorted(list(map(int, input().split()))))
x = 0
y = 0
deff = 0
for i in range(n):
	if deff == 0:
		y += a[-1]
		del a[-1]
		deff = 1
	else:
		x += a[0]
		del a[0]
		deff = 0
res = x ** 2 + y ** 2
print(res)


import math

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	x = 0
	y = 0
	for i in range(int(math.ceil(n / 2))):
		x += arr.pop()
	y = sum(arr)
	print(x ** 2 + y ** 2)
main()


N = int(input())
nums = [int(x) for x in input().strip().split(' ')]
nums.sort(reverse=True)
x = 0
y = 0
X = True
for i in range(N // 2):
	x += nums[i]
	y += nums[N - 1 - i]
if N % 2:
	x += nums[N // 2]
print(pow(x, 2) + pow(y, 2))


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

def ai():
	a = list(map(int, input().split()))
	return a

def mi():
	a = map(int, input().split())
	return a
n = ii()
lst = ai()
lst.sort()
ans = sum(lst[:n // 2]) ** 2 + sum(lst[n // 2:]) ** 2
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
ln = len(a)
print(sum(a[:ln // 2]) ** 2 + sum(a[ln // 2:]) ** 2)


n = int(input())
l = list(map(int, input().split()))
m = len(l)
k = []
l.sort()
x = 0
if m % 2 == 0:
	for i in range(m // 2):
		x = x + l[i]
	k.append(x)
	x = 0
	for i in range(m // 2, m):
		x = x + l[i]
	k.append(x)
else:
	for i in range(m // 2):
		x = x + l[i]
	k.append(x)
	x = 0
	for i in range(m // 2, m):
		x = x + l[i]
	k.append(x)
	x = 0
y = k[0] * k[0] + k[1] * k[1]
print(y)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
h = sum(a[n // 2:])
v = s - h
print(h * h + v * v)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
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 I():
	return int(sys.stdin.readline())

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

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

def S():
	return input()

def main():
	n = I()
	l = LI()
	l.sort()
	i = n // 2
	x = sum(l[:i])
	y = sum(l[i:])
	return x ** 2 + y ** 2
print(main())


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


from sys import stdin
inp = stdin.readline
n = int(inp().strip())
a = [int(x) for x in inp().strip().split()]
a.sort()
x = 0
y = 0
for i in range(n):
	if i < n // 2:
		x += a[i]
	else:
		y += a[i]
print(x ** 2 + y ** 2)


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

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

def rsingle_char():
	return stdin.read(1)

def sortFirst(val):
	return val[0]

def main():
	n = rsingle_int()
	sticks = rmult_int()
	if n == 1:
		print(sticks[0] ** 2)
	else:
		sticks.sort(reverse=True)
		horizontal = n // 2
		if n % 2 != 0:
			horizontal += 1
		x = 0
		for i in range(horizontal):
			x += sticks[i]
		y = 0
		for i in range(horizontal, n):
			y += sticks[i]
		print(x ** 2 + y ** 2)
main()


n = int(input())
s = sorted(map(int, input().split()))
print(sum(s[:n // 2]) ** 2 + sum(s[n // 2:]) ** 2)


import sys

def I():
	return sys.stdin.readline().rstrip()
n = int(I())
a = list(map(int, I().split()))
a.sort()
n2 = n // 2
(b, c) = (sum(a[:n2]), sum(a[n2:]))
print(b * b + c * c)


def largest_tree(a):
	a.sort(reverse=True)
	x = 0
	y = 0
	for i in range((len(a) + 1) // 2):
		x += a[i]
	for i in range((len(a) + 1) // 2, len(a)):
		y += a[i]
	return x ** 2 + y ** 2

def main():
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	print(largest_tree(a))
	return
main()


n = int(input())
a = [int(i) for i in input().split()]
c = 0
d = 0
a.sort()
for i in range(n // 2):
	c += a[i]
	d += a[n - 1 - i]
if n % 2 != 0:
	d += a[n // 2]
print(pow(c, 2) + pow(d, 2))


n = int(input())
a = input().split()
a = map(int, a)
a = list(a)
a.sort()
if n % 2:
	half = (n - 1) / 2
	half = int(half)
	x = sum(a[:half])
	y = sum(a) - x
else:
	x = sum(a[:int(n / 2)])
	y = sum(a) - x
length = x ** 2 + y ** 2
print(length)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s1 = sum(a[len(a) // 2:])
s2 = sum(a[0:len(a) // 2])
print(s1 ** 2 + s2 ** 2)


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


n = int(input())
a = list(map(int, input().split()))
ne = no = 0
a.sort()
for i in range(n):
	if i < n // 2:
		ne += a[i]
	else:
		no += a[i]
print(ne * ne + no * no)


n = int(input())
k = list(map(int, input().split()))
h = sorted(k)
c = 0
d = 0
if n % 2 == 0:
	for i in range(n // 2):
		c = c + h[i]
		d = d + h[-i - 1]
else:
	for i in range(n // 2):
		c = c + h[i]
		d = d + h[-i - 1]
	d = d + h[n // 2]
q = d * d + c * c
print(q)


n = int(input())
s = list(map(int, input().split()))
s.sort()
s.reverse()
a = sum(s[:(n + 1) // 2])
b = sum(s[(n + 1) // 2:])
print(a * a + b * b)


n = int(input())
a = sorted(list(map(int, input().split())))
if n == 2:
	print(a[0] ** 2 + a[1] ** 2)
elif n != 2:
	val = n // 2
	print(sum(a[val:]) ** 2 + sum(a[:val]) ** 2)


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


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


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
n = int(input())
l = list(map(int, input().split()))
l.sort()
i = -1
j = 0
(x1, y1, x2, y2) = (0, 0, 0, 0)
for k in range(n):
	if k % 2 == 0:
		x1 += l[i]
		i -= 1
	else:
		y1 += l[j]
		j += 1
print(x1 ** 2 + y1 ** 2)


import math
n = input()
s = list(map(int, input().split()))
s.sort(reverse=True)
total = sum(s)
tsum = 0
if len(s) % 2 == 0:
	x = len(s) / 2
else:
	x = math.ceil(len(s) / 2)
for i in range(int(x)):
	tsum = tsum + s[i]
print(tsum * tsum + (total - tsum) * (total - tsum))


import sys, math
t = 1
for _ in range(t):
	n = int(input()) // 2
	l = list(map(int, input().split()))
	l.sort()
	print(sum(l[:n]) ** 2 + sum(l[n:]) ** 2)


n = int(input())
a = sorted(map(int, input().split()))
pos = [0, n - 1]
turn = 1
(e1, e2) = (0, 0)
while pos[0] <= pos[1]:
	if turn:
		e2 += a[pos[1]]
		pos[1] -= 1
	else:
		e1 += a[pos[0]]
		pos[0] += 1
	turn ^= 1
print(e1 ** 2 + e2 ** 2)


import collections
n = int(input())
ai = list(map(int, input().split()))
ai.sort()
ai = collections.deque(ai)
(w, h) = (0, 0)
while ai:
	w += ai.pop()
	if ai:
		h += ai.popleft()
print(w * w + h * h)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N % 2 == 0:
	ans = sum(A[:N // 2]) ** 2 + sum(A[N // 2:]) ** 2
else:
	ans = max(sum(A[:N // 2]) ** 2 + sum(A[N // 2:]) ** 2, sum(A[:N // 2 + 1]) ** 2 + sum(A[N // 2 + 1:]) ** 2)
print(ans)


def tree(arr):
	sum_1 = 0
	sum_2 = 0
	result = 0
	arr = sorted(arr)
	if len(arr) % 2 == 0:
		for i in range(len(arr) // 2):
			sum_1 += arr[i]
			sum_2 += arr[len(arr) - 1 - i]
	else:
		for i in range(len(arr) // 2):
			sum_1 += arr[i]
			sum_2 += arr[len(arr) - 1 - i]
		sum_2 += arr[len(arr) // 2]
	result = sum_1 ** 2 + sum_2 ** 2
	return result
n = int(input())
array = list(map(int, input().split()))
print(tree(array))


n = int(input())
a = list(map(lambda x: int(x), input().split()))
if len(a) != n:
	exit()
sep = int(n / 2)
a.sort()
sum1 = sum(a[0:sep])
sum2 = sum(a[sep:n])
print(sum1 * sum1 + sum2 * sum2)


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

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

def solve(ax):
	ax = sorted(ax)
	n = len(ax)
	a = sum(ax[:n // 2])
	s = sum(ax)
	return a ** 2 + (s - a) ** 2
n = read_int()
ax = list(map(int, read_str().split()))
res = solve(ax)
print('%s' % res)


a = int(input())
b = sorted(list(map(int, input().split())), reverse=True)
from math import ceil as c
print(sum(b[:c(len(b) / 2)]) ** 2 + sum(b[c(len(b) / 2):]) ** 2)


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
from heapq import heappush as hpush
from heapq import heappop as hpop
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(reverse=True)
ans = 0
first = 0
if n % 2 == 1:
	for i in range(n // 2 + 1):
		first += a[i]
else:
	for i in range(n // 2):
		first += a[i]
second = sum(a) - first
print(first ** 2 + second ** 2)


n = int(input())
nArr = list(map(int, input().split()))
nArr.sort(reverse=True)
mid = n // 2
if n % 2 != 0:
	mid = mid + 1
x_di = 0
y_di = 0
for i in range(mid):
	x_di += nArr[i]
for i in range(mid, n):
	y_di += nArr[i]
print(x_di ** 2 + y_di ** 2)


input()
lst = list(map(int, input().split()))
lst.sort()
half = len(lst) // 2
a = 0
b = 0
for i in range(half):
	a += lst[i]
for j in range(half, len(lst)):
	b += lst[j]
print(a ** 2 + b ** 2)


import os
import sys
from io import BytesIO, IOBase
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')
import collections
n = int(input())
vals = list(map(int, input().split()))
vals.sort()
vals = collections.deque(vals)
vert = 0
hor = 0
checker = 0
for s in range(n):
	if checker % 2 == 0:
		hor += vals.pop()
	else:
		vert += vals.popleft()
	checker += 1
print(vert ** 2 + hor ** 2)


n = int(input())
ls = sorted(map(int, input().split(' ')))
xs = sum(ls[:n // 2])
ys = sum(ls[n // 2:])
out = xs ** 2 + ys ** 2
print(out)


import math
n = int(input())
ar = list(sorted(list(map(int, input().split(' ')))))
x = n // 2
(a, b) = (0, 0)
for (idx, num) in enumerate(ar):
	if idx < x:
		a += num
	else:
		b += num
print(a * a + b * b)


from collections import deque
n = int(input())
l = list(map(int, input().split()))
l.sort()
d = deque(l)
a = 0
b = 0
while 1:
	if d:
		a += d.pop()
	else:
		break
	if d:
		b += d.popleft()
	else:
		break
x = a ** 2 + b ** 2
print(x)


amount = int(input())
array = [int(s) for s in input().split()]
i = 0
j = len(array) - 1
hor = 0
vert = 0
array = sorted(array)
hor = sum(array[len(array) // 2:])
vert = sum(array[:len(array) // 2])
print(hor ** 2 + vert ** 2)


n = int(input())
sticks = list(map(int, input().strip().split()))
sticks = sorted(sticks)
val = n // 2
x = sum(sticks[:val])
y = sum(sticks[val:])
print(x * x + y * y)


n = int(input())
n = n // 2 if n % 2 == 0 else n // 2 + 1
m = sorted(list(map(int, input().split())), reverse=True)
print(sum(m[0:n]) ** 2 + sum(m[n:]) ** 2)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	n = I()
	arr = L()
	arr.sort()
	if n % 2 == 0:
		sm1 = sum(arr[:n // 2])
		sm2 = sum(arr[n // 2:])
	else:
		sm1 = sum(arr[:n // 2])
		sm2 = sum(arr[n // 2:])
	print(sm1 * sm1 + sm2 * sm2)
main()


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


n = int(input())
ch = input()
T = ch.split()
for i in range(n):
	T[i] = int(T[i])
T.sort()
T.reverse()
x = 0
y = 0
if n % 2 == 0:
	for i in range(n):
		if i < n // 2:
			x = x + T[i]
		else:
			y = y + T[i]
else:
	for i in range(n):
		if i <= n // 2:
			x = x + T[i]
		else:
			y = y + T[i]
d = pow(x, 2) + pow(y, 2)
print(d)


from collections import deque
try:
	import pytest

	@pytest.mark.parametrize('items, result', [((1, 2, 3), 26), ((1, 1, 2, 2), 20)])
	def test(items, result):
		assert solve(items) == result
except Exception:
	pass

def solve(items) -> int:
	items = deque(sorted(items))
	hor = ver = 0
	while items:
		if len(items) == 1:
			if hor > ver:
				hor += items.popleft()
			else:
				ver += items.popleft()
		try:
			hor += items.popleft()
			ver += items.pop()
		except IndexError:
			pass
	return hor ** 2 + ver ** 2

def main():
	input()
	items = list(map(int, input().split()))
	print(solve(items))
main()


n = int(input())
array = list(map(int, input().split()))
array = sorted(array)
if n % 2 == 0:
	s = sum(array[:n // 2])
	print(s * s + (sum(array) - s) * (sum(array) - s))
else:
	s1 = sum(array[:n // 2])
	s2 = sum(array[:n // 2 + 1])
	ans = max(s1 * s1 + (sum(array) - s1) * (sum(array) - s1), s2 * s2 + (sum(array) - s2) * (sum(array) - s2))
	print(ans)


import sys
line_count = 0
segments = []
for line in sys.stdin.readlines():
	if line_count == 0:
		n = int(line.split()[0])
	else:
		inputs = line.split()
		for i in range(n):
			segments.append(int(inputs[i]))
	if line_count > 1:
		break
	line_count += 1
segments.sort()
cut = n // 2
a = sum(segments[:cut])
b = sum(segments[cut:])
print(a * a + b * b)


from collections import deque
numSticks = int(input())
lengths = [int(l) for l in input().split()]
lengths.sort()
queue = deque(lengths)
x = 0
y = 0
while queue:
	x += queue.pop()
	if queue:
		y += queue.popleft()
print(x ** 2 + y ** 2)


input()
arr = list(map(int, input().split()))
arr.sort()
arr.reverse()
l = len(arr)
print(sum(arr[:(l + 1) // 2]) ** 2 + sum(arr[(l + 1) // 2:]) ** 2)


_ = int(input())
a = list(map(int, input().split()))
a.sort()
x = int(len(a) / 2)
ax = a[0:x]
ay = a[x:]
val = sum(ax) ** 2 + sum(ay) ** 2
print(val)


from sys import stdin, stdout

def scal(typ=int):
	return typ(stdin.readline())

def vec(typ=int):
	if isinstance(typ, list):
		inp = stdin.readline().split()
		return [typ[i](inp[i]) for i in range(len(inp))]
	else:
		return list(map(typ, stdin.readline().split()))
(n, a) = (scal(), vec())
a.sort()
(x, y) = (sum(a[:n // 2]), sum(a[n // 2:]))
print(x * x + y * y)


n = int(input())
a = list(map(int, input().split()))
h1 = 0
h2 = 0
a.sort()
u1 = 0
u2 = n - 1
while u2 > u1:
	h2 += a[u2]
	h1 += a[u1]
	u2 -= 1
	u1 += 1
if len(a) % 2 == 1:
	h2 += a[u2]
print(h2 * h2 + h1 * h1)


try:
	n = int(input())
	lst = list(map(int, input().split()))
	lst.sort()
	(x, y) = (0, 0)
	for i in lst[n // 2:]:
		x += i
	for i in lst[:n // 2]:
		y += i
	print(x ** 2 + y ** 2)
except:
	pass


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans1 = sum(a[0:(n + 1) // 2])
ans2 = sum(a[(n + 1) // 2:n])
print(ans1 ** 2 + ans2 ** 2)


import sys, math
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = list(a[:len(a) // 2])
w = list(a[len(a) // 2:])
print(sum(q) ** 2 + sum(w) ** 2)


n = int(input())
l = sorted(list(map(int, input().split())))
x = sum(l[n // 2:])
y = sum(l[:n // 2])
print(x ** 2 + y ** 2)


n = int(input())
arr = sorted(list(map(int, input().split())))
print(sum(arr[:n // 2]) ** 2 + sum(arr[n // 2:]) ** 2)


t = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum(a[0:t // 2]) ** 2 + sum(a[t // 2:t]) ** 2)


try:
	n = int(input())
	l1 = list(map(int, input().split()))
	l1.sort()
	a = n // 2
	s1 = s2 = 0
	for i in range(n):
		if i < a:
			s1 += l1[i]
		else:
			s2 += l1[i]
	print(s1 ** 2 + s2 ** 2)
except:
	pass


a = input()
b = list(map(int, input().split(' ')))
b.sort()
c = 0
d = 0
if len(b) % 2 == 0:
	for i in range(0, int(len(b) / 2)):
		c = c + b[-1]
		del b[-1]
	for i in range(len(b)):
		d = d + b[0]
		del b[0]
else:
	for i in range(0, int(len(b) / 2) + 1):
		c = c + b[-1]
		del b[-1]
	for i in range(len(b)):
		d = d + b[0]
		del b[0]
print(c * c + d * d)
c
d


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


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
k = n // 2
(s, t) = (sum(a[:k]), sum(a[k:]))
print(s * s + t * t)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
if n % 2 == 0:
	k = n // 2
	s1 = sum(a[0:k])
	s2 = sum(a[k:])
else:
	k = n // 2
	s1 = sum(a[0:k + 1])
	s2 = sum(a[k + 1:])
print(s1 * s1 + s2 * s2)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
if n % 2 == 0:
	print(sum(l[0:n // 2]) ** 2 + sum(l[n // 2:n]) ** 2)
else:
	print(sum(l[0:(n + 1) // 2]) ** 2 + sum(l[(n + 1) // 2:n]) ** 2)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n % 2 == 0:
	t = n // 2
	y = sum(arr[t:])
	x = sum(arr[:t])
	print(x ** 2 + y ** 2)
else:
	u = (n - 1) // 2
	x = sum(arr[:u])
	y = sum(arr[u:])
	print(x ** 2 + y ** 2)


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


mod = 10 ** 9 + 7
INF = float('inf')

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

def readTuples():
	return tuple(map(int, input().split()))

def I():
	return int(input())
import math
n = I()
loop = math.ceil(n / 2)
A = sorted(readInts(), reverse=True)
x = 0
y = 0
for i in range(loop):
	x += A[i]
for i in range(loop, n):
	y += A[i]
print(x ** 2 + y ** 2)


N = int(input())
f = [int(x) for x in input().split()]
f.sort()
solA = 0
solB = 0
indA = 0
indB = len(f) - 1
while indB >= indA:
	solB += f[indB]
	indB -= 1
	if indB < indA:
		break
	solA += f[indA]
	indA += 1
print(solA * solA + solB * solB)


from collections import deque
test = int(input())
array = list(map(int, input().split()))
array.sort(reverse=True)
array = deque(array)
x = 0
y = 0
flag = 5
while True:
	if array == deque():
		break
	elif flag == 5:
		x += array[0]
		array.popleft()
		flag = 6
	else:
		y += array[-1]
		array.pop()
		flag = 5
print(x * x + y * y)


n = int(input())
a_array = sorted([int(x) for x in input().split()])
print(sum(a_array[:n // 2]) ** 2 + sum(a_array[n // 2:]) ** 2)


from collections import deque
n = int(input())
a = deque(sorted(map(int, input().split())))
up = 0
right = 0
for i in range(n):
	if i % 2:
		up += a.popleft()
	else:
		right += a.pop()
print(up * up + right * right)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
isEven = True if n % 2 == 0 else False
x = 0
y = 0
iFront = 0
iBack = n - 1
while iFront != iBack and iFront < iBack:
	x += arr[iBack]
	y += arr[iFront]
	iFront += 1
	iBack -= 1
if not isEven:
	x += arr[n // 2]
print(x * x + y * y)


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


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
if n % 2 == 0:
	b = a[0:int(n / 2)]
	c = a[int(n / 2):n]
	e = sum(b)
	f = sum(c)
	s = e * e + f * f
	print(s)
else:
	b = a[0:int(n / 2) + 1]
	c = a[int(n / 2) + 1:n]
	e = sum(b)
	f = sum(c)
	g = e * e + f * f
	print(g)


number = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
count = int(number / 2)
sum1 = 0
sum2 = 0
for i in range(count):
	sum1 += sticks[i]
for j in range(count, number):
	sum2 += sticks[j]
print(sum1 ** 2 + sum2 ** 2)


n = int(input())
if n >= 1 and n <= 100000:
	a = list(map(int, input().split()))
	if min(a) >= 1 and max(a) <= 10000:
		a.sort()
		x = y = 0
		j = n - 1
		for i in range(n // 2):
			x += a[j]
			y += a[i]
			j -= 1
		if n % 2 == 1:
			x += a[n // 2]
		print(x * x + y * y)


n = int(input())
arr = [int(i) for i in input().split()]
arr = sorted(arr)
count = n
hor = 0
ver = 0
i = 0
j = n - 1
while True:
	hor += arr[j]
	j -= 1
	count -= 1
	if count == 0:
		break
	ver += arr[i]
	i += 1
	count -= 1
	if count == 0:
		break
ans = hor ** 2 + ver ** 2
print(ans)


import math
n = int(input())
arr = list(map(int, input().strip().split()))[:n]
arr.sort()
if n % 2 == 0:
	x_co = arr[int(n / 2):n]
	y_co = arr[0:int(n / 2)]
	x_coordinate = sum(x_co)
	y_coordinate = sum(y_co)
else:
	y_co = arr[math.floor(n / 2):n]
	x_co = arr[0:math.floor(n / 2)]
	y_coordinate = sum(y_co)
	x_coordinate = sum(x_co)
total = x_coordinate * x_coordinate + y_coordinate * y_coordinate
print(total)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=False)
f = 0
s = 0
for i in range(n):
	if i < n // 2:
		f += a[i]
	else:
		s += a[i]
print(f ** 2 + s ** 2)


n = int(input())
lengths = list(map(int, input().split(' ')))
lengths.sort()
metade = int(len(lengths) / 2)
vertical = lengths[:metade]
horizontal = lengths[metade:]
x = sum(horizontal) ** 2
y = sum(vertical) ** 2
print(x + y)


import math as m
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
arrr = arr[::-1]
b = m.ceil(n / 2)
s1 = sum(arrr[:b])
s2 = sum(arrr[b:])
print(s1 ** 2 + s2 ** 2)


import math
n = int(input())
points = list(map(int, input().split(' ')))
points.sort(reverse=True)
horizontal = 0
vertical = 0
if n % 2 == 0:
	first = n // 2 - 1
else:
	first = (n - 1) // 2
for i in range(n):
	if i <= first:
		horizontal += points[i]
	else:
		vertical += points[i]
result = horizontal ** 2 + vertical ** 2
print(result)


n = int(input())
ar = list(map(int, input().split()))[0:n]
a = 0
b = 0
new = sorted(ar)
for i in range(0, n // 2):
	a += new[i]
for j in range(n // 2, n):
	b += new[j]
print(a ** 2 + b ** 2)


n = int(input())
A = list(map(int, input().split()))
A.sort()
print(sum(A[0:n // 2]) ** 2 + sum(A[n // 2:n]) ** 2)


import math
n = int(input())
l = sorted(list(map(int, input().split(' '))))
a = int(math.ceil(len(l)) / 2)
print(sum(l[a:]) ** 2 + sum(l[:a]) ** 2)


n = int(input())
array = list(map(int, input().split()))
array.sort(reverse=True)
if n % 2 == 0:
	x = sum(array[:n // 2])
	y = sum(array[n // 2:])
else:
	x = sum(array[:n // 2 + 1])
	y = sum(array[n // 2 + 1:])
ans = x ** 2 + y ** 2
print(ans)


n = int(input())
sp = list(map(int, input().split()))
sp.sort()
l = 0
r = n
(x, y) = (0, 0)
count = 1
while l != r:
	if count == 1:
		r -= 1
		x += sp[r]
		count = 0
	else:
		count = 1
		y += sp[l]
		l += 1
print(x ** 2 + y ** 2)


N = int(input())
X = sorted(list(map(int, input().split())))
print(sum(X[:N // 2]) ** 2 + sum(X[N // 2:]) ** 2)


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


n = int(input())
a = list(map(int, input().split()))
a.sort()
s1 = 0
s2 = 0
for i in range(0, n):
	if i < int(n / 2):
		s1 += a[i]
	if i >= int(n / 2):
		s2 += a[i]
print(s1 ** 2 + s2 ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(j, k) = (0, 0)
for i in range(n):
	if i >= n // 2:
		j += a[i]
	else:
		k += a[i]
print(j ** 2 + k ** 2)


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


def main():
	n = int(input())
	arr = [int(i) for i in input().split()]
	half = n // 2
	arr.sort()
	first = sum(arr[:half])
	second = sum(arr[half:])
	print(first * first + second * second)
main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
h = 0
b = 0
if n > 1:
	h = sum(a[:n // 2])
b = sum(a[n // 2:])
ans = b * b + h * h
print(ans)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	n = ri()
	A = rl()
	A.sort(reverse=True)
	if n % 2 == 0:
		l = n // 2
		h = sum(A[:l])
		v = sum(A[l:])
	else:
		l = n // 2
		h = sum(A[:l + 1])
		v = sum(A[l + 1:])
	print(h ** 2 + v ** 2)
mode = 's'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


n = int(input())
line = input().split()
arr = []
for i in range(n):
	arr.append(int(line[i]))
arr.sort(reverse=True)
import math
x = sum(arr[:math.ceil(n / 2)])
y = sum(arr[math.ceil(n / 2):])
print(x ** 2 + y ** 2)


n = int(input())
a = sorted([int(x) for x in input().split()])
v = sum(a[n // 2:]) * sum(a[n // 2:])
h = sum(a[:n // 2]) * sum(a[:n // 2])
print(v + h)


inp = int(input())
l = sorted(list(map(int, input().split())))
x = sum(l[:inp // 2])
y = sum(l[inp // 2:])
print(pow(x, 2) + pow(y, 2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n % 2 != 0:
	pos = (n + 1) // 2 - 1
else:
	pos = (n + 1) // 2
a = sum(l[0:pos])
b = sum(l[pos:n])
print(a ** 2 + b ** 2)


n = int(input())
sticks = [int(i) for i in input().split()]
sticks.sort()
p1 = 0
p2 = n - 1
coord = [0, 0]
while True:
	if p2 < p1:
		break
	if p1 == p2:
		coord[0] += sticks[p1]
		break
	coord[0] += sticks[p2]
	coord[1] += sticks[p1]
	p1 += 1
	p2 -= 1
square = coord[1] ** 2 + coord[0] ** 2
print(square)


n = int(input())
l = list(map(int, input().split()))
l.sort()
(x, y) = (0, 0)
while l:
	x += l.pop(-1)
	if len(l) == 0:
		break
	y += l.pop(0)
print(x * x + y * y)


n = int(input())
sticks = list(map(int, input().split()))

def solve(n, sticks):
	sticks = sorted(sticks)
	r = []
	h = []
	v = []
	i = 0
	while sticks:
		if len(sticks) == 1:
			v.append(sticks.pop())
		else:
			h.append(sticks.pop(0))
			v.append(sticks.pop())
	return sum(h) ** 2 + sum(v) ** 2
r = solve(n, sticks)
print(r)


from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf
from collections import Counter
import sys
sys.setrecursionlimit(1000000)
from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf, factorial, log2
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
l.sort()
(x, y) = (0, 0)
i = 0
j = n - 1
count = 0
while i <= j:
	if count % 2 == 0:
		x += l[j]
		j -= 1
	else:
		y += l[i]
		i += 1
	count += 1
print(x ** 2 + y ** 2)


n = int(input())
(*l,) = map(int, input().split())
l.sort()
left = 0
right = n - 1
v = 0
h = 0
k = 0
while left <= right:
	if k % 2 == 0:
		h += l[right]
		right -= 1
	else:
		v += l[left]
		left += 1
	k += 1
print(h ** 2 + v ** 2)


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


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


n = int(input())
p = [int(x) for x in input().split()]
p = sorted(p)
a = 0
b = 0
if n % 2 == 0:
	for i in range(0, int(n / 2)):
		a = a + p[i]
		b = b + p[i + int(n / 2)]
else:
	for i in range(0, int(n / 2)):
		a = a + p[i]
		b = b + p[i + int(n / 2)]
	b = b + p[n - 1]
print(a * a + b * b)


from math import ceil
leng = int(input())
l = list(map(int, input().split()))
l = sorted(l)
print(sum(l[int(leng / 2):]) ** 2 + sum(l[:int(leng / 2)]) ** 2)


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


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
n = intput()
a = list(intsput())
a.sort()
ss = sum(a)
verts = n // 2
xx = 0
for i in range(verts):
	xx += a[i]
yy = ss - xx
print(xx ** 2 + yy ** 2)


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


a = int(input())
b = list(map(int, input().split()))
b.sort(reverse=True)
c = 0
d = 0
if a % 2 != 0:
	c = sum(b[:a - (a - 1) // 2])
	d = sum(b[a - (a - 1) // 2:])
	print(c ** 2 + d ** 2)
else:
	c = sum(b[:a // 2])
	d = sum(b[a // 2:])
	print(c ** 2 + d ** 2)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(n, arr):
	arr.sort()
	(f_half, s_half) = (arr[:n // 2], arr[n // 2:])
	write(sum(f_half) ** 2 + sum(s_half) ** 2)

def main():
	n = r_int()
	arr = r_array()
	solution(n, arr)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


def grow_the_tree():
	number_of_sticks = int(input())
	sticks = list(map(int, input().split()))
	sticks.sort()
	if number_of_sticks % 2 == 0:
		horizontal = sum(sticks[0:number_of_sticks // 2])
		vertical = sum(sticks[number_of_sticks // 2:])
		longest_distance = horizontal ** 2 + vertical ** 2
	else:
		horizontal = sum(sticks[:number_of_sticks // 2])
		vertical = sum(sticks[number_of_sticks // 2:])
		longest_distance = horizontal ** 2 + vertical ** 2
	print(longest_distance)

def main():
	grow_the_tree()
main()


n = int(input())
numbers = input().split()
numbers = [int(i) for i in numbers]
numbers.sort()

def getSum1(n, numbers):
	summ1 = 0
	for i in range(n // 2):
		summ1 += int(numbers[i])
	return summ1

def getSum2(n, numbers):
	summ1 = 0
	for i in range(n // 2):
		summ1 += int(numbers[-1 - i])
	return summ1

def getSum3(n, numbers):
	summ1 = 0
	for i in range(n // 2 + 1):
		summ1 += int(numbers[-1 - i])
	return summ1
if n % 2 == 0:
	summ1 = getSum1(n, numbers)
	summ2 = getSum2(n, numbers)
else:
	summ1 = getSum1(n, numbers)
	summ2 = getSum3(n, numbers)
print(summ1 ** 2 + summ2 ** 2)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
sum1 = 0
sum2 = 0
for i in range(n):
	if i < int(n / 2):
		sum1 += a[i]
	else:
		sum2 += a[i]
print(sum1 * sum1 + sum2 * sum2)


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


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


a = int(input())
b = list(map(int, input().split()))
X = 0
Y = 0
b.sort()
for i in range(0, len(b)):
	if i < len(b) // 2:
		Y += b[i]
	else:
		X += b[i]
print(Y ** 2 + X ** 2)


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
INF = float('inf')

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

def main():
	n = int(input())
	a = getlist()
	a = sorted(a)
	x = 0
	y = 0
	for i in range(int(n // 2)):
		x += a[i]
	y = sum(a) - x
	ans = x ** 2 + y ** 2
	print(ans)
main()


n = int(input())
sticks = [int(i) for i in input().split(' ')]
sticks.sort()
x = 0
y = 0
i = 0
j = n - 1
while True:
	x += sticks[j]
	j -= 1
	if i > j:
		break
	y += sticks[i]
	i += 1
	if i > j:
		break
print(x * x + y * y)


n = int(input())
lis = sorted(map(int, input().split()))
k = n // 2
a = sum(lis[:k])
b = sum(lis[k:])
print(a * a + b * b)


import math
n = int(input())
l = []
(a, b) = (0, 0)
l = list(map(int, input().split()))
l.sort(reverse=True)
if n % 2 == 0:
	for i in range(n // 2):
		a += l[i]
	for i in range(n // 2, n):
		b += l[i]
else:
	for i in range(n // 2 + 1):
		a += l[i]
	for i in range(n // 2 + 1, n):
		b += l[i]
print(a * a + b * b)


import sys

def atoi(line):
	line = line.rstrip().split()
	return list(map(int, line))

def count(a):
	l = 0
	r = len(a) - 1
	h = 0
	v = 0
	while l < r:
		h += a[l]
		v += a[r]
		l += 1
		r -= 1
	if l == r:
		h += a[l]
	return v ** 2 + h ** 2
n = int(input())
a = atoi(sys.stdin.readline())
a.sort(reverse=True)
ans = count(a)
print(ans)


def axis(n, li):
	l = sorted(li)
	x = sum(l[0:n // 2]) ** 2 + sum(l[n // 2:]) ** 2
	print(x)
n = int(input())
li = [int(i) for i in input().split()]
ans = axis(n, li)
ans


n = int(input())
arr = list(map(int, input().split()))
x = y = counter = i = 0
j = n - 1
arr.sort()
while i != j + 1:
	if counter % 2 == 0:
		y += arr[j]
		j -= 1
	else:
		x += arr[i]
		i += 1
	counter += 1
print(x ** 2 + y ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
sum1 = 0
i = 0
limit = (n + 1) // 2
while i < limit:
	sum1 += l[i]
	i += 1
sum2 = 0
while i < n:
	sum2 += l[i]
	i += 1
print(sum1 ** 2 + sum2 ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l1 = 0
l2 = 0
if n % 2 == 0:
	l1 = n // 2
	l2 = n // 2
else:
	l1 = n // 2
	l2 = n // 2 + 1
sn1 = sum(a[0:l1])
sn2 = sum(a) - sn1
ans = sn1 * sn1 + sn2 * sn2
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
s1 = sum(a[:n // 2])
s2 = sum(a[n // 2:])
print(s1 ** 2 + s2 ** 2)


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


from sys import stdin
t = 1
while t > 0:
	n = int(stdin.readline().rstrip())
	l = list(map(int, stdin.readline().split()))
	l.sort()
	(x, y) = (0, 0)
	f = 0
	while len(l) != 0:
		if f == 0:
			x += l[len(l) - 1]
			l.pop(len(l) - 1)
		else:
			y += l[0]
			l.pop(0)
		f = 1 - f
	print(x * x + y * y)
	t -= 1


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


n = int(input())
arr = list(map(int, input().split()))
v = 0
h = 0
i = 0
j = n - 1
arr.sort()
while i != j:
	h = h + arr[j]
	v = v + arr[i]
	j = j - 1
	i = i + 1
	if i > j:
		break
if h > v and n & 1:
	h = h + arr[i]
elif n & 1:
	v = v + arr[i]
print(h * h + v * v)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
p = sum([a[x] for x in range(n // 2)])
q = sum(a) - p
print(p ** 2 + q ** 2)


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


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
l = len(ai) // 2
x = sum(ai[:l])
y = sum(ai[l:])
print(x ** 2 + y ** 2)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scanner()
	a = get_list()
	a.sort()
	x = 0
	y = 0
	for i in range(n // 2):
		x += a[i]
		y += a[n - i - 1]
	if n % 2 == 1:
		y += a[n // 2]
	print(x ** 2 + y ** 2)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
lst = sorted(get_int_list())
first = sum(lst[0:n // 2])
second = sum(lst[n // 2:])
print(first ** 2 + second ** 2)


n = int(input())
c = list(map(int, input().split()))
l = sorted(c)
m = sum(l[n // 2:])
r = sum(l) - m
print(m * m + r * r)


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


a = int(input())
b = list(map(int, input().split()))
b.sort()
k = len(b)
r = 0
q = 0
m = int(k / 2)
for i in range(0, m):
	r = r + int(b[i])
for j in range(m, k):
	q = q + int(b[j])
print(q * q + r * r)


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(reverse=True)
sa = sum(s[:(a - 1) // 2 + 1])
sb = sum(s[(a - 1) // 2 + 1:])
ans = 0
print(sa ** 2 + sb ** 2)


from math import *
we = int(input())
a = list(map(int, input().split()))
b = ceil(we / 2)
c = 0
d = 0
a = sorted(a)
if we % 2 == 1:
	b -= 1
for i in range(len(a)):
	if i >= b:
		d += a[i]
	else:
		c += a[i]
print(d ** 2 + c ** 2)


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


n = eval(input())
ai = list(map(int, input().split()))
len = int(n / 2)
l_sum = 0
r_sum = 0
ai.sort()
for i in range(0, len):
	l_sum += ai[i]
for i in range(len, n):
	r_sum += ai[i]
print(l_sum ** 2 + r_sum ** 2)


n = int(input())
h = n // 2
d = [int(i) for i in input().split()]
d.sort()
print(sum(d[:h]) ** 2 + sum(d[h:]) ** 2)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
d = int(n / 2)
l1 = l[:d]
l2 = l[d:]
sl1 = sum(l1)
sl2 = sum(l2)
print(sl2 * sl2 + sl1 * sl1)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import *

def li():
	return [int(____) for ____ in input().rstrip('\n').split(' ')]

def val():
	return int(input().rstrip('\n'))

def st():
	return input().rstrip('\n')

def sttoli():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = li()
l.sort(reverse=1)
ind = len(l) // 2
if len(l) & 1:
	ind += 1
su = sum(l[:ind])
su2 = sum(l) - su
print(su ** 2 + su2 ** 2)


def rin():
	return int(input())

def rlist(n):
	return [int(i) for i in input().split()]

def main():
	n = rin()
	a = rlist(n)
	a.sort()
	be = sum((a[i] for i in range(int(n / 2))))
	lon = sum((i for i in a)) - be
	print(lon ** 2 + be ** 2)
main()


n = int(input())
n1 = list(map(int, input().split()))
n1.sort()
sum = 0
sum1 = 0
for i in range(int(len(n1) / 2)):
	sum += n1[i]
for j in range(int(len(n1) / 2), len(n1)):
	sum1 += n1[j]
length = sum ** 2 + sum1 ** 2
print(length)


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

def main():
	n = int(input())
	arr = GetList()
	arr.sort(reverse=True)
	ans1 = 0
	ans2 = 0
	if n % 2 == 0:
		for num1 in arr[:n // 2]:
			ans1 += num1
		for num2 in arr[n // 2:]:
			ans2 += num2
		print(ans1 * ans1 + ans2 * ans2)
	else:
		for num1 in arr[:(n + 1) // 2]:
			ans1 += num1
		for num2 in arr[(n + 1) // 2:]:
			ans2 += num2
		print(ans1 * ans1 + ans2 * ans2)
main()


n = int(input())
a = sorted(map(int, input().split()))
(best, i, j, x, y) = (True, 0, n - 1, 0, 0)
while i <= j:
	if best == True:
		x += a[j]
		j -= 1
	else:
		y += a[i]
		i += 1
	best = not best
print(x * x + y * y)


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


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


import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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

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

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

def fi():
	return float(input())

def mfi():
	return map(float, input().rstrip().split())

def lmfi():
	return list(map(float, input().rstrip().split()))

def li():
	return list(input().rstrip())

def debug(*args, sep=' ', end='\n'):
	print('debug:', *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None

def exit(*arg):
	print(*arg)
	sys.exit()

def main():
	n = ii()
	a = lmi()
	a.sort()
	ans = 0
	s = sum(a[0:n // 2])
	ps = sum(a) - s
	print(s * s + ps * ps)
	return
main()


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
if n % 2:
	k = int(n / 2)
else:
	k = int(n / 2)
som1 = sum(list[:k])
som2 = sum(list) - som1
print(som1 * som1 + som2 * som2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n == 1:
	print(l[0] ** 2)
else:
	h = 0
	v = 0
	i = 0
	j = n - 1
	flag = False
	while i <= j:
		if flag:
			h += l[i]
			i += 1
			flag = False
		else:
			v += l[j]
			j -= 1
			flag = True
	print(h ** 2 + v ** 2)


def main():
	n = int(input())
	aa = [int(a) for a in input().split()]
	aa.sort()
	short = sum(aa[:n // 2])
	long = sum(aa[n // 2:])
	print(short * short + long * long)
main()


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	n = read_int()
	A = read_ints()
	A.sort()
	x = sum(A[:n // 2])
	y = sum(A) - x
	print(x * x + y * y)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
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')

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

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def fib_to_n(n):
	f = []
	(a, b) = (0, 1)
	while a <= n:
		f.append(a)
		(a, b) = (b, a + b)
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		debug(n, i)
		if n % i == 0:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P

def is_lucky(n):
	return set(list(str(n))).issubset({'4', '7'})
main()


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


t = int(input())
x = list(map(int, input().split()))
x.sort()
s1 = 0
s2 = 0
for i in range(t // 2):
	s1 = s1 + x[i]
for j in range(t // 2, t):
	s2 = s2 + x[j]
print(s1 ** 2 + s2 ** 2)


n = int(input())
k = list(map(int, input().split()))
k = sorted(k, reverse=True)
a = []
b = []
if len(k) % 2 != 0:
	a = k[0:len(k) // 2 + 1]
	b = k[len(k) // 2 + 1:len(k)]
else:
	a = k[0:len(k) // 2]
	b = k[len(k) // 2:len(k)]
o = sum(a)
o = o ** 2
j = sum(b)
j = j ** 2
print(o + j)


sticks = int(input())
lengths = list(map(lambda x: int(x), input().split()))
lengths.sort()
if sticks % 2 == 0:
	ending = sticks // 2
else:
	ending = sticks // 2
(horizontal, vertical) = (sum(lengths[:ending]), sum(lengths[ending:]))
print(horizontal ** 2 + vertical ** 2)


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


n = int(input())
st = list(map(int, input().split()))
st = sorted(st)
(le, ri) = (0, n - 1)
(x, y) = (0, 0)
while le < ri:
	x += st[ri]
	y += st[le]
	ri -= 1
	le += 1
if le == ri:
	x += st[ri]
print(x * x + y * y)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

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

def li():
	return list(mi())
mod = 1000000007
inf = float('inf')

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
n = ii()
a = li()
a.sort()
s1 = 0
s2 = 0
for i in range(n // 2):
	s1 += a[i]
for i in range(n // 2, n):
	s2 += a[i]
ans = s1 ** 2 + s2 ** 2
print(ans)


i = int
cin = input
le = len
s = str
seg = i(cin())
arr = list(map(i, cin().split()))
arr.sort()
seg_1 = 0
seg_2 = seg // 2
(x, y) = (0, 0)
while seg_1 < seg // 2 or seg_2 < seg:
	if seg_2 < seg:
		pick_horizontal = arr[seg_2]
		x += pick_horizontal
		seg_2 += 1
	if seg_1 < seg // 2:
		pick_vertical = arr[seg_1]
		y += pick_vertical
		seg_1 += 1
print(x ** 2 + y ** 2)


from math import ceil
n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
print(sum(l[0:ceil(n // 2)]) ** 2 + sum(l[ceil(n // 2):n]) ** 2)


import math
n = int(input())
array_n = sorted(list(map(int, input().split())))
x = array_n[int(len(array_n) / 2):]
y = array_n[:int(len(array_n) / 2)]
res = sum(x) ** 2 + sum(y) ** 2
print(res)


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


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


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
ans = sum(a[:n // 2]) ** 2 + sum(a[n // 2:]) ** 2
print(ans)


n = int(input())
lst1 = list(map(int, input().split()))
lst1.sort()
if len(lst1) % 2 == 0:
	lst2 = lst1[:int(len(lst1) / 2)]
	lst3 = lst1[int(len(lst1) / 2):]
else:
	lst2 = lst1[:int(len(lst1) / 2)]
	lst3 = lst1[int(len(lst1) / 2):]
k = sum(lst2) ** 2 + sum(lst3) ** 2
print(k)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
a = [int(item) for item in input().split()]
a.sort()
front = sum(a[:n // 2])
back = sum(a[n // 2:])
print(front * front + back * back)


import heapq
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
small_half = sum(heapq.nsmallest(n // 2, A))
print(small_half ** 2 + (S - small_half) ** 2)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort()
print(sum(a[:n // 2]) ** 2 + sum(a[n // 2:]) ** 2)


t = int(input())
n = [int(i) for i in input().split()]
n.sort()
firsthalf = t // 2
sum1 = sum(n[:firsthalf])
sum2 = sum(n[firsthalf:])
print(sum1 ** 2 + sum2 ** 2)


from math import ceil

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_product(n, m, arr):
	product = 1
	if n <= m:
		for i in range(n):
			for j in range(i + 1, n):
				product = product * abs(arr[i] - arr[j]) % m
		return product
	return 0

def find_subarrays(n, k, word):
	curr_sum = 0
	count = 0
	mp = {}
	for i in range(n):
		curr_sum += int(word[i])
		if curr_sum not in mp:
			mp[curr_sum] = 0
		mp[curr_sum] += 1
		if curr_sum == k:
			count += 1
		elif curr_sum - k in mp:
			count += mp[curr_sum - k]
	return count

def find_max_len(n, arr):
	b = 0
	arr.sort(reverse=True)
	for i in range(ceil(n / 2)):
		b += int(arr[i])
	h = sum(arr) - b
	return b * b + h * h
t = 1
while t:
	t = t - 1
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	print(find_max_len(n, l))


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


def largest_polyline(number_of_sticks, sticks_lengths):
	sticks_lengths.sort()
	lower_half = sticks_lengths[:len(sticks_lengths) // 2]
	bigger_half = sticks_lengths[len(sticks_lengths) // 2:]
	return sum(bigger_half) ** 2 + sum(lower_half) ** 2
n = map(int, input())
a = list(map(int, input().split()))
print(largest_polyline(n, a))


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
(i, j) = (0, len(a) - 1)
(x, y) = (0, 0)
alface = True
while j >= i:
	if alface:
		x += a[j]
		j = j - 1
	else:
		y += a[i]
		i = i + 1
	alface = not alface
print(x * x + y * y)


n = int(input())
x = [int(w) for w in input().split()]
e = n // 2
y = sorted(x)
a = y[:e]
b = y[e:]
print(sum(a) ** 2 + sum(b) ** 2)


def main():
	n = int(input())
	a = tuple(map(int, input().split()))
	a = sorted(a)
	st = int(n / 2) if n % 2 == 0 else int((n - 1) / 2)
	l = 0
	for i in range(st):
		l += a[i]
	r = 0
	for i in range(st, n):
		r += a[i]
	print(l ** 2 + r ** 2)
main()


p = int(input())
t = sorted(list(map(int, input().split())))
if p % 2 == 0:
	o = sum(t[:int(p / 2)])
	m = sum(t[int(p / 2):])
	r = o * o + m * m
else:
	o = sum(t[:int(p / 2)])
	m = sum(t[int(p / 2):])
	r = o * o + m * m
print(r)


n = int(input())
a = [int(a) for a in input().split()]
a.sort()
if n == 1:
	print(a[0] * a[0])
else:
	print(pow(sum(a[:n // 2]), 2) + pow(sum(a[n // 2:]), 2))


import math
n = int(input())
a = [int(i) for i in input().split()]
x = n / 2
x = math.ceil(x)
sum3 = 0
a.sort()
sum1 = 0
sum2 = 0
if n % 2 == 0:
	x = x + 1
for i in range(0, x - 1):
	sum1 += a[i]
for j in range(x - 1, n):
	sum2 += a[j]
sum3 = sum1 * sum1 + sum2 * sum2
print(sum3)


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


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


from math import pow
t = int(input())
li = [int(i) for i in input().split()]
x = len(li) // 2
li.sort()
l1 = sum(li[:x])
l2 = sum(li[x:])
print(l1 ** 2 + l2 ** 2)


n = int(input())
a = [int(n) for n in input().split()]
a.sort()
mid = n // 2
sum = sum(a[0:mid]) ** 2 + sum(a[mid:]) ** 2
print(sum)


import math
input()
a = sorted(list(map(int, input().split())))
print(pow(sum(a[0:len(a) // 2]), 2) + pow(sum(a[len(a) // 2:len(a) + 1]), 2))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
	x = 0
	y = 0
if n % 2 != 0:
	n = n - 1
	x = a[n // 2]
	a.pop(n // 2)
	y = 0
k = n // 2
for i in range(k):
	y = y + a[i]
	x = x + a[k + i]
ans = x * x + y * y
print(ans)


n = int(input())
x = input()
xx = x.split()
for i in range(0, n):
	xx[i] = int(xx[i])
xx.sort()
f = int(n // 2)
s1 = 0
s2 = 0
for i in range(0, f):
	s1 += xx[i]
for i in range(f, n):
	s2 += xx[i]
h = s1 ** 2 + s2 ** 2
print(h)


n = int(input())
a = 0
b = 0
i = 0
lst1 = list(map(int, input().split()))
lst1.sort(reverse=True)
while len(lst1) != 0:
	a += lst1[i]
	del lst1[i]
	if len(lst1) == 0:
		break
	b += lst1[len(lst1) - 1]
	del lst1[len(lst1) - 1]
print(a * a + b * b)


n = int(input())
a = [int(i) for i in input().split()]
(x, y) = (0, 0)
a.sort()
i = n - 1
j = 0
flag = 0
while i >= n // 2:
	if i == j:
		x += a[i]
		i -= 1
	else:
		x += a[i]
		i -= 1
		y += a[j]
		j += 1
print(x * x + y * y)


n = int(input())
sticks = sorted([int(x) for x in input().split()])
upT = 0
rightT = 0
for sticki in range(len(sticks)):
	stick = sticks[sticki]
	up = sticki < len(sticks) // 2
	if up:
		upT += stick
	else:
		rightT += stick
	up = not up
print(rightT ** 2 + upT ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
x = 0
y = 0
while i < j:
	x += l[j]
	y += l[i]
	i += 1
	j -= 1
if len(l) % 2 == 1:
	x += l[len(l) // 2]
print(x ** 2 + y ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
x = 0
y = 0
i = n - 1
while i > n // 2 - 1:
	x = x + l[i]
	i -= 1
while i > -1:
	y = y + l[i]
	i -= 1
print(x ** 2 + y ** 2)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	a.sort()
	v = sum(a)
	l = n // 2
	x = 0
	for i in range(l):
		x += a[i]
	v -= x
	print(v * v + x * x)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


from math import ceil, floor
n = int(input())
l = sorted(list(map(int, input().split())))
(sumh, sumb, i) = (0, 0, 0)
while i < n:
	if i < floor(n / 2):
		sumh += l[i]
	elif i >= floor(n / 2):
		sumb += l[i]
	i += 1
print(sumh ** 2 + sumb ** 2)


T = int(input())
L = list(map(int, input().split()))
L.sort()
if len(L) % 2 == 0:
	A = sum(L[:len(L) // 2])
	B = sum(L[len(L) // 2:])
	print(A ** 2 + B ** 2)
else:
	C = sum(L[:len(L) // 2])
	D = sum(L[len(L) // 2:])
	print(C ** 2 + D ** 2)


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


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


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


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

def si():
	return input()

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

def li():
	return list(mi())
n = ii()
a = li()
a.sort()
x = y = 0
for i in range(n // 2):
	x += a[i]
	y += a[n - i - 1]
if n % 2:
	y += a[n // 2]
print(x * x + y * y)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
start = 0
end = len(a) - 1
vertical = 0
horizontal = 0
flag = 0
while start <= end:
	if flag == 0:
		horizontal += a[end]
		end -= 1
		flag = 1
	else:
		vertical += a[start]
		start += 1
		flag = 0
print(horizontal * horizontal + vertical * vertical)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
(q, w) = (0, 0)
for i in range(n // 2):
	q += a[i]
if n % 2 != 0:
	q += a[n // 2]
	for i in range(n // 2 + 1, n, 1):
		w += a[i]
else:
	for i in range(n // 2, n, 1):
		w += a[i]
print(q * q + w * w)


from math import *
n = int(input())
s = input().split()
for i in range(len(s)):
	s[i] = int(s[i])
s.sort()
dx = s[len(s) // 2:]
dy = s[:len(s) // 2]
x = 0
y = 0
for i in dx:
	x += i
for i in dy:
	y += i
print(x ** 2 + y ** 2)


class Position:

	def __init__(self, x=0, y=0):
		self.x = x
		self.y = y

def algorithm(a):
	pos = Position()
	a.sort()
	start = 0
	end = len(a) - 1
	horizontal = True
	while True:
		if horizontal:
			pos.x += a[end]
			end -= 1
			horizontal = False
		else:
			pos.y += a[start]
			start += 1
			horizontal = True
		if end < start:
			return pow(pos.x, 2) + pow(pos.y, 2)
inputstring = input()
a = int(inputstring)
l = []
inputline = input()
inputline = inputline.split(' ')
for i in inputline:
	l.append(int(i))
print(algorithm(l))


import array
import math as m

def buffer():
	req = int(input())
	for i in range(req):
		input()
		prices = array_to_int(input().split(' '))
		first = len(prices) * [0]
		intermidiate = array_to_int(input().split(' '))
		for ii in range(0, len(first), intermidiate[1]):
			if ii == 0:
				continue
			first[ii] += intermidiate[0]
		intermidiate = array_to_int(input().split(' '))
		for ii in range(0, len(first), intermidiate[1]):
			if ii == 0:
				continue
			first[ii] += intermidiate[0]
		ii = 1
		while ii < len(first):
			if prices[ii - 1] < prices[ii] and first[ii - 1] > first[ii] or (prices[ii - 1] > prices[ii] and first[ii - 1] < first[ii]):
				(prices[ii - 1], prices[ii]) = (prices[ii], prices[ii - 1])
				ii = 1
			else:
				ii += 1
		print(prices)
		print([first[i] * prices[i] // 100 for i in range(len(first))])
		must_sum = int(input())
		for j in range(len(first)):
			must_sum -= first[j] * prices[j]
			if must_sum <= 0:
				print(j + 1)
				break
		else:
			print(-1)

def deleted_segments(array):
	result = 0
	last_palindrome = False
	for i in range(len(array)):
		for spl in range(2, len(array), 2):
			if i + spl > len(array):
				break
			if stack_deleted(array[i:i + spl]):
				result += 1
	return result

def stack_deleted(sub_array):
	new_stack = array.array('u', [])
	last = 0
	for i in sub_array:
		if len(new_stack) == 0:
			new_stack.append(i)
		elif new_stack[-1] == i:
			new_stack.pop(len(new_stack) - 1)
		else:
			new_stack.append(i)
	return len(new_stack) == 0

def solution():
	input()
	sticks = array_to_int(input().split(' '))
	sticks.sort()
	minimum = sticks[0:len(sticks) // 2]
	maximum = sticks[len(sticks) // 2:]
	minimum = sum(minimum)
	maximum = sum(maximum)
	result = minimum * minimum + maximum * maximum
	print(result)

def count_of_one(number):
	result = 0
	while number:
		result += number % 2
		number /= 2
	return result

def rindex(seq, thing):
	for i in range(len(seq) - 1, -1, -1):
		if seq[i] == thing:
			return i

def to_mixed_frac(first, second):
	while True:
		for i in range(2, first + 1):
			if first % i == 0 and second % i == 0:
				first //= i
				second //= i
				break
		else:
			break
	return str(first) + '/' + str(second)

def array_to_int(array):
	for i in range(len(array)):
		array[i] = int(array[i])
	return array

def join0(array):
	result = ''
	for i in array:
		result += str(i)
	return result

def replace(string, new_ch, index):
	new_str = ''
	for i in range(len(string)):
		if i == index:
			new_str += new_ch
		else:
			new_str += string[i]
	return new_str
solution()


n = int(input())
a = map(int, input().split())
a = sorted(a)
count1 = 0
count2 = 0
mid = n // 2
if n % 2 == 0:
	for elem in a[:mid]:
		count1 += elem
	for elem in a[mid:]:
		count2 += elem
	print(count1 ** 2 + count2 ** 2)
else:
	for elem in a[:mid]:
		count1 += elem
	for elem in a[mid:]:
		count2 += elem
	print(count1 ** 2 + count2 ** 2)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
c = sum(l[:n // 2])
d = sum(l[n // 2:])
print(c * c + d * d)


def solve(lines):
	lines.sort()
	div = len(lines) // 2
	sum_x = sum(lines[:div])
	sum_y = sum(lines[div:])
	return sum_x ** 2 + sum_y ** 2
n = int(input())
lines = [int(r) for r in input().split(' ')]
print(solve(lines))


n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
smmx = sum(lst[n // 2:])
smmn = sum(lst[:n // 2])
print(smmx ** 2 + smmn ** 2)


def main():
	(N, *A) = map(int, open(0).read().split())
	A.sort(reverse=True)
	X = sum((A[i] for i in range(-(-N // 2))))
	Y = sum((A[i] for i in range(-(-N // 2), N)))
	print(X * X + Y * Y)
main()


input()
sticks = sorted(list(map(int, input().split())))
print(sum(sticks[:len(sticks) // 2]) ** 2 + sum(sticks[len(sticks) // 2:]) ** 2)


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


n = int(input())
b = list(map(int, input().split(' ')))
b.sort()
suma = 0
sumb = 0
for (i, stick) in enumerate(b, start=1):
	if i <= n / 2:
		suma += stick
	else:
		sumb += stick
print(suma * suma + sumb * sumb)


n = int(input())
l = list(map(int, input().split()))

def largestdistance(n, l):
	l.sort()
	vert = l[:int(n / 2)]
	horiz = l[int(n / 2):]
	print(sum(vert) ** 2 + sum(horiz) ** 2)
largestdistance(n, l)


def main():
	n = int(input())
	a = list(map(int, input().strip().split()))
	a.sort()
	i = 0
	j = n - 1
	x = 0
	y = 0
	while i <= j:
		x += a[j]
		if i != j:
			y += a[i]
		i += 1
		j -= 1
	ans = x ** 2 + y ** 2
	print(ans)
main()


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
result = sum(a[:n // 2]) ** 2 + sum(a[n // 2:]) ** 2
print(result)


import sys
input = sys.stdin.readline
x = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=False)
sum1 = 0
sum2 = 0
for i in range(x):
	if x % 2 == 0:
		if i < x / 2:
			sum1 += arr[i]
		else:
			sum2 += arr[i]
	elif i < (x - 1) / 2:
		sum1 += arr[i]
	else:
		sum2 += arr[i]
ans = sum1 * sum1 + sum2 * sum2
print(ans)


from sys import stdout, stdin
for i in stdin:
	n = int(i)
	break
for i in stdin:
	l = list(map(int, i.strip().split()))
	break
l.sort()
a = []
b = []
while len(l) > 1:
	a.append(l[0])
	del l[0]
	b.append(l[-1])
	del l[-1]
if len(l):
	b.append(l[0])

def power(a):
	return a ** 2
stdout.write(str(sum(a) ** 2 + sum(b) ** 2))


def main():
	n = int(input())
	array = list(map(int, input().split(' ')))
	array.sort(reverse=True)
	if n == 0:
		print(0)
		return
	if n == 1:
		print(array[0] * array[0])
		return
	if n % 2 == 0:
		mid = int(n / 2)
	else:
		mid = int(n / 2) + 1
	x = 0
	for i in range(0, mid):
		x += array[i]
	y = 0
	for i in range(mid, n):
		y += array[i]
	result = x * x + y * y
	print(result)
main()


n = int(input())
sum1 = 0
sum2 = 0
stick_len = list(map(int, input().split()))
stick_len.sort()
for j in range(n):
	if j < n // 2:
		sum1 += stick_len[j]
	else:
		sum2 += stick_len[j]
print(sum1 * sum1 + sum2 * sum2)


n = input()
k = input()
num = []
t = k.split(' ')
for i in t:
	num.append(int(i))
num.sort()
num1 = num[0:int(n) // 2]
q = sum(num1) ** 2 + (sum(num) - sum(num1)) ** 2
print(q)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = sum(a[n // 2:])
print(res * res + (sum(a) - res) ** 2)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
(a, b) = (0, 0)
if n % 2 == 0:
	(a, b) = (sum(l[:n // 2]), sum(l[n // 2:]))
else:
	(a, b) = (sum(l[:n // 2]), sum(l[n // 2:]))
print(a * a + b * b)


n = int(input())
x = list(sorted(map(int, input().split()), reverse=True))
a = []
if n % 2:
	b = sum(x[:n // 2 + 1])
	c = sum(x[n // 2 + 1:])
else:
	b = sum(x[:n // 2])
	c = sum(x[n // 2:])
print(b * b + c * c)


n = int(input())
s = [int(i) for i in input().split()]
s.sort()
d = s[:n // 2]
r = s[n // 2:]
print(sum(d) ** 2 + sum(r) ** 2)


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()
if n == 1:
	print(l[0] ** 2)
	exit()
l.sort(reverse=True)
h = sum(l[:n // 2 + n % 2])
print(h ** 2 + (sum(l) - h) ** 2)


import sys
s = int(input())
l = list(map(int, sys.stdin.readline().split()))
l = sorted(l)
low = 0
high = len(l)
mid = (low + high) // 2
horizon = sum(l[:mid])
vertic = sum(l[mid:])
print(vertic * vertic + horizon * horizon)


x = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum(a[x // 2:]) ** 2 + sum(a[:x // 2]) ** 2)


a = int(input())
z = list(map(int, input().split()))
z = sorted(z)
eve = 0
odd = 0
for i in range(len(z)):
	if i % 2 == 0:
		eve = eve + z[i]
	else:
		odd = odd + z[i]
t = eve ** 2 + odd ** 2
ans = sum(z[0:len(z) // 2]) ** 2 + sum(z[len(z) // 2:]) ** 2
print(ans)


n = int(input())
a = list(map(int, input().strip().split(' ')))
a.sort(reverse=True)
x = y = 0
for i in range(0, n // 2 + n % 2):
	x += a[i]
for i in range(n // 2 + n % 2, n):
	y += a[i]
ans = x * x + y * y
print(ans)


from math import *
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
res = sum(a[n // 2:]) ** 2 + sum(a[:n // 2]) ** 2
print(res)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a1 = sum(a[len(a) // 2:])
print(a1 ** 2 + sum(a[:len(a) // 2]) ** 2)


def main():
	n = int(input())
	v = sorted(list(map(int, input().split())))
	a = sum(v[:n // 2])
	b = sum(v[n // 2:])
	print(a * a + b * b)
main()


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s.sort()
from collections import deque
s = deque(s)
x = 0
y = 0
while len(s) > 0:
	x += s[-1]
	s.pop()
	if len(s) > 0:
		y += s[0]
		s.popleft()
print(x * x + y * y)


n = int(input())
l = list(map(int, input().split()))
l.sort()
tot = sum(l)
x = sum(l[:n // 2])
y = tot - x
print(x * x + y * y)


n = int(input())
l = sorted(list(map(int, input().split())))
a = 0
b = 0
for x in range(n):
	if x < n // 2:
		a += l[x]
	else:
		b += l[x]
print(a ** 2 + b ** 2)


n = int(input())
a = sorted([int(x) for x in input().split()])
print(sum(a[:len(a) // 2]) ** 2 + sum(a[len(a) // 2:]) ** 2)


nSticks = int(input())
sticks = [int(x) for x in input().split()]
sticks.sort()
if nSticks % 2 == 0:
	mid = nSticks // 2
else:
	mid = nSticks // 2
x = sum(sticks[0:mid])
y = sum(sticks[mid:nSticks])
print(x * x + y * y)


n = int(input())
s_lines = list(sorted(map(int, input().split())))
print(sum(s_lines[:len(s_lines) // 2]) ** 2 + sum(s_lines[len(s_lines) // 2:]) ** 2)


import math
n = int(input())
l = map(int, input().split())
l = sorted(l, reverse=True)
c = math.ceil(len(l) / 2)
(a1, a2) = (sum(l[0:c]), sum(l[c:]))
print(a1 * a1 + a2 * a2)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
num = sum(ai[:n // 2])
num2 = sum(ai) - num
print(num ** 2 + num2 ** 2)


n = int(input())
l = sorted([int(i) for i in input().split()])
length = len(l)
if len(l) % 2 == 0:
	big = l[len(l) // 2:]
	small = l[:len(l) // 2]
	print(sum(big) ** 2 + sum(small) ** 2)
else:
	big = l[len(l) // 2:]
	small = l[:len(l) // 2]
	print(sum(big) ** 2 + sum(small) ** 2)


n = int(input())
s = map(int, input().split())
s = list(s)
s.sort()
import math
minim = 0
for i in range(math.floor(len(s) / 2)):
	minim = minim + s[i]
s.reverse()
maxim = 0
for i in range(math.ceil(len(s) / 2)):
	maxim = maxim + s[i]
print(minim ** 2 + maxim ** 2)


import sys
input = sys.stdin.readline

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

def read_is(n=1):
	return [read_i() for _ in range(n)]
n = int(input())
ls = read_i()
ls.sort()
print(sum(ls[:n // 2]) ** 2 + sum(ls[n // 2:]) ** 2)


n = int(input())
s = [int(x) for x in input().split()]
s = sorted(s)
rev = sorted(s, reverse=True)
x = y = 0
for i in range(n // 2):
	x += rev[i]
	y += s[i]
if n % 2 != 0:
	x += s[n // 2]
print(x * x + y * y)


import sys
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
cnt = n // 2
l1 = 0
for i in range(cnt):
	l1 += a[i]
l2 = sum(a) - l1
print(l1 * l1 + l2 * l2)


n = int(input())
trees = list(map(int, input().split()))
trees.sort()
left = trees[:n // 2]
right = trees[n // 2:]
print(sum(left) ** 2 + sum(right) ** 2)


n = int(input())
a = list(map(int, input().split()))
(x, y) = (0, 0)
a = sorted(a, reverse=True)
if len(a) % 2 != 0:
	i = 0
	j = -1
	while True:
		x += a[i]
		i += 1
		if i == len(a) // 2 + 1:
			break
		y += a[j]
		j -= 1
		if j == len(a) // 2:
			break
	print(x ** 2 + y ** 2)
else:
	i = 0
	j = -1
	while True:
		if i == len(a) // 2:
			break
		if j == len(a) // 2:
			break
		x += a[i]
		i += 1
		y += a[j]
		j -= 1
	print(x ** 2 + y ** 2)


k = input()
l = list(map(int, input().split(' ')))
l.sort()
if len(l) % 2 == 0:
	mid = len(l) // 2
	q = sum(l[:mid])
	q = q ** 2
	p = sum(l[mid:])
	p = p * p
	print(p + q)
else:
	mid = len(l) // 2
	q = sum(l[:mid + 1])
	q = q * q
	p = sum(l[mid + 1:])
	p = p * p
	q1 = sum(l[:mid])
	q1 = q1 * q1
	p2 = sum(l[mid:])
	p2 = p2 * p2
	print(max(q + p, q1 + p2))


n = int(input())
p = list(map(int, input().split()))
p.sort(reverse=True)
if len(p) % 2 == 0:
	k = len(p) // 2
else:
	k = len(p) // 2 + 1
a = sum(p[:k])
b = sum(p[k:])
print(a ** 2 + b ** 2)


from math import *
from collections import *
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
(x, y) = (0, 0)
t = 0
for i in range(n // 2):
	x += a[i]
	y += a[n - i - 1]
if n % 2:
	x += a[n // 2]
print(x ** 2 + y ** 2)


n = int(input())
sticks = list(map(int, input().strip().split()))
sticks = sorted(sticks)
val = n // 2
(x, y) = (0, 0)
for idx in range(val):
	x += sticks[idx]
for idx in range(val, n):
	y += sticks[idx]
print(x * x + y * y)


n = int(input())
a = sorted(map(int, input().split()))
if n % 2 == 0:
	m = n // 2
else:
	m = (n - 1) // 2
print(sum(a[0:m]) ** 2 + sum(a[m:n]) ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
n = n // 2
l1 = l[:n]
l2 = l[n:]
su1 = sum(l1)
su2 = sum(l2)
print(su1 * su1 + su2 * su2)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
le = len(l)
h = 0
if le % 2 == 0:
	h = le // 2
else:
	h = (le - 1) // 2
s1 = s2 = 0
for i in range(len(l)):
	if i < h:
		s1 = s1 + l[i]
	else:
		s2 = s2 + l[i]
print(s1 * s1 + s2 * s2)


from math import sqrt
n = int(input())
stick = list(map(int, input().split(' ')))
stick = sorted(stick)
x = 0
y = 0
y = sum(stick[:n // 2])
x = sum(stick[n // 2:])
print(x ** 2 + y ** 2)


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


n = int(input())
a = list(sorted(map(int, input().split())))
(l, d) = (0, 0)
(i, j) = (0, n - 1)
while i <= j:
	if i == j:
		(l, d) = (max(l, d) + a[i], min(l, d))
	else:
		l += a[i]
		d += a[j]
	i += 1
	j -= 1
print(l ** 2 + d ** 2)


import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
	n = ni()
	a = na()
	a.sort()
	mid = n // 2
	if n % 2 == 0:
		y = sum(a[mid:])
		x = sum(a[:mid])
	else:
		y = sum(a[mid:])
		x = sum(a[:mid])
	print(y ** 2 + x ** 2)
main()


n = int(input())
l = list(map(int, input().split()))
sh = 0
sv = 0
s = 0
l.sort()
a = []
i = len(l) - 1
j = 0
while i >= j:
	a.append(l[i])
	a.append(l[j])
	if i == j:
		a.append(l[i])
	i -= 1
	j += 1
for i in range(0, len(l), 2):
	sh += a[i]
for j in range(1, len(l), 2):
	sv += a[j]
s = sh ** 2 + sv ** 2
print(s)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
s = sum(a)
c = []
d = []
for i in range(int(n / 2)):
	c.append(a[i])
for i in range(int(n / 2), len(a)):
	d.append(a[i])
print(sum(c) * sum(c) + sum(d) * sum(d))


t = int(input())
L = [int(i) for i in input().split(' ')]
L = sorted(L)
x = 0
y = 0
while len(L) != 0:
	x = x + L.pop(len(L) - 1)
	if len(L) != 0:
		y = y + L.pop(0)
result = x * x + y * y
print(result)


n = int(input()) // 2
L = list(map(int, input().split()))
L.sort()
s = sum(L[:n]) ** 2 + sum(L[n:]) ** 2
print(s)


import sys

def input():
	return sys.stdin.readline().strip()

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 list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A.sort()
A1 = A[:N // 2]
A2 = A[N // 2:]
ans = 0
if N == 1:
	ans = sum(A2) ** 2
else:
	ans = sum(A1) ** 2 + sum(A2) ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = sum(l[:n // 2])
s2 = sum(l[n // 2:])
print(s ** 2 + s2 ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = 0
if int(n / 2) == n / 2:
	m = n / 2
	m = int(m)
	a = l[:m]
	b = l[m:]
	print(sum(a) ** 2 + sum(b) ** 2)
else:
	m = int(n / 2)
	a = l[:m]
	b = l[m:]
	print(sum(a) ** 2 + sum(b) ** 2)


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


n = int(input())
a = [int(s) for s in input().split()]
a.sort()
if len(a) == 1:
	print(a[0] ** 2)
else:
	s1 = sum(a[0:n // 2])
	s2 = sum(a[n // 2:])
	print(s1 ** 2 + s2 ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mp = n // 2
sl = sum(a[:mp])
sm = sum(a[mp:])
smd = sl ** 2 + sm ** 2
print(smd)


import sys
import collections
input = sys.stdin.readline

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

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

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if a == 0:
		return b
	return gcd(a % b, a)
n = rint()
l = rintas()
l.sort(reverse=True)
if n > 1:
	d = (n + 1) // 2
	x = sum(l[:d])
	y = sum(l[d:])
	print(x * x + y * y)
else:
	print(l[0] * l[0])


def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if int(L[i]) < int(R[j]):
				arr[k] = int(L[i])
				i += 1
			else:
				arr[k] = int(R[j])
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
not_in_range = True
correct_sticks = False
replace = True
sticks = []
x = 0
y = 0
while True:
	number = int(input())
	if 1 <= number <= 100000:
		break
	else:
		print('Please enter a suitable number!')
while not_in_range or not correct_sticks:
	sticks = input().split()
	if len(sticks) == number:
		correct_sticks = True
	else:
		print('Please enter the correct amount of sticks!')
		continue
	for i in sticks:
		if int(i) < 1 or int(i) > 10000:
			not_in_range = True
			print('Please enter the numbers again with the correct numbers!')
			break
		else:
			not_in_range = False
mergeSort(sticks)
counter1 = len(sticks) - 1
counter2 = 0
for i in range(len(sticks)):
	if i % 2 == 0:
		x = x + int(sticks[counter1])
		counter1 -= 1
	else:
		y = y + int(sticks[counter2])
		counter2 += 1
print(x ** 2 + y ** 2)


import math
n = int(input())
array = [int(s) for s in input().split()]
array = sorted(array)
half = math.floor(n / 2.0)
x = 0
for i in range(half):
	x += array[i]
y = 0
for i in range(half, n):
	y += array[i]
print(x * x + y * y)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	a_sorted = sorted(a)
	w = 0
	h = 0
	count = 0
	for i in range(n):
		w += a_sorted[-i - 1]
		count += 1
		if count == n:
			break
		h += a_sorted[i]
		count += 1
		if count == n:
			break
	print(w ** 2 + h ** 2)
main()


n = int(input())
a = [i for i in map(int, input().split())]
a.sort()
(s1, s2) = (0, 0)
(a1, a2) = (a[0:n // 2], a[n // 2:])
s1 += sum(a1)
s2 += sum(a2)
print(s1 ** 2 + s2 ** 2)


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


def main():
	t = int(input())
	s = [int(x) for x in input().split()]
	s.sort()
	a = len(s) // 2
	b = sum(s[0:a])
	c = sum(s[a:])
	print(b ** 2 + c ** 2)
main()


n = int(input())
ar = sorted(list(map(int, input().split())))
k = n // 2
t = sum(ar[:k])
t1 = sum(ar[k:])
print(t ** 2 + t1 ** 2)


from sys import stdin
import math
n = int(stdin.readline())
size = list(map(int, stdin.readline().split()))
size.sort(reverse=True)
h = math.ceil(n / 2) - 1
x = sum(size[:h + 1])
y = sum(size) - x
k = x ** 2 + y ** 2
print(k)


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


import os
import heapq
import sys
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

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

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	n = int(input())
	arr = inar()
	arr.sort(reverse=True)
	(x, y) = (0, 0)
	for i in range(n // 2):
		x += arr[i]
		y += arr[n - i - 1]
	if n % 2 != 0:
		x += arr[n // 2]
	print(x ** 2 + y ** 2)
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')
main()


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, reverse=True)
	m = (n + 1) // 2
	x = sum(a[:m])
	y = sum(a[m:])
	wi(x * x + y * y)
main()


n = int(input())
a = [int(i) for i in input().split()]
x = 0
y = 0
start = 0
end = len(a) - 1
a = sorted(a)
if len(a) == 1:
	x = a[0]
	y = 0
else:
	while start < end:
		x = x + a[end]
		end = end - 1
		y = y + a[start]
		start = start + 1
		if start == end:
			x = x + a[end]
			break
print(x ** 2 + y ** 2)


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


import sys
import math
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
a.sort(reverse=True)
val = math.ceil(n / 2)
c = 0
s1 = 0
s2 = 0
for i in range(n):
	c += 1
	if c <= val:
		s1 += a[i]
	else:
		s2 += a[i]
ans1 = pow(s1, 2) + pow(s2, 2)
if n % 2 == 0:
	print(ans1)
else:
	ans2 = pow(s1 - a[n // 2], 2) + pow(s2 + a[n // 2], 2)
	print(max(ans1, ans2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = l[0:n // 2]
l2 = l[n // 2:]
s1 = sum(l1)
s2 = sum(l2)
s1 = s1 ** 2
s2 = s2 ** 2
print(s1 + s2)


n = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
c1 = sum(sticks[:n // 2])
c2 = sum(sticks[n // 2:])
height = c1 * c1 + c2 * c2
print(height)


import collections
n = int(input())
arr = sorted(list(map(int, input().split())))
dq = collections.deque(arr)
x = 0
y = 0
for i in range(n):
	if i % 2 == 0:
		x += dq.pop()
	else:
		y += dq.popleft()
print(x ** 2 + y ** 2)


n = int(input())
arr = list(map(int, input().strip().split()))
arr.sort()
sum1 = 0
sum2 = 0
for i in range(len(arr) // 2):
	sum1 += arr[i]
for i in range(len(arr) // 2, len(arr)):
	sum2 += arr[i]
print(sum1 * sum1 + sum2 * sum2)


x = int(input())
p = list(sorted(map(int, input().split())))
(a, b) = (p[:x // 2], p[x // 2:])
print(sum(a) ** 2 + sum(b) ** 2)


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


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a[0:n // 2]) ** 2 + sum(a[n // 2:]) ** 2
print(ans)


n = int(input().strip())
ls = list(map(int, input().strip().split()))
ls = sorted(ls, reverse=True)
half = (n + 1) // 2
sum1 = 0
for i in range(half):
	sum1 += ls[i]
sum2 = 0
for i in range(half, n):
	sum2 += ls[i]
ans = sum1 ** 2 + sum2 ** 2
print(ans)


x = input()
S = [int(x) for x in input().split()]
if len(S) == 1:
	print(S[0] ** 2)
elif len(S) == 2:
	print(S[0] ** 2 + S[1] ** 2)
else:
	S.sort()
	meio = len(S) // 2
	x = sum(S[:meio])
	y = sum(S[meio:])
	print(x ** 2 + y ** 2)


import sys
n = int(next(sys.stdin))
sizes = sorted(map(int, next(sys.stdin).split(' ')))
print(sum(map(lambda x: x * x, [sum(sizes[0:n // 2]), sum(sizes[n // 2:])])))


l = int(input())
lst = list(map(int, input().split()))
lst.sort()
left = sum(lst[:l // 2])
right = sum(lst[l // 2:])
print(left ** 2 + right ** 2)


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


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
n = I()
A = sorted(IL())
print(sum(A[n // 2:]) ** 2 + sum(A[:n // 2]) ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = sum(l)
(j, b) = (n - 1, 0)
while j >= n // 2:
	b += l[j]
	j -= 1
a = a - b
print(a ** 2 + b ** 2)


n = int(input())
arr = sorted([int(x) for x in input().split()])
s = sum(arr[:n // 2]) ** 2 + sum(arr[n // 2:]) ** 2
print(s)


sticks = int(input())
length = list(map(int, input().split()))
length.sort()

def max_distance(sti, len):
	if sti % 2 == 0:
		x = sum(len[:int(sti / 2)])
		y = sum(len[int(sti / 2):])
		distance = x * x + y * y
	else:
		x = sum(len[:int((sti - 1) / 2)])
		y = sum(len[int((sti - 1) / 2):])
		distance = x * x + y * y
	return distance
print(max_distance(sticks, length))


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = listin()
a.sort()
(x, y) = (0, 0)
a = deque(a)
for i in range(n):
	if i % 2:
		y += a.popleft()
	else:
		x += a.pop()
print(x ** 2 + y ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = l[:n // 2]
l2 = l[n // 2:]
pr = sum(l2) ** 2 + sum(l1) ** 2
print(pr)


i = int(input())
A = list(map(int, input().strip().split()))
A.sort()
a = sum(A[:int(len(A) // 2)])
b = sum(A[int(len(A) // 2):])
print(a * a + b * b)


n = int(input())
f = list(map(int, input().split()))
f.sort()
x = 0
y = 0
for i in range(n):
	if i % 2 == 0:
		x += f[-1]
		del f[-1]
	else:
		y += f[0]
		del f[0]
print(x ** 2 + y ** 2)


n = int(input())
a = input().split(' ')
for i in range(len(a)):
	a[i] = int(a[i])
a.sort()
mid = len(a) // 2
fir = 0
sec = 0
for j in range(mid):
	fir += a[j]
for j in range(mid, len(a)):
	sec += a[j]
ans = fir * fir + sec * sec
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mid = n // 2
left = a[:mid]
right = a[mid:]
rang = sum(left) ** 2 + sum(right) ** 2
print(rang)


input()
data = sorted(map(int, input().split()))
b = len(data) // 2
print(sum(data[:b]) ** 2 + sum(data[b:]) ** 2)


n = int(input())
x = 0
y = 0
sticks = [int(x) for x in input().split()]
sticks.sort()
for i in range(n // 2):
	x += sticks[i]
for j in range(n // 2, n):
	y += sticks[j]
print(x ** 2 + y ** 2)


n = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
if n % 2 == 1:
	print(sum(A[:n // 2 + 1]) ** 2 + sum(A[n // 2 + 1:]) ** 2)
else:
	print(sum(A[:n // 2]) ** 2 + sum(A[n // 2:]) ** 2)


R = lambda : map(int, input().split())
(n,) = R()
arr = sorted(R())
n = n // 2
print(sum(arr[:n]) ** 2 + sum(arr[n:]) ** 2)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
i = 0
j = n - 1
k = 0
p = [0, 0]
while i <= j:
	if k % 2:
		p[0] += l[i]
		i += 1
	else:
		p[1] += l[j]
		j -= 1
	k = k ^ 1
print(p[0] ** 2 + p[1] ** 2)


n = int(input())
woods = [int(x) for x in input().split()]
woods.sort()
left = sum(woods[:n // 2])
right = sum(woods[n // 2:])
print(left ** 2 + right ** 2)


R = lambda : list(map(int, input().split()))
(n,) = R()
a = R()
a.sort()
(x, y) = (0, 0)
(st, en) = (0, n - 1)
while st - 1 != en:
	x += a[en]
	en -= 1
	if st - 1 == en:
		break
	y += a[st]
	st += 1
print(x * x + y * y)


import sys

def main():
	n = int(input())
	a = list(map(int, sys.stdin.readline().split()))
	a.sort(reverse=True)
	x = y = 0
	i = 0
	while i < n - i - 1:
		x += a[i]
		y += a[n - i - 1]
		i += 1
	if n % 2:
		x += a[i]
	print(x * x + y * y)
main()


n = int(input())
sticks_length = list(map(int, input().split()))
sticks_length.sort()
print(pow(sum(sticks_length[:n // 2]), 2) + pow(sum(sticks_length[n // 2:]), 2))


from sys import stdin

def solution(n) -> None:
	input = stdin.readline
	arr = sorted(map(int, input().split()), reverse=True)
	start = proc = 0
	end = n - 1
	flip = 1
	pos = [0, 0]
	while proc < n:
		if flip:
			pos[0] += arr[start]
			start += 1
			flip = 0
		else:
			pos[1] += arr[end]
			end -= 1
			flip = 1
		proc += 1
	print(pos[0] * pos[0] + pos[1] * pos[1])

def main():
	t = int(input())
	solution(t)
main()


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


(len_a, arr) = (int(input()), list(map(int, input().split())))
arr = sorted(arr)
height = sum(arr[0:len_a // 2])
wight = sum(arr[len_a // 2:])
print(height ** 2 + wight ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s_1 = sum(a)
half = len(a) // 2
s_left = sum(a[:half])
s_right = sum(a[-half:])
print(max((s_1 - s_left) ** 2 + s_left ** 2, (s_1 - s_right) ** 2 + s_right ** 2))


(a, b) = (int(input()), sorted(list(map(int, input().split()))))
print(sum(b[0:a // 2]) ** 2 + sum(b[a // 2:a]) ** 2)


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)

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

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

def main():
	n = iin()
	a = lin()
	a.sort()
	(v, h) = (0, 0)
	(i, j) = (0, n - 1)
	while i < j:
		v += a[j]
		h += a[i]
		i += 1
		j -= 1
	else:
		if i == j:
			v += a[i]
	print(v * v + h * h)
main()


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


n = int(input())
lengths = input()
lengths = lengths.split()
i = 0
while i < n:
	lengths[i] = int(lengths[i])
	i = i + 1
lengths.sort()
width = 0
i = 0
lim = int(n / 2)
while i < lim:
	width = width + lengths[i]
	i = i + 1
heigh = 0
while i < n:
	heigh = heigh + lengths[i]
	i = i + 1
result = width ** 2 + heigh ** 2
print(result)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort(reverse=True)
if n % 2 == 0:
	i = n // 2
	he = sum(arr[0:i])
	he *= he
	ve = sum(arr[i:n])
	ve *= ve
	res = he + ve
else:
	i = (n + 1) // 2
	ho = sum(arr[0:i])
	ho *= ho
	vo = sum(arr[i:n])
	vo *= vo
	res = ho + vo
print(res)


n = int(input())
a = [int(x) for x in input().split()]
(x, y) = (int(0), int(0))
a.sort()
for i in range(n >> 1):
	x += a[i]
	y += a[n - i - 1]
if n & 1:
	y += a[n >> 1]
print(x * x + y * y)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
y = sum(l[0:n // 2])
x = sum(l[n // 2:n])
print(y * y + x * x)


n = int(input())
arr = sorted(map(int, input().split()))
if n % 2 == 0:
	print(sum(arr[:n // 2]) ** 2 + sum(arr[n // 2:]) ** 2)
else:
	r1 = sum(arr[:n // 2]) ** 2 + sum(arr[n // 2:]) ** 2
	r2 = sum(arr[:n // 2 + 1]) ** 2 + sum(arr[n // 2 + 1:]) ** 2
	print(max(r1, r2))


import sys, math, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
l.sort(reverse=True)
if n % 2 == 0:
	print(sum(l[:n // 2]) ** 2 + sum(l[n // 2:]) ** 2)
else:
	print(sum(l[:n // 2 + 1]) ** 2 + sum(l[n // 2 + 1:]) ** 2)


n = int(input())
a = list(map(int, input().split()))[:n]
a.sort()
b = []
c = []
for i in range(int(len(a) / 2)):
	b.append(a[i])
for i in range(int(len(a) / 2), len(a)):
	c.append(a[i])
d = int(sum(c) ** 2 + sum(b) ** 2)
print(d)


import math
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
nmin = math.floor(n / 2)
summin = 0
summax = 0
for i in range(0, nmin):
	summin += arr[i]
for i in range(nmin, n):
	summax += arr[i]
print(summin * summin + summax * summax)


import sys
input = sys.stdin.readline
n = int(input())
b = sorted(list(map(int, input().split())))
k = n // 2
p = b[k:]
q = b[:k]
r = sum(p)
s = sum(q)
print(r * r + s * s)


n = int(input())
skaitli = list(map(int, input().split()))
isakais = n // 2
skaitli.sort()
isie = skaitli[0:isakais]
garie = skaitli[isakais:]
issum = sum(isie)
garsum = sum(garie)
suma = issum * issum + garsum * garsum
print(suma)


import sys
import math as m
for line in sys.stdin:
	n = int(line) // 2
	S = sorted(map(int, input().split()))
	print(sum(S[:n]) ** 2 + sum(S[n:]) ** 2)


n = int(input())
l = sorted(list(map(int, input().split())))
l1 = l[:n // 2]
l2 = l[n // 2:]
t1 = sum(l1)
t2 = sum(l2)
print(t1 ** 2 + t2 ** 2)


n = int(input())
entrada = input().split()
for x in range(n):
	entrada[x] = int(entrada[x])
x = 0
y = 0
aux = n - 1
entrada.sort()
if n % 2 == 0:
	for i in range(n // 2):
		x += entrada[aux]
		y += entrada[i]
		aux -= 1
else:
	for i in range(n // 2):
		x += entrada[aux]
		y += entrada[i]
		aux -= 1
	x += entrada[n // 2]
print(x * x + y * y)


n = int(input().strip())
lst = list(map(int, input().strip().split()))
new_lst = sorted(lst)
sum1 = sum(new_lst[n // 2:])
sum2 = sum(new_lst[:n // 2])
print(sum1 * sum1 + sum2 * sum2)


n = int(input())
x = list(map(int, input().split()))[:n]
x.sort()
a = sum(x[:len(x) // 2]) * sum(x[:len(x) // 2])
b = sum(x[len(x) // 2:]) * sum(x[len(x) // 2:])
print(a + b)


n = int(input())
ch = input()
L = [int(i) for i in ch.split()]
L.sort(reverse=True)
if n % 2 == 0:
	L1 = L[0:n // 2]
	L2 = L[n // 2:n]
else:
	L1 = L[0:1 + n // 2]
	L2 = L[1 + n // 2:n]
print(sum(L1) ** 2 + sum(L2) ** 2)


x = int(input())
a = sorted(list(map(int, input().split())))
print(sum(a[:x // 2]) ** 2 + sum(a[x // 2:]) ** 2)


a = int(input())
b = list(map(int, input().split()))
b.sort()
x = a // 2
y = sum(b[0:x]) ** 2 + sum(b[x:]) ** 2
print(y)


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


n = int(input())
A = list(map(int, input().split()))
A.sort()
s1 = sum(A[:n // 2])
s2 = sum(A[n // 2:])
print(s1 ** 2 + s2 ** 2)


n = int(input())
g = [int(i) for i in input().split()]
f = sorted(g)
t = f[:n // 2]
k = f[n // 2:]
m = 0
n = 0
for j in range(0, len(t)):
	m += t[j]
for a in range(0, len(k)):
	n += k[a]
print(m ** 2 + n ** 2)


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


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
horizontal = []
vertical = []
for i in range(len(a) // 2):
	vertical.append(a[i])
for i in range(len(a) // 2, len(a)):
	horizontal.append(a[i])
print(sum(horizontal) * sum(horizontal) + sum(vertical) * sum(vertical))


import sys
input = sys.stdin.readline
n = int(input())
l = [int(x) for x in input().split()]
a = [0, 0]
l.sort(reverse=True)
for i in range(n):
	if i >= (n + 1) // 2:
		a[1] += l[i]
	else:
		a[0] += l[i]
print(a[0] ** 2 + a[1] ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(length, height) = (0, 0)
length = sum(a[n // 2:])
height = sum(a[0:n // 2])
print(length ** 2 + height ** 2)


n = int(input())
sticks = list(map(int, input().split()))
sticks.sort(reverse=True)
up = 0
left = 0
o = n % 2
for i in range(n):
	if i < n // 2 + o:
		up += sticks[i]
	else:
		left += sticks[i]
print(up ** 2 + left ** 2)


t = int(input())
arr = list(map(int, input().split()))
arr.sort()
if t % 2 == 0:
	x = sum(arr[0:t // 2])
	y = sum(arr[t // 2:])
	print(x ** 2 + y ** 2)
else:
	x = sum(arr[0:t // 2])
	y = sum(arr[t // 2:])
	print(x ** 2 + y ** 2)


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


n = int(input())
i = 0
m = 0
k = 0
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
while i < n // 2:
	m += a[i]
	k += a[n - 1 - i]
	i += 1
if n % 2 != 0:
	m += a[n // 2]
print(m * m + k * k)


n = int(input())
l = list(map(int, input().split()))
x = (n + 1) // 2
l.sort(reverse=True)
print(sum(l[:x]) ** 2 + sum(l[x:]) ** 2)


import math
n = int(input())
A = [*map(int, input().split())]
A.sort(reverse=True)
(w, h) = (0, 0)
(i, j) = (0, len(A) - 1)
while i < j:
	w += A[i]
	i += 1
	h += A[j]
	j -= 1
if i == j:
	w += A[i]
print(w * w + h * h)


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


n = int(input())
arr = sorted(list(map(int, input().split())))
p = 0
if n % 2 == 0:
	p = int(n / 2)
else:
	p = int(n // 2) + 1
arr_max = arr[n - p:]
arr_min = arr[:n - p]
print(sum(arr_min) ** 2 + sum(arr_max) ** 2)


n = int(input())
p = input()
p = p.split()
p = list(map(int, p))
p.sort()
upper = 0
lower = 0
if n % 2 == 0:
	for i in range(n // 2, n):
		upper += p[i]
	for i in range(0, n // 2):
		lower += p[i]
else:
	for i in range(n // 2, n):
		upper += p[i]
	for i in range(0, n // 2):
		lower += p[i]
ans = upper ** 2 + lower ** 2
print(ans)


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

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

def li():
	return list(mi())
n = ii()
ar = li()
ar.sort(reverse=True)
if n & 1:
	print(sum(ar[:n // 2 + 1]) ** 2 + sum(ar[n // 2 + 1:]) ** 2)
else:
	print(sum(ar[:n // 2]) ** 2 + sum(ar[n // 2:]) ** 2)


n = int(input())
sticks = list(map(int, input().split()))

def solve(n, sticks):
	sticks = sorted(sticks, reverse=True)
	return sum(sticks[:(n + 1) // 2]) ** 2 + sum(sticks[(n + 1) // 2:]) ** 2
r = solve(n, sticks)
print(r)


def main():
	integer = int
	scan = input
	useless_number = scan()
	sticks = list(map(integer, scan().split()))
	sticks.sort()
	horizontal_distance = 0
	vertical_distance = 0
	while sticks:
		horizontal_distance += sticks.pop()
		if sticks:
			vertical_distance += sticks.pop(0)
	print(horizontal_distance ** 2 + vertical_distance ** 2)
main()


n = int(input())
l = list(map(int, input().split()))
l.sort()
k = len(l)
s1 = sum(l[:k // 2])
s2 = sum(l[k // 2:])
print(s1 ** 2 + s2 ** 2)


n = int(input())
a = sorted(list(map(int, input().split())))
v = sum(a[:n // 2])
h = sum(a[n // 2:])
print(v ** 2 + h ** 2)


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


import math
n = int(input())
p = [int(i) for i in input().strip().split()]
p.sort()
m = n // 2
s_v = sum(p[:m])
s_h = sum(p[m:])
print(s_h ** 2 + s_v ** 2)


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


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
x = 0
y = 0
i = 0
j = n - 1
while i < j:
	x += a[j]
	y += a[i]
	j -= 1
	i += 1
if n % 2 == 0:
	print(x ** 2 + y ** 2)
else:
	x += a[n // 2]
	print(x ** 2 + y ** 2)


n = int(input())
sticks = [int(_) for _ in input().split()]
sticks.sort()
a = sum(sticks[:n // 2])
b = sum(sticks) - a
print(a * a + b * b)


n = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
stick_height = sticks[:n // 2]
stick_length = sticks[n // 2:]
height = sum(stick_height)
length = sum(stick_length)
print(length * length + height * height)


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


num = int(input())
length = input()
length = length.split()
length = [int(x) for x in length]
length.sort()
vert = 0
hor = 0
if len(length) % 2 == 0:
	horizontal = length[len(length) // 2:]
	hor = sum(horizontal)
	vertical = length[0:len(length) // 2]
	vert = sum(vertical)
else:
	horizontal = length[len(length) // 2:]
	hor = sum(horizontal)
	vertical = length[0:len(length) // 2]
	vert = sum(vertical)
print(hor * hor + vert * vert)


n = int(input())
a = list(map(int, input().split()))
a.sort()
so = sum(a[:n // 2])
se = sum(a[n // 2:])
print(so ** 2 + se ** 2)


n = int(input())
a = sorted(list(map(int, input().split())))
ans = sum(a[:n // 2]) ** 2 + (sum(a) - sum(a[:n // 2])) ** 2
print(ans)


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


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
x = 0
y = 0
x += sum(arr[:math.ceil(n / 2)])
y += sum(arr) - x
print(pow(x, 2) + pow(y, 2))


(h, v) = (0, 0)
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
if n % 2 == 0:
	mid = n // 2
else:
	mid = n // 2 + 1
for i in range(mid):
	h += a[i]
v = sum(a[mid:])
ans = pow(h, 2) + pow(v, 2)
print(ans)


t = int(input())
z = list(map(int, input().split()[:t]))
z.sort()
x = sum(z[:t // 2])
y = sum(z[t // 2:])
print(x * x + y * y)


import math
n = int(input())
l = list(map(int, input().split()))
x = math.ceil(n / 2)
s = 0
l.sort(reverse=True)
g = sum(l)
for i in range(x):
	s = s + l[i]
print(s ** 2 + (g - s) ** 2)


n = int(input())
A = [int(i) for i in input().split()]
A.sort()
m = sum(A)
a = sum(A[:n // 2])
print((m - a) ** 2 + a ** 2)


n = int(input())
a = sorted(list(map(int, input().split())))
s = sum(a)
if len(a) % 2 == 0:
	x = sum(a[:len(a) // 2])
	y = s - x
else:
	x = sum(a[:len(a) // 2])
	y = s - x
print(x ** 2 + y ** 2)


num = int(input())
li = [int(i) for i in input().split()]
li.sort()
mid = num // 2
print(sum(li[:mid]) ** 2 + sum(li[mid:]) ** 2)


def patate(n, l):
	l.sort()
	somme1 = 0
	somme2 = 0
	for k in range(int(n / 2)):
		somme1 += l[k]
	for k in range(int(n / 2), n):
		somme2 += l[k]
	print(somme1 ** 2 + somme2 ** 2)
n = int(input())
longeur = list(map(int, input().split()))
patate(n, longeur)


from math import ceil
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
(x, y) = (0, 0)
for i in range(ceil(n / 2)):
	j = n - i - 1
	x += a[j]
	if i != j:
		y += a[i]
print(x ** 2 + y ** 2)


num = int(input())
distance = input().split()
x = 0
y = 0
for i in range(len(distance)):
	distance[i] = int(distance[i])
distance.sort()
for_y = distance[:len(distance) // 2]
for_x = distance[len(distance) // 2:]
for k in for_y:
	y += k
for h in for_x:
	x += h
print(x ** 2 + y ** 2)


t = int(input())
l = list(map(int, input().split()))
l.sort()
a = sum(l[0:int(len(l) / 2)])
b = sum(l[int(len(l) / 2):])
print(a ** 2 + b ** 2)


import decimal
D = decimal.Decimal
n = int(input())
n1 = int(n / 2) + n % 2
i = 0
l1 = [int(x) for x in input().split()]
l1.sort(reverse=True)
ans1 = 0
while i < n1:
	ans1 += l1[i]
	i += 1
ans = 0
while i < n:
	ans += l1[i]
	i += 1
print(ans ** 2 + ans1 ** 2)


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


n = int(input())
t = list(map(int, input().split()))
t.sort()
if n % 2 == 0:
	print(sum(t[n // 2:]) ** 2 + sum(t[0:n // 2]) ** 2)
else:
	print(sum(t[0:n // 2]) ** 2 + sum(t[n // 2:]) ** 2)


from collections import deque
n = int(input())
sticks = list(map(int, input().split()))
dq = deque(sorted(sticks))
lenx = 0
leny = 0
while len(dq) > 0:
	lenx += dq.pop()
	if len(dq) > 0:
		leny += dq.popleft()
print(lenx ** 2 + leny ** 2)


x = int(input())
y = list(map(int, input().split()))
y.sort()
w = 0
len = 0
wid = 0
for item in y:
	w += item
if x % 2 == 0:
	u = int(x / 2)
	for i in y[0:u]:
		len += i
	wid = w - len
	print(int(len ** 2 + wid ** 2))
else:
	u = int(x / 2)
	for i in y[0:u]:
		len += i
	wid = w - len
	print(int(len ** 2 + wid ** 2))


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


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = list(mints())
a.sort()
b = sum(a[:n // 2])
c = sum(a)
print(b * b + (c - b) * (c - b))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
print(sum(arr[:n // 2]) ** 2 + sum(arr[n // 2:]) ** 2)


i1 = int(input()) // 2
li = list(map(int, input().split()))
li.sort()
print(sum(li[0:i1]) ** 2 + sum(li[i1:]) ** 2)


n = int(input())
l = list(map(int, input().split()))
l.sort()
v = n // 2
s1 = sum(l[:v])
s = sum(l)
s2 = s - s1
print(pow(s2, 2) + pow(s1, 2))


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
i = 0
a.sort(reverse=True)
if n % 2 == 0:
	m = n // 2
else:
	m = n // 2 + 1
for i in range(m):
	x = x + a[i]
for j in range(m, n):
	y = y + a[j]
print(x ** 2 + y ** 2)


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


n = int(input())
A = [0] * n
A = list(map(int, input().split()))
A.sort()
a = 0
b = 0
for i in range(n):
	if i >= n // 2:
		b += A[i]
	else:
		a += A[i]
print(a ** 2 + b ** 2)


def main():
	n = int(input())
	a = readIntArr()
	x = 0
	y = 0
	a.sort()
	shorterCnts = n // 2
	cnt = 0
	for i in range(n):
		cnt += 1
		if cnt <= shorterCnts:
			x += a[i]
		else:
			y += a[i]
	ans = x * x + y * y
	print(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


n = int(input())
mas = [int(i) for i in input().split()]
mas.sort()
x = sum(mas[:len(mas) // 2])
y = sum(mas[len(mas) // 2:])
print(x * x + y * y)


from math import ceil
n = int(input())
li = [int(i) for i in input().split()]
li.sort(reverse=True)
k = ceil(n / 2)
print(sum(li[:k]) ** 2 + sum(li[k:]) ** 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(l, r) = (0, n - 1)
(x, y) = ([], [])
k = 0
while len(x) + len(y) < n:
	if k & 1:
		x.append(a[l])
		l += 1
	else:
		y.append(a[r])
		r -= 1
	k += 1
print(sum(x) ** 2 + sum(y) ** 2)


n = int(input())
a = sorted(map(int, input().split()))
t = sum(a[:n // 2])
s = sum(a) - t
print(s * s + t * t)


n = int(input())
b = map(int, input().split())
a = [a for a in b]
a.sort()
c = 0
d = 0
e = 0
if n % 2 == 0:
	q = int(n / 2)
	for i in range(q):
		c = c + a[i]
		d = d + a[i + q]
if n % 2 != 0:
	p = int((n - 1) / 2)
	for f in range(p):
		c = c + a[f]
		e = e + a[f + p]
	d = e + a[n - 1]
h = c ** 2 + d ** 2
print(h)


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


def solve(n, a):
	a = sorted(a, reverse=True)
	x = sum(a[:n // 2 + (n & 1)])
	y = sum(a[n // 2 + (n & 1):])
	return pow(x, 2) + pow(y, 2)
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))


n = int(input())
arr = sorted([int(j) for j in input().split()], reverse=True)
if len(arr) % 2 == 0:
	index = len(arr) // 2
else:
	index = len(arr) // 2 + 1
x_coord = 0
y_coord = 0
for i in range(len(arr[:index])):
	x_coord += arr[i]
for j in range(index, len(arr)):
	y_coord += arr[j]
print(x_coord ** 2 + y_coord ** 2)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
flag = side1 = side2 = 0
for i in range(n):
	if i == n // 2:
		break
	side1 += arr[i]
side2 = sum(arr) - side1
print(side1 ** 2 + side2 ** 2)


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


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
n = ii()
a = li()
a.sort(reverse=True)
print(sum(a[:n // 2 + n % 2]) ** 2 + sum(a[n // 2 + n % 2:]) ** 2)


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


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


def main_function():
	input()
	a = sorted([int(i) for i in input().split(' ')])
	if not len(a) % 2:
		return sum(a[:len(a) // 2]) ** 2 + sum(a[len(a) // 2:]) ** 2
	return sum(a[:len(a) // 2]) ** 2 + sum(a[len(a) // 2:]) ** 2
print(main_function())


num = int(input()) // 2
s = sorted(map(int, input().split()))
print(sum(s[:num]) ** 2 + sum(s[num:]) ** 2)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		a.sort()
		r = sum(a[:n // 2]) ** 2 + sum(a[n // 2:]) ** 2
		rr.append(r)
	return JA(rr, '\n')
print(main())


n = int(input())
s = [int(x) for x in input().split()]
arr = sorted(s)
s1 = arr[:n // 2]
s2 = arr[n // 2:]
c1 = 0
c2 = 0
for i in range(0, len(s1)):
	c1 += s1[i]
for i in range(0, len(s2)):
	c2 += s2[i]
ans = c1 * c1 + c2 * c2
print(ans)


import sys
import os
from io import IOBase, BytesIO

def main():
	n = int(input())
	arr = get_array()
	(x, y) = (0, 0)
	arr.sort()
	i = 0
	j = n - 1
	while i < j:
		x += arr[j]
		j -= 1
		y += arr[i]
		i += 1
	if j == i:
		x += arr[j]
	ans = x ** 2 + y ** 2
	print(ans)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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))

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()
main()


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


n = int(input())
l = list(map(int, input().split()))
l.sort()
print(sum(l[:n // 2]) ** 2 + sum(l[n // 2:]) ** 2)


import math
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
print(sum(A[:math.floor(len(A) / 2)]) ** 2 + sum(A[math.floor(len(A) / 2):]) ** 2)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
l = 0
r = n - 1
(b, h) = (0, 0)
while l < r:
	b += arr[l]
	h += arr[r]
	l += 1
	r -= 1
if n % 2 != 0:
	h += arr[n // 2]
print(pow(b, 2) + pow(h, 2))


n = int(input())
list_of_lengths = list(map(int, input().split()))
list_of_lengths.sort()
width = 0
length = 0
for k in list_of_lengths[len(list_of_lengths) // 2:]:
	width += k
for kk in list_of_lengths[:len(list_of_lengths) // 2]:
	length += kk
print(width ** 2 + length ** 2)


from collections import deque
n = int(input())
l = deque(sorted([int(k) for k in input().split(' ')]))
if n % 2 != 0:
	n += 1
	l.appendleft(0)
(x, y) = (0, 0)
t = 1
for i in range(n):
	if i % 2 != 0:
		x += l.pop()
	else:
		y += l.popleft()
print(x ** 2 + y ** 2)


n = int(input())
x = sorted(list(map(int, input().split(' '))))
print(sum(x[:n // 2]) ** 2 + sum(x[n // 2:]) ** 2)


n = int(input())
A = list(map(int, input().split()))
A.sort()
c1 = sum(A[:n // 2])
c2 = sum(A) - c1
print(c1 ** 2 + c2 ** 2)


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
yf = False
a.sort()
(l, r) = (0, n - 1)
for i in range(n):
	if yf:
		y += a[l]
		l += 1
	else:
		x += a[r]
		r -= 1
	yf = not yf
h = x ** 2 + y ** 2
print(h)


from math import ceil
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
mid = ceil(n // 2)
print(sum(a[:mid]) ** 2 + sum(a[mid:]) ** 2)


n = int(input())
li = list(map(int, input().split()))
li.sort(reverse=True)
if n % 2 == 0:
	s = sum(li[:n // 2]) ** 2 + sum(li[n // 2:]) ** 2
else:
	s = sum(li[:n // 2 + 1]) ** 2 + sum(li[n // 2 + 1:]) ** 2
print(s)


from math import *
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
(x, y) = (0, 0)
for i in range(len(arr) // 2):
	x += arr[i]
	y += arr[len(arr) - 1 - i]
if len(arr) % 2 == 1:
	y += arr[len(arr) // 2]
print(x ** 2 + y ** 2)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
(sh, sv) = (0, 0)
for i in arr[0:n // 2]:
	sh += i
for i in arr[n // 2:]:
	sv += i
print(sh ** 2 + sv ** 2)


n = int(input())
p = [int(j) for j in input().split()]
a = 0
b = 0
k = 0
p.sort()
while len(p) != 0:
	if k == 0:
		a = a + p[-1]
		p.pop(-1)
		k = k + 1
	else:
		b = b + p[0]
		p.pop(0)
		k = k - 1
print(a ** 2 + b ** 2)


x = int(input())
ar = sorted(map(int, input().split(' ')))
(dx, dy) = (0, 0)
for i in range(len(ar)):
	if i < len(ar) // 2:
		dx += ar[i]
	else:
		dy += ar[i]
print(dx * dx + dy * dy)


a = int(input())
b = list(map(int, input().split()))
b.sort()
if a % 2 == 0:
	print(sum(b[:int(a / 2)]) ** 2 + sum(b[int(a / 2):]) ** 2)
else:
	temp1 = sum(b[:int(a / 2)]) ** 2 + sum(b[int(a / 2):]) ** 2
	temp2 = sum(b[:int(a / 2) + 1]) ** 2 + sum(b[int(a / 2) + 1:]) ** 2
	print(max(temp1, temp2))


n = int(input())
a = sorted(list(map(int, input().split())))
print(sum(a[n // 2:]) ** 2 + sum(a[0:n // 2]) ** 2)


n = int(input())
x = sorted(list(map(int, input().split())))
if n % 2 == 0:
	print(sum(x[:n // 2]) ** 2 + sum(x[n // 2:]) ** 2)
else:
	maximum = max(int(sum(x[:n // 2])), int(sum(x[n // 2 + 1:]))) + x[n // 2]
	print(maximum ** 2 + min(sum(x[:n // 2]) ** 2, sum(x[n // 2 + 1:]) ** 2))


from sys import stdin, stdout
stick_count = int(stdin.readline())
stick_lengths = list(map(int, stdin.readline().split(' ')))
import functools
stick_lengths = sorted(stick_lengths)
sum_of_x = functools.reduce(lambda x, y: x + y, stick_lengths[stick_count // 2:])
sum_of_y = functools.reduce(lambda x, y: x + y, stick_lengths[:stick_count // 2], 0)
stdout.write(str(sum_of_y ** 2 + sum_of_x ** 2) + '\n')


n = int(input())
A = list(map(int, input().split()))
(x1, y1, x2, y2) = (0, 0, 0, 0)
A.sort()
s1 = sum(A[:n // 2])
s2 = sum(A[n // 2:])
print(s1 * s1 + s2 * s2)


n = int(input())
l = list(map(int, input().split()))
l1 = sorted(l)
q = n // 2
count = 0
c = 0
for i in l1[0:q]:
	c += i
for j in l1[q:]:
	count += j
print(count ** 2 + c ** 2)


i = input()
b = list(input().split())
b = [int(h) for h in b]
b.sort(reverse=True)
n = len(b) // 2 + len(b) % 2
print(sum(b[:n]) ** 2 + sum(b[n:]) ** 2)


def polyline(lista):
	soma_x = 0
	soma_y = 0
	lista.sort()
	ini = 0
	fim = len(lista) - 1
	while ini < fim:
		x = lista[fim]
		fim = fim - 1
		soma_x += x
		y = lista[ini]
		ini += 1
		soma_y += y
	if ini == fim:
		soma_x += lista[fim]
	return soma_x ** 2 + soma_y ** 2
t = int(input())
l = list(map(int, input().split()))
print(polyline(l))


import math
n = int(input())
a = [int(i) for i in input().split()]
dp = [0] * n
a.sort(reverse=True)
dp = a
x = math.ceil(len(dp) / 2)
w = 0
h = 0
for i in dp[:x]:
	w += i
for i in dp[x:]:
	h += i
print(h * h + w * w)


a = int(input())
l = list(map(int, input().split()))
l.sort()
w = a // 2
s = sum(l[:w])
ww = sum(l[w:])
print(s * s + ww * ww)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
s = sum(l)
c = 0
if n % 2 == 0:
	for i in range(n // 2):
		c = c + l[i]
	x = s - c
	print(c ** 2 + x ** 2)
else:
	for i in range(n // 2 + 1):
		c = c + l[i]
	x = s - c
	print(c ** 2 + x ** 2)


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


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
v = a[:int(len(a) / 2)]
h = a[int(len(a) / 2):]
vertical = 0
horizontal = 0
for i in range(0, len(v)):
	vertical += v[i]
for i in range(0, len(h)):
	horizontal += h[i]
print(vertical ** 2 + horizontal ** 2)


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	l = c = x = y = 0
	r = n - 1
	while l <= r:
		if c & 1:
			x += a[l]
			l += 1
		else:
			y += a[r]
			r -= 1
		c += 1
	print(x * x + y * y)


n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
line = int((n + 1) // 2)
a_hori = a[:line]
a_vert = a[line:]
sqr = sum(a_hori) ** 2 + sum(a_vert) ** 2
print(sqr)


import sys, math, queue, collections
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
a = sorted(map(int, input().split()))
(x, y) = (sum(a[:n // 2]), sum(a[n // 2:]))
print(x ** 2 + y ** 2)


import sys
import math
input = sys.stdin.readline
from collections import defaultdict as dc
n = int(input())
l = sorted(list(map(int, input().split())), reverse=True)
x = math.ceil(n / 2)
p = sum(l[:x])
q = sum(l[x:])
print(p * p + q * q)


n = int(input())
l = list(map(int, input().split()))
l.sort()
sum1 = sum(l[0:len(l) // 2])
sum2 = sum(l[len(l) // 2:])
print(sum1 ** 2 + sum2 ** 2)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
mid = len(a) // 2
aMax = []
aMin = []
for i in range(mid):
	aMin.append(a[i])
for i in range(mid, n):
	aMax.append(a[i])
sumY = 0
sumX = 0
for i in aMin:
	sumY += i
for i in aMax:
	sumX += i
print(sumY * sumY + sumX * sumX)


n = int(input())
sticks = sorted(map(int, input().split()))
i = 0
j = n - 1
a = 0
b = 0
while i < j:
	a += sticks[i]
	b += sticks[j]
	i += 1
	j -= 1
if n % 2 == 1:
	b += sticks[i]
print(a ** 2 + b ** 2)


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


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
n = int_input()
length = list_input()
length = sorted(length)
queue = deque(length)
x = 0
y = 0
k = 0
while len(queue) > 0:
	if k % 2 == 0:
		x += queue.pop()
	else:
		y += queue.popleft()
	k += 1
print(int(x * x + y * y))


N = int(input())
sticks = sorted(list(map(int, input().split())))
(lo, hi) = (0, N - 1)
X = 0
Y = 0
step = 0
while lo <= hi:
	if step == 0:
		X += sticks[hi]
		hi -= 1
	else:
		Y += sticks[lo]
		lo += 1
	step = 1 - step
print(X * X + Y * Y)


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
if n % 2 != 0:
	n += 1
x = sum(a[:n // 2])
y = sum(a[n // 2:])
print(x * x + y * y)


n = int(input())
daf = list(map(int, input().split()))
daf.sort()
print(sum(daf[:n // 2]) ** 2 + sum(daf[n // 2:]) ** 2)


from itertools import combinations
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = sum(arr[0:n // 2])
b = sum(arr[n // 2:])
print(a ** 2 + b ** 2)


from sys import stdin

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	mid = len(a) // 2
	shorta = sum(a[:mid])
	longa = sum(a[mid:])
	print(shorta ** 2 + longa ** 2)
main()


n = int(input())
l = sorted(list(map(int, input().split())))
print(sum(l[:n // 2]) ** 2 + sum(l[n // 2:]) ** 2)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
x = 0
y = 0
if n >= 2:
	for i in range(n // 2):
		x = x + arr[n - 1 - i]
		y = y + arr[i]
	if n // 2 < n / 2:
		x = x + arr[n - 2 - i]
else:
	x = x + arr[0]
	y = 0
root = x * x + y * y
print(root)


import sys

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

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
n = oint()
a = list(rint())
a.sort()
h = n // 2
hh = sum(a[:h])
vv = sum(a[h:])
print(hh ** 2 + vv ** 2)


n_sticks = int(input())
x = 0
y = 0
lengths = list(map(int, input().split()))
lengths = sorted(lengths, key=lambda x: x)
while lengths != []:
	x += lengths.pop()
	if lengths == []:
		break
	y += lengths.pop(0)
print(x * x + y * y)


n = int(input())
mass = list(reversed(sorted(list(map(int, input().split())))))
(x, y) = (0, 0)
while len(mass) > 0:
	x += mass[0]
	del mass[0]
	if len(mass) > 0:
		y += mass[len(mass) - 1]
		del mass[len(mass) - 1]
print(x ** 2 + y ** 2)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
z = n // 2
s = sum(a[:z]) ** 2 + sum(a[z:]) ** 2
print(s)


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


t = int(input())
arr = []
arr = list(map(int, input().split()))
arr.sort()
sum = 0
sum1 = 0
p = t
for i in range(0, t // 2):
	sum = sum + arr[i]
	sum1 = sum1 + arr[p - i - 1]
if t % 2 != 0:
	sum1 = sum1 + arr[t // 2]
print(sum * sum + sum1 * sum1)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = n // 2
sm1 = sum(a[:m])
sm2 = sum(a) - sm1
print(sm1 ** 2 + sm2 ** 2)


n = int(input())
l = list(map(int, input().rstrip().split()))
l.sort()
heigth = sum(l[:n // 2])
width = sum(l[n // 2:])
ans = width ** 2 + heigth ** 2
print(ans)


def main():
	n = int(input())
	sticks = list(map(int, input().split()))
	sticks.sort()
	x = y = 0
	while sticks:
		x += sticks.pop()
		if sticks:
			y += sticks.pop(0)
	return int(x * x + y * y)
print(main())


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


t = int(input())
n = list(map(int, input().split()))
n.sort()
n.reverse()
n1 = []
n2 = []
k = len(n)
x = 0
y = 0
if len(n) % 2 != 0:
	for i in range(k // 2 + 1):
		x += n[i]
	for i in range(k // 2 + 1, k):
		y += n[i]
else:
	for i in range(k // 2):
		x += n[i]
	for i in range(k // 2, k):
		y += n[i]
print(x * x + y * y)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	i = N // 2
	x = sum(A[i:])
	y = sum(A[:i])
	print(x * x + y * y)
main()


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
x = 0
y = 0
for i in range(n // 2):
	x += arr[i]
for i in range(n // 2, n):
	y += arr[i]
ans = x * x + y * y
print(ans)


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


n = int(input())
l = list(map(int, input().split()))
l.sort()
hor = sum(l[:n // 2])
ver = sum(l[n // 2:])
print(pow(ver, 2) + pow(hor, 2))


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


n = int(input())
arr = sorted(map(int, input().split()))
x = 0
y = 0
while arr:
	x += arr.pop(-1)
	if arr:
		y += arr.pop(0)
print(x ** 2 + y ** 2)


m = int(input())
bricks = sorted(list(map(int, input().split(' '))))
(x, y) = (bricks[:m // 2], bricks[m // 2:])
print(str(sum(x) ** 2 + sum(y) ** 2))


def dist(n, l):
	l.sort()
	i = n // 2
	a = sum(l[0:i])
	b = sum(l[i:])
	print(a ** 2 + b ** 2)
n = int(input())
l = list(map(int, input().split()))
dist(n, l)


n = int(input()) // 2
A = sorted(map(int, input().split()))
print(sum(A[n:]) ** 2 + sum(A[:n]) ** 2)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = 0
c = 0
s = sum(a[:n // 2])
t = sum(a[n // 2:])
r = int(s * s + t * t)
print(r)


import sys
import itertools
import math
import collections
from collections import Counter

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
n = ii()
d = sorted(li())
print(sum(d[:n // 2]) ** 2 + sum(d[n // 2:]) ** 2)


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


n = int(input())
b = [int(x) for x in input().split(' ')]
b.sort()
y = len(b) - 1
a = 0
n = 0
for t in range(len(b)):
	if y == t and len(b) % 2 != 0:
		a += b[y]
		break
	elif y == t + 1 and len(b) % 2 == 0:
		a += b[y]
		n += b[t]
		break
	a += b[y]
	n += b[t]
	y -= 1
print(a ** 2 + n ** 2)


import math
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = math.floor(n / 2)
x = 0
for i in range(m):
	x += a[i]
y = 0
for i in range(m, n):
	y += a[i]
print(x ** 2 + y ** 2)


from sys import stdin
from collections import deque
read = stdin.readline

def main():
	n = int(read().strip())
	nums = list(map(int, read().strip().split()))
	nums.sort()
	deq = deque(nums)
	x = y = 0
	while len(deq):
		x += deq.pop()
		if len(deq):
			y += deq.popleft()
	print(x ** 2 + y ** 2)
main()


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


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


n = int(input())
a = []
d = 0
d1 = 0
for b in input().split():
	a.append(int(b))
a.sort()
for i in range(0, n // 2):
	d += a[i]
for i in range(n // 2, n):
	d1 += a[i]
print(d * d + d1 * d1)


n = int(input())
x = input()
l = x.split()
l = [int(i) for i in l]
h = 0
v = 0
if n % 2 != 0:
	l.append(0)
l.sort()
for i in range(len(l) // 2):
	h += l[i]
	v += l[len(l) - i - 1]
print(h ** 2 + v ** 2)


import sys
input = sys.stdin.readline
from collections import deque

def solve():
	n = int(input())
	a = deque(sorted(map(int, input().split(' '))))
	(x, y) = (0, 0)
	while a:
		y += a.pop()
		if a:
			x += a.popleft()
	print(x ** 2 + y ** 2)
solve()


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
p = len(l)
print(sum(l[:p // 2]) ** 2 + sum(l[p // 2:]) ** 2)


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


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


numofn = int(input())
allns = input().split()
for n in range(numofn):
	allns[n] = int(allns[n])
allns = sorted(allns)
bigns = []
smallns = []
if numofn % 2 == 0:
	for n in range(numofn):
		if n >= numofn / 2:
			bigns.append(allns[n])
		else:
			smallns.append(allns[n])
else:
	for n in range(numofn):
		if n >= (numofn + 1) / 2 - 1:
			bigns.append(allns[n])
		else:
			smallns.append(allns[n])
print(sum(bigns) * sum(bigns) + sum(smallns) * sum(smallns))


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


n = int(input())
li = [int(x) for x in input().split(' ')]
li.sort()
(li1, li2) = (li[0:n // 2], li[n // 2:])
print(sum(li1) * sum(li1) + sum(li2) * sum(li2))


from collections import Counter
from collections import defaultdict
import math
n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
l = sorted(a, reverse=True)
x = 0
y = 0
c1 = 0
c2 = 0
for i in range(0, n):
	if i % 2 == 0:
		x = x + l[c1]
		c1 = c1 + 1
	else:
		y = y + s[c2]
		c2 = c2 + 1
print(x * x + y * y)


n = int(input())
p = [int(x) for x in input().split()]
p.sort()
mid = len(p) // 2
(a, b) = (sum(p[:mid]), sum(p[mid:]))
print(a * a + b * b)


t = int(input())
l = list(map(int, input().split()))
l.sort()
x = 0
y = 0
for i in range(0, len(l), 1):
	if i < t // 2:
		x += l[i]
	else:
		y += l[i]
print(x * x + y * y)


n = int(input())
arr = list(map(int, input().split()))
x = 0
y = 0
arr = sorted(arr)
take_from_top = True
while arr:
	if take_from_top:
		x += arr.pop(-1)
		take_from_top = False
	else:
		y += arr.pop(0)
		take_from_top = True
result = x ** 2 + y ** 2
print(result)


n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
arr = arr[::-1]
temp = (n + 1) // 2
x = sum(arr[:temp])
y = sum(arr[temp:])
print(x ** 2 + y ** 2)


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


n = int(input())
sticks = list(map(int, input().split(' ')))
sticks = sorted(sticks)
x = []
y = []
for i in range(n // 2):
	y.append(sticks.pop(0))
	x.append(sticks.pop(-1))
if len(sticks) == 1:
	x.append(sticks[0])
print(sum(x) ** 2 + sum(y) ** 2)


n = int(input())
numbers = [int(n) for n in input().split()]
numbers.sort()
horizontal = 0
vertical = 0
horizontal = sum((x for x in numbers[0:n // 2]))
vertical = sum((vertical + x for x in numbers[n // 2:n]))
print(horizontal * horizontal + vertical * vertical)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
if n % 2 == 0:
	d = n // 2
else:
	d = n // 2 + 1
x = sum(arr[0:d])
y = sum(arr[d:d + n])
print(x * x + y * y)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)
i = 0
length = height = 0
j = n - 1
while i < j:
	length += l[i]
	height += l[j]
	i += 1
	j -= 1
if i == j:
	length += l[i]
print(length ** 2 + height ** 2)


n = int(input())
r = list(map(int, input().split()))
r.sort()
print(sum(r[:n // 2]) ** 2 + (sum(r) - sum(r[:n // 2])) ** 2)