n=int(eval(input()))



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



t.sort()



ans = 100000000000000



for i in range(t[0],t[-1]+1):

    memo = 0

    for j in t:

        memo += (i-j)**2

    ans = min(memo, ans)

print(ans)    

n=int(eval(input()))



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



ans = 10000000000



for i in range(-100, 101):

    memo = 0

    for j in t:

        memo += (i-j)**2

    ans = min(ans, memo)

print(ans)
n = int(eval(input()))
t = list(map(int, input().split()))
t.sort()
ans = 100000000000000
for i in range(t[0], t[-1] + 1):
    memo = 0
    for j in t:
        memo += (i - j) ** 2
    ans = min(memo, ans)
print(ans)

n = int(eval(input()))
t = list(map(int, input().split()))
ans = 10000000000
for i in range(-100, 101):
    memo = 0
    for j in t:
        memo += (i - j) ** 2
    ans = min(ans, memo)
print(ans)

-t.sort() -ans = 100000000000000 -for i in range(t[0], t[-1] + 1): +ans = 10000000000 +for i in range(-100, 101): -    ans = min(memo, ans) +    ans = min(ans, memo)