#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>

#ifdef GONGKUNPENG
#include <cassert>
#endif

#define GG 1
#define GIO 1
#define uint unsigned
#define max(a, b) std::max((a), (b))
#define min(a, b) std::min((a), (b))
#define sort(...) std::sort(__VA_ARGS__)
#define ms(a, v) memset(a, v, sizeof(a))
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)

#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
#else
typedef long long ll;
typedef unsigned long long ull;
#endif

#if GIO
class GLIB
{
#define BUFSIZE 1 << 20
#define uns(x) (x == ' ' || x == '\t' || x == '\n' || x == '\r')
	char ruf[BUFSIZE], wuf[BUFSIZE], *p, *q, *r, rcha;
	bool rneg;

public:
#if GG
#else
	GLIB() : p(ruf), q(ruf), r(wuf), rcha(' ')
	{
	}

	~GLIB()
	{
		fwrite(wuf, 1, r - wuf, stdout);
	}
#endif
	inline void flush()
	{
		fwrite(wuf, 1, r - wuf, stdout), r = wuf;
	}

	inline int readc()
	{
#if GG
		return getchar();
#else
		return (p == q && (q = (p = ruf) + fread(ruf, 1, BUFSIZE, stdin), p == q) ? -1 : *p++);
#endif
	}

	template <typename T, typename... Args>
	void read(T &x, Args &... args)
	{
		read(x), read(args...);
	}

	inline void read() {}

	inline void read(char *s)
	{
		while (uns(rcha))
			rcha = readc();
		while (!uns(rcha) && rcha > 0)
			*s++ = rcha, rcha = readc();
		*s = '\0';
	}

	inline void readl(char *s)
	{
		while (uns(rcha))
			rcha = readc();
		while (rcha != '\n' && rcha > 0)
			*s++ = rcha, rcha = readc();
		*s = '\0';
	}

	template <typename T>
	inline void read(T &x)
	{
#ifdef GONGKUNPENG
		static_assert(std::is_integral<T>::value);
#endif
		x = rcha = rneg = 0;
		while (!isdigit(rcha) && rcha != '-')
			rcha = readc();
		rcha == '-' && (rneg = true, rcha = readc());
		while (isdigit(rcha))
			x = (x << 3) + (x << 1) - 48 + rcha,
			rcha = readc();
		rneg && (x = -x);
	}

	inline void writec(const char &c)
	{
#if GG
		putchar(c);
#else
		(r - ruf == BUFSIZE) && (fwrite(wuf, 1, BUFSIZE, stdout), r = wuf);
		*r++ = c;
#endif
	}

	template <typename T, typename... Args>
	void write(const T &x, const Args &... args)
	{
		write(x), write(args...);
	}

	inline void write() {}

	template <typename T>
	void write(T x)
	{
#ifdef GONGKUNPENG
		static_assert(std::is_integral<T>::value);
#endif
		if (x < 0)
		{
			writec('-');
			write(-ll(x));
			return;
		}
		if (x > 9)
			write(x / 10);
		writec(x % 10 ^ 48);
	}

	inline void write(const char *s)
	{
		while (*s)
			writec(*s++);
	}
#undef BUFSIZE
} io;
#endif

const double INF = 1e11;
const uint MAXN =
#ifdef GONGKUNPENG
	15
#else
	105
#endif
	;

int pos[MAXN];

int main()
{
	int n, left = 0x3f3f3f3f, right = -1, mid, nl, nr;
	double v, evl, evr, bv = INF;
	io.read(n);
	tfor(i, n)
	{
		io.read(pos[i]);
		left = min(left, pos[i]);
		right = max(right, pos[i]);
	}
	while (left <= right)
	{
		mid = (left + right >> 1);
		nl = (mid + left >> 1);
		nr = (mid + right >> 1);
		evl = evr = 0;
		tfor(i, n)
		{
			v = pos[i] - nl;
			evl += v * v;
		}
		tfor(i, n)
		{
			v = pos[i] - nr;
			evr += v * v;
		}
		if (evl < evr)
		{
			bv = min(bv, evl);
			right = nr - 1;
		}
		else
		{
			bv = min(bv, evr);
			left = nl + 1;
		}
	}
	io.write(ll(bv), "\n");
	return 0;
}

Measured memory_bytes: 128