AtCoder Beginner Contest 156 - Rally

There are N people living on a number line.
The i-th person lives at coordinate X_i.
You are going to hold a meeting that all N people have to attend.
The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.
Find the minimum total points of stamina the N people have to spend.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 100
 - 1 \leq X_i \leq 100

-----Input-----
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N

-----Output-----
Print the minimum total stamina the N people have to spend.

-----Sample Input-----
2
1 4

-----Sample Output-----
5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.
Note that you can hold the meeting only at an integer coordinate.

Difficulty: EASY

Starter code:

Solutions:
n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / n)
ans = 0
for i in x:
	ans += (i - p) ** 2
print(ans)


a = int(input())
n = list(map(int, input().split()))
m = round(sum(n) / len(n))
print(sum(((i - m) ** 2 for i in n)))


N = int(input())
list1 = list(map(int, input().split()))
list1.sort()
max = list1[-1]
min = list1[0]
cost = []
for i in range(min, max + 1):
	tairyoku = 0
	for k in range(N):
		tairyoku += (list1[k] - i) ** 2
	cost.append(tairyoku)
cost.sort()
print(cost[0])


n = int(input())
x = [int(s) for s in input().split()]
hp = []
for i in range(min(x), max(x) + 1):
	sum_ = 0
	for j in x:
		sum_ = sum_ + (j - i) ** 2
	hp.append(sum_)
print(min(hp))


n = int(input())
xs = list(map(int, input().split()))
print(min([sum([(x - p) ** 2 for x in xs]) for p in range(min(xs), max(xs) + 1)]))


N = int(input())
X = list(map(int, input().split()))
P = round(sum(X) * 1.0 / N)
h = [(i - P) ** 2 for i in X]
print(sum(h))


n = int(input())
x = [int(i) for i in input().split()]
hp = []
for p in range(min(x), max(x) + 1):
	sum = 0
	for i in x:
		sum = sum + (i - p) ** 2
	hp.append(sum)
print(min(hp))


n = int(input())
x = list(map(int, input().split()))
ans = 1000000
for i in range(100):
	tmp = 0
	for j in range(n):
		tmp += (x[j] - (i + 1)) ** 2
	ans = min(ans, tmp)
print(ans)


n = int(input())
x = list(map(int, input().split()))
ans = 1000000
for i in range(101):
	score = 0
	for j in range(n):
		score += (x[j] - i) ** 2
	ans = min(ans, score)
print(ans)


n = int(input())
l = list(map(int, input().split()))
a = round(sum(l) / n)
k = 0
for j in l:
	k += (j - a) ** 2
print(k)


N = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / N)
ans = 0
for x in X:
	ans += (x - p) ** 2
print(ans)


n = int(input())
L = list(map(int, input().split()))
(l, r, ans) = (min(L), max(L), 10 ** 18)
for i in range(l, r + 1):
	total = 0
	for l in L:
		total += (l - i) ** 2
	ans = min(ans, total)
print(ans)


n = int(input())
l = list(map(int, input().split()))
cnt_m = float('inf')
for i in range(1, 101):
	cnt = 0
	for j in range(n):
		cnt += (l[j] - i) ** 2
	cnt_m = min(cnt_m, cnt)
print(cnt_m)


N = int(input())
A = list(map(int, input().split()))
P = round(sum(A) / N)
B = 0
for i in range(N):
	B = B + (A[i] - P) ** 2
print(B)


N = int(input())
Xs = list(map(int, input().split()))
res = 0
for i in Xs:
	res = res + (i - round(sum(Xs) / N)) ** 2
print(res)


N = int(input())
X = list(map(int, input().split()))
T = sum(X) // len(X)
a = 0
b = 0
c = 0
for i in X:
	a += (i - T) ** 2
	b += (i - T - 1) ** 2
	c += (i - T + 1) ** 2
ans = min(a, b)
print(min(ans, c))


n = int(input())
x = list(map(int, input().split()))
ans = []
if len(set(x)) == 1:
	print(0)
else:
	for p in range(min(x), max(x)):
		meter = 0
		for xi in x:
			meter += pow(xi - p, 2)
		ans.append(meter)
	print(min(ans))


N = int(input())
X = list(map(int, input().split()))
P = round(sum(X) / N)
for i in range(N):
	X[i] = (X[i] - P) ** 2
print(sum(X))


import numpy as np
N = int(input())
Xi = list(map(int, input().split()))
Xi = np.array(Xi)
min = float('inf')
for i in range(1, 101):
	tmp = np.sum(np.square(Xi - i))
	if tmp < min:
		min = tmp
print(min)


(N, *X) = map(int, open(0).read().split())
print(int(sum(map(lambda x: (round(sum(X) / N, 0) - x) ** 2, X))))


n = int(input())
a = list(map(int, input().split()))
avg = round(sum(a) / n)
print(sum([(x - avg) ** 2 for x in a]))


n = int(input())
x = [int(i) for i in input().split()]
p = round(sum(x) / n)
print(sum(((i - p) ** 2 for i in x)))


N = int(input())
X = list(map(int, input().split()))
ans = 10 ** 18
for p in range(1, 101):
	tmp = 0
	for x in X:
		tmp += (x - p) ** 2
	ans = min(tmp, ans)
print(ans)


N = int(input())
X = list(map(int, input().split()))
print(min((sum(((X[i] - j) ** 2 for i in range(N))) for j in range(1, 101))))


n = int(input())
l = list(map(int, input().split()))
import statistics as st
m = round(st.mean(l))
print(sum(((m - i) ** 2 for i in l)))


