#include <bits/stdc++.h>

using namespace std;

const int N = 110;

int vec[N];

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		scanf("%d", &vec[i]);
	}
	long long ans = 0x3f3f3f3f;
	for (int i = -100; i <= 100; ++i) {
		long long at = 0;
		for (int j = 0; j < n; ++j) {
			at += (i-vec[j]) * 1ll * (i-vec[j]);
		}
		ans = min(ans, at);
	}
	printf("%lld\n", ans);
}