#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m,sum=0,ans=0,i=0,k=0;
	cin >> n ;
	while(i<n){
		cin>>m;
		ans+=m*m;
		sum+=m;
		i++;
	}
	i=0;
	while(1){
		if(n*i*i-2*sum*i>k) break;
		k=n*i*i-2*sum*i;
		i++;
	}
	cout << ans+k << endl;
	return 0;
}