#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	double sum = 0;
	auto a = vector<int>(n);
	for(auto&& aa : a){
		cin >> aa;
		sum += aa;
	}
	int d = (int)(sum / n + (sum > 0.0 ? 0.5: -0.5));
	int ans = 0;
	for(auto aa : a){
		ans += ((aa - d) * (aa - d));
	}
	cout << ans << endl;
	return 0;
}