#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	int n;
	cin >> n;
	ll a[n];
	ll ans=1000000000000000;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=-100;i<=100;i++){
		ll t=0;
		for(int j=0;j<n;j++){
			t+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,t);
	}
	cout<<ans<<endl;
    return 0;
}