#include <iostream>
#include<cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	int n,a[100],sum=0;
	while(scanf("%d",&n)!=EOF)
	{
	    for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        int k=sum/n;
        int p=k+1;
        int b=0,c=0;
        for(int i=0;i<n;i++)
        {
            b+=(k-a[i])*(k-a[i]);
            c+=(p-a[i])*(p-a[i]);
        }
        if(b<c)printf("%d\n",b);
        else printf("%d\n",c);
	}
	return 0;
}