n = int(eval(input()))

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



#print(a)



amin = min(a)

amax = max(a)

min_sum=10**8

for x in range(amin,amax+1):

    sum_for_x = sum([(y-x)**2 for y in a])

    if sum_for_x < min_sum:

        min_sum = sum_for_x



print(min_sum)   
# -*- coding: utf-8 -*-

"""

Created on Sat Aug  4 18:19:03 2018



@author: maezawa

"""



n = int(eval(input()))

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



mean_a = round(sum(a)/n)



ans = 0

for i in a:

    ans += (i-mean_a)**2



print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
# print(a)
amin = min(a)
amax = max(a)
min_sum = 10**8
for x in range(amin, amax + 1):
    sum_for_x = sum([(y - x) ** 2 for y in a])
    if sum_for_x < min_sum:
        min_sum = sum_for_x
print(min_sum)

# -*- coding: utf-8 -*-
"""
Created on Sat Aug  4 18:19:03 2018
@author: maezawa
"""
n = int(eval(input()))
a = list(map(int, input().split()))
mean_a = round(sum(a) / n)
ans = 0
for i in a:
    ans += (i - mean_a) ** 2
print(ans)

+# -*- coding: utf-8 -*- +""" +Created on Sat Aug  4 18:19:03 2018 +@author: maezawa +""" -# print(a) -amin = min(a) -amax = max(a) -min_sum = 10**8 -for x in range(amin, amax + 1): -    sum_for_x = sum([(y - x) ** 2 for y in a]) -    if sum_for_x < min_sum: -        min_sum = sum_for_x -print(min_sum) +mean_a = round(sum(a) / n) +ans = 0 +for i in a: +    ans += (i - mean_a) ** 2 +print(ans)