N = int(eval(input()))

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



total_costs = {}

if( len(set(A)) == 1 ):

    print((0))

else:

    for i in range(-100, 101):

        cost = 0

        for a in A:

            cost += (a - i)**2

        total_costs[i] = cost

    print((min(total_costs.values())))
N = int(eval(input()))

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



total_costs = {}

if( len(set(A)) == 1 ):

    print((0))

else:

    for i in range(-100, 101):

        cost = 0

        for a in A:

            cost += (a - i)*(a - i)

        total_costs[i] = cost

    print((min(total_costs.values())))
N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if len(set(A)) == 1:
    print((0))
else:
    for i in range(-100, 101):
        cost = 0
        for a in A:
            cost += (a - i) ** 2
        total_costs[i] = cost
    print((min(total_costs.values())))

N = int(eval(input()))
A = list(map(int, input().split()))
total_costs = {}
if len(set(A)) == 1:
    print((0))
else:
    for i in range(-100, 101):
        cost = 0
        for a in A:
            cost += (a - i) * (a - i)
        total_costs[i] = cost
    print((min(total_costs.values())))

-            cost += (a - i) ** 2 +            cost += (a - i) * (a - i)