def resolve():

	n = int(eval(input()))

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

	ans = 100**6

	for i in range(-100, 101):

		tmp = 0

		for j in a:

			if i == j:

				continue

			tmp += (j - i)**2

		if tmp < ans:

			ans = tmp

	print(ans)

resolve()
def resolve():

	n = int(eval(input()))

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

	ans = 10000000

	for i in range(-100, 101):

		s = 0

		for j in a:

			s += (i-j)**2

		if ans > s:

			ans = s

	print(ans)

resolve()
def resolve():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    ans = 100**6
    for i in range(-100, 101):
        tmp = 0
        for j in a:
            if i == j:
                continue
            tmp += (j - i) ** 2
        if tmp < ans:
            ans = tmp
    print(ans)


resolve()

def resolve():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    ans = 10000000
    for i in range(-100, 101):
        s = 0
        for j in a:
            s += (i - j) ** 2
        if ans > s:
            ans = s
    print(ans)


resolve()

-    ans = 100**6 +    ans = 10000000 -        tmp = 0 +        s = 0 -            if i == j: -                continue -            tmp += (j - i) ** 2 -        if tmp < ans: -            ans = tmp +            s += (i - j) ** 2 +        if ans > s: +            ans = s