n = int(eval(input()))

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



s = sum(a)

m1 = s // n

m2 = -(-s // n)

ans1 = 0

ans2 = 0



for x in a:

    ans1 += (x - m1)**2

    ans2 += (x - m2)**2



print((min(ans1, ans2)))
n = int(eval(input()))

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



ans = float("inf")

for i in range(-100, 101):

    tmp = 0

    for ai in a:

        tmp += (ai - i) ** 2

    ans = min(ans, tmp)



print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
m1 = s // n
m2 = -(-s // n)
ans1 = 0
ans2 = 0
for x in a:
    ans1 += (x - m1) ** 2
    ans2 += (x - m2) ** 2
print((min(ans1, ans2)))

n = int(eval(input()))
a = list(map(int, input().split()))
ans = float("inf")
for i in range(-100, 101):
    tmp = 0
    for ai in a:
        tmp += (ai - i) ** 2
    ans = min(ans, tmp)
print(ans)

-s = sum(a) -m1 = s // n -m2 = -(-s // n) -ans1 = 0 -ans2 = 0 -for x in a: -    ans1 += (x - m1) ** 2 -    ans2 += (x - m2) ** 2 -print((min(ans1, ans2))) +ans = float("inf") +for i in range(-100, 101): +    tmp = 0 +    for ai in a: +        tmp += (ai - i) ** 2 +    ans = min(ans, tmp) +print(ans)