N = int(input())
X = [int(_) for _ in input().split()]
P = round(sum(X) / N)
print(sum([(x - P) ** 2 for x in X]))


N = int(input())
X = list(map(int, input().split()))
M = round(sum(X) / N)
re = 0
for i in X:
	re += (i - M) ** 2
print(re)


N = int(input())
L = list(map(int, input().split()))
c = round(sum(L) / N)
ans = 0
for i in L:
	ans += (c - i) * (c - i)
print(ans)


n = int(input())
l = list(map(int, input().split()))
k = round(sum(l) / n)
ans = 0
for i in l:
	ans += (k - i) ** 2
print(ans)


n = int(input())
x = input().split()
min = 2 ** 20
for p in range(100):
	min_i = 0
	if p in x:
		continue
	for i in x:
		min_i = min_i + (int(i) - p) ** 2
	if min_i <= min:
		min = min_i
print(min)


N = int(input())
X = input().split()
distance = 0
min_distance = float('Inf')
for i in range(1, 101):
	for j in range(N):
		distance += (int(X[j]) - i) ** 2
	min_distance = min(min_distance, distance)
	distance = 0
print(min_distance)


n = int(input())
x = list(map(int, input().split()))
hp_min = 10000000
for i in range(101):
	hp_min = min(hp_min, sum(((y - i) ** 2 for y in x)))
print(hp_min)


N = int(input())
X = list(map(int, input().split()))
r = 0
a = round(sum(X) / N)
for x in X:
	r += (x - a) ** 2
print(r)


N = int(input())
X = list(map(int, input().split()))
avg = round(sum(X) / N)
print(sum([(x - avg) ** 2 for x in X]))


(n, *ps) = map(int, open(0).read().split())
pave = round(sum(ps) / n)
psig = 0
for p in ps:
	psig += (p - pave) ** 2
print(psig)


n = int(input())
x = list(map(int, input().split()))
r = round(sum(x) / n)
res = 0
for i in range(n):
	res += (x[i] - r) ** 2
print(res)


a = int(input())
b = list(map(int, input().split()))
d = round(sum(b) / a)
b = list(map(lambda x: (d - x) ** 2, b))
print(sum(b))


n = int(input())
a = input().split()
print(min([sum([(int(i) - j) ** 2 for i in a]) for j in range(1, n + 10000)]))


N = int(input())
X = list(map(int, input().split()))
xp = round(sum(X) / N)
Xe = map(lambda x: abs(x - xp) ** 2, X)
print(sum(Xe))


N = int(input())
lst = list(map(int, input().split()))
P = round(sum(lst) / N)
print(sum([(i - P) ** 2 for i in lst]))


n = int(input())
x = list(map(int, input().split()))
p = int(sum(x) / n + 0.5)
print(sum(((i - p) ** 2 for i in x)))


n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
mxi = min(x)
mxa = max(x)
for p in range(mxi, mxa + 1):
	sm = 0
	for xi in x:
		sm += (xi - p) ** 2
	ans = min(ans, sm)
print(ans)


a = int(input())
b = list(map(int, input().split()))
p = round(sum(b) / a)
hp = 0
for i in b:
	hp += (i - p) ** 2
print(hp)


n = int(input())
x = [int(i) for i in input().split()]
ave = sum(x) // n
ansl = 0
ansr = 0
for i in x:
	ansl += pow(i - ave, 2)
	ansr += pow(i - ave - 1, 2)
print(min([ansl, ansr]))


N = int(input())
x = [int(i) for i in input().split()]
y = 0
d = 0
for n in x:
	y += n
z = y // N
if y / N - z >= 0.5:
	g = z + 1
else:
	g = z
for s in x:
	d += (s - g) ** 2
print(d)


N = int(input())
X_list = list(map(int, input().split()))
distance = 10 ** 9
min_val = min(X_list)
max_val = max(X_list)
P_list = list(range(min_val, max_val + 1))
for _ in range(N):
	for p in P_list:
		temp = 0
		for x in X_list:
			temp += (p - x) ** 2
		if temp < distance:
			distance = temp
print(distance)


n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / n)
s = 0
for i in x:
	s += abs(t - i) ** 2
print(s)


n = int(input())
x = list(map(int, input().split()))
s = round(sum(x) / n)
ans = [(a - s) ** 2 for a in x]
print(sum(ans))


N = int(input())
X = list(map(int, input().split()))
ans = 10000000000.0
for p in range(max(X) + 1):
	sum_power = 0
	for i in range(N):
		sum_power += (X[i] - p) ** 2
	if ans > sum_power:
		ans = sum_power
print(ans)


