#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;

	vector<int> array;
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		array.push_back(x);
	}
	int minSum = INT_MAX;
	for(int a=-100;a<=100;a++){
		int sum=0;
		for(auto e:array){
			sum+=(a-e)*(a-e);
		}
		minSum=min(minSum,sum);
	}
	cout<<minSum;
}