# AtCoder Regular Contest 059

# C - いっしょ

# https://atcoder.jp/contests/arc059/tasks/arc059_a

N = int(eval(input()))

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



mincost = 10**10

for i in range(-100, 101):

    cost = 0

    for a in A:

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



    if cost < mincost:

        mincost = cost



print(mincost)

N, *A = list(map(int, open(0).read().split()))



ans = 10**10

for i in range(-100, 101):

    sn = sum((a-i)*(a-i) for a in A)

    if sn < ans:

        ans = sn

print(ans)

# AtCoder Regular Contest 059
# C - いっしょ
# https://atcoder.jp/contests/arc059/tasks/arc059_a
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
mincost = 10**10
for i in range(-100, 101):
    cost = 0
    for a in A:
        cost += (a - i) * (a - i)
    if cost < mincost:
        mincost = cost
print(mincost)

N, *A = list(map(int, open(0).read().split()))
ans = 10**10
for i in range(-100, 101):
    sn = sum((a - i) * (a - i) for a in A)
    if sn < ans:
        ans = sn
print(ans)

-# AtCoder Regular Contest 059 -# C - いっしょ -# https://atcoder.jp/contests/arc059/tasks/arc059_a -N = int(eval(input())) -(*A,) = list(map(int, input().split())) -mincost = 10**10 +N, *A = list(map(int, open(0).read().split())) +ans = 10**10 -    cost = 0 -    for a in A: -        cost += (a - i) * (a - i) -    if cost < mincost: -        mincost = cost -print(mincost) +    sn = sum((a - i) * (a - i) for a in A) +    if sn < ans: +        ans = sn +print(ans)