import sys



n = int(eval(input()))

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

m = sys.maxsize

for x in range(min(a), max(a) + 1):

    b = sum([(x - y) ** 2 for y in a])

    if m > b:

        m = b

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

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

b = round(sum([0 + x for x in a]) / n)

m = sum([(x - b) ** 2 for x in a])

print(m)
import sys

n = int(eval(input()))
a = list(map(int, input().split()))
m = sys.maxsize
for x in range(min(a), max(a) + 1):
    b = sum([(x - y) ** 2 for y in a])
    if m > b:
        m = b
print(m)

n = int(eval(input()))
a = list(map(int, input().split()))
b = round(sum([0 + x for x in a]) / n)
m = sum([(x - b) ** 2 for x in a])
print(m)

-import sys - -m = sys.maxsize -for x in range(min(a), max(a) + 1): -    b = sum([(x - y) ** 2 for y in a]) -    if m > b: -        m = b +b = round(sum([0 + x for x in a]) / n) +m = sum([(x - b) ** 2 for x in a])