#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;
typedef unsigned long long ull;
ull res;
int n;
int main()
{
priority_queue<int> dheap;
priority_queue<int,vector<int>,greater<int> > xheap;
scanf("%d",&n);
xheap.push(0);
for(int i = 1;i <= n;i++)
{
int x;
scanf("%d",&x);
dheap.push(x);
xheap.push(x);
}
int t = 0;
while(t <= n)
{
res+= (dheap.top() - xheap.top()) * (dheap.top() - xheap.top());
if(!t % 2) xheap.pop();
else dheap.pop();
t++;
}
printf("%lld",res);
return 0;
}