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

int main()
{
    int n,ave = 0,ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        ave += a[i];
    }
    ave = round((double)ave/n);
    for(int i = 0; i < n; i++) ans += pow(a[i]-ave,2);
    cout << ans << endl;
    return 0;
}