N = int(eval(input()))

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



p_min = min(X)

p_max = max(X)



ans = p_min

cost_min = N * p_max ** 2

for p in range(p_min, p_max + 1):

  tmp_cost = sum([(x - p) ** 2 for x in X])

  if tmp_cost < cost_min:

    ans = p

    cost_min = tmp_cost

    

print(cost_min)
N = int(eval(input()))

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



avg_p = int(sum(X) / N)



cost_l = sum([(x - avg_p)**2 for x in X])

cost_r = sum([(x - avg_p - 1)**2 for x in X])



print((min(cost_l, cost_r)))
N = int(eval(input()))
X = list(map(int, input().split()))
p_min = min(X)
p_max = max(X)
ans = p_min
cost_min = N * p_max**2
for p in range(p_min, p_max + 1):
    tmp_cost = sum([(x - p) ** 2 for x in X])
    if tmp_cost < cost_min:
        ans = p
        cost_min = tmp_cost
print(cost_min)

N = int(eval(input()))
X = list(map(int, input().split()))
avg_p = int(sum(X) / N)
cost_l = sum([(x - avg_p) ** 2 for x in X])
cost_r = sum([(x - avg_p - 1) ** 2 for x in X])
print((min(cost_l, cost_r)))

-p_min = min(X) -p_max = max(X) -ans = p_min -cost_min = N * p_max**2 -for p in range(p_min, p_max + 1): -    tmp_cost = sum([(x - p) ** 2 for x in X]) -    if tmp_cost < cost_min: -        ans = p -        cost_min = tmp_cost -print(cost_min) +avg_p = int(sum(X) / N) +cost_l = sum([(x - avg_p) ** 2 for x in X]) +cost_r = sum([(x - avg_p - 1) ** 2 for x in X]) +print((min(cost_l, cost_r)))