#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592654
#define EPS 1e-9
#define forr(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a; i<=b;i++)
#define clr(x, val) memset(x, val, sizeof(x))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const long long modl=1000000007;

//STLS
/*
stack <int > si;
queue < int > qi;
deque <int> dqi;
multiset<int> msi;
set < pair<int, string> > sp;
set < int > s;
map <int, string> m;
iterator;
*/

//map < ll, ll > farr;
int farr[2000000];
int prea[100002];
int preb[100002];
int cuma[2000000];
int cumb[2000000];

//functions
unsigned long long poow(int base, int po);
void swaap(int *a, int *b);

int main()
{
     cin.tie(0);
     cin.sync_with_stdio(0);
    // s :: itr it;
    int n;

    cin >> n;

    signed int arr[n];
    arr[0]=0;

    signed int mini=INT_MAX, maxi=INT_MIN;

    fore(i,1,n)
    {
        cin >> arr[i];
        mini=min(mini,arr[i]);
        maxi=max(maxi,arr[i]);
    }

    int res=INT_MAX;

    for(int i=mini; i <= maxi; i++)
    {
        int sum=0;

        fore(j,1,n)
        {
            sum+=( (arr[j]-i)*(arr[j]-i) );
        }

        res=min(res,sum);
    }

    cout << res;

     return 0;
}

unsigned long long poow(int base, int po)
{
    // take modelus of base in main
    if(po == 0)
        return 1;
    if(po == 1)
        return base;

    unsigned long long ans = poow(base, po/2);
    ans = (ans * ans) /* % modl */;

    if(po & 1)
       return (ans * base) /* % modl */ ;

    return ans  ;
}

void swaap(int *a, int *b)
{
	//send addresses from the main
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}
