#include <bits/stdc++.h>
using namespace std;

#define debug(args...) fprintf(stderr,args)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int N = 5e6 + 5;
const ll inf = 1791791791;
const ll mod = 1e9+7;

int a[N];

int main() {
	int n; scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	ll mn = inf;
	for (int j=-100;j<=100;j++) {
		ll cost = 0;
		for (int i=0;i<n;i++) {
			cost += (a[i]-j)*(a[i]-j);
		}
		mn = min(mn, cost);
	}
	printf("%lld\n", mn);
    return 0;
}
