from math import ceil



n = int(eval(input()))

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

saida = 2000000000000000



for i in range(min(numeros), max(numeros)+1):

	valor = 0

	for j in numeros:

		valor += (j-i)**2

	

	saida = min(valor, saida)



print(saida)





import sys



n = int(eval(input()))

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

saida = sys.maxsize



for i in range(min(numeros), max(numeros)+1):

	valor = 0

	for j in numeros:

		valor += (j-i)**2

	

	saida = min(valor, saida)



print(saida)



from math import ceil

n = int(eval(input()))
numeros = [int(x) for x in input().split()]
saida = 2000000000000000
for i in range(min(numeros), max(numeros) + 1):
    valor = 0
    for j in numeros:
        valor += (j - i) ** 2
    saida = min(valor, saida)
print(saida)

import sys

n = int(eval(input()))
numeros = [int(x) for x in input().split()]
saida = sys.maxsize
for i in range(min(numeros), max(numeros) + 1):
    valor = 0
    for j in numeros:
        valor += (j - i) ** 2
    saida = min(valor, saida)
print(saida)

-from math import ceil +import sys -saida = 2000000000000000 +saida = sys.maxsize