num = int(eval(input()))



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



val2 = [int(x) for x in range(min(val), max(val))]





array = []

for i in val2:

    res = 0

    for j in val:

        res += pow(abs(i - j), 2)

    array.append(res)

print((min(array) if len(array) != 0 else 0))

import math



n = int(eval(input()))

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



tmp = math.ceil(sum(array)/n)

tmp2 = math.floor(sum(array)/n)



print((min(sum([pow(abs(x-tmp2),2) for x in array]), sum([pow(abs(x-tmp),2) for x in array]))))
num = int(eval(input()))
val = [int(x) for x in input().split()]
val2 = [int(x) for x in range(min(val), max(val))]
array = []
for i in val2:
    res = 0
    for j in val:
        res += pow(abs(i - j), 2)
    array.append(res)
print((min(array) if len(array) != 0 else 0))

import math

n = int(eval(input()))
array = [int(x) for x in input().split()]
tmp = math.ceil(sum(array) / n)
tmp2 = math.floor(sum(array) / n)
print(
    (
        min(
            sum([pow(abs(x - tmp2), 2) for x in array]),
            sum([pow(abs(x - tmp), 2) for x in array]),
        )
    )
)

-num = int(eval(input())) -val = [int(x) for x in input().split()] -val2 = [int(x) for x in range(min(val), max(val))] -array = [] -for i in val2: -    res = 0 -    for j in val: -        res += pow(abs(i - j), 2) -    array.append(res) -print((min(array) if len(array) != 0 else 0)) +import math + +n = int(eval(input())) +array = [int(x) for x in input().split()] +tmp = math.ceil(sum(array) / n) +tmp2 = math.floor(sum(array) / n) +print( +    ( +        min( +            sum([pow(abs(x - tmp2), 2) for x in array]), +            sum([pow(abs(x - tmp), 2) for x in array]), +        ) +    ) +)