N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
k = 10**6

for i in range(a[0],a[-1]+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total)
print(k)   N = int(input()) N int(input()) int input() input a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a = sorted(a) a sorted(a) sorted a k = 10**6 k 10**6 10 6 for i in range(a[0],a[-1]+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total) i range(a[0],a[-1]+1) range a[0] a 0 a[-1]+1 a[-1] a -1 1 total = 0 total 0 for s in a:
    total +=(i-s)**2
  #print(total)
   s a total +=(i-s)**2 total (i-s)**2 i-s i s 2 k = min(k,total) k min(k,total) min k total print(k) print k a = sorted(a) sorted(a) a k = 10**6 10**6 k total = 0 0 total k = min(k,total) min(k,total) k a = list(map(int,input().split())) list(map(int,input().split())) a total +=(i-s)**2 (i-s)**2 total N = int(input()) int(input()) N
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
k = 10**6

for i in range(a[0],a[-1]+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total)
print(k)  