#include <iostream>
using namespace std;
int main() {
int n;
int a[113];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for(int x = -100; x <= 100; x++){
int current_cost = 0;
for(int i=0;i<n;i++) {
current_cost += (x - a[i]) * (x - a[i]);
}
a[112] = min(a[112],current_cost+4000000-2147483647);
}
cout << a[112] - 4000000 + 2147483647 << endl;
}