#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <unistd.h>
#include <utility>
#include <vector>
#define dbc(x) cerr << x << '\n'
#define dbn(x) cerr << #x << " == " << x << '\n'
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

//

int v[112];

int main(){
	ios::sync_with_stdio(false), cin.tie(0);

	int n; cin >> n;

	int mn = 0x3f3f3f3f;
	int mx = -1;

	for (int i=0; i<n; i++) {
		cin >> v[i];
		mn = min(mn, v[i]);
		mx = max(mx, v[i]);
	}

	int aux = 0x3f3f3f3f;
	for (int i=mn; i<=mx; i++) {
		int cost = 0;

		for (int j=0; j<n; j++) {
			cost += (v[j] - i) * (v[j] - i);
		}

		if (cost < aux) {
			aux = cost;
		}
	}

	cout << aux << endl;
}