#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n,s=0; cin>>n;
  ll a[n]; for(int i=0;i<n;++i) { cin>>a[i]; s+=a[i]; }
  ll x1=s/n , x2 = s/n + 1;
  s=0;
  ll s2=0;
  for(int i=0;i<n;++i) {
  	s += (a[i]-x1)*(a[i]-x1);
    s2 += (a[i]-x2)*(a[i]-x2);
  }
    cout << min(s,s2);
}
