iN = int(eval(input()))

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



i2M = (min(aA) + max(aA)) // 2

iMM = sum(aA) // len(aA)



if i2M < iMM :

    iLM = i2M

    iUM = iMM + 1

else:

    iLM = iMM

    iUM = i2M + 1



aR = []

for iM in range(iLM,iUM+1):

    aR.append(0)

    for iA in aA:

        aR[-1] += (iA - iM) ** 2

print((min(aR)))



iN = int(eval(input()))

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



#i2M = (min(aA) + max(aA)) // 2

iMM = sum(aA) // len(aA)



#if i2M < iMM :

#   iLM = i2M

#   iUM = iMM + 1

#else:

#   iLM = iMM

#   iUM = i2M + 1



iLM = iMM

iUM = iMM + 1



aR = []

for iM in range(iLM,iUM+1):

    aR.append(0)

    for iA in aA:

        aR[-1] += (iA - iM) ** 2

print((min(aR)))

iN = int(eval(input()))
aA = [int(x) for x in input().split()]
i2M = (min(aA) + max(aA)) // 2
iMM = sum(aA) // len(aA)
if i2M < iMM:
    iLM = i2M
    iUM = iMM + 1
else:
    iLM = iMM
    iUM = i2M + 1
aR = []
for iM in range(iLM, iUM + 1):
    aR.append(0)
    for iA in aA:
        aR[-1] += (iA - iM) ** 2
print((min(aR)))

iN = int(eval(input()))
aA = [int(x) for x in input().split()]
# i2M = (min(aA) + max(aA)) // 2
iMM = sum(aA) // len(aA)
# if i2M < iMM :
#   iLM = i2M
#   iUM = iMM + 1
# else:
#   iLM = iMM
#   iUM = i2M + 1
iLM = iMM
iUM = iMM + 1
aR = []
for iM in range(iLM, iUM + 1):
    aR.append(0)
    for iA in aA:
        aR[-1] += (iA - iM) ** 2
print((min(aR)))

-i2M = (min(aA) + max(aA)) // 2 +# i2M = (min(aA) + max(aA)) // 2 -if i2M < iMM: -    iLM = i2M -    iUM = iMM + 1 -else: -    iLM = iMM -    iUM = i2M + 1 +# if i2M < iMM : +#   iLM = i2M +#   iUM = iMM + 1 +# else: +#   iLM = iMM +#   iUM = i2M + 1 +iLM = iMM +iUM = iMM + 1