n = int(eval(input()))

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

mn = 10**9

for i in range(-100,101):

    x = 0

    for j in a:

        x += (j-i)**2

    mn = min(mn,x)

print(mn)
n = int(eval(input()))

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

x = round(sum(a)/n)

ans = 0

for i in a:

    ans += (i-x)**2

print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
mn = 10**9
for i in range(-100, 101):
    x = 0
    for j in a:
        x += (j - i) ** 2
    mn = min(mn, x)
print(mn)

n = int(eval(input()))
a = list(map(int, input().split()))
x = round(sum(a) / n)
ans = 0
for i in a:
    ans += (i - x) ** 2
print(ans)

-mn = 10**9 -for i in range(-100, 101): -    x = 0 -    for j in a: -        x += (j - i) ** 2 -    mn = min(mn, x) -print(mn) +x = round(sum(a) / n) +ans = 0 +for i in a: +    ans += (i - x) ** 2 +print(ans)