N = int(input())
l = []
l = list(map(int, input().split()))
s = sum(l)
n = int((s / N * 2 + 1) // 2)
ans = 0
for e in l:
	ans += (e - n) ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
av = round(sum(a) / n)
x = 0
for i in a:
	x = x + (i - av) ** 2
print(x)


n = int(input())
x = list(map(int, input().split()))
for i in range(1, n + 1000):
	count = 0
	for j in range(n):
		count += (x[j] - i) * (x[j] - i)
	if i == 1:
		min = count
	elif count < min:
		min = count
	else:
		break
print(min)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
M = lst[-1]
m = lst[0]
total = float('inf')
for i in range(m, M + 1):
	s = sum([(x - i) ** 2 for x in lst])
	if s < total:
		total = s
print(total)


n = int(input())
x = list(map(int, input().split()))
s = round(sum(x) / n)
print(sum([(i - s) ** 2 for i in x]))


n = int(input())
x = list(map(int, input().split()))
min_x = 100 * 100 * 100 + 1
for p in range(1, 100 + 1, 1):
	total = 0
	for xi in x:
		total += (xi - p) ** 2
	min_x = min([min_x, total])
print(min_x)


N = int(input())
X = sorted(list(map(int, input().split())))
Y = [0] * (max(X) - min(X) + 1)
for i in range(max(X) - min(X) + 1):
	for j in X:
		Y[i] += (j - i - min(X)) ** 2
print(min(Y))


n = int(input())
x = list(map(int, input().split()))
y = round(sum(x) / n)
print(sum([abs(i - y) ** 2 for i in x]))


n = int(input())
X = list(map(int, input().split()))
m1 = sum(X) // n
m2 = (sum(X) + (n - 1)) // n
a1 = sum([(x - m1) ** 2 for x in X])
a2 = sum([(x - m2) ** 2 for x in X])
print(min(a1, a2))


N = int(input())
X = list(map(int, input().split()))
a = round(sum(X) / N)
Y = []
for i in X:
	Y.append((i - a) ** 2)
print(sum(Y))


N = int(input())
X = [int(i) for i in input().split()]
avg = round(sum(X) / len(X))
summy = 0
for i in X:
	summy += (i - avg) ** 2
print(summy)


n = int(input())
x = [int(i) for i in input().split()]
sq = [sum([(i - j) ** 2 for i in x]) for j in range(min(x), max(x) + 1)]
print(min(sq))


N = int(input())
L = list(map(int, input().split()))
res = 0
p = round(sum(L) / N)
for i in L:
	res += (i - p) ** 2
print(res)


input()
l = list(map(int, input().split()))
m = round(sum(l) / len(l))
print(sum(((m - i) ** 2 for i in l)))


n = int(input())
X = list(map(int, input().split()))
a = round(sum(X) / n)
ans = 0
for x in X:
	ans += (x - a) ** 2
print(ans)


n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for p in range(1, 101):
	hp = 0
	for i in x:
		hp += (i - p) ** 2
	ans = min(ans, hp)
print(ans)


n = int(input())
x = list(map(int, input().split()))
print(sum(((xi - round(sum(x) / n)) ** 2 for xi in x)))


N = int(input())
X = list(map(int, input().split()))
_min = min(X)
_max = max(X)
_sum = 1000000000
for i in range(_min, _max + 1):
	temp = 0
	for x in X:
		temp += (x - i) * (x - i)
	if temp < _sum:
		_sum = temp
print(_sum)


n = int(input())
x = list(map(int, input().split()))
avr = round(sum(x) / n)
sum = 0
for i in range(n):
	sum += (x[i] - avr) ** 2
print(sum)


n = int(input())
x = list(map(int, input().split()))
p = (2 * sum(x) + n) // (2 * n)
ans = 0
for xi in x:
	ans += (xi - p) ** 2
print(ans)


N = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = 0
for num in X:
	b += num ** 2
ans = float('inf')
for i in range(1, 101):
	ans = min(ans, N * i * i - 2 * a * i + b)
print(ans)


a = input()
b = input().split()
c = [int(n) for n in b]
d = sum(c)
e = round(d / int(a))
f = [(f - e) * (f - e) for f in c]
g = sum(f)
print(g)


n = int(input())
a = list(map(int, input().split()))
mean = round(sum(a) / n)
print(sum([(v - mean) ** 2 for v in a]))


N = int(input())
X = list(map(int, input().split()))
P = int(sum(X) / N + 0.5)
print(sum(((x - P) * (x - P) for x in X)))


n = int(input())
l = list(map(int, input().split()))
ans = 1000000
for p in range(1, 101):
	d = 0
	for x in l:
		d += (x - p) ** 2
	ans = min(d, ans)
print(ans)


N = int(input())
xlist = list(map(int, input().split()))
p = round(sum(xlist) / N)
s = 0
for x in xlist:
	s += (x - p) ** 2
print(s)


N = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / N)
cnt = 0
for i in X:
	cnt += (i - p) ** 2
print(cnt)


n = int(input())
ans = 10 ** 7 + 9
x = list(map(int, input().split()))
X = len(x)
for i in range(100):
	total = 0
	for j in range(X):
		total += (x[j] - i) ** 2
	else:
		ans = min(ans, total)
print(ans)


input()
X = [int(x) for x in input().split()]
P = round(sum(X) / len(X))
S = 0
for x in X:
	S += (P - x) ** 2
print(S)


n = int(input())
x = list(map(int, input().split()))
sumX = 0
for i in x:
	sumX += (i - round(sum(x) / n)) ** 2
print(sumX)


N = int(input())
xs = list(map(int, input().split()))
P = round(sum(xs) / N)
ans = 0
for x in xs:
	ans += (x - P) ** 2
print(ans)


import math
N = int(input())
Xlist = list(map(int, input().split()))
min = 10 ** 5
meandown = math.floor(sum(Xlist) / N)
meanup = math.ceil(sum(Xlist) / N)
sumdown = 0
sumup = 0
for i in range(len(Xlist)):
	sumdown += (Xlist[i] - meandown) ** 2
	sumup += (Xlist[i] - meanup) ** 2
if sumdown < sumup:
	print(sumdown)
else:
	print(sumup)


N = int(input())
X = list(map(int, input().split()))
c = 0
d = round(sum(X) / N)
for i in X:
	c += (i - d) ** 2
print(c)


