N = int(eval(input()))

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

ans = 100*100*100

for d in range(-100,101):

    t = 0

    for e in A:

        t += (e-d)**2

    ans = min(t,ans)

print(ans)

import sys, math



def input():

    return sys.stdin.readline()[:-1]



def main():

    N = int(eval(input()))

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

    ans = 10**9

    for k in range(-100,101):

        temp = 0

        for e in a:

            temp += (k-e)**2

        ans = min(ans,temp)

    print(ans)

if __name__ == '__main__':

    main()

N = int(eval(input()))
A = list(map(int, input().split()))
ans = 100 * 100 * 100
for d in range(-100, 101):
    t = 0
    for e in A:
        t += (e - d) ** 2
    ans = min(t, ans)
print(ans)

import sys, math


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    ans = 10**9
    for k in range(-100, 101):
        temp = 0
        for e in a:
            temp += (k - e) ** 2
        ans = min(ans, temp)
    print(ans)


if __name__ == "__main__":
    main()

-N = int(eval(input())) -A = list(map(int, input().split())) -ans = 100 * 100 * 100 -for d in range(-100, 101): -    t = 0 -    for e in A: -        t += (e - d) ** 2 -    ans = min(t, ans) -print(ans) +import sys, math + + +def input(): +    return sys.stdin.readline()[:-1] + + +def main(): +    N = int(eval(input())) +    a = list(map(int, input().split())) +    ans = 10**9 +    for k in range(-100, 101): +        temp = 0 +        for e in a: +            temp += (k - e) ** 2 +        ans = min(ans, temp) +    print(ans) + + +if __name__ == "__main__": +    main()