n = int(eval(input()))

a_array = [int(x) for x in input().split()]

ans = float("inf")

for i in range(-100, 101):

    tmp = 0

    for a in a_array:

        tmp += abs(a-i)**2

    ans = min(ans, tmp)

print(ans)

n = int(eval(input()))

a_array = [int(x) for x in input().split()]

sum_a = sum(a_array)

if sum_a % n == 0:

    sum_a = int(sum_a/len(a_array))

    ans = 0

    for a in a_array:

        ans += abs(sum_a-a)**2

    print((int(ans)))

else:

    sum_a1 = int(sum_a/len(a_array))

    sum_a2 = int(sum_a/len(a_array))+1

    ans1 = 0

    ans2 = 0

    for a in a_array:

        ans1 += abs(sum_a1-a)**2

        ans2 += abs(sum_a2-a)**2

    print((int(min(ans1, ans2))))

n = int(eval(input()))
a_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(-100, 101):
    tmp = 0
    for a in a_array:
        tmp += abs(a - i) ** 2
    ans = min(ans, tmp)
print(ans)

n = int(eval(input()))
a_array = [int(x) for x in input().split()]
sum_a = sum(a_array)
if sum_a % n == 0:
    sum_a = int(sum_a / len(a_array))
    ans = 0
    for a in a_array:
        ans += abs(sum_a - a) ** 2
    print((int(ans)))
else:
    sum_a1 = int(sum_a / len(a_array))
    sum_a2 = int(sum_a / len(a_array)) + 1
    ans1 = 0
    ans2 = 0
    for a in a_array:
        ans1 += abs(sum_a1 - a) ** 2
        ans2 += abs(sum_a2 - a) ** 2
    print((int(min(ans1, ans2))))

-ans = float("inf") -for i in range(-100, 101): -    tmp = 0 +sum_a = sum(a_array) +if sum_a % n == 0: +    sum_a = int(sum_a / len(a_array)) +    ans = 0 -        tmp += abs(a - i) ** 2 -    ans = min(ans, tmp) -print(ans) +        ans += abs(sum_a - a) ** 2 +    print((int(ans))) +else: +    sum_a1 = int(sum_a / len(a_array)) +    sum_a2 = int(sum_a / len(a_array)) + 1 +    ans1 = 0 +    ans2 = 0 +    for a in a_array: +        ans1 += abs(sum_a1 - a) ** 2 +        ans2 += abs(sum_a2 - a) ** 2 +    print((int(min(ans1, ans2))))