N = int(input())
X = [int(x) for x in input().split()]
a = int((sum(X) + N / 2) // N)
print(sum([(x - a) ** 2 for x in X]))


(n, *x) = map(int, open(0).read().split())
p = round(sum(x) / n)
print(sum([(i - p) ** 2 for i in x]))


N = int(input())
X = list(map(int, input().split()))
min = 100 * 10000
for p in range(100):
	sum = 0
	for i in X:
		sum += (i - p) ** 2
	if sum < min:
		min = sum
print(min)


N = int(input())
X = list(map(int, input().split()))
max_x = max(X)
min_x = min(X)
min_y = 9999999999
for p in range(min_x, max_x + 1):
	y = sum([(x - p) ** 2 for x in X])
	if y < min_y:
		min_y = y
print(min_y)


N = int(input())
X = list(map(int, input().split()))
ave = 0
for i in X:
	ave += i
if ave / N // 0.5 % 2 == 1:
	ave = ave // N + 1
else:
	ave = ave // N
ans = 0
for i in X:
	ans += (ave - i) ** 2
print(ans)


n = int(input())
a = [*map(int, input().split())]
d = []
for i in range(min(a), max(a) + 1):
	temp = []
	for j in range(n):
		temp.append((a[j] - i) ** 2)
	d.append(sum(temp))
print(min(d))


import math

def power(P, X):
	ans = 0
	for x in X:
		ans += (x - P) ** 2
	return ans
N = int(input())
X = list(map(int, input().split()))
ave = sum(X) / N
candP = (math.ceil(ave), math.floor(ave))
power = min([power(P, X) for P in candP])
print(power)


n = int(input())
x = list(map(int, input().split()))
ans = 10 ** 18
for i in range(1, 101):
	t = 0
	for j in range(n):
		t += (x[j] - i) ** 2
	ans = min(ans, t)
print(ans)


n = int(input())
x = list(map(int, input().split()))
h = round(sum(x) / n)
ans = 0
for i in range(n):
	ans += (x[i] - h) ** 2
print(ans)


n = int(input())
x = list(map(int, input().split()))
s = 0
for i in x:
	s += i
p = int(s / n + 0.5)
result = 0
for i in x:
	result += (i - p) ** 2
print(result)


N = int(input())
Xs = [int(e) for e in input().split(' ')]
P = int(sum(Xs) / N + 0.5)
sum = 0
for X in Xs:
	sum += (X - P) ** 2
print(sum)


n = int(input())
x = list(map(int, input().split()))
ave = sum(x) // len(x)
ans_list = []
ans_list2 = []
for i in x:
	ans = (i - ave) ** 2
	ans_list.append(ans)
ans1 = sum(ans_list)
ave2 = ave + 1
for i in x:
	ans = (i - ave2) ** 2
	ans_list2.append(ans)
ans2 = sum(ans_list2)
if ans1 < ans2:
	print(ans1)
else:
	print(ans2)


n = int(input())
x = [int(i) for i in input().split()]
p = [sum([(j - i) ** 2 for j in x]) for i in range(101)]
print(min(p))


N = int(input())
X = list(map(int, input().split()))
a = round(sum(X) / len(X))
n = 0
for i in X:
	n += (int(i) - a) ** 2
print(n)


def main():
	n = int(input())
	x = [int(v) for v in input().split()]
	x.sort()
	closest = x[0]
	farest = x[-1]
	startPoint = 0
	sofar = float('inf')
	for i in range(0, farest + 1):
		p = i
		cur = 0
		for j in range(len(x)):
			cur += (x[j] - p) ** 2
		if cur < sofar:
			sofar = cur
	return sofar

def __starting_point():
	print(main())
__starting_point()


(n, *d) = map(int, open(0).read().split())
m = round(sum(d) / n)
print(sum(map(lambda x: (x - m) ** 2, d)))


N = int(input())
X = list(map(int, input().split()))
result = min([sum(((x - p) ** 2 for x in X)) for p in range(1, 101)])
print(result)


a = 0
b = 0
N = int(input())
X = list(map(int, input().split()))
avg = sum(X) // N
for tai in X:
	a += (tai - avg) ** 2
for tai in X:
	b += (tai - (avg + 1)) ** 2
if a > b:
	print(b)
else:
	print(a)


n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / n)
m = []
for i in x:
	m.append((i - p) ** 2)
print(sum(m))


N = int(input())
X = list(map(int, input().split()))
print(min(list((sum(((x - P) ** 2 for x in X)) for P in range(min(X), max(X) + 1)))))


N = int(input())
XX = list(map(int, input().split()))
sumX = sum(XX)
P = round(sumX / N)
ss = [(x - P) ** 2 for x in XX]
print(sum(ss))


N = int(input())
X = list(map(int, input().split()))
ans = 10 ** 9
for i in range(1, 101):
	total = 0
	for x in X:
		total += (x - i) ** 2
	ans = min(ans, total)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
print(sum([(x - round(sum(a) / n)) ** 2 for x in a]))


N = int(input())
X = [int(i) for i in input().split()]
p = round(sum(X) / N)
h = [(x - p) ** 2 for x in X]
print(sum(h))


N = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for i in range(1, max(X) + 1):
	tmp = 0
	for j in range(N):
		tmp += pow(X[j] - i, 2)
	ans = min(ans, tmp)
print(ans)


N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
	val = 0
	for j in X_ls:
		val += (i - j) ** 2
	if rst == -1:
		rst = val
	else:
		rst = min(rst, val)
print(rst)


N = int(input())
X = [int(x) for x in input().split()]
G = int(sum(X) / N + 0.5)
ans = sum(((x - G) ** 2 for x in X))
print(ans)


n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = (s + 0.5 * n) // n
r = 0
for y in x:
	r += (y - p) ** 2
