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

int main() {
	int ans = INT_MAX, sum;
	size_t N;
	cin >> N;
	vector<int> a(N);
	for (auto& x : a) cin >> x;
	for (int i = -100; i <= 100; ++i) {
		sum = 0;
		for (auto&x : a) sum += (x - i) * (x - i);
		ans = min(ans, sum);
	}
	cout << ans;
}