N = int(eval(input()))

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

print((min(sum((a-n)**2 for a in A) for n in range(min(A),1+max(A)))))
N = int(eval(input()))

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

m = round(sum(A)/N)

print((sum((a-m)**2 for a in A)))
N = int(eval(input()))
A = list(map(int, input().split()))
print((min(sum((a - n) ** 2 for a in A) for n in range(min(A), 1 + max(A)))))

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

-print((min(sum((a - n) ** 2 for a in A) for n in range(min(A), 1 + max(A))))) +m = round(sum(A) / N) +print((sum((a - m) ** 2 for a in A)))