print(int(r))


N = int(input())
X = list(map(int, input().split()))
ans = 10 ** 6
for i in range(1, 101):
	tem = 0
	for j in range(N):
		tem += (X[j] - i) ** 2
	if tem <= ans:
		ans = tem
print(ans)


N = int(input())
X = list(map(int, input().split()))
P = round(sum(X) / N)
T = [(X[i] - P) * (X[i] - P) for i in range(0, N, 1)]
print(sum(T))


(n, *x) = map(int, open(0).read().split())
print(min([sum([(a - i) ** 2 for a in x]) for i in range(1, 101)]))


N = int(input())
l = list(map(int, input().split()))
ans = 0
ave = round(sum(l) / N)
for i in l:
	ans += (i - ave) ** 2
print(ans)


input()
(*X,) = sorted(map(int, input().split()))
print(min((sum(((n - p) ** 2 for n in X)) for p in range(X[0], X[-1] + 1))))


n = int(input())
x = list(map(int, input().split()))
d = min([sum([(k - i) ** 2 for k in x]) for i in range(1, 101)])
print(d)


N = int(input())
A = list(map(int, input().split()))
G = round(sum(A) / N)
HP = 0
for i in range(N):
	HP += (A[i] - G) ** 2
print(HP)


import math
a = int(input())
b = list(map(int, input().split()))
n = round(sum(b) / a)
ans = 0
for i in b:
	ans += (n - i) ** 2
print(ans)


N = int(input())
X = tuple(sorted(map(int, input().split())))
print(min((sum(((x - p) ** 2 for x in X)) for p in range(X[0], X[-1] + 1))))


(_, x) = open(0)
print(min((sum(((i - int(j)) ** 2 for j in x.split())) for i in range(99))))


n = int(input())
x_list = list(map(int, input().split(' ')))
p = round(sum(x_list) / n)
print(sum([(x - p) ** 2 for x in x_list]))


n = int(input())
x = list(map(int, input().split()))
max_x = max(x)
min_x = min(x)
f = 0
ans = 1000000
for p in range(min_x, max_x + 1):
	for i in range(n):
		f += (x[i] - p) ** 2
	else:
		ans = min(ans, f)
		f = 0
print(ans)


N = int(input())
X = tuple(map(int, input().split()))
p = int(round(sum(X) / N))
ans = sum([(x - p) ** 2 for x in X])
print(ans)


N = int(input())
X = [int(x) for x in input().split()]
m = round(sum(X) / N)
score = 0
for x in X:
	score += (x - m) ** 2
print(score)


n = int(input())
x_list = list(map(int, input().split()))
ave = sum(x_list) / n
p = int(ave) + (1 if ave - int(ave) > 1 / 2 else 0)
ans = sum([(p - x_i) ** 2 for x_i in x_list])
print(ans)


N = int(input())
X = list(map(int, input().split()))
dX = round(sum(X) / N)
e = 0
for x in X:
	e = e + (x - dX) ** 2
print(e)


n = int(input())
a = list(map(int, input().split()))
m = int(sum(a) / n + 0.5)
print(sum(((i - m) ** 2 for i in a)))


N = int(input())
A = [int(x) for x in input().split()]
count = 0
for j in range(len(A)):
	count += pow(A[j] - round(sum(A) / len(A)), 2)
print(count)


N = int(input())
X = list(map(int, input().split()))
P = round(sum(X) / N)
ans = sum(list(map(lambda x: (x - P) ** 2, X)))
print(ans)


N = int(input())
X = [int(i) for i in input().split()]
mean_x = round(sum(X) / len(X))
print(sum([(x - mean_x) ** 2 for x in X]))


import numpy as np
N = int(input())
X_ls = np.array(list(map(int, input().split())))
ans = 0
for p in range(max(X_ls) + 1):
	sub = X_ls - p
	ans_1 = sum(sub ** 2)
	if ans_1 <= ans or ans == 0:
		ans = ans_1
print(ans)


N = int(input())
x = list(map(int, input().split()))
p = sum(x) / N
P = round(p)
ans = 0
for i in x:
	ans += (i - P) * (i - P)
print(ans)


n = int(input())
xi = list(map(int, input().split()))
p = round(sum(xi) / n)
hp = 0
for x in xi:
	hp += (x - p) ** 2
print(hp)


N = int(input())
X = list(map(int, input().split(' ')))
P = int(sum(X) / N + 0.5)
print(sum([(X[i] - P) ** 2 for i in range(N)]))


n = int(input())
x = list(map(int, input().split()))
x_max = max(x)
x_min = min(x)
hp_min = 10000 * 100
for p in range(x_min, x_max + 1):
	hp = 0
	for x_i in x:
		hp += (x_i - p) ** 2
	if hp < hp_min:
		hp_min = hp
print(hp_min)


def __starting_point():
	N = int(input())
	Xli = list(map(int, input().split()))
	ans = float('inf')
	for i in range(101):
		cnt = 0
		for j in range(N):
			cnt += abs(Xli[j] - i) ** 2
		ans = min(ans, cnt)
	print(ans)
__starting_point()


input()
X = tuple(map(int, input().split()))
print(min((sum(((x - p) ** 2 for x in X)) for p in range(min(X), max(X) + 1))))


n = input()
x = list(map(int, input().split()))
print(min((sum(((i - j) ** 2 for j in x)) for i in range(min(x), max(x) + 1))))


N = int(input())
X = list(map(int, input().split()))
P = int(sum(X) / N + 0.5)
print(sum(map(lambda x_i: (x_i - P) ** 2, X)))


