n = int (eval(input()))

x = list (map (int, input().split()))



ans = int (2e9)

l, r = min (x), max (x)



for p in range (l, r + 1) :

    tmp = 0

    for loc in x:

        tmp += (loc - p) ** 2

    ans = min (ans, tmp)



print (ans)
import math



N=eval(input())

n=int(N)



p=input().split()

for i in range (len(p)):

    p[i]=int(p[i])



sum1=0



q=p.copy()



for i in range (len(q)):

    sum1=sum1+q[i]



avg=sum1/n



if avg-math.floor(avg)>=0.5:

    avg=math.floor(avg)+1

else:

    avg=math.floor(avg)





stamina=0



for i in range(len(p)):

    stamina=stamina+(avg-p[i])**2

    

print(stamina)
n = int(eval(input()))
x = list(map(int, input().split()))
ans = int(2e9)
l, r = min(x), max(x)
for p in range(l, r + 1):
    tmp = 0
    for loc in x:
        tmp += (loc - p) ** 2
    ans = min(ans, tmp)
print(ans)

import math

N = eval(input())
n = int(N)
p = input().split()
for i in range(len(p)):
    p[i] = int(p[i])
sum1 = 0
q = p.copy()
for i in range(len(q)):
    sum1 = sum1 + q[i]
avg = sum1 / n
if avg - math.floor(avg) >= 0.5:
    avg = math.floor(avg) + 1
else:
    avg = math.floor(avg)
stamina = 0
for i in range(len(p)):
    stamina = stamina + (avg - p[i]) ** 2
print(stamina)

-n = int(eval(input())) -x = list(map(int, input().split())) -ans = int(2e9) -l, r = min(x), max(x) -for p in range(l, r + 1): -    tmp = 0 -    for loc in x: -        tmp += (loc - p) ** 2 -    ans = min(ans, tmp) -print(ans) +import math + +N = eval(input()) +n = int(N) +p = input().split() +for i in range(len(p)): +    p[i] = int(p[i]) +sum1 = 0 +q = p.copy() +for i in range(len(q)): +    sum1 = sum1 + q[i] +avg = sum1 / n +if avg - math.floor(avg) >= 0.5: +    avg = math.floor(avg) + 1 +else: +    avg = math.floor(avg) +stamina = 0 +for i in range(len(p)): +    stamina = stamina + (avg - p[i]) ** 2 +print(stamina)