PROGRAM ATCODER
implicit none
integer :: n, i, j
integer, allocatable :: a(:), sum(:)
  
read(*,*) n
allocate(a(n),sum(201))
read(*,*)(a(i), i=1,n)

sum = 0
do i = 101+minval(a), 101+maxval(a)
	do j = 1, n
        sum(i) = sum(i) + ((i-101)-a(j))**2
	end do
end do
	
write(*,'(i0)') minval(sum(101+minval(a):101+maxval(a)))

END PROGRAM ATCODER