n = int(input())
x = list(map(int, input().split()))
sum = 1000000000000000
for p in range(1, 101):
	tmp = 0
	for i in range(len(x)):
		tmp += (x[i] - p) ** 2
	sum = min(sum, tmp)
print(sum)


n = int(input())
x = list(map(int, input().split()))
div = round(sum(x) / len(x))
ans = 0
for i in x:
	ans += (div - i) ** 2
print(ans)


n = int(input())
x = [int(i) for i in input().split()]
min_x = round(sum(x) / n)
ans = sum([(min_x - i) ** 2 for i in x])
print(ans)


n = int(input())
x_list = list(map(int, input().split()))
my_func = lambda x: int((x * 2 + 1) // 2)
x_list_mean = my_func(sum(x_list) / len(x_list))
count = 0
for i in x_list:
	count += (i - x_list_mean) ** 2
print(count)


N = int(input())
X = list(map(int, input().split()))
small = 10000000
temp = 0
p_max = max(X)
for p in range(1, p_max + 1):
	for i in range(N):
		temp += (X[i] - p) ** 2
	if temp < small:
		small = temp
	temp = 0
print(small)


(n, *a) = map(int, open(0).read().split())
ave = sum(a) // n
b = sum(((x - ave) ** 2 for x in a))
c = sum(((x - ave - 1) ** 2 for x in a))
print(min(b, c))


N = int(input())
X = list(map(int, input().split()))
a = round(sum(X) / N)
sum = 0
for i in X:
	sum += pow(i - a, 2)
print(sum)


(n, *a) = map(int, open(0).read().split())
print(sum(((round(sum(a) / n) - i) ** 2 for i in a)))


n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / n)
print(sum([(x[i] - p) ** 2 for i in range(n)]))


N = int(input())
X = list(map(int, input().split()))
R = round(sum(X) / N)
ans = 0
for i in range(N):
	ans += (R - X[i]) ** 2
print(ans)


n = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / n)
ans = 0
for i in range(n):
	ans += (X[i] - p) ** 2
print(ans)


N = int(input())
list1 = list(map(int, input().split()))
list1.sort()
x = list1[0]
y = list1[-1]
s = 0
list2 = []
while x + s <= y:
	list2.append(x + s)
	s = s + 1
list3 = []
for j in list2:
	w = 0
	for i in list1:
		w = w + (i - j) * (i - j)
	list3.append(w)
list3.sort()
print(list3[0])


import os, sys, re, math
N = int(input())
X = [int(n) for n in input().split()]
d = [i ** 2 for i in range(101)]
min_v = 100 ** 2 * 100
for i in range(1, 101):
	min_v = min(min_v, sum((d[abs(x - i)] for x in X)))
print(min_v)


import math
N = int(input())
lst = list(map(int, input().split()))
X = math.floor(sum(lst) / N + 0.5)
ans = 0
for i in lst:
	ans = ans + (X - i) ** 2
print(ans)


N = int(input())
X = list(map(int, input().split()))
y = round(sum(X) / N)
ans = sum([(y - i) ** 2 for i in X])
print(ans)


n = int(input())
xs = [int(e) for e in input().split(' ')]
print(min([sum([(x - p) ** 2 for x in xs]) for p in range(1, 101)]))


N = int(input())
A = list(map(int, input().split()))
t = int(round(sum(A) / N, 0))
c = 0
for i in A:
	c += (i - t) ** 2
print(c)


n = int(input())
x = list(map(int, input().split()))
x.sort()
m = round(sum(x) / n)
s = 0
for i in range(n):
	s += (m - x[i]) ** 2
print(s)


n = int(input())
x = list(map(int, input().split()))
m = 0
p = round(sum(x) / n)
for c in x:
	m += (c - p) ** 2
print(m)


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	N = I()
	L = LI()
	num = math.ceil(sum(L) / N)
	ans = 0
	ans2 = 0
	for i in L:
		ans += pow(i - num, 2)
		ans2 += pow(i - num + 1, 2)
	print(min(ans, ans2))

def __starting_point():
	main()
__starting_point()


n = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / n)
r = 0
for x in X:
	r += (p - x) * (p - x)
print(r)


N = int(input())
X = list(map(int, input().split()))
P = round(sum(X) / N)
hp = 0
for i in X:
	hp += (i - P) ** 2
print(hp)


N = int(input())
X = list(map(int, input().split()))
A = round(sum(X) / N)
T = 0
for i in range(N):
	T += (X[i] - A) ** 2
print(T)


N = int(input())
X = list(map(int, input().split()))
import numpy as np
p = np.floor(np.mean(X))
ans = min(np.sum([(x - p) ** 2 for x in X]), np.sum([(x - (p + 1)) ** 2 for x in X]))
print(int(ans))


import numpy as np
n = int(input())
x = list(map(int, input().split()))
p = round(np.mean(x))
cost = np.dot(np.array(x) - p, np.array(x) - p)
print(int(cost))


N = int(input())
X = list(map(int, input().split()))
cost = 10 ** 18
for i in range(1, 101):
	cost_count = 0
	for j in range(N):
		cost_count += (X[j] - i) ** 2
	if cost > cost_count:
		cost = cost_count
	else:
		pass
print(cost)


import sys
n = int(input())
x = [int(k) for k in input().split()]
p = round(sum(x) / n)
ans = 0
for i in x:
	ans += (p - i) ** 2
print(ans)


N = int(input())
X = [int(_) for _ in input().split()]
ans = 10 ** 6
for i in range(min(X), max(X) + 1):
	p = 0
	for j in range(N):
		p += (X[j] - i) ** 2
	ans = min(ans, p)
