n = int(eval(input()))

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



mn = min(l)

mx = max(l)



ms = 10**9

ll = [0]*n

for j in range(mn, mx+1):

    for i in range(n):

        ll[i] = (l[i]-j)**2

        

    s = sum(ll)

    ms = min(ms, s)

    

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

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



mn = min(l)

mx = max(l)



ms = 10**9

for j in range(mn, mx+1):

    s = sum([(i-j)**2 for i in l])

    ms = min(ms, s)

    

print(ms)
n = int(eval(input()))
l = list(map(int, input().split()))
mn = min(l)
mx = max(l)
ms = 10**9
ll = [0] * n
for j in range(mn, mx + 1):
    for i in range(n):
        ll[i] = (l[i] - j) ** 2
    s = sum(ll)
    ms = min(ms, s)
print(ms)

n = int(eval(input()))
l = list(map(int, input().split()))
mn = min(l)
mx = max(l)
ms = 10**9
for j in range(mn, mx + 1):
    s = sum([(i - j) ** 2 for i in l])
    ms = min(ms, s)
print(ms)

-ll = [0] * n -    for i in range(n): -        ll[i] = (l[i] - j) ** 2 -    s = sum(ll) +    s = sum([(i - j) ** 2 for i in l])