n = int(eval(input()))

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

ans = 10**9

for x in range(-100,101):

    res = 0

    for i in range(n):

        res += (a[i] - x)**2

    ans = min(ans,res)

print(ans)

        
n = int(eval(input()))

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

ans = 10**9

for x in range(-100,101):

    res = 0

    for y in a:

        res += (x-y)**2

    ans = min(ans,res)

print(ans)

    

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

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

-    for i in range(n): -        res += (a[i] - x) ** 2 +    for y in a: +        res += (x - y) ** 2