print(ans)


N = int(input())
A = list(map(int, input().split()))
p = round(sum(A) / N)
print(sum([(a - p) ** 2 for a in A]))


(_, *X) = list(map(int, open(0).read().split()))
print(min(map(lambda p: sum(((x - p) ** 2 for x in X)), range(min(X), max(X) + 1))))


N = int(input())
X = list(map(int, input().split()))
a = round(sum(X) / N)
c = 0
for i in range(N):
	c += (X[i] - a) ** 2
print(c)


N = int(input())
X = [int(i) for i in input().split()]
P = round(sum(X) / N)
ans = 0
for x in X:
	ans += (x - P) ** 2
print(ans)


N = int(input())
XN = list(map(int, input().split()))

def answer(N, XN):
	a = min(XN)
	b = max(XN)
	min_distance = float('inf')
	for i in range(a, b + 1):
		distance = 0
		for j in XN:
			distance += (i - j) ** 2
		min_distance = min(distance, min_distance)
	print(min_distance)
answer(N, XN)


N = int(input())
X = list(map(int, input().split()))
sum = sum(X)
ave = round(sum / N)
Y = 0
for i in X:
	Y += (i - ave) ** 2
print(Y)


n = int(input())
l = list(map(int, input().split()))
a = round(sum(l) / n)
m = 0
for i in range(n):
	m = m + (l[i] - a) ** 2
print(m)


n = int(input())
seq = [int(x) for x in input().split()]
d = round(sum(seq) / len(seq))
print(sum([(x - d) ** 2 for x in seq]))


N = int(input())
a = list(map(int, input().split()))
loc = round(sum(a) / N)
print(sum(map(lambda x: (x - loc) ** 2, a)))


n = int(input())
X = list(map(int, input().split()))
x_min = min(X)
x_max = max(X)
min_val = 10 ** 6 + 1
for i in range(x_min, x_max + 1):
	min_val = min(min_val, sum(map(lambda x: (x - i) ** 2, X)))
print(min_val)


N = int(input())
X = list(map(int, input().split()))
A = sum(X)
y = N * (round(A / N) - A / N) ** 2 - A ** 2 / N
B = sum([i ** 2 for i in X])
print(int(y + B))


input()
a = list(map(int, input().split()))
print(min((sum(((x - p) ** 2 for x in a)) for p in range(1, 101))))


N = int(input())
X = list(map(int, input().split()))
total = 0
m = round(sum(X) / N)
for i in X:
	total += (m - i) ** 2
print(total)


N = int(input())
X = list(map(int, input().split()))
print(min([sum([(x - i) * (x - i) for x in X]) for i in range(1, 101)]))


ans = 1000000
n = int(input())
X = list(map(int, input().split()))
for i in range(1, 101):
	tmp = 0
	for x in X:
		tmp += (x - i) ** 2
	ans = min(ans, tmp)
print(ans)


N = int(input())
(*X,) = map(int, input().split())
G = round(sum(X) / N)
print(sum([(x - G) ** 2 for x in X]))


N = int(input())
X = list(map(int, input().split()))
min_X = min(X)
max_X = max(X)
ans = []
for i in range(min_X, max_X + 1):
	score = []
	for j in range(N):
		score.append((X[j] - i) ** 2)
	ans.append(sum(score))
print(min(ans))


N = int(input())
X = list(map(int, input().split()))
X.sort()
if N == 1:
	print(0)
elif X[0] == X[-1]:
	print(0)
else:
	sum = [0] * (X[-1] - X[0])
	for i in range(X[0], X[-1]):
		for j in X:
			sum[i - X[0]] += (j - i) ** 2
	print(min(sum))


n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / n)
print(sum(list(map(lambda xi: (xi - p) ** 2, x))))


N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
ans = float('inf')
for i in range(X_min, X_max + 1):
	d = 0
	for x in X:
		d += (x - i) ** 2
	ans = min(ans, d)
print(int(ans))
return


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

def I():
	return map(int, input().split())

def X():
	return list(input())

def L():
	return list(input().split())

def l():
	return list(map(int, input().split()))

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
n = k()
x = l()
a = sum(x) // n
b = sum(x) // n + 1
for i in x:
	ans += pow(i - a, 2)
	cnt += pow(i - b, 2)
print(min(ans, cnt))


(n, *a) = map(int, open(0).read().split())
b = 10 ** 8
for i in range(1, 101):
	b = min(b, sum(((j - i) ** 2 for j in a)))
print(b)


N = int(input())
X = list(map(int, input().split()))
MIN = 100 ** 3
for i in range(min(X), max(X) + 1):
	ans = 0
	for j in range(N):
		ans += (X[j] - i) ** 2
	if MIN > ans:
		MIN = ans
print(MIN)


n = int(input())
x = [int(i) for i in input().split()]
print(min((sum(((xx - p) ** 2 for xx in x)) for p in range(max(x) + 2))))


n = int(input())
x_list = list(map(int, input().split()))
m = int(sum(x_list) / n + 0.5)
print(sum(((x - m) ** 2 for x in x_list)))


n = int(input())
x = sorted(list(map(int, input().split())))
m = round(sum(x) / n)
ans = 0
for i in x:
	ans += (i - m) ** 2
print(ans)


N = int(input())
X = list(map(int, input().split()))
temp = round(sum(X) / N)
ans = 0
for i in X:
	ans += (temp - i) ** 2
print(ans)


n = int(input())
A = list(map(int, input().split()))
g = round(sum(A) / n)
s = 0
for i in range(0, n):
	s = s + (A[i] - g) ** 2
