#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#define maxn 500
using namespace std;
int n,a[maxn],sum,temp,temp2,b[maxn];
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
b[i] = a[i];
}
a[0] = 0;
for(int i = 1;i <= n;i++)
{
temp = a[i] - a[i-1];
temp2 = i;
for(int j = 1;j <= n;j++)
{
if(a[j] - a[j-1] > temp)
{
temp = a[j] - a[j-1];
temp2 = a[j];
}
}
sum += pow((b[temp2] - b[temp2-1]),2);
a[temp2] = 0;
temp2 = 0;
temp = 0;
}
printf("%d",sum);
return 0;
}