#include <bits/stdc++.h>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	int min{1 << 30};
	for (int i = -100; i <= 100; i++)
	{
		int cost{};
		for (int j = 0; j < n; j++)
			cost += (a[j] - i) * (a[j] - i);

		min = std::min(cost, min);
	}
	printf("%d\n", min);

	return 0;
}