Code:
#include <bits/stdc++.h>
using namespace std;
int n,h[500]={0},ans,point=1;
int main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
cin >> n;
for(int i=1;i<=n;i++)
cin >> h[i];
sort(h,h+n);
int l=0,r=n;
while(r>l)
{
ans+=pow(h[r]-h[l],2);
l++;
ans+=pow(h[l]-h[r],2);
r--;
}
cout << ans;
return 0;
}