N=int(eval(input()))

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

st=int(sum(A)/len(A))

go=st+1

ans=10**9+1

for i in range(st,go+1):

  val=0

  for a in A:

    val+=(a-i)**2

  ans=min(ans,val)

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

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

ans=10**9+1

for i in (0,1):

  val=0

  for a in A:

    val+=(a-int(sum(A)/len(A))-i)**2

  ans=min(ans,val)

print(ans)
N = int(eval(input()))
A = list(map(int, input().split()))
st = int(sum(A) / len(A))
go = st + 1
ans = 10**9 + 1
for i in range(st, go + 1):
    val = 0
    for a in A:
        val += (a - i) ** 2
    ans = min(ans, val)
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
ans = 10**9 + 1
for i in (0, 1):
    val = 0
    for a in A:
        val += (a - int(sum(A) / len(A)) - i) ** 2
    ans = min(ans, val)
print(ans)

-st = int(sum(A) / len(A)) -go = st + 1 -for i in range(st, go + 1): +for i in (0, 1): -        val += (a - i) ** 2 +        val += (a - int(sum(A) / len(A)) - i) ** 2