



#include<bits/stdc++.h>
using namespace std;
int main(){long long n,i=0,r,t,s=0,p=0,l,m=0;
cin>>n;long long a[n];
for(i=0;i<n;i++){
    cin>>a[i];
    s=s+a[i];
}
s=s/n;
t=s+1;
for(i=0;i<n;i++){r=abs(s-a[i]);l=(t-a[i]);
    p=p+r*r;m=m+l*l;
}if(p<=m)
cout<<p;
else
cout<<m;
    return 0;
  
}