print(s)


n = int(input())
x = [int(s) for s in input().split()]
a = []
for i in range(min(x), max(x) + 1):
	ans = 0
	for j in range(n):
		ans += (i - x[j]) ** 2
	a.append(ans)
print(min(a))


n = int(input())
x = tuple(map(int, input().split()))
s = sum(x)
ave = s // n + (1 if s / n > s // n + 0.5 else 0)
print(sum([pow(ave - i, 2) for i in x]))


n = int(input())
a = list(map(int, input().split()))
p = round(sum(a) / n)
dis = 0
for i in range(n):
	dis += (a[i] - p) ** 2
print(dis)


input()
x = list(map(int, input().split()))
r = 10 ** 10
for i in range(min(x), max(x) + 1):
	s = 0
	for j in x:
		s += (i - j) ** 2
	r = min(r, s)
print(r)


(N, *A) = map(int, open(0).read().split())
m = int(sum(A) / N + 0.5)
cost = sum([(a - m) ** 2 for a in A])
print(cost)


N = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / len(X))
print(sum([(x - p) ** 2 for x in X]))


n = int(input())
x = list(map(int, input().split()))
ans = n * 100 ** 2
for p in range(101):
	ans = min(ans, sum([(xi - p) ** 2 for xi in x]))
print(ans)


N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 10 ** 1000
for p in range(X[0], X[-1] + 1):
	tmp = 0
	for x in X:
		tmp += (x - p) ** 2
	ans = min(ans, tmp)
print(ans)


n = int(input())
x = list(map(int, input().split()))
p = sum(x) // n
e1 = 0
e2 = 0
for i in x:
	e1 += (p - i) ** 2
	e2 += (p + 1 - i) ** 2
print(min(e1, e2))


a = int(input())
b = input().split()
b = [int(j) for j in b]
x = round(sum(b) / a)
y = []
for i in range(a):
	y.append((x - b[i]) ** 2)
print(sum(y))


N = int(input())
x_list = list(map(int, input().split()))
P = round(sum(x_list) / N)
ans = 0
for i in x_list:
	ans += (i - P) ** 2
print(ans)


n = int(input())
x = list(map(int, input().split()))
num = 0
for i in x:
	num += i
num = round(float(num / n))
ans = 0
for i in x:
	ans += (i - num) ** 2
print(ans)


n = int(input())
x = list(map(int, input().split()))
d = float('inf')
for i in range(max(x) + 1):
	c = 0
	for j in range(len(x)):
		c += (x[j] - i) ** 2
	d = min(c, d)
print(d)


N = int(input())
X_list = list(map(int, input().split()))
ans_list = []
for i in range(min(X_list), max(X_list) + 1):
	summarize = 0
	for x in X_list:
		summarize += (x - i) ** 2
	ans_list.append(summarize)
print(min(ans_list))


_ = input()
a = list(map(int, input().split()))
b = round(sum(a) / len(a))
res = 0
for i in a:
	res += (i - b) ** 2
print(res)


N = int(input())
A = list(map(int, input().split()))
ave = round(sum(A) / len(A))
print(sum([(i - ave) ** 2 for i in A]))


N = int(input())
X = list(map(int, input().split()))
p = round(sum(X) / len(X))
ans = 0
for a in X:
	ans += (a - p) * (a - p)
print(ans)


n = int(input())
X = list(map(int, input().split()))
m = round(sum(X) / n)
print(sum(((x - m) ** 2 for x in X)))


n = int(input())
h = list(map(int, input().split()))
mnx = -1
mxx = 10 ** 8
avg = sum(h) // len(h)
avgx = avg + 1
s1 = 0
s2 = 0
for i in h:
	s1 += (i - avg) ** 2
	s2 += (i - avgx) ** 2
print(min(s1, s2))


n = int(input())
X = list(map(int, input().split()))
p = 0
s = 0
while abs(p - sum(X) / n) > 1 / 2:
	p += 1
for x in X:
	s += (x - p) ** 2
print(s)


n = int(input())
X = list(map(int, input().split()))
s = 0
p = round(sum(X) / n)
for x in X:
	s += (x - p) ** 2
print(s)


input()
x = list(map(int, input().split()))
print(sum(((i - round(sum(x) / len(x))) ** 2 for i in x)))


n = int(input())
arr = list(map(int, input().split()))
s = sum(arr) * 2
z = round(s / (2 * n))
for k in range(n):
	arr[k] = (arr[k] - z) ** 2
print(sum(arr))


N = int(input())
X = list(map(int, input().split()))
ave = round(sum(X) / N)
s = [(i - ave) ** 2 for i in X]
print(sum(s))


N = int(input())
A = list(map(int, input().split()))
p = round(sum(A) / N)
print(sum(map(lambda x: (x - p) ** 2, A)))


import math
import numpy as np
n = int(input())
X = np.array(list(map(int, input().split())))
lower = min(X)
upper = max(X)
ans = (X - lower) ** 2
ans = ans.sum()
for i in range(lower + 1, upper + 1):
	m = (X - i) ** 2
	if m.sum() < ans:
		ans = m.sum()
print(ans)


n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(min(x), max(x) + 1):
	dist = 0
	for j in x:
		dist += (j - i) ** 2
	ans = min(ans, dist)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ave = round(sum(a) / n)
ans = 0
for i in range(n):
	ans += abs(ave - a[i]) ** 2
print(ans)


(n, *l) = map(int, open(0).read().split())
m = round(sum(l) / n)
print(sum(((i - m) ** 2 for i in l)))