N = int(eval(input()))

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

cost = []



for n in range(min(A),max(A)+1):

  cost.append(sum([(a-n)**2 for a in A]))



print((min(cost)))
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()))
cost = []
for n in range(min(A), max(A) + 1):
    cost.append(sum([(a - n) ** 2 for a in A]))
print((min(cost)))

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

-cost = [] -for n in range(min(A), max(A) + 1): -    cost.append(sum([(a - n) ** 2 for a in A])) -print((min(cost))) +m = round(sum(A) / N) +print((sum([(a - m) ** 2 for a in A])))