N=int(eval(input()))

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



mx=max(A)

mn=min(A)



ans=float('inf')

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

    ans=min(ans, sum([(k-i)**2 for k in A]))

print(ans)
N=eval(input())

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



a=float('inf')

for i in range(min(A),max(A)+1):a=min(a, sum([(k-i)**2 for k in A]))

print(a)
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
mx = max(A)
mn = min(A)
ans = float("inf")
for i in range(mn, mx + 1):
    ans = min(ans, sum([(k - i) ** 2 for k in A]))
print(ans)

N = eval(input())
(*A,) = list(map(int, input().split()))
a = float("inf")
for i in range(min(A), max(A) + 1):
    a = min(a, sum([(k - i) ** 2 for k in A]))
print(a)

-N = int(eval(input())) +N = eval(input()) -mx = max(A) -mn = min(A) -ans = float("inf") -for i in range(mn, mx + 1): -    ans = min(ans, sum([(k - i) ** 2 for k in A])) -print(ans) +a = float("inf") +for i in range(min(A), max(A) + 1): +    a = min(a, sum([(k - i) ** 2 for k in A])) +print(a)