N = int(eval(input()))

A = [int(i) for i in input().split()]



mi = 1e10

for m in range(-100, 101):

    mi = min(mi, sum((a - m) ** 2 for a in A))

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

A = [int(i) for i in input().split()]



m = round(sum(A) / N)

print((sum((a - m) ** 2 for a in A)))
N = int(eval(input()))
A = [int(i) for i in input().split()]
mi = 1e10
for m in range(-100, 101):
    mi = min(mi, sum((a - m) ** 2 for a in A))
print(mi)

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

-mi = 1e10 -for m in range(-100, 101): -    mi = min(mi, sum((a - m) ** 2 for a in A)) -print(mi) +m = round(sum(A) / N) +print((sum((a - m) ** 2 for a in A)))