N = int(eval(input()))

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





def get_cost(now, target):

    return (now - target) * (now - target)





ans = 10000000

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

    cost_sum = 0

    for j in a:

        cost_sum += get_cost(j, i)

    if cost_sum < ans:

        ans = cost_sum

print(ans)

N = int(eval(input()))

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



mean = int(round(sum(a) / len(a)))



ans = 0

for i in range(len(a)):

    ans += (a[i] - mean) ** 2

print(ans)

N = int(eval(input()))
a = list(map(int, input().split()))


def get_cost(now, target):
    return (now - target) * (now - target)


ans = 10000000
for i in range(min(a), max(a) + 1):
    cost_sum = 0
    for j in a:
        cost_sum += get_cost(j, i)
    if cost_sum < ans:
        ans = cost_sum
print(ans)

N = int(eval(input()))
a = list(map(int, input().split()))
mean = int(round(sum(a) / len(a)))
ans = 0
for i in range(len(a)):
    ans += (a[i] - mean) ** 2
print(ans)

- - -def get_cost(now, target): -    return (now - target) * (now - target) - - -ans = 10000000 -for i in range(min(a), max(a) + 1): -    cost_sum = 0 -    for j in a: -        cost_sum += get_cost(j, i) -    if cost_sum < ans: -        ans = cost_sum +mean = int(round(sum(a) / len(a))) +ans = 0 +for i in range(len(a)): +    ans += (a[i] - mean) ** 2