
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#include <string>
#include <cstdio>
#define ll long long
#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef pair<int,int> pii;
const ll mod = 1000000007 ;
const int INF=0x3f3f3f3f;
#define test(n) cout<<"Test "<<n<<endl;
#define pb push_back
#define rp(n) for(int i=1;i<=n;i++)
#define rep(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
ll ksm(ll x,ll n){ll ans=1;while (n){if (n&1)ans=(ans*x)%mod;x=x*x%mod;n>>=1;}return ans;}
using namespace std;
double pi = atan(1.0)*4 ;
const int mxn = 1e3+7 ;
int n,t,m,k,l,r;
/// ll mat[mxn][mxn], prime[mxn], isprime[mxn];
ll phi[mxn];
string str,s;char ch[27][27] ;
ll exgcd(ll a,ll b, ll &x ,ll &y){    if(!a&&!b) return -1;    if(!b) {x=1,y=0;return a;}    ll d=exgcd(b,a%b,y,x);    y-=a/b*x ;    return d;}
int vis[mxn][mxn];
int a[mxn];
int check(int x)
{
    int ans = 0 ;
    rp(n) ans+=(x-a[i])*(x-a[i]);
    return ans;
}
int main()
{
    cin>>n;
    int l = 1e3 ,r = -1;
    rp(n) {cin>>a[i];l = min(a[i],l) , r = max(a[i],r) ;}
    int mx = INF;
    for(int k=l;k<=r;k++)
    {
        rp(n)
        {
            int ans = check(k) ;
            if(ans < mx )
                m = k , mx = ans ;
        }

    }
    cout<<mx<<endl;
}

