N = int(eval(input()))

A = [int(i) for i in input().split()]



ans = float('inf')

for x in range(-100,101):

  tmp = 0

  for a in A:

    tmp += (x-a)**2

  ans = min(ans,tmp)

print(ans)
def c_be_together(N, A):

    a_sum = sum(A)

    option = (a_sum // N, (a_sum + N - 1) // N)

    ans = float('inf')

    for opt in option:

        ans = min(ans, sum([(a - opt)**2 for a in A]))

    return ans



N = int(eval(input()))

A = [int(i) for i in input().split()]

print((c_be_together(N, A)))
N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = float("inf")
for x in range(-100, 101):
    tmp = 0
    for a in A:
        tmp += (x - a) ** 2
    ans = min(ans, tmp)
print(ans)

def c_be_together(N, A):
    a_sum = sum(A)
    option = (a_sum // N, (a_sum + N - 1) // N)
    ans = float("inf")
    for opt in option:
        ans = min(ans, sum([(a - opt) ** 2 for a in A]))
    return ans


N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_be_together(N, A)))

+def c_be_together(N, A): +    a_sum = sum(A) +    option = (a_sum // N, (a_sum + N - 1) // N) +    ans = float("inf") +    for opt in option: +        ans = min(ans, sum([(a - opt) ** 2 for a in A])) +    return ans + + -ans = float("inf") -for x in range(-100, 101): -    tmp = 0 -    for a in A: -        tmp += (x - a) ** 2 -    ans = min(ans, tmp) -print(ans) +print((c_be_together(N, A)))