import sys



def main():

    def input():

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

    N = int(eval(input()))

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

    ans = 1000000

    for k in range(-100,101):

        t = 0

        for e in a:

            t += (e-k)**2

        ans = min(ans,t)

    print(ans)

if __name__ == '__main__':

    main()

N = int(eval(input()))

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

ans = 10**12

for k in range(-100,101):

    temp = 0

    for e in a:

        temp += (k-e)**2

    ans = min(ans,temp)

print(ans)

import sys


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

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


if __name__ == "__main__":
    main()

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

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