#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;
namespace Arithmetics {
	template<typename T>
	T original_pow(T a, T b) {
		T ans = 1;
		rep(i, b) {
			ans *= a;
		}

		return  ans;
	}
	template<typename T>
	T gcd(T a, T b) {
		if (a > b) {
			T c = a;
			a = b;
			b = c;
		}
		if (a == 0) {
			return b;
		}

		return gcd(b % a, a);
	}
	template<typename T>
	T gcd_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = gcd(temp, elem);
		}

		return temp;
	}
	template<typename T>
	T lcm(T a, T b) {
		T GCD = gcd(a, b);
		return a * b / GCD;
	}
	template<typename T>
	T lcm_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = lcm(temp, elem);
		}
		return temp;
	}
}
using namespace Arithmetics;
void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

void prob140() {
	int N; cin >> N;
	vector<int> B(N + 1);
	B[0] = int_INF; B[N] = int_INF;
	for (int i = 1; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int j = 0; j < N; j++) {
		ans += min(B[j], B[j + 1]);
	}

	cout << ans << endl;
}

void prob141() {
	int N, K, Q; cin >> N >> K >> Q;
	vi Contestants(N);
	rep(i, Q) {
		int x;
		cin >> x;
		Contestants[--x]++;
	}

	rep(i, N) {
		if (Contestants[i] + K - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

void prob148() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}
bool is_prime[100000000 + 1];
vi Eratosthenes(const int N) { // return primes up to N
	vector<int> P;
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}
void prob149() {
	int x; cin >> x;
	vi Eratos = Eratosthenes(1000003);
	auto iter = lower_bound(Eratos.begin(), Eratos.end(), x);
	int index = distance(Eratos.begin(), iter);
	cout << Eratos[index] << endl;
}

void prob149A() {
	string s, t;
	cin >> s >> t;
	cout << t+s << endl;
}

void prob158() {
	int a, b; cin >> a >> b;
	bool flag = false; int ans;
	for (int i = 1; i < 1010; i++) {
		int x = i * 0.08; int y = i * 0.10;

		if (x == a and y == b) {
			ans = i;
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}

int subfunc(int P, int N, int sum, int p2sum) {
	return N * P* P - 2 * P * sum + p2sum;
}
void prob156() {
	int N; cin >> N;
	vi X(N);
	int sum = 0; int p2sum = 0;
	for (int& elem : X) {
		cin >> elem;
		sum += elem;
		p2sum += elem * elem;
	}

	int T = sum / N;
	int min = int_INF;
	for (int i = -1; i < 2; i++) {
		subfunc(T + i, N, sum, p2sum) < min ? min = subfunc(T + i, N, sum, p2sum) : 1;
	}

	cout << min << endl;

}
int main() {
	prob156();
}

Measured memory_bytes: 256