n = int(eval(input()))

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

ans = 10**10

for i in range(-100, 101):

    t = 0

    for j in A:

        t += (j-i)**2

    if t < ans:

        ans = t

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

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

avg = sum(A)//n

avg2 = sum(A)//n + 1

ans = 0

ans2 = 0

for i in A:

    ans += (i-avg)**2

    ans2 += (i-avg2)**2

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

n = int(eval(input()))
A = list(map(int, input().split()))
avg = sum(A) // n
avg2 = sum(A) // n + 1
ans = 0
ans2 = 0
for i in A:
    ans += (i - avg) ** 2
    ans2 += (i - avg2) ** 2
print((min(ans, ans2)))

-ans = 10**10 -for i in range(-100, 101): -    t = 0 -    for j in A: -        t += (j - i) ** 2 -    if t < ans: -        ans = t -print(ans) +avg = sum(A) // n +avg2 = sum(A) // n + 1 +ans = 0 +ans2 = 0 +for i in A: +    ans += (i - avg) ** 2 +    ans2 += (i - avg2) ** 2 +print((min(ans, ans2)))