#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define PI 3.14159265359
#define x first
#define y second

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;
    cin.tie(0);
    cin.sync_with_stdio(0);

    int n; cin>>n;
    vector<ll> a(n);

    loop(i,n) cin>>a[i];
    int x = *max_element(a.begin(),a.end());
    x+= *min_element(a.begin(),a.end());
    ll ans2 = 1e7;

    if(x%2 != 0){
        ans2=0;
        int y=(x+1)/2;
        loop(i,n){
            ans2+= (a[i] - y) * (a[i] - y);
        }
    }
    x/= 2;

    ll ans=0;
    loop(i,n){
        ans+= (a[i] - x) * (a[i] - x);
    }

    cout<<min(ans2,